Skip to content

feat: expose reader user-state APIs - #1050

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/reader-user-state-api
May 15, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/reader-user-state-api

Conversation

@Sinity

@Sinity Sinity commented May 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Expose the existing durable reader user-state substrate through daemon HTTP APIs for conversation marks, saved views, and recall packs, with deterministic JSON contracts and reader smoke coverage.

Problem

#867 already had partial storage/API substrate for marks, saved views, and recall packs, but the daemon reader surface had no /api/user/* routes for that state. The existing SQLite helpers also opened ordinary request-scoped connections without committing, so mark/view/pack writes were not durable across HTTP requests.

Solution

  • Add /api/user/marks list/create/delete routes for conversation-target marks.
  • Add /api/user/saved-views list/create/get/delete routes.
  • Validate saved-view query params with strict ConversationQuerySpec construction before storing canonical JSON.
  • Add /api/user/recall-packs list/create/get/delete routes for cited conversation bundles.
  • Extract user-state transport helpers into polylogue/daemon/user_state_http.py to keep polylogue/daemon/http.py within file budgets.
  • Commit mark/saved-view/recall writes in the existing SQLite query helpers.
  • Extend reader smoke tests for idempotent mark CRUD, saved-view roundtrip/rejection, and recall-pack payloads.

Remaining #867 scope: annotations, message/range targets, UI controls, CLI parity, and MCP parity remain open.

Ref #867

Verification

  • ruff format --check polylogue/daemon/http.py polylogue/daemon/user_state_http.py polylogue/storage/sqlite/queries/conversations_identity.py tests/unit/daemon/test_web_reader.py -> 4 files already formatted
  • ruff check polylogue/daemon/http.py polylogue/daemon/user_state_http.py polylogue/storage/sqlite/queries/conversations_identity.py tests/unit/daemon/test_web_reader.py -> All checks passed
  • mypy polylogue/daemon/http.py polylogue/daemon/user_state_http.py polylogue/storage/sqlite/queries/conversations_identity.py tests/unit/daemon/test_web_reader.py -> Success
  • pytest -q tests/unit/daemon/test_web_reader.py -k "UserState or marks or saved_views or recall_packs" -> 4 passed
  • pytest -q tests/unit/daemon/test_web_reader.py -> 41 passed
  • pytest -q tests/visual -> 4 passed
  • devtools render-pages -> site built
  • devtools render-all --check -> OK: .cache/site matches sources
  • devtools verify --quick -> all structural gates passed after render-pages refresh
  • devtools verify --affected --skip-slow -> all structural gates passed; pytest affected passed

Problem: #867 had durable mark, saved-view, and recall-pack substrate, but the daemon reader surface still reported annotation/user-state actions as unavailable and exposed no deterministic API for the existing user-state tables. The existing write helpers also did not commit across ordinary request-scoped connections, so read-after-write behavior failed across HTTP requests.\n\nWhat changed: add daemon /api/user routes for conversation marks, saved views, and recall packs; validate saved-view query params with the strict ConversationQuerySpec contract; move the transport helpers into a focused daemon module to keep http.py within file budgets; commit user-state writes in the existing SQLite helpers; and extend reader smoke coverage for idempotent mark CRUD, saved-view roundtrips, invalid query rejection, and recall-pack references.\n\nRemaining #867 scope: annotations, message/range targets, UI controls, CLI parity, and MCP parity remain open.\n\nVerification:\n- ruff format --check polylogue/daemon/http.py polylogue/daemon/user_state_http.py polylogue/storage/sqlite/queries/conversations_identity.py tests/unit/daemon/test_web_reader.py\n- ruff check polylogue/daemon/http.py polylogue/daemon/user_state_http.py polylogue/storage/sqlite/queries/conversations_identity.py tests/unit/daemon/test_web_reader.py\n- mypy polylogue/daemon/http.py polylogue/daemon/user_state_http.py polylogue/storage/sqlite/queries/conversations_identity.py tests/unit/daemon/test_web_reader.py\n- pytest -q tests/unit/daemon/test_web_reader.py -k 'UserState or marks or saved_views or recall_packs'\n- pytest -q tests/unit/daemon/test_web_reader.py\n- pytest -q tests/visual\n- devtools verify --quick\n- devtools verify --affected --skip-slow\n\nRef #867
@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 49 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 26c12b3d-e0e8-4149-9ffe-f24cca245daa

📥 Commits

Reviewing files that changed from the base of the PR and between b7536ae and a91f73f.

📒 Files selected for processing (7)
  • docs/plans/mk3-execution-log.md
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/daemon/http.py
  • polylogue/daemon/user_state_http.py
  • polylogue/storage/sqlite/queries/conversations_identity.py
  • tests/unit/daemon/test_web_reader.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/reader-user-state-api

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 b8c513f into master May 15, 2026
4 checks passed
@Sinity
Sinity deleted the feature/feat/reader-user-state-api branch May 15, 2026 13:58

@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: a91f73fb78

ℹ️ 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/daemon/http.py Resolved
Comment thread polylogue/daemon/user_state_http.py Resolved
Sinity added a commit that referenced this pull request May 15, 2026
## Summary

Wire the MK3 reader shell to the durable user-state APIs added in #1050 so marks and saved views are visible and actionable in the local reader instead of remaining placeholder text.

## Problem

#867 requires durable marks and saved views to be reader product state, not browser-local or hidden API data. After #1050, the daemon exposed `/api/user/*`, but the web reader still did not load marks, display them in the conversation list/header, toggle them, or save/open query-backed views.

