Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ tdc conversation view <ref> --pinned # only the pinned messages
tdc conversation done <ref> --yes # archive a conversation
tdc conversation undone <ref> --yes # unarchive it
tdc conversation mark-read <ref> # mark a conversation read
tdc conversation mark-unread <ref> # mark its latest message unread again (--from <message-ref> for more)
tdc msg view <ref> # view a conversation message
tdc msg pin <ref> # pin a message for everyone in the chat (unpin to undo)
tdc comment pin <ref> # pin a comment for everyone in the thread (unpin to undo)
Expand Down
16 changes: 16 additions & 0 deletions docs/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,22 @@ Options:
- `--dry-run` - Show what would happen without executing
- `--json` - One `{ id, isRead }` row per conversation

#### `tdc conversation mark-unread [conversation-refs...]`

Mark conversations unread for the current user. By default this marks the latest message unread, as "Mark unread" on a conversation does in the Comms app; `--from` marks unread from an earlier message onward. Conversations already unread from that message or an earlier one are reported and left alone.

Arguments:

- `conversation-refs` - Conversation IDs or Comms URLs

Options:

- `--from <message-ref>` - Mark unread from this message onward (single conversation only)
- `--yes` - Confirm a bulk run (required to execute more than one conversation)
- `--stdin` - Read conversation refs from stdin, one per line (`#` lines are skipped)
- `--dry-run` - Show what would happen without executing
- `--json` - One `{ id, isRead, lastReadObjIndex }` row per conversation, where `lastReadObjIndex` is the last message still read (`-1` when every message is unread)

---

### Conversation Message Commands
Expand Down
6 changes: 4 additions & 2 deletions skills/comms-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ tdc conversation reply <ref> "content" --file ./a.png # Attach a file (repeatab
tdc conversation reply <ref> "content" --no-mark-read # Reply but leave the conversation unread (a reply marks it read by default)
tdc conversation mark-read <ref> # Mark a conversation read
tdc conversation mark-read <ref> <ref> --yes # Mark multiple conversations read
tdc conversation mark-unread <ref> # Mark a conversation's latest message unread, as the Comms app does
tdc conversation mark-unread <ref> --from <message-ref> # Mark unread from a message onward
tdc conversation done <ref> # Preview conversation archive (requires --yes to execute)
tdc conversation done <ref> --yes # Archive conversation
tdc conversation done <ref> --yes --json # Archive and return status as JSON
Expand Down Expand Up @@ -478,7 +480,7 @@ Mutating commands accept `--dry-run` to preview the operation without making the
Run without --dry-run to execute.
```

Destructive commands (`channel delete`, `comment delete`, `msg delete`, `groups delete`, `thread delete`, `thread done`/`undone`, `conversation done`/`undone`, bulk `thread mark-read`/`mark-unread` and bulk `conversation mark-read`) only preview without `--yes`: they print `Would …` and `Use --yes to confirm.` and change nothing. Under `--json`, a missing `--yes` (without `--dry-run`) fails with `CONFIRMATION_REQUIRED` ("Pass --yes to execute <command>, or --dry-run to preview it.") before any API call, so a script never reads a preview as the result. `--dry-run --json` prints one `{ "status": "preview", "command", "messages" }` object instead of the text preview; bulk `mark-read`/`mark-unread` keep their per-thread or per-conversation rows with `dryRun: true`.
Destructive commands (`channel delete`, `comment delete`, `msg delete`, `groups delete`, `thread delete`, `thread done`/`undone`, `conversation done`/`undone`, and bulk `mark-read`/`mark-unread` on threads and conversations) only preview without `--yes`: they print `Would …` and `Use --yes to confirm.` and change nothing. Under `--json`, a missing `--yes` (without `--dry-run`) fails with `CONFIRMATION_REQUIRED` ("Pass --yes to execute <command>, or --dry-run to preview it.") before any API call, so a script never reads a preview as the result. `--dry-run --json` prints one `{ "status": "preview", "command", "messages" }` object instead of the text preview; bulk `mark-read`/`mark-unread` keep their per-thread or per-conversation rows with `dryRun: true`.

## Reference System

Expand All @@ -499,7 +501,7 @@ echo "Quick reply" | tdc conversation reply <ref> --stdin

If neither a content argument nor `--stdin` is given, the CLI opens `$EDITOR` for interactive input. In non-TTY environments (e.g. when called by an agent or in a pipeline), the editor is automatically skipped and the command fails fast with an actionable error message. Use `--non-interactive` to force this behavior even in a TTY, or `--interactive` to override auto-detection.

`tdc thread mark-read`, `tdc thread mark-unread` and `tdc conversation mark-read` read their refs from stdin with `--stdin`, one per line (`#` lines are skipped), added to any refs passed as arguments:
`tdc thread mark-read`, `tdc thread mark-unread`, `tdc conversation mark-read` and `tdc conversation mark-unread` read their refs from stdin with `--stdin`, one per line (`#` lines are skipped), added to any refs passed as arguments:

```bash
printf "id:CbT8n2Kp4Qx6Rz9Lm3Va\nid:CbT9m4Qr7Vz2Nx8Lp5Sa\n" | tdc thread mark-read --stdin --yes
Expand Down
238 changes: 238 additions & 0 deletions src/commands/conversation/conversation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const apiMocks = vi.hoisted(() => ({

const refsMocks = vi.hoisted(() => ({
resolveConversationId: vi.fn((ref: string) => ref),
resolveMessageId: vi.fn((ref: string) => ref),
resolveWorkspaceRef: vi.fn(),
resolveUserRefs: vi.fn(),
}))
Expand Down Expand Up @@ -92,12 +93,14 @@ function createClient({
messagesByConversation = {},
pinnedByConversation = {},
users = {},
messagesById = {},
}: {
activeConversations?: TestConversation[]
archivedConversations?: TestConversation[]
messagesByConversation?: Record<string, Array<Record<string, unknown>>>
pinnedByConversation?: Record<string, Array<Record<string, unknown>>>
users?: Record<number, { id: number; fullName: string }>
messagesById?: Record<string, { id: string; conversationId: string; objIndex?: number }>
}) {
const conversationsById = new Map(
[...activeConversations, ...archivedConversations].map((conversation) => [
Expand Down Expand Up @@ -130,8 +133,12 @@ function createClient({
markRead: vi.fn(async (_args: { id: string; messageId: string }) => ({
status: 'ok',
})),
markUnread: vi.fn(async (_args: { id: string; objIndex: number }) => ({
status: 'ok',
})),
},
conversationMessages: {
getMessage: vi.fn(async (id: string) => messagesById[id]),
getPinnedMessages: vi.fn(
async (conversationId: string) => pinnedByConversation[conversationId] ?? [],
),
Expand Down Expand Up @@ -2115,3 +2122,234 @@ describe('conversation mark-read', () => {
])
})
})

describe('conversation mark-unread', () => {
beforeEach(() => {
vi.clearAllMocks()
})

// Conversation 42 runs to message index 7; M5 is its message at index 5, M0 one with no
// index, and M9 belongs elsewhere.
function setupMarkUnread(unread: Array<{ conversationId: string; objIndex: number }> = []) {
const client = createClient({
activeConversations: [
{ ...createConversation(42, [1, 2], '2026-03-08T10:00:00.000Z'), lastObjIndex: 7 },
{ ...createConversation(43, [1, 3], '2026-03-08T11:00:00.000Z'), lastObjIndex: 2 },
],
messagesById: {
M5: { id: 'M5', conversationId: '42', objIndex: 5 },
M9: { id: 'M9', conversationId: '99', objIndex: 9 },
M0: { id: 'M0', conversationId: '42' },
},
})
client.conversations.getUnread.mockResolvedValue({
data: unread.map((entry) => ({ ...entry, directMention: false })),
version: 1,
})
apiMocks.getCommsClient.mockResolvedValue(client)
return { client, program: createProgram() }
}

it('marks the latest message unread by default, as the Comms app does', async () => {
const { client, program } = setupMarkUnread()
const logSpy = captureConsole('log')

await program.parseAsync(['node', 'tdc', 'conversation', 'mark-unread', '42'])

expect(client.conversations.markUnread).toHaveBeenCalledWith({ id: '42', objIndex: 7 })
expect(logSpy).toHaveBeenCalledWith(
'Conversation 42 marked unread from its latest message.',
)
})

it('marks unread from the message given with --from', async () => {
const { client, program } = setupMarkUnread()
const logSpy = captureConsole('log')

await program.parseAsync([
'node',
'tdc',
'conversation',
'mark-unread',
'42',
'--from',
'M5',
])

expect(client.conversationMessages.getMessage).toHaveBeenCalledWith('M5')
expect(client.conversations.markUnread).toHaveBeenCalledWith({ id: '42', objIndex: 5 })
expect(logSpy).toHaveBeenCalledWith('Conversation 42 marked unread from message M5.')
})

it('reports the last message still read in --json', async () => {
const { program } = setupMarkUnread()
const logSpy = captureConsole('log')

await program.parseAsync([
'node',
'tdc',
'conversation',
'mark-unread',
'42',
'--from',
'M5',
'--json',
])

expect(JSON.parse(String(logSpy.mock.calls.at(-1)?.[0]))).toEqual([
{ id: '42', isRead: false, lastReadObjIndex: 4 },
])
})

it('leaves a conversation already unread from an earlier message unchanged', async () => {
const { client, program } = setupMarkUnread([{ conversationId: '42', objIndex: 3 }])
const logSpy = captureConsole('log')

await program.parseAsync([
'node',
'tdc',
'conversation',
'mark-unread',
'42',
'--from',
'M5',
'--json',
])

expect(client.conversations.markUnread).not.toHaveBeenCalled()
expect(JSON.parse(String(logSpy.mock.calls.at(-1)?.[0]))).toEqual([
{ id: '42', isRead: false, lastReadObjIndex: 2 },
])
})

it('says so when the latest message is already unread', async () => {
const { client, program } = setupMarkUnread([{ conversationId: '42', objIndex: 7 }])
const logSpy = captureConsole('log')

await program.parseAsync(['node', 'tdc', 'conversation', 'mark-unread', '42'])

expect(client.conversations.markUnread).not.toHaveBeenCalled()
expect(logSpy).toHaveBeenCalledWith(
'Conversation 42 is already unread from its latest message.',
)
})

it('moves the marker back when it sits after the --from message', async () => {
const { client, program } = setupMarkUnread([{ conversationId: '42', objIndex: 6 }])
captureConsole('log')

await program.parseAsync([
'node',
'tdc',
'conversation',
'mark-unread',
'42',
'--from',
'M5',
])

expect(client.conversations.markUnread).toHaveBeenCalledWith({ id: '42', objIndex: 5 })
})

it('shows help instead of reading piped refs when given no refs', async () => {
const { client, program } = setupMarkUnread()
const stdout = captureStream('stdout')
mockStdin('42\n')

await program.parseAsync(['node', 'tdc', 'conversation', 'mark-unread']).catch(() => {})

expect(stdout.mock.calls.map((args) => String(args[0])).join('')).toContain(
'Usage: tdc conversation mark-unread',
)
expect(client.conversations.markUnread).not.toHaveBeenCalled()
})

it('refuses --from with more than one conversation', async () => {
const { client, program } = setupMarkUnread()

await expect(
program.parseAsync([
'node',
'tdc',
'conversation',
'mark-unread',
'42',
'43',
'--from',
'M5',
'--yes',
]),
).rejects.toMatchObject({
code: 'CONFLICTING_OPTIONS',
message:
'--from applies to a single conversation; pass one conversation ref when using it.',
})
expect(client.conversations.markUnread).not.toHaveBeenCalled()
})

it('refuses a --from message from another conversation', async () => {
const { client, program } = setupMarkUnread()

await expect(
program.parseAsync([
'node',
'tdc',
'conversation',
'mark-unread',
'42',
'--from',
'M9',
]),
).rejects.toMatchObject({
code: 'INVALID_REF',
message: 'Message M9 belongs to conversation 99, not 42.',
})
expect(client.conversations.markUnread).not.toHaveBeenCalled()
})

it('refuses a --from message that has no object index', async () => {
const { client, program } = setupMarkUnread()

await expect(
program.parseAsync([
'node',
'tdc',
'conversation',
'mark-unread',
'42',
'--from',
'M0',
]),
).rejects.toMatchObject({
code: 'INVALID_REF',
message: 'Message M0 has no object index; cannot mark unread from it.',
})
expect(client.conversations.markUnread).not.toHaveBeenCalled()
})

it('previews several conversations without --yes and marks them with it', async () => {
const { client, program } = setupMarkUnread()
const logSpy = captureConsole('log')

await program.parseAsync(['node', 'tdc', 'conversation', 'mark-unread', '42', '43'])

expect(client.conversations.markUnread).not.toHaveBeenCalled()
expect(logSpy).toHaveBeenCalledWith(
'Would mark unread conversation 42 from its latest message.',
)
expect(logSpy).toHaveBeenCalledWith('Use --yes to confirm.')

await createProgram().parseAsync([
'node',
'tdc',
'conversation',
'mark-unread',
'42',
'43',
'--yes',
])

expect(client.conversations.markUnread).toHaveBeenCalledWith({ id: '42', objIndex: 7 })
expect(client.conversations.markUnread).toHaveBeenCalledWith({ id: '43', objIndex: 2 })
})
})
29 changes: 29 additions & 0 deletions src/commands/conversation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { collect } from '../../lib/options.js'
import { markConversationDone, markConversationUndone } from './archive.js'
import { listConversations } from './list.js'
import { markConversationRead } from './mark-read.js'
import { markConversationUnread } from './mark-unread.js'
import { muteConversation } from './mute.js'
import { replyToConversation } from './reply.js'
import { unmuteConversation } from './unmute.js'
Expand Down Expand Up @@ -205,6 +206,34 @@ Examples:
return markConversationRead(refs, options)
})

const markUnreadCmd = conversation
.command('mark-unread [conversation-refs...]')
.description('Mark a conversation unread for the current user; inverse of mark-read')
.option(
'--from <message-ref>',
'Mark unread from this message onward (single conversation only; default: its latest message)',
)
.option('--yes', 'Skip confirmation for bulk operations')
.option('--stdin', 'Read conversation refs from stdin, one per line')
.option('--dry-run', 'Show what would happen without executing')
.option('--json', 'Output result as JSON')
.addHelpText(
'after',
`
Examples:
tdc conversation mark-unread id:CbV8n2Kp4Qx6Rz9Lm3Va
tdc conversation mark-unread id:CbV8n2Kp4Qx6Rz9Lm3Va --from id:CbM8n2Kp4Qx6Rz9Lm3Va
tdc conversation mark-unread id:CbV8n2Kp4Qx6Rz9Lm3Va id:CbV9m4Qr7Vz2Nx8Lp5Sa --yes
printf "id:CbV8n2Kp4Qx6Rz9Lm3Va\\nid:CbV9m4Qr7Vz2Nx8Lp5Sa\\n" | tdc conversation mark-unread --stdin --yes`,
)
.action((refs, options) => {
if (refs.length === 0 && !options.stdin) {
markUnreadCmd.help()
return
}
return markConversationUnread(refs, options)
})

conversation
.command('mute <conversation-ref>')
.description('Mute a conversation (stop notifications)')
Expand Down
Loading