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
3 changes: 2 additions & 1 deletion CODEBASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ don't duplicate it here.
`withCaseInsensitiveChoices`, `withUnvalidatedChoices`.
- **`progress.ts`** — `ProgressTracker` JSONL event writer (`--progress-jsonl`).
- **`dates.ts`** — `formatRelativeDate`, `parseDate`; **`input.ts`** —
`readStdin`, `openEditor`; **`validation.ts`** — `validateNonEmptyName`;
`readContent` / `readStdinLines` (explicit `--stdin`, via cli-core's
`readStdin`), `openEditor`; **`validation.ts`** — `validateNonEmptyName`;
**`update.ts`** — `fetchLatestVersion`, `getConfiguredUpdateChannel`;
**`errors.ts`** — `CliError(code, message, hints?)`, `ErrorCode` union,
`isInsufficientScope`.
Expand Down
25 changes: 14 additions & 11 deletions docs/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,17 @@ Post a comment to a thread.
Arguments:

- `thread-ref` - Thread ID or Comms URL
- `content` - Comment content (optional if using stdin or editor)
- `content` - Comment content (optional if using `--stdin` or the editor)

Content input priority:
Content input:

1. Stdin (if piped: `echo "text" | tdc thread reply id:CbT8n2Kp4Qx6Rz9Lm3Va`)
2. Argument (if provided)
3. Opens `$EDITOR` (if neither stdin nor argument)
1. Argument (if provided)
2. Stdin, only with `--stdin` (`echo "text" | tdc thread reply id:CbT8n2Kp4Qx6Rz9Lm3Va --stdin`). Passing both an argument and `--stdin` is an error
3. Opens `$EDITOR` (if neither an argument nor `--stdin`)

Options:

- `--stdin` - Read content from stdin
- `--dry-run` - Show what would be posted without posting

Output:
Expand Down Expand Up @@ -255,12 +256,13 @@ Send a message in a conversation.
Arguments:

- `conversation-ref` - Conversation ID or Comms URL
- `content` - Message content (optional if using stdin or editor)
- `content` - Message content (optional if using `--stdin` or the editor)

Content input: Same as `tdc thread reply` (stdin → arg → $EDITOR)
Content input: Same as `tdc thread reply` (arg or `--stdin`, else $EDITOR)

Options:

- `--stdin` - Read content from stdin
- `--dry-run` - Show what would be sent without sending

Output:
Expand Down Expand Up @@ -306,12 +308,13 @@ Edit a conversation message.
Arguments:

- `message-ref` - Message ID or Comms URL
- `content` - New message content (optional if using stdin or editor)
- `content` - New message content (optional if using `--stdin` or the editor)

Content input: Same as `tdc thread reply` (stdin → arg → $EDITOR)
Content input: Same as `tdc thread reply` (arg or `--stdin`, else $EDITOR)

Options:

- `--stdin` - Read content from stdin
- `--dry-run` - Show what would be updated without updating

#### `tdc msg delete <message-ref>`
Expand Down Expand Up @@ -499,7 +502,7 @@ tdc thread view https://comms.todoist.com/a/12345/ch/CbC8n2Kp4Qx6Rz9Lm3Va/t/CbT8

# Reply to a thread
tdc thread reply id:CbT8n2Kp4Qx6Rz9Lm3Va "Great idea!"
echo "Multiline\nreply" | tdc thread reply id:CbT8n2Kp4Qx6Rz9Lm3Va
echo "Multiline\nreply" | tdc thread reply id:CbT8n2Kp4Qx6Rz9Lm3Va --stdin
tdc thread reply id:CbT8n2Kp4Qx6Rz9Lm3Va # opens $EDITOR

# Mark thread as done
Expand Down Expand Up @@ -557,6 +560,6 @@ tdc search "project" --ndjson

4. **Batch Operations**: Use `client.batch()` for parallel API calls when fetching related data (channels, users for display)

5. **Content Input**: For reply commands, check stdin first, then arg, then spawn $EDITOR
5. **Content Input**: For reply commands, take the arg or, with `--stdin`, piped stdin (never both), else spawn $EDITOR

