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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ tdc conversation undone <ref> --yes # unarchive it
tdc msg view <ref> # view a conversation message
tdc search "keyword" # search across workspace
tdc search "keyword" --all # fetch all result pages
tdc search "name" --type conversations # find a titled group chat (whole words)
tdc conversation list --name "part" # match part of a title; use --participant for chats without a title
tdc react thread <ref> 👍 # add reaction
tdc status # show your status
tdc status set "Deep work" --emoji 🎯 --for 2h --pause-notifications # set it (--until <iso> for a date)
Expand Down
10 changes: 8 additions & 2 deletions skills/comms-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ tdc mentions # Show content mentioning current user
tdc mentions --since 2026-04-01 --all # Fetch every mention since a date
tdc mentions --type threads --json # Limit mentions to threads
tdc search "query" # Search content
tdc search "query" --type threads # Filter: threads, messages, or all
tdc search "query" --type threads # Filter: threads, messages, conversations, or all
tdc search "name" --type conversations # Find a group chat by title
tdc search "query" --author <ref> # Filter by author
tdc search "query" --to <ref> # Messages sent to user
tdc search "query" --title-only # Search thread titles only
Expand All @@ -245,6 +246,10 @@ tdc search "query" --all # Fetch all result pages

`--since` and `--until` filter by when the matching content was posted, not when a thread was last active, so a thread found by its title (`--title-only`) counts from when it was created.

To find a group chat by name, use `tdc search "name" --type conversations` first. It matches whole words in group chat titles, and skips chats without a title. Use `tdc conversation list --name` for partial words, or `--participant` for chats without a title. Both `--name` and `--participant` can be combined with `--kind` or `--state`.

`--type conversations` can't be combined with `--to`, `--channel`, or `--mention-me`. `--author` and `--since`/`--until` match the chat's creator and creation date.

## Users, Channels & Groups

```bash
Expand Down Expand Up @@ -509,7 +514,8 @@ tdc thread view <thread-id>
**Check DMs:**
```bash
tdc conversation unread --json
tdc conversation list --kind group --json # find a group DM by participants/name
tdc search "Release team" --type conversations --json # find a group chat by name
tdc conversation list --kind group --json # find a group DM by participants
tdc conversation view <conversation-id>
tdc conversation with "Alice Example"
tdc conversation reply <conversation-ref> "Got it, thanks!"
Expand Down
9 changes: 9 additions & 0 deletions src/commands/mentions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ describe('mentions', () => {
)
})

it('rejects the conversations type', async () => {
const program = createProgram()

await expect(
program.parseAsync(['node', 'tdc', 'mentions', '--type', 'conversations']),
).rejects.toThrow('Allowed choices are threads, messages, all')
expect(searchApiMocks.extendedSearch).not.toHaveBeenCalled()
})

it('emits an empty JSON payload when no mentions match', async () => {
const program = createProgram()
const logSpy = captureConsole('log')
Expand Down
206 changes: 206 additions & 0 deletions src/commands/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ vi.mock('../lib/search-api.js', () => searchApiMocks)

vi.mock('chalk')

import { includePrivateChannels } from '../lib/global-args.js'
import { getPublicChannelIds } from '../lib/public-channels.js'
import { registerSearchCommand } from './search.js'

const createProgram = () => createTestProgram(registerSearchCommand)
Expand Down Expand Up @@ -122,3 +124,207 @@ describe('search --workspace conflict', () => {
)
})
})

describe('search result URLs', () => {
const conversationResult = {
id: 'conversation_BY2ETq2pEneE5MxErhvx5',
type: 'conversation',
title: "Jack's Outcasts",
snippet: "Jack's Outcasts",
snippetCreatorId: 23910351,
snippetLastUpdated: new Date('2026-11-04T00:00:00Z'),
conversationId: 'BY2ETq2pEneE5MxErhvx5',
}

async function searchForUrl(result: Record<string, unknown>): Promise<string> {
searchApiMocks.extendedSearch.mockResolvedValue({
items: [result],
hasMore: false,
isPlanRestricted: false,
})
const program = createProgram()
const logSpy = captureConsole('log')

await program.parseAsync(['node', 'tdc', 'search', 'Outcasts', '--json'])

return JSON.parse(logSpy.mock.calls[0][0]).results[0].url
}

beforeEach(() => {
vi.clearAllMocks()
})

it('links a chat with no messageId to the conversation', async () => {
await expect(searchForUrl(conversationResult)).resolves.toMatch(
/\/1\/msg\/BY2ETq2pEneE5MxErhvx5\/$/,
)
})

it('links a message hit to the message in its conversation', async () => {
await expect(
searchForUrl({ ...conversationResult, messageId: 'Cgim4JfqR97yE3PoxUYrj' }),
).resolves.toMatch(/\/1\/msg\/BY2ETq2pEneE5MxErhvx5\/m\/Cgim4JfqR97yE3PoxUYrj\/?$/)
})
})

describe('search result links', () => {
beforeEach(() => {
vi.clearAllMocks()
vi.mocked(includePrivateChannels).mockReturnValue(true)
})

function mockThreadHit(commentId?: string) {
searchApiMocks.extendedSearch.mockResolvedValue({
items: [
{
id: 'thread_thread-1',
type: 'thread',
title: 'Release',
snippet: 'Release',
snippetLastUpdated: new Date('2026-01-01T00:00:00Z'),
threadId: 'thread-1',
channelId: 'channel-1',
commentId,
},
],
hasMore: false,
isPlanRestricted: false,
})
}

it('links a comment hit to the comment', async () => {
mockThreadHit('comment-1')
const program = createProgram()
const log = captureConsole('log')

await program.parseAsync(['node', 'tdc', 'search', 'Release'])

expect(log).toHaveBeenCalledWith(
expect.stringContaining('/ch/channel-1/t/thread-1/c/comment-1'),
)
})

it('links a thread hit to the thread', async () => {
mockThreadHit()
const program = createProgram()
const log = captureConsole('log')

await program.parseAsync(['node', 'tdc', 'search', 'Release'])

expect(log).toHaveBeenCalledWith(expect.stringMatching(/\/ch\/channel-1\/t\/thread-1\/?$/))
})
})

describe('search --type conversations', () => {
beforeEach(() => {
vi.clearAllMocks()
vi.mocked(includePrivateChannels).mockReturnValue(true)
searchApiMocks.extendedSearch.mockResolvedValue({
items: [],
hasMore: false,
isPlanRestricted: false,
})
})

it('requests the conversations type', async () => {
const program = createProgram()
captureConsole('log')

await program.parseAsync(['node', 'tdc', 'search', 'Outcasts', '--type', 'conversations'])

expect(searchApiMocks.extendedSearch).toHaveBeenCalledWith(
expect.objectContaining({ query: 'Outcasts', type: 'conversations' }),
)
})

it.each([
['--to', ['--to', 'id:1']],
['--channel', ['--channel', 'id:1']],
['--mention-me', ['--mention-me']],
])('rejects %s', async (_flag, flagArgs) => {
const program = createProgram()

await expect(
program.parseAsync([
'node',
'tdc',
'search',
'Outcasts',
'--type',
'conversations',
...flagArgs,
]),
).rejects.toThrow(
'--to, --channel and --mention-me cannot be used with --type conversations',
)
expect(searchApiMocks.extendedSearch).not.toHaveBeenCalled()
})

it('ignores case when rejecting a flag', async () => {
const program = createProgram()

await expect(
program.parseAsync([
'node',
'tdc',
'search',
'Outcasts',
'--type',
'CONVERSATIONS',
'--mention-me',
]),
).rejects.toThrow('cannot be used with --type conversations')
})

it('skips the channel lookup when no result has a channel', async () => {
vi.mocked(includePrivateChannels).mockReturnValue(false)
searchApiMocks.extendedSearch.mockResolvedValue({
items: [
{
id: 'conversation_chat-1',
type: 'conversation',
title: 'Outcasts',
snippet: 'Outcasts',
snippetLastUpdated: new Date('2026-01-01T00:00:00Z'),
conversationId: 'chat-1',
},
],
hasMore: false,
isPlanRestricted: false,
})
const program = createProgram()
const log = captureConsole('log')

await program.parseAsync(['node', 'tdc', 'search', 'Outcasts', '--type', 'conversations'])

expect(getPublicChannelIds).not.toHaveBeenCalled()
expect(log).toHaveBeenCalledWith(expect.stringContaining('Outcasts'))
})

it('still filters results that have a channel', async () => {
vi.mocked(includePrivateChannels).mockReturnValue(false)
vi.mocked(getPublicChannelIds).mockResolvedValue(new Set(['public-channel']))
searchApiMocks.extendedSearch.mockResolvedValue({
items: [
{
id: 'thread_private',
type: 'thread',
title: 'Private thread',
snippet: 'Private thread',
snippetLastUpdated: new Date('2026-01-01T00:00:00Z'),
threadId: 'private',
channelId: 'private-channel',
},
],
hasMore: false,
isPlanRestricted: false,
})
const program = createProgram()
const log = captureConsole('log')

await program.parseAsync(['node', 'tdc', 'search', 'thread'])

expect(getPublicChannelIds).toHaveBeenCalledTimes(1)
expect(log).not.toHaveBeenCalledWith(expect.stringContaining('Private thread'))
})
})
22 changes: 21 additions & 1 deletion src/commands/search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command } from 'commander'
import { CliError } from '../lib/errors.js'
import {
addSharedSearchOptions,
printSearchResults,
Expand All @@ -16,6 +17,13 @@ async function search(
workspaceRef: string | undefined,
options: SearchOptions,
): Promise<void> {
if (options.type === 'conversations' && (options.to || options.channel || options.mentionMe)) {
throw new CliError(
'CONFLICTING_OPTIONS',
'--to, --channel and --mention-me cannot be used with --type conversations',
)
}

const { workspaceId, response } = await runSearch(workspaceRef, {
...options,
query: options.titleOnly ? undefined : query,
Expand All @@ -31,6 +39,9 @@ export function registerSearchCommand(program: Command): void {
.command('search <query> [workspace-ref]')
.description('Search content across a workspace'),
{
typeChoices: ['threads', 'messages', 'conversations', 'all'],
Comment thread
frankieyan marked this conversation as resolved.
Resolved
typeDescription:
'Filter: threads, messages, conversations (group chats by title), or all',
addUniqueFilters: (command) => {
command
.option('--title-only', 'Search in thread titles only')
Expand All @@ -47,7 +58,16 @@ Examples:
tdc search "deployment issue"
tdc search "bug report" --type threads --channel id:CbC8n2Kp4Qx6Rz9Lm3Va
tdc search "API" --author id:5678 --since 2025-01-01 --json
tdc search "incident" --all --json`,
tdc search "incident" --all --json
tdc search "Release team" --type conversations --json

To find a group chat by name, use --type conversations first. It matches whole
Comment thread
frankieyan marked this conversation as resolved.
Resolved
words in group chat titles, and skips chats without a title. Use tdc conversation
list --name for partial words, or --participant for chats without a title. Both
--name and --participant can be combined with --kind or --state.

--type conversations can't be combined with --to, --channel, or --mention-me.
--author and --since/--until match the chat's creator and creation date.`,
)
.action(search)
}
7 changes: 7 additions & 0 deletions src/lib/search-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ describe('extendedSearch', () => {
)
})

it('sends the conversations type', async () => {
await extendedSearch({ workspaceId: 69, query: 'Outcasts', type: 'conversations' })

const requestUrl = new URL(fetchMock.mock.calls[0][0])
expect(requestUrl.searchParams.get('type')).toBe('conversations')
})

it('attributes the request to the CLI via Doist-Platform', async () => {
await extendedSearch({ workspaceId: 69, query: 'roadmap' })

Expand Down
2 changes: 1 addition & 1 deletion src/lib/search-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function getBaseUrl(authResource?: string): string {
return `https://api.comms.todoist.com/api/${DEFAULT_API_VERSION}`
}

export type SearchType = 'threads' | 'messages' | 'all'
export type SearchType = 'threads' | 'messages' | 'conversations' | 'all'

export interface ExtendedSearchParams {
workspaceId: number
Expand Down
Loading
Loading