# Design: research annotations and saved views

Status: backend implemented (`cd904ee`): tags, annotations on flows,
targets and findings, saved views, server-side history filters, REST, MCP
and events; reference in `docs/guides/annotations.md`. Interface in progress.
Part of the research object model ([Concepts](../concepts.md#research-objects-and-references)).

## Problem

Researchers need to mark what matters in a large history: star a request,
tag it (`auth`, `idor-candidate`), write a short note, and come back to the
same filtered view later. In Phantom this should be one mechanism that works on every research object, so the same tag
can join a captured request, a target and a finding into one line of
inquiry.

## Objects

### Tag

A vault-scoped label.

| Field | Type | Notes |
|---|---|---|
| `id` | int | |
| `vault_id` | int | Tags never cross vaults. |
| `name` | str ≤ 48 | Unique per vault, case-insensitive. |
| `color` | enum | Small fixed palette, so tags stay legible on the Kuro theme. |
| `created_at` | datetime | |

### Annotation

A link from one research object to the user's knowledge about it.

| Field | Type | Notes |
|---|---|---|
| `id` | int | |
| `vault_id` | int | Must equal the object's vault, enforced in the service. |
| `object_kind` | enum | `flow`, `target`, `finding`, later `asset`, `scan`. |
| `object_id` | int | |
| `bookmarked` | bool | The star. |
| `note` | text ≤ 4000 | Markdown, optional. |
| `tag_ids` | many-to-many | Through `annotation_tags`. |
| `actor` | enum | `user` or `agent`, for provenance. |
| `updated_at` | datetime | |

There is one annotation per object (unique `(object_kind, object_id)`).
Polymorphic references are validated in the service layer, because SQL
cannot enforce a foreign key across several tables. Deleting an object
deletes its annotation, in the same transaction as the object delete.

### Saved view

A named, reusable filter for one module.

| Field | Type | Notes |
|---|---|---|
| `id` | int | |
| `vault_id` | int | |
| `module` | enum | `history` first; later `findings`, `targets`. |
| `name` | str ≤ 64 | Unique per vault and module. |
| `query` | JSON | Versioned (`{"v": 1, ...}`). For history: methods, status classes, hosts, in-scope, search text, tag ids, bookmarked-only. |
| `columns` | JSON? | Optional table layout to restore. |
| `pinned` | bool | Shown in the sidebar. |

## API (REST and MCP, same services)

- `GET/POST/PATCH/DELETE /vaults/{id}/tags`
- `GET /vaults/{id}/annotations?kind=&ids=` (batch, for table rows)
- `PUT /vaults/{id}/annotations/{kind}/{object_id}`: upsert bookmark, note
  and tags; an empty annotation is deleted.
- `GET/POST/PATCH/DELETE /vaults/{id}/views?module=history`
- History filtering gains `tag`, `bookmarked`, and server-side evaluation
  of a saved view (`view_id`), which closes the "filters run on loaded rows
  only" limitation.
- Events: `annotation.updated`, `tag.updated`, `view.updated`.
- MCP tools: `tag_*`, `annotation_get/set`, `view_*`, and `flow_list` takes
  `tag` / `bookmarked` / `view_id`. Agent-written annotations are recorded
  with `actor = agent`.

## Interface

- **History:** a star column, tag chips in a column, `B` to bookmark, `T`
  to tag, and "Bookmark", "Add tag…" and "Note…" in the context menu.
  Multi-select allows batch tagging.
- **Request panel:** a note field and tags under the summary.
- **Sidebar:** pinned saved views under Traffic, and Bookmarked as a
  built-in view. Saving the current filters creates a view.
- **Target and finding pages:** the same tag chips and note. Clicking a tag
  shows every object with it, across modules.

## Out of scope for the first cut

Tag hierarchies, shared or team tags, annotation history (versions), and
notes as full documents (that is the Notes module, M5).
