Skip to content

refactor: share the mark-read loop across entities - #145

Merged
scottlovegrove merged 3 commits into
scottl/reply-mark-readfrom
scottl/read-state-runner
Dec 4, 2026
Merged

scottlovegrove merged 3 commits into
scottl/reply-mark-readfrom
scottl/read-state-runner

Conversation

@scottlovegrove

@scottlovegrove scottlovegrove commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

tdc thread mark-read and tdc thread mark-unread ran on a loop in src/commands/thread/helpers.ts that only knew about threads: the bulk refs, --stdin, the --yes guard for bulk runs, --dry-run, the per-workspace unread lookup, the per-item messages, --json rows and the summary. The PRs above this one add tdc conversation mark-read and mark-unread, which need the same loop.

It now lives in src/lib/read-state.ts as runReadStateMutation. An entity plugs in through ReadStateEntity: how to resolve a ref, load the item (threads still check the channel is public), fetch its workspace's unread list, and label it. THREAD_READ_STATE in thread/helpers.ts is the thread one, and the messages take the entity's noun, so the thread output is word for word what it was.

No behaviour change: the thread mark-read and mark-unread tests pass untouched. CODEBASE.md lists the new helper in its src/lib/ catalogue.

@scottlovegrove
scottlovegrove added this pull request to stack #146 December 4, 2026 14:34
@scottlovegrove scottlovegrove self-assigned this Dec 4, 2026

@doistbot doistbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR extracts the shared mark-read/mark-unread loop from src/commands/thread/helpers.ts into a reusable runReadStateMutation in src/lib/read-state.ts, with threads plugging in via THREAD_READ_STATE — a clean, behavior-preserving refactor that sets up the upcoming conversation mark-read/mark-unread commands. No inline issues were flagged. The review confirmed the thread output, confirmation guards, dry-run handling, JSON rows, and error paths are unchanged, the existing thread tests continue to pin the behavior, the private-channel check still runs during entity load before any mutation, and the new helper is catalogued in CODEBASE.md. One note: static inspection confirmed the structure, but tests and npm run verify weren't run during review, so worth a final green check before merge.

I also left one optional follow-up note in the details below.

Optional follow-up note (1)
  • P3 src/commands/thread/helpers.ts:101: This re-implements fetchUnreadThreads from src/lib/threads.ts, which already calls client.threads.getUnread(workspaceId) and normalizes the SDK's { data, version } response into a Map. Building the id → objIndex map on top of it keeps the normalization in one place: loadUnread: async (client, workspaceId) => new Map([...await fetchUnreadThreads(client, workspaceId)].map(([id, u]) => [id, u.objIndex])).

Share Feedback • Review Logs • Trace

`tdc thread mark-read` and `mark-unread` ran on a loop in
thread/helpers.ts that only knew threads. It now lives in
src/lib/read-state.ts as runReadStateMutation, with each entity
plugging in how to resolve a ref, load the item and its workspace's
unread list, and label it (THREAD_READ_STATE for threads). Conversations
can then get the same commands without a second copy of the loop.

The thread commands' output, JSON rows and errors are unchanged; their
tests pass as they were.
ReadState.lastReadObjIndex held the item's raw entry from the workspace's
unread list. For threads the CLI reads that as the last comment read,
but a conversation's entry is its first unread message, so the name
would mislead there. It is now unreadObjIndex, and each entity's
commands say what the index means. No behaviour change.
@scottlovegrove
scottlovegrove force-pushed the scottl/read-state-runner branch from 0a2953b to ab4623b Compare December 4, 2026 14:49
@scottlovegrove scottlovegrove added the 🚢 Ship PR requires passing checks before merge, but no independent human review. label Dec 4, 2026
@scottlovegrove
scottlovegrove merged commit a1b49c1 into main Dec 4, 2026
9 checks passed
@scottlovegrove
scottlovegrove deleted the scottl/read-state-runner branch December 4, 2026 15:04
@doist-release-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 6.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released 🚢 Ship PR requires passing checks before merge, but no independent human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants