Skip to content

feat(mcp,web): add annotated timeline scenes to render_timelines - #1253

Merged
kyasbal merged 26 commits into
mainfrom
epic/mcp-annotated-timeline
Nov 10, 2026
Merged

kyasbal merged 26 commits into
mainfrom
epic/mcp-annotated-timeline

Conversation

@kyasbal

@kyasbal kyasbal commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Part of #1193
Fixes #1205

Background

render_timelines could only return a plain screenshot of the timeline view. When an AI agent writes an incident report, it needs to point at specific moments, highlight the affected resources, connect cause and effect, and show the matching manifest diffs and log lines next to the timeline. Before this change, agents had to explain all of that in prose, and a reader had to find each item in the KHI UI by hand.

Approach

This merges the epic/mcp-annotated-timeline branch. It adds annotated, stateful timeline scenes to render_timelines.

  • Scene model and resolver (pkg/server/mcp/scene): Agents describe a scene with a shared color palette and annotation layers: markers, spans, row highlights, connectors, callouts, and diff and log excerpt cards. Anchors accept a log ID, a revision index, or a time. The resolver checks every anchor against the inspection and returns clear errors such as INVALID_ANCHOR, ANCHOR_OUT_OF_VIEWPORT, and SLICE_QUERY_NOT_FOUND. Excerpt cards slice unified diffs and structured log bodies with query windows, and items on the same anchor inherit palette colors.
  • Stateful scenes: Every call stores an immutable scene in memory with a TTL and returns its sceneId. A later call can pass parentSceneId to refine filters and annotations, or to branch a variant with clearLayers and removeIds. Scene documents are served at /api/v1/mcp-scenes/:sceneId.
  • Rendering: Screenshots are captured at 2x device scale, and the stage size now fits the content. Headless rendering moved to a dedicated /render/mcp-timeline page backed by McpTimelineRenderSmartComponent. /render/timeline stays as a standalone page that users can open in a browser with query parameters.
  • Web UI: New overlay, evidence deck, and render layout components draw the annotations and the excerpt cards. The interactive URL opens the same scene in the KHI Web UI, with jump links to the full diff and log. Selection and filter state are now kept in the session URL query parameters.
  • Workbench and MCP tools: get_resource_manifest and get_resource_diff omit metadata.managedFields by default. Pass includeManagedFields: true to include it. Log excerpts include the log insertId and timestamp, so readers can find the same entry in Cloud Logging.
  • Tests: Several flaky tests are stabilized. These include headless Chrome startup, async index cleanup, the workbench loading state, and web fetch retry tests that were affected by background requests. Multi-line Go test fixtures now follow the raw string literal rule.

UI / Output Changes

Annotated overview scene (render_timelines, UTC, Retina 2x)

Annotated overview scene

Branched zoom scene (parentSceneId with timezoneShiftHours: 9, clearLayers, and removeIds)

Branched zoom scene

Sample render_timelines Markdown text output
# Rendered timeline view

Rendered 27 of 27 matched timelines (2026-09-14T01:55:00Z to 2026-09-14T02:35:00Z).
Annotations: 4 markers [1, 2, REF, 3], 3 spans, 3 row highlights, 4 deck excerpts [E1, E2, E3, E4], 3 connectors, 3 callouts, unlisted rows dimmed.

- Scene ID: `scn_nx2qvaoi2nxzusjj`
- Image URL: `http://127.0.0.1:8080/api/v1/mcp-assets/JPVQMANS6EBEZHC2X2IJ3QD74L.png`
- Interactive URL: `http://127.0.0.1:8080/render/mcp-timeline?sceneId=scn_nx2qvaoi2nxzusjj`
- Expires at: 2026-11-10T01:29:18Z