6. **Markdown Rendering**: Defer library choice. Start with raw markdown, add terminal rendering later based on real usage
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"CHANGELOG.md"
],
"dependencies": {
"@doist/cli-core": "1.7.2",
"@doist/cli-core": "1.8.0",
"@doist/comms-sdk": "3.11.0",
"@pnpm/tabtab": "0.5.4",
"chalk": "5.6.2",
Expand Down
24 changes: 12 additions & 12 deletions skills/comms-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ tdc thread undone <ref> --yes # Unarchive thread (move it back to your i
tdc thread undone <ref> --yes --json # Unarchive and return status as JSON
tdc thread mark-read <ref> # Mark a thread read
tdc thread mark-read <ref> <ref> --yes # Mark multiple threads read
printf "id:CbT8n2Kp4Qx6Rz9Lm3Va\nid:CbT9m4Qr7Vz2Nx8Lp5Sa\n" | tdc thread mark-read --dry-run # Preview bulk mark-read from stdin
printf "id:CbT8n2Kp4Qx6Rz9Lm3Va\nid:CbT9m4Qr7Vz2Nx8Lp5Sa\n" | tdc thread mark-read --stdin --dry-run # Preview bulk mark-read from stdin
tdc thread mark-unread <ref> # Mark a whole thread unread; inverse of mark-read
tdc thread mark-unread <ref> --from <comment-ref> # Mark unread from that comment onward (single thread only)
tdc thread mark-unread <ref> <ref> --yes # Mark multiple threads unread (also accepts refs on stdin)
tdc thread mark-unread <ref> <ref> --yes # Mark multiple threads unread (also accepts refs on stdin with --stdin)
tdc thread mute <ref> # Mute thread for 60 minutes (default)
tdc thread mute <ref> --minutes 480 # Mute for custom duration
tdc thread mute <ref> --json # Mute and return { id, mutedUntil } as JSON
Expand All @@ -140,7 +140,7 @@ tdc thread rename <ref> "New title" # Rename a thread (change its title)
tdc thread rename <ref> "New title" --json # Rename and return { id, title } as JSON
tdc thread rename <ref> "New title" --json --full # Rename and return full thread as JSON
tdc thread update <ref> "New body" # Update a thread's body (the first post)
echo "New body" | tdc thread update <ref> # Update body from stdin
echo "New body" | tdc thread update <ref> --stdin # Update body from stdin
tdc thread update <ref> "New body" --dry-run # Preview without updating
tdc thread update <ref> "New body" --json # Update and return { id, content } as JSON
tdc thread update <ref> "New body" --json --full # Update and return full thread as JSON
Expand Down Expand Up @@ -412,8 +412,8 @@ Translate old `twist.com` URLs to their Comms equivalents (e.g. for rewriting bo
# Comma-separated list as an argument (token from the environment)
TWIST_AUTH_TOKEN="$(tw auth token view)" tdc migrate urls "https://twist.com/a/1/ch/2/t/3,https://twist.com/a/1/ch/2/t/4"

# Or pipe URLs via stdin (comma- or newline-separated)
cat old-urls.txt | TWIST_AUTH_TOKEN="$(tw auth token view)" tdc migrate urls
# Or pipe URLs in with --stdin (comma- or newline-separated)
cat old-urls.txt | TWIST_AUTH_TOKEN="$(tw auth token view)" tdc migrate urls --stdin

# --twist-token overrides the env var (visible in process lists — prefer the env var)
tdc migrate urls "https://twist.com/a/1/ch/2/t/3" --twist-token <token>
Expand Down Expand Up @@ -467,20 +467,20 @@ Commands accept flexible references:

## Piping Input

Commands that accept content (`thread create`, `thread reply`, `comment update`, `conversation reply`, `msg update`) auto-detect piped stdin:
Commands that accept content (`thread create`, `thread reply`, `thread update`, `comment update`, `conversation reply`, `msg update`) read it from stdin only with `--stdin`; without the flag, piped input is ignored. `--stdin` can't be combined with a content argument, and with nothing piped in (stdin is a terminal) it fails with `STDIN_IS_TTY` instead of waiting:

```bash
cat notes.md | tdc thread reply <ref>
tdc thread create <channel-ref> "Title" < body.md
echo "Quick reply" | tdc conversation reply <ref>
cat notes.md | tdc thread reply <ref> --stdin
tdc thread create <channel-ref> "Title" --stdin < body.md
echo "Quick reply" | tdc conversation reply <ref> --stdin
```

If no content argument is provided and no stdin is piped, 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.
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` and `tdc thread mark-unread` also accept thread refs from stdin, one per line:
`tdc thread mark-read` and `tdc thread mark-unread` read thread 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 --yes
printf "id:CbT8n2Kp4Qx6Rz9Lm3Va\nid:CbT9m4Qr7Vz2Nx8Lp5Sa\n" | tdc thread mark-read --stdin --yes
```

## Common Workflows
Expand Down
11 changes: 5 additions & 6 deletions src/commands/comment/comment.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { captureConsole, createTestProgram } from '@doist/cli-core/testing'
import { captureConsole, createTestProgram, mockStdin } from '@doist/cli-core/testing'
import { beforeEach, describe, expect, it, vi } from 'vitest'

const apiMocks = vi.hoisted(() => ({
Expand All @@ -14,8 +14,8 @@ vi.mock('../../lib/api.js', async (importOriginal) => ({
getCommsClient: apiMocks.getCommsClient,
}))

vi.mock('../../lib/input.js', () => ({
readStdin: vi.fn().mockResolvedValue(''),
vi.mock('../../lib/input.js', async (importOriginal) => ({
...(await importOriginal<typeof import('../../lib/input.js')>()),
openEditor: vi.fn().mockResolvedValue(''),
}))

Expand All @@ -25,7 +25,6 @@ vi.mock('../../lib/markdown.js', () => ({

vi.mock('chalk')

import { readStdin } from '../../lib/input.js'
import { registerCommentCommand } from './index.js'

function createCommentFixture(id: string, creator = 1) {
Expand Down Expand Up @@ -191,13 +190,13 @@ describe('comment update', () => {
})

it('reads content from stdin', async () => {
vi.mocked(readStdin).mockResolvedValueOnce('Content from stdin')
mockStdin('Content from stdin')
const client = createClient()
apiMocks.getCommsClient.mockResolvedValue(client)
const program = createProgram()
captureConsole('log')

await program.parseAsync(['node', 'tdc', 'comment', 'update', '300'])
await program.parseAsync(['node', 'tdc', 'comment', 'update', '300', '--stdin'])

expect(client.comments.updateComment).toHaveBeenCalledWith({
id: '300',
Expand Down
3 changes: 2 additions & 1 deletion src/commands/comment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Examples:
comment
.command('update <comment-ref> [content]')
.description('Update a thread comment')
.option('--stdin', 'Read content from stdin')
.option('--dry-run', 'Show what would be updated without updating')
.option('--json', 'Output updated comment as JSON')
.option('--full', 'Include all fields in JSON output')
Expand All @@ -41,7 +42,7 @@ Examples:
`
Examples:
tdc comment update id:CbM8n2Kp4Qx6Rz9Lm3Va "Updated text"
echo "New content" | tdc comment update id:CbM8n2Kp4Qx6Rz9Lm3Va
echo "New content" | tdc comment update id:CbM8n2Kp4Qx6Rz9Lm3Va --stdin
tdc comment update id:CbM8n2Kp4Qx6Rz9Lm3Va "Fixed" --json`,
)
.action(updateComment)
Expand Down
13 changes: 5 additions & 8 deletions src/commands/comment/update.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getCommsClient } from '../../lib/api.js'
import { CliError } from '../../lib/errors.js'
import { openEditor, readStdin } from '../../lib/input.js'
import type { MutationOptions } from '../../lib/options.js'
import { openEditor, readContent } from '../../lib/input.js'
import type { MutationOptions, StdinOptions } from '../../lib/options.js'
import { formatJson, printDryRun } from '../../lib/output.js'
import { resolveCommentId } from '../../lib/refs.js'

type UpdateOptions = MutationOptions
type UpdateOptions = MutationOptions & StdinOptions

export async function updateComment(
ref: string,
Expand All @@ -14,17 +14,14 @@ export async function updateComment(
): Promise<void> {
const commentId = resolveCommentId(ref)

let newContent = await readStdin()
if (!newContent && content) {
newContent = content
}
let newContent = await readContent(content, options)
if (!newContent) {
newContent = await openEditor()
}
if (!newContent || newContent.trim() === '') {
throw new CliError(
'MISSING_CONTENT',
'No content provided. Pass content as an argument or pipe via stdin.',
'No content provided. Pass content as an argument, or pipe it in with --stdin.',
)
}

Expand Down
23 changes: 21 additions & 2 deletions src/commands/conversation/conversation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
captureConsole,
createTestProgram,
describeEmptyMachineOutput,
mockStdin,
} from '@doist/cli-core/testing'
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { clearWorkspaceUserCache } from '../../lib/api.js'
Expand Down Expand Up @@ -35,8 +36,8 @@ vi.mock('../../lib/markdown.js', () => ({

vi.mock('chalk')

vi.mock('../../lib/input.js', () => ({
readStdin: vi.fn().mockResolvedValue(''),
vi.mock('../../lib/input.js', async (importOriginal) => ({
...(await importOriginal<typeof import('../../lib/input.js')>()),
openEditor: vi.fn().mockResolvedValue(''),
}))

Expand Down Expand Up @@ -1369,6 +1370,24 @@ describe('conversation undone', () => {
})
})

describe('conversation reply --stdin', () => {
beforeEach(() => {
vi.clearAllMocks()
})

it('reads the message from stdin with --stdin', async () => {
const { client, program } = setupFileTest()
captureConsole('log')
mockStdin('Piped message\n')

await program.parseAsync(['node', 'tdc', 'conversation', 'reply', '42', '--stdin'])

expect(client.conversationMessages.createMessage).toHaveBeenCalledWith(
expect.objectContaining({ conversationId: '42', content: 'Piped message' }),
)
})
})

describe('conversation reply --file', () => {
const files = useFileFixtures('tdc-convo-reply-', 'photo.png', 'doc.pdf')

Expand Down
9 changes: 7 additions & 2 deletions src/commands/conversation/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { formatRelativeDate } from '../../lib/dates.js'
import { CliError } from '../../lib/errors.js'
import { isAccessible } from '../../lib/global-args.js'
import { renderMarkdown } from '../../lib/markdown.js'
import type { MutationOptions, PaginatedViewOptions, ViewOptions } from '../../lib/options.js'
import type {
MutationOptions,
PaginatedViewOptions,
StdinOptions,
ViewOptions,
} from '../../lib/options.js'
import { colors, formatJson, formatNdjson } from '../../lib/output.js'

export type UnreadOptions = ViewOptions & { workspace?: string }
Expand Down Expand Up @@ -40,7 +45,7 @@ export type ConversationRenderOptions = {

export type ConversationState = 'active' | 'all' | 'archived'

export type ReplyOptions = MutationOptions & { file?: string[] }
export type ReplyOptions = MutationOptions & StdinOptions & { file?: string[] }

export type MuteOptions = MutationOptions & { minutes?: string }

Expand Down
3 changes: 2 additions & 1 deletion src/commands/conversation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Examples:
.command('reply <conversation-ref> [content]')
.description('Send a message in a conversation')
.option('--file <path>', 'Attach a file (repeatable; content optional)', collect, [])
.option('--stdin', 'Read content from stdin')
.option('--dry-run', 'Show what would be sent without sending')
.option('--json', 'Output sent message as JSON')
.option('--full', 'Include all fields in JSON output')
Expand All @@ -139,7 +140,7 @@ Examples:
`
Examples:
tdc conversation reply id:CbV8n2Kp4Qx6Rz9Lm3Va "Hello!"
echo "Message body" | tdc conversation reply id:CbV8n2Kp4Qx6Rz9Lm3Va
echo "Message body" | tdc conversation reply id:CbV8n2Kp4Qx6Rz9Lm3Va --stdin
tdc conversation reply id:CbV8n2Kp4Qx6Rz9Lm3Va "Update" --json
tdc conversation reply id:CbV8n2Kp4Qx6Rz9Lm3Va "See attached" --file ./photo.jpg`,
)
Expand Down
9 changes: 3 additions & 6 deletions src/commands/conversation/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chalk from 'chalk'
import { getCommsClient } from '../../lib/api.js'
import { uploadAttachments, validateAttachmentFiles } from '../../lib/attachments.js'
import { CliError } from '../../lib/errors.js'
import { openEditor, readStdin } from '../../lib/input.js'
import { openEditor, readContent } from '../../lib/input.js'
import { formatJson, printDryRun } from '../../lib/output.js'
import { resolveConversationId } from '../../lib/refs.js'
import type { ReplyOptions } from './helpers.js'
Expand All @@ -17,18 +17,15 @@ export async function replyToConversation(
const files = options.file ?? []
const hasFiles = files.length > 0

let replyContent = await readStdin()
if (!replyContent && content) {
replyContent = content
}
let replyContent = await readContent(content, options)
// A file-only message is allowed: skip the editor prompt and the empty-content guard.
if (!replyContent && !hasFiles) {
replyContent = await openEditor()
}
if ((!replyContent || replyContent.trim() === '') && !hasFiles) {
throw new CliError(
'MISSING_CONTENT',
'No content provided. Pass content as an argument, pipe via stdin, or attach a file.',
'No content provided. Pass content as an argument, pipe it in with --stdin, or attach a file.',
)
}
const messageContent = replyContent ?? ''
Expand Down
3 changes: 2 additions & 1 deletion src/commands/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function registerMigrateCommand(program: Command): void {
.command('urls [urls]')
.description('Translate twist.com URLs to their Comms equivalents')
.option('--twist-token <token>', 'Twist auth token (overrides $TWIST_AUTH_TOKEN)')
.option('--stdin', 'Read URLs from stdin (comma- or newline-separated)')
.option('--json', 'Output as JSON')
.option('--ndjson', 'Output as newline-delimited JSON')
.addHelpText(
Expand All @@ -19,7 +20,7 @@ Twist CLI (tw) is installed, you can populate it inline:

Examples:
TWIST_AUTH_TOKEN="$(tw auth token view)" tdc migrate urls "https://twist.com/a/1/ch/2/t/3,https://twist.com/a/1/ch/2/t/4"
cat old-urls.txt | TWIST_AUTH_TOKEN="$(tw auth token view)" tdc migrate urls
cat old-urls.txt | TWIST_AUTH_TOKEN="$(tw auth token view)" tdc migrate urls --stdin
tdc migrate urls "https://twist.com/a/1/ch/2/t/3" --json # token from $TWIST_AUTH_TOKEN`,
)
.action(migrateUrls)
Expand Down
Loading
Loading