## Solution

- Load `/api/user/marks` and `/api/user/saved-views` during reader startup.
- Display star/pin/archive state in the conversation list and detail header.
- Add header and Notes-panel controls that toggle marks through the daemon API.
- Add saved-view controls that save the current query/provider view and reopen saved query JSON.
- Seed visual fixtures with durable marks and a saved view so DOM/API evidence proves archive-backed state wiring.
- Update the MK3 execution log with the active slice, verification lane, and remaining #867 scope.

Remaining #867 scope: annotation storage, message/range targets, CLI parity, and MCP parity.

Ref #867

## Verification

- `ruff format --check polylogue/daemon/web_shell.py tests/visual/conftest.py tests/visual/test_reader_dom_smoke.py` -> 3 files already formatted
- `ruff check polylogue/daemon/web_shell.py tests/visual/conftest.py tests/visual/test_reader_dom_smoke.py` -> All checks passed
- `mypy polylogue/daemon/web_shell.py tests/visual/conftest.py tests/visual/test_reader_dom_smoke.py` -> Success
- `node -e "... new Function(script) ..."` -> script ok
- `pytest -q tests/visual tests/unit/daemon/test_web_reader.py -k "reader or UserState or saved_views or marks"` -> 45 passed
- `devtools verify --quick` -> exit_code 0
- `devtools verify --affected --skip-slow` -> exit_code 0; pytest count 6361
Sinity added a commit that referenced this pull request May 17, 2026
## Summary

Wire the existing `/api/user/saved-views` substrate (shipped via
#1050-#1057 under the #867 user-state umbrella) into the web reader so
an operator can save the current filter chain under a name, recall it,
and delete it without leaving the reader. Adds a toolbar entry-point, a
Delete affordance, a naming-conflict guard, and an actionable empty
state.

## Problem

#1118 calls out the reader UI gap for saved views: the storage table and
the HTTP envelope existed, and the Notes inspector tab could already
save/open a view, but there was no way to delete an existing view from
the UI, no naming-conflict UX (the SQLite `UNIQUE(name)` constraint
would surface as an opaque error), and no toolbar-level entry-point —
saved views were reachable only by opening the Notes inspector tab on a
selected conversation. The acceptance criteria require
list/recall/delete affordances, an empty state distinct from a populated
one, and naming-conflict handling.

## Solution

- `polylogue/daemon/web_shell_workspace.py`: adds a `Saved views`
`<select>` and a `Save view` button to the workspace toolbar (mirroring
the existing `Restore workspace` select pattern). Populates the select
in `renderWorkspaceToolbar` with `state.savedViews`, disables it when
empty, and falls back through `applySavedView` → `loadConversations` +
`loadFacets`. Moves `saveCurrentView` and adds `deleteSavedView` here.
`saveCurrentView` now trims whitespace, rejects empty names, and detects
a naming clash against `state.savedViews` locally — prompting
`window.confirm` to overwrite (DELETE the existing view_id, then POST)
or abort. `deleteSavedView` confirms by name before issuing the DELETE.
- `polylogue/daemon/web_shell.py`: the Notes inspector list now renders
a per-row Delete button next to Open; the empty state is reworded to
name the next action (`Click "Save current view" to name the current
filter chain.`).
- `tests/unit/daemon/test_web_reader.py`: adds `TestReaderSavedViewsUI`
with five tests — toolbar entry-point presence, naming-conflict UX
strings, delete-button wiring, actionable empty-state copy, and an HTTP
roundtrip (save → list → delete) that catches regressions in the new
toolbar surface.

The MCP coverage criterion (#1118 AC: "At least one MCP read tool
exposes saved views by id") was already satisfied by `list_saved_views`
/ `save_saved_view` / `delete_saved_view` in
`polylogue/mcp/server_mutation_tools.py` — no change there.

The naming-conflict handling is client-side rather than at the HTTP
envelope. The shared `user_state_http.py` is owned by another lane per
the dispatch plan and the existing `save_view` SQL is an `INSERT OR
REPLACE BY view_id`; the UNIQUE constraint is on `name`, which means a
different `view_id` for the same name would 500. Detecting the conflict
client-side keeps the UX coherent without changing the contract.

`polylogue/daemon/web_shell.py` net change is −13 LOC (functions moved
into the workspace asset module), keeping the file under the 1100-line
budget enforced by `verify-file-budgets`.

## Verification

```
nix develop -c pytest tests/unit/daemon/test_web_reader.py -q
# 62 passed in 14.74s (5 new under TestReaderSavedViewsUI)

nix develop -c pytest tests/unit/daemon -q
# 389 passed in 13.45s

nix develop -c devtools verify --quick
# exit_code: 0  (format + lint + mypy + render-all + manifest/lifecycle/topology lints)
```

`devtools verify` (full pytest path) requires `devtools verify
--seed-testmon` on this fresh worktree; the affected unit suite was
exercised directly above. `render-pages` was re-emitted to clear a
pre-existing `.cache/site` drift unrelated to this PR.

Closes #1118

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@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.

@Sinity

Sinity commented Oct 1, 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.

  • 63.F072 / P2: fixed-already at the checked revision: _parse_path now unquotes every path segment at polylogue/daemon/http.py:1735 before routing or user-state lookup. A URL segment such as my%20view consequently reaches the handler as the stored identifier 'my view'.

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.

1 participant