Pass `parentSceneId: "scn_nx2qvaoi2nxzusjj"` to `render_timelines` to refine or branch this scene, or open the Interactive URL in a browser to jump directly to pinned diffs and logs in KHI.
Embed the static PNG in Markdown (`![Timeline](http://127.0.0.1:8080/api/v1/mcp-assets/JPVQMANS6EBEZHC2X2IJ3QD74L.png)`) or download it before it expires:

```sh
curl --fail-with-body -o timeline.png 'http://127.0.0.1:8080/api/v1/mcp-assets/JPVQMANS6EBEZHC2X2IJ3QD74L.png'
```

## Applied filter
Enter these values in the KHI Web UI filter to see the same data.

```yaml
timelineQuery: ""
timelineExclusionQuery: ""
logQuery: ""
startTime: 2026-09-14T01:55:00Z
endTime: 2026-09-14T02:35:00Z
excludeTimelinesWithoutLogs: false
```

Behavior Changes

  • render_timelines no longer accepts width. The output PNG is rendered at 2x scale, so it has about 4 times as many pixels as before. It falls back to 1x when a side would exceed 8192 physical pixels.
  • render_timelines accepts annotations and parentSceneId. Its response includes sceneId, an image URL, and an interactive URL.
  • New HTTP endpoints: GET and HEAD /api/v1/mcp-scenes/:sceneId.
  • get_resource_manifest and get_resource_diff omit metadata.managedFields unless includeManagedFields is true.
  • The Web UI writes selection and filter state to the session URL query parameters.
  • The .khi file format is unchanged.

Included PRs

#1227, #1218, #1219, #1244, #1220, #1221, #1222, #1223, #1224, #1231, #1232, #1233, #1234, #1235, #1236, #1237, #1238, #1239, #1240, #1241, #1242, #1247, #1249, #1250, #1251, #1252

Follow-ups

