From 6f93fefc8030890bb435c71553cbd5a2ba701364 Mon Sep 17 00:00:00 2001 From: Scott Lovegrove Date: Tue, 17 Nov 2026 11:21:12 +0000 Subject: [PATCH] feat(status): set a status with only an emoji The API now accepts a status with an emoji and no message, so the message argument to `tdc status set` becomes optional. Leaving it out sends `message: null`, matching how `set` already clears an omitted emoji, expiry or pause flag. A status still needs a message, an emoji or both: with neither, the command fails with MISSING_CONTENT before calling the API. An explicit empty message is still rejected, now with a hint to leave it out. --- skills/comms-cli/SKILL.md | 3 +- src/commands/status/index.ts | 10 +++--- src/commands/status/set.ts | 23 +++++++++++--- src/commands/status/status.test.ts | 50 ++++++++++++++++++++++++++++++ src/lib/skills/content.ts | 3 +- 5 files changed, 79 insertions(+), 10 deletions(-) diff --git a/skills/comms-cli/SKILL.md b/skills/comms-cli/SKILL.md index 456913f..50e4ba3 100644 --- a/skills/comms-cli/SKILL.md +++ b/skills/comms-cli/SKILL.md @@ -263,6 +263,7 @@ tdc users --ids-only # Output only user IDs tdc status # Show your status (default login is enough) tdc status --json # Show it as { status } JSON (null when unset; --full for the whole user) tdc status set "Deep work" --emoji 🎯 --for 2h --pause-notifications # Set supported fields (needs --full-access) +tdc status set --emoji 🤒 --for 1d # Emoji-only status: leave the message out (a status needs a message, an emoji or both) tdc status set "On holiday" --pause-activity # Pause Todoist Karma and streaks while it is active (independent of --pause-notifications) tdc status set "On holiday" --until 2026-10-20T09:00 # End at a date (YYYY-MM-DD, YYYY-MM-DDTHH:MM or a full ISO 8601 timestamp; local time unless it has Z or an offset) tdc status set "Away" --dry-run # Preview without setting @@ -328,7 +329,7 @@ All group *writes* (`groups create`, `rename`, `delete`, `add-user`, `remove-use `tdc status set` and `tdc status clear` need the `user:write` scope, which only `tdc auth login --full-access` grants. `tdc status` (show) works on a default login. -`tdc status set` replaces the fields this CLI supports: omitted emoji, expiration and pause flags clear those values, while other fields and effects are preserved. +`tdc status set` replaces the fields this CLI supports: an omitted message, emoji, expiration or pause flag clears that value, while other fields and effects are preserved. Give a message, an `--emoji` or both; with neither it fails with `MISSING_CONTENT`. Only pass `--pause-notifications` when the user asks for it. It holds back Comms notifications only for now: each app has to read the status and hold its own notifications back, and Todoist does not yet. Held notifications are not sent later. diff --git a/src/commands/status/index.ts b/src/commands/status/index.ts index 0d37fae..c5a4ac4 100644 --- a/src/commands/status/index.ts +++ b/src/commands/status/index.ts @@ -21,9 +21,9 @@ Examples: .action(showStatus) status - .command('set ') + .command('set [message]') .description('Set your status, replacing its message, emoji, expiration, and pause effects') - .option('--emoji ', 'Emoji to show next to the message') + .option('--emoji ', 'Emoji to show next to the message, or on its own without one') .option( '--until ', 'When the status ends: YYYY-MM-DD, YYYY-MM-DDTHH:MM or a full ISO 8601 timestamp. Local time unless it has Z or an offset', @@ -43,17 +43,19 @@ Examples: .addHelpText( 'after', ` -The message is 1 to 80 characters. The status is shared with your Todoist account. +A status needs a message, an emoji or both. The message is 1 to 80 characters. +The status is shared with your Todoist account. Setting or clearing it needs the user:write scope, so log in with tdc auth login --full-access. --pause-notifications only affects Comms for now. Each app has to read the status and hold its own notifications back, and Todoist does not yet. Held notifications are not sent later. --pause-activity protects your Todoist Karma and streaks. It does not hold back notifications, and --pause-notifications does not protect Karma, so pass both if you want both. -Omitted emoji, expiration, and pause flags clear those values. Other fields and effects are preserved. +An omitted message, emoji, expiration, or pause flag clears that value. Other fields and effects are preserved. Examples: tdc status set "On holiday" --emoji 🏝️ --until 2026-10-20T09:00 tdc status set "Deep work" --emoji 🎯 --for 2h --pause-notifications + tdc status set --emoji 🤒 --for 1d tdc status set "On holiday" --emoji 🏝️ --until 2026-10-30 --pause-activity`, ) .action(setStatus) diff --git a/src/commands/status/set.ts b/src/commands/status/set.ts index 39b9b8c..b9bc5b0 100644 --- a/src/commands/status/set.ts +++ b/src/commands/status/set.ts @@ -18,13 +18,19 @@ type SetStatusOptions = MutationOptions & { pauseActivity?: boolean } -function resolveMessage(message: string): string { +function resolveMessage(message: string | undefined): string | undefined { + if (message === undefined) { + return undefined + } const trimmed = message.trim() const length = [...trimmed].length if (length < 1 || length > MAX_MESSAGE_LENGTH) { throw new CliError( 'INVALID_VALUE', `The message must be 1 to ${MAX_MESSAGE_LENGTH} characters`, + length < 1 + ? ['To set only an emoji, leave the message out: --emoji '] + : undefined, ) } return trimmed @@ -81,13 +87,22 @@ function resolveExpiry(options: SetStatusOptions): Date | undefined { return expiry } -export async function setStatus(message: string, options: SetStatusOptions): Promise { +export async function setStatus( + message: string | undefined, + options: SetStatusOptions, +): Promise { const text = resolveMessage(message) const emoji = resolveEmoji(options.emoji) + if (text === undefined && emoji === undefined) { + throw new CliError('MISSING_CONTENT', 'A status needs a message, an emoji or both', [ + 'tdc status set "Deep work"', + 'tdc status set --emoji 🎯', + ]) + } const activeUntil = resolveExpiry(options) const args: SetStatusArgs = { - message: text, + message: text ?? null, emoji: emoji ?? null, activeUntil: activeUntil ?? null, effects: { @@ -98,7 +113,7 @@ export async function setStatus(message: string, options: SetStatusOptions): Pro if (options.dryRun) { printDryRun('set status', { - Message: text, + Message: text ?? 'cleared', Emoji: emoji ?? 'cleared', Until: activeUntil ? formatDateTime(activeUntil) : 'cleared', 'Pause notifications': options.pauseNotifications ? 'yes' : 'cleared', diff --git a/src/commands/status/status.test.ts b/src/commands/status/status.test.ts index 550958e..7bfa6f0 100644 --- a/src/commands/status/status.test.ts +++ b/src/commands/status/status.test.ts @@ -321,6 +321,56 @@ describe('tdc status', () => { status: { message: 'Away', emoji: null }, }) }) + + describe('with only an emoji', () => { + it('sends a null message and prints the emoji', async () => { + const spy = captureConsole('log') + await run('set', '--emoji', '🤒', '--for', '1d', '--pause-activity') + expect(users.setStatus).toHaveBeenCalledWith({ + message: null, + emoji: '🤒', + activeUntil: new Date('2026-10-15T12:00:00.000Z'), + effects: { pauseNotifications: null, pauseActivity: {} }, + }) + expect(logged(spy)).toBe('Status set: 🤒') + }) + + it('prints a null message in JSON', async () => { + const spy = captureConsole('log') + await run('set', '--emoji', '🤒', '--json') + expect(JSON.parse(logged(spy))).toEqual({ + status: { message: null, emoji: '🤒' }, + }) + }) + + it('previews the message as cleared on --dry-run', async () => { + const spy = captureConsole('log') + await run('set', '--emoji', '🤒', '--dry-run') + expect(users.setStatus).not.toHaveBeenCalled() + const out = logged(spy) + expect(out).toContain('Message: cleared') + expect(out).toContain('Emoji: 🤒') + }) + + it.each([[[]], [['--for', '2h', '--pause-notifications']]])( + 'fails with MISSING_CONTENT before calling the API when %j gives neither a message nor an emoji', + async (flags) => { + const error = await run('set', ...flags).catch((e) => e) + expect(error).toMatchObject({ + code: 'MISSING_CONTENT', + message: expect.stringContaining('message, an emoji or both'), + }) + expect(users.setStatus).not.toHaveBeenCalled() + }, + ) + + it('rejects an explicitly empty message, pointing at leaving it out', async () => { + const error = await run('set', '', '--emoji', '🤒').catch((e) => e) + expect(error.code).toBe('INVALID_VALUE') + expect(error.hints.join(' ')).toContain('leave the message out') + expect(users.setStatus).not.toHaveBeenCalled() + }) + }) }) describe('clear', () => { diff --git a/src/lib/skills/content.ts b/src/lib/skills/content.ts index 606227f..c87b7c4 100644 --- a/src/lib/skills/content.ts +++ b/src/lib/skills/content.ts @@ -267,6 +267,7 @@ tdc users --ids-only # Output only user IDs tdc status # Show your status (default login is enough) tdc status --json # Show it as { status } JSON (null when unset; --full for the whole user) tdc status set "Deep work" --emoji 🎯 --for 2h --pause-notifications # Set supported fields (needs --full-access) +tdc status set --emoji 🤒 --for 1d # Emoji-only status: leave the message out (a status needs a message, an emoji or both) tdc status set "On holiday" --pause-activity # Pause Todoist Karma and streaks while it is active (independent of --pause-notifications) tdc status set "On holiday" --until 2026-10-20T09:00 # End at a date (YYYY-MM-DD, YYYY-MM-DDTHH:MM or a full ISO 8601 timestamp; local time unless it has Z or an offset) tdc status set "Away" --dry-run # Preview without setting @@ -332,7 +333,7 @@ All group *writes* (\`groups create\`, \`rename\`, \`delete\`, \`add-user\`, \`r \`tdc status set\` and \`tdc status clear\` need the \`user:write\` scope, which only \`tdc auth login --full-access\` grants. \`tdc status\` (show) works on a default login. -\`tdc status set\` replaces the fields this CLI supports: omitted emoji, expiration and pause flags clear those values, while other fields and effects are preserved. +\`tdc status set\` replaces the fields this CLI supports: an omitted message, emoji, expiration or pause flag clears that value, while other fields and effects are preserved. Give a message, an \`--emoji\` or both; with neither it fails with \`MISSING_CONTENT\`. Only pass \`--pause-notifications\` when the user asks for it. It holds back Comms notifications only for now: each app has to read the status and hold its own notifications back, and Todoist does not yet. Held notifications are not sent later.