…hout unwrap (#1227)

* feat(khifile): add ResolveStructStringField to read struct fields without unwrap

* perf(khifile): avoid IndexByte scan in matchFieldKeySegments
…metadata (#1218)

* feat(workbench): strip managedFields by default and expose log query metadata

* refactor(workbench): return named structs for revision bounds and log query metadata

* test(workbench): use raw string literals for multiline test fixtures
…d fit stage dimensions to content (#1219)

* feat(mcp): render timeline screenshots at Retina 2x resolution

* fix(mcp,web): remove width input and size timeline renders to fit content

* fix(mcp,web): drop render image metadata and generalize font loading

* refactor(web): rely directly on document.fonts.ready in timeline renderer

* fix(web): wait for document.fonts.ready in CDP bridge functions
…1220)

* feat(mcp): add timeline scene spec types and named palette registry

* perf(mcp): replace JSON round-trip with slice cloning in cloneAnnotations

* refactor(mcp): simplify scene spec types and use integer IDs and enums

* fix(mcp): remove width field from timeline scene spec and document
* feat(mcp): add in-memory timeline scene store and patch merging

* refactor(mcp): adapt scene store to updated scene spec types

* fix(mcp): drop width merging from timeline scene store

* refactor(mcp): remove unnecessary Stored.clone and cloneDocument
…ner (#1222)

* feat(web): add timeline scene overlay schema and session jump URL opener

* refactor(web): document palette color tokens and unify excerpt line kinds

* refactor(web): promote session URL sync to core service and drop redundant checks

* refactor(web): simplify selection query parameter sync
* feat(web): add marker and span scene ViewModel

* fix(web): compute timeline scene stage width from fitted index pane

* refactor(web): split timeline scene ViewModel builders into tested helpers

* refactor(web): split timeline scene types from ViewModel builders and use math-util
…Model (#1224)

* feat(web): add row highlight, connector, callout, and deck scene ViewModel

* test(web): use TimelineExcerptLineKind.CONTEXT in deck scene spec

* feat(web): expand timeline stage width for role badges and evidence deck cards

* refactor(web): extract switch-based connector SVG path builders
…1231)

* feat(mcp): add multi-window search and structured log excerpt slicer

* fix(mcp): guard rune boundary check and ignore YAML comment lines
* feat(mcp): add unified diff excerpt slicer

* fix(mcp): render mixed unchanged and skipped diff hunk gaps

* test(mcp): use raw string literals in slice diff tests
* feat(mcp): add timeline anchor and subtree scope resolution

* fix(mcp): check search index readiness and auto-include scoped subtrees

* fix(mcp): replace anchor field count with direct boolean check

* test(mcp): use whole-struct want in TestResolveAnchor
…solver (#1234)

* feat(mcp): add marker, span, row highlight, connector, and callout resolver

* test(mcp): update resolve error tests for anchor precedence

* test(mcp): use raw string literals in resolver tests
#1235)

* feat(mcp): add excerpt card resolver and co-anchor palette inheritance

* fix(mcp): hoist search index lookup out of log excerpt loop
* feat(web): add timeline scene overlay component

* fix(web): enable hover on non-navigable markers and clean up span borders

* refactor(web): simplify scene overlay class bindings and capture scene with @let
…erlay (#1237)

* test(web): add unit tests and Storybook stories for timeline scene overlay

* refactor(web): import buildTimelineSceneViewModel from scene builder in overlay specs
* feat(web): add timeline evidence deck component

* fix(web): use idiomatic class bindings, direct property access in spec, and update builder imports

* feat(web): add Storybook stories for timeline evidence deck

* refactor(web): capture deck with @let in evidence deck template
…#1239)

* feat(web): add timeline render layout component and Storybook stories

* fix(web): bind stage width directly, guard frame readiness, and update builder imports

* refactor(web): capture scene with @let in render layout template
…eRenderSmartComponent (#1240)

* feat(web): integrate scene overlays and interactive mode into TimelineRenderSmartComponent

* fix(web): extract session ID dynamically, guard destroyed state, and update builder imports
…er_timelines (#1241)

* feat(mcp): wire stateful scenes, annotations, and dual URLs into render_timelines

* fix(mcp): return structured ErrorResult on scene store and template failures

* fix(mcp): update interactive URL to /render/mcp-timeline
…1250)

* fix(web): route multi-row evidence deck tethers behind upper cards

* perf(web): avoid forced layout reads on every render in evidence deck
* test(core): disable Chrome launch in TestDefaultInitializers_Resolution

* test(mcp): scope timeouts per subtest in TestChromeTimelineImageRenderer

* test(api/v1): wait for async indexManager before TempDir cleanup

* test(mcp): ensure deterministic loading state in TestWorkbenchHandler_AcquireWorkbench
@kyasbal
kyasbal requested a review from K53 as a code owner November 10, 2026 03:15
@kyasbal kyasbal added type:feature New feature or request area:backend-core Core backend frameworks, DAG task runner, and server API area:frontend Web frontend application and UI components area:khifile .khi file format, serialization, and schema labels Nov 10, 2026
@kyasbal
kyasbal enabled auto-merge November 10, 2026 03:17

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive scene management system for timeline rendering, enabling scene branching and persistent state via the new scene package. Key changes include updates to the Workbench API to support managed field filtering in diffs, the addition of ResolveStructStringField for efficient data access in InternPool, and significant updates to the frontend to support the new MCP timeline rendering flow, including a new McpTimelineRenderSmartComponent and associated layout components. The review comment regarding high-frequency polling in mcp-timeline-render-smart.component.ts is valid and highlights a potential performance issue that should be addressed by adopting an event-driven approach.

@kyasbal
kyasbal added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 29b7bc1 Nov 10, 2026
21 checks passed
@kyasbal
kyasbal deleted the epic/mcp-annotated-timeline branch November 10, 2026 03:32
@kyasbal kyasbal mentioned this pull request Nov 11, 2026
16 of 23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend-core Core backend frameworks, DAG task runner, and server API area:frontend Web frontend application and UI components area:khifile .khi file format, serialization, and schema type:feature New feature or request

1 participant