From b656e6c05ad71c401886048a24216d762a01df7a Mon Sep 17 00:00:00 2001 From: positonic Date: Mon, 16 Nov 2026 20:25:27 +0100 Subject: [PATCH 1/2] feat(actions): --assignee on create/update, plus --unassign and --clear-assignees (v1.31.0) --assignee takes a user id or email, repeatable or comma-separated. On create the assignees are written with the action. On update it is additive (action.assign); --unassign removes and --clear-assignees removes everyone. Order is clear, then unassign, then assign, so --clear-assignees --assignee x replaces the set with x. An update that only changes assignees skips the field update call. --- README.md | 9 ++++ package.json | 2 +- src/commands/actions.test.ts | 84 ++++++++++++++++++++++++++++++++++++ src/commands/actions.ts | 71 +++++++++++++++++++++++++++--- 4 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 src/commands/actions.test.ts diff --git a/README.md b/README.md index 631ebe5..3488457 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,15 @@ exponential actions update --id -n "New name" --priority "2nd Priori exponential actions update --id --scheduled-start 2026-08-05T09:00 exponential actions update --id --scheduled-start null # clear it +# Assign people (user id or email; repeat the flag or comma-separate). +# On create the assignees land with the action. On update --assignee is additive: +# existing assignees stay. --unassign removes; --clear-assignees removes everyone, +# and runs first, so --clear-assignees --assignee leaves exactly . +exponential actions create -n "Follow up" -p --assignee ada@example.com +exponential actions update --id --assignee --assignee bob@example.com +exponential actions update --id --unassign bob@example.com +exponential actions update --id --clear-assignees + # What's actually on your plate: overdue + today + inbox exponential actions today diff --git a/package.json b/package.json index 84aad40..f84eee3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "exponential-cli", - "version": "1.30.0", + "version": "1.31.0", "description": "CLI to interact with Exponential productivity app - pull actions for LLM consumption", "type": "module", "bin": { diff --git a/src/commands/actions.test.ts b/src/commands/actions.test.ts new file mode 100644 index 0000000..168a79d --- /dev/null +++ b/src/commands/actions.test.ts @@ -0,0 +1,84 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { createActionsCommand } from './actions.js'; +import * as clientModule from '../client/index.js'; + +vi.mock('../client/index.js', () => ({ + getClient: vi.fn(), + isTRPCError: () => false, +})); + +const ACTION = { id: 'a1', name: 'Follow up', status: 'ACTIVE', assignees: [] }; + +function makeClient() { + const actions = { + create: vi.fn().mockResolvedValue(ACTION), + update: vi.fn().mockResolvedValue(ACTION), + assign: vi.fn().mockResolvedValue(ACTION), + unassign: vi.fn().mockResolvedValue(ACTION), + }; + vi.mocked(clientModule.getClient).mockReturnValue( + { actions } as unknown as ReturnType, + ); + return actions; +} + +async function run(args: string[]) { + const cmd = createActionsCommand(); + cmd.exitOverride(); + await cmd.parseAsync(args, { from: 'user' }); +} + +beforeEach(() => { + vi.restoreAllMocks(); + vi.spyOn(console, 'log').mockImplementation(() => undefined); + vi.spyOn(console, 'error').mockImplementation(() => undefined); + Object.defineProperty(process.stdout, 'isTTY', { value: false, configurable: true }); +}); + +describe('actions create --assignee', () => { + it('splits repeated and comma-separated refs into ids and emails', async () => { + const actions = makeClient(); + await run(['create', '-n', 'Follow up', '--assignee', 'u1,ada@example.com', '--assignee', 'u2']); + expect(actions.create).toHaveBeenCalledWith( + expect.objectContaining({ name: 'Follow up', assigneeIds: ['u1', 'u2'], assigneeEmails: ['ada@example.com'] }), + ); + }); + + it('sends no assignee fields without the flag', async () => { + const actions = makeClient(); + await run(['create', '-n', 'Follow up']); + const input = actions.create.mock.calls[0]![0] as Record; + expect(input).not.toHaveProperty('assigneeIds'); + expect(input).not.toHaveProperty('assigneeEmails'); + }); +}); + +describe('actions update assignees', () => { + it('--assignee adds through actions.assign and skips the empty field update', async () => { + const actions = makeClient(); + await run(['update', '--id', 'a1', '--assignee', 'cmdfuz6eu0000a08xmknsk4gc']); + expect(actions.assign).toHaveBeenCalledWith('a1', { userIds: ['cmdfuz6eu0000a08xmknsk4gc'], emails: [] }); + expect(actions.update).not.toHaveBeenCalled(); + }); + + it('--unassign removes by id or email', async () => { + const actions = makeClient(); + await run(['update', '--id', 'a1', '--unassign', 'ada@example.com,u3']); + expect(actions.unassign).toHaveBeenCalledWith('a1', { userIds: ['u3'], emails: ['ada@example.com'] }); + }); + + it('--clear-assignees with --assignee clears first, then adds (replace)', async () => { + const actions = makeClient(); + await run(['update', '--id', 'a1', '--clear-assignees', '--assignee', 'u1']); + expect(actions.unassign).toHaveBeenCalledWith('a1', { all: true }); + expect(actions.assign).toHaveBeenCalledWith('a1', { userIds: ['u1'], emails: [] }); + expect(actions.unassign.mock.invocationCallOrder[0]!).toBeLessThan(actions.assign.mock.invocationCallOrder[0]!); + }); + + it('field changes and assignees together run both', async () => { + const actions = makeClient(); + await run(['update', '--id', 'a1', '--name', 'Renamed', '--assignee', 'u1']); + expect(actions.update).toHaveBeenCalledWith(expect.objectContaining({ id: 'a1', name: 'Renamed' })); + expect(actions.assign).toHaveBeenCalled(); + }); +}); diff --git a/src/commands/actions.ts b/src/commands/actions.ts index 8b21c57..ed2f7e2 100644 --- a/src/commands/actions.ts +++ b/src/commands/actions.ts @@ -18,6 +18,7 @@ import { outputOverdueTriageJson, outputOverdueTriagePretty, } from '../utils/output.js'; +import { splitAssigneeRefs } from 'exponential-sdk'; import type { Action, KanbanStatus, Priority } from 'exponential-sdk'; interface GlobalOptions { @@ -59,6 +60,13 @@ function parseIds(raw: string): string[] { return ids; } +/** Commander collector so `--assignee` can repeat: `--assignee a --assignee b`. */ +function collect(value: string, previous: string[] = []): string[] { + return [...previous, value]; +} + +const ASSIGNEE_REF_HELP = 'user id or email; repeat the flag or comma-separate values'; + export function createActionsCommand(): Command { const actions = new Command('actions') .description('Manage actions/tasks'); @@ -280,6 +288,9 @@ export function createActionsCommand(): Command { .option('--due ', 'Due date (YYYY-MM-DD or "null" to clear)') .option('--scheduled-start ', 'Do-date: when you plan to work on it (YYYY-MM-DD, ISO datetime, or "null" to clear). This is what /today partitions on.') .option('--scheduled-end ', 'End of the time block (YYYY-MM-DD, ISO datetime, or "null" to clear)') + .option('--assignee ', `Add an assignee (${ASSIGNEE_REF_HELP}). Additive: existing assignees stay. Must be assignable in the action's project or workspace`, collect) + .option('--unassign ', `Remove an assignee (${ASSIGNEE_REF_HELP}). Users not assigned are ignored`, collect) + .option('--clear-assignees', 'Remove every assignee (runs before --assignee, so the two together replace the set)') .action(async (options: { id: string; name?: string; @@ -291,6 +302,9 @@ export function createActionsCommand(): Command { due?: string; scheduledStart?: string; scheduledEnd?: string; + assignee?: string[]; + unassign?: string[]; + clearAssignees?: boolean; }, cmd: Command) => { const globalOpts = cmd.optsWithGlobals() as GlobalOptions; const useJson = shouldUseJson(globalOpts.json, globalOpts.pretty); @@ -316,8 +330,7 @@ export function createActionsCommand(): Command { const scheduledEnd = parseNullableDate(options.scheduledEnd, 'scheduled-end'); const client = getClient(); - const action = await client.actions.update({ - id: options.id, + const fieldPatch = { name: options.name, description: options.description, projectId: options.project, @@ -327,13 +340,26 @@ export function createActionsCommand(): Command { dueDate, scheduledStart, scheduledEnd, - }); + }; + const hasFieldChanges = Object.values(fieldPatch).some((v) => v !== undefined); + const hasAssigneeChanges = Boolean(options.clearAssignees || options.unassign?.length || options.assignee?.length); + + let action: Action | undefined; + if (hasFieldChanges || !hasAssigneeChanges) { + action = await client.actions.update({ id: options.id, ...fieldPatch }); + } + + // Assignees go through action.assign / action.unassign: clear first, + // then remove, then add, so `--clear-assignees --assignee x` leaves + // exactly x. + const assigned = await applyAssigneeChanges(client, options.id, options); + const result = (assigned ?? action) as Action; if (useJson) { - outputActionJson(action); + outputActionJson(result); } else { console.log('\nāœ“ Action updated successfully'); - outputActionPretty(action); + outputActionPretty(result); } } catch (error) { handleError(error, useJson); @@ -351,6 +377,7 @@ export function createActionsCommand(): Command { .option('--effort ', 'Effort estimate in minutes', parseInt) .option('--ticket ', 'Link action to a product ticket (CUID) after creation') .option('--epic ', 'Epic CUID to attach the action to') + .option('--assignee ', `Assign the new action (${ASSIGNEE_REF_HELP}). Each must be assignable in the project or workspace, or nothing is created`, collect) .action(async (options: { name: string; description?: string; @@ -360,6 +387,7 @@ export function createActionsCommand(): Command { effort?: number; ticket?: string; epic?: string; + assignee?: string[]; }, cmd: Command) => { const globalOpts = cmd.optsWithGlobals() as GlobalOptions; const useJson = shouldUseJson(globalOpts.json, globalOpts.pretty); @@ -388,6 +416,7 @@ export function createActionsCommand(): Command { dueDate, effortEstimate: options.effort, epicId: options.epic, + ...assigneesForCreate(options.assignee), }); // The server's action.create router doesn't accept ticketId, so when @@ -554,3 +583,35 @@ export function createActionsCommand(): Command { return actions; } + +/** `--assignee` values on create → `assigneeIds` / `assigneeEmails`, omitting empty lists. */ +export function assigneesForCreate(refs: string[] | undefined): { assigneeIds?: string[]; assigneeEmails?: string[] } { + if (!refs?.length) return {}; + const { userIds, emails } = splitAssigneeRefs(refs); + return { + ...(userIds.length ? { assigneeIds: userIds } : {}), + ...(emails.length ? { assigneeEmails: emails } : {}), + }; +} + +/** + * Apply `--clear-assignees`, `--unassign` and `--assignee` in that order. + * Returns the action as the last call left it, or undefined when no flag was given. + */ +export async function applyAssigneeChanges( + client: ReturnType, + actionId: string, + options: { assignee?: string[]; unassign?: string[]; clearAssignees?: boolean }, +): Promise { + let result: Action | undefined; + if (options.clearAssignees) { + result = await client.actions.unassign(actionId, { all: true }); + } + if (options.unassign?.length) { + result = await client.actions.unassign(actionId, splitAssigneeRefs(options.unassign)); + } + if (options.assignee?.length) { + result = await client.actions.assign(actionId, splitAssigneeRefs(options.assignee)); + } + return result; +} From 39656fafb00cd6ca367295c54f214daaca6eb1c0 Mon Sep 17 00:00:00 2001 From: positonic Date: Wed, 18 Nov 2026 18:55:14 +0100 Subject: [PATCH 2/2] chore: depend on exponential-sdk ^1.34.0 (actions.assign/unassign) --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 198e9df..857ddad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,17 @@ { "name": "exponential-cli", - "version": "1.29.0", + "version": "1.31.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "exponential-cli", - "version": "1.29.0", + "version": "1.31.0", "license": "AGPL-3.0-or-later", "dependencies": { "chalk": "^5.3.0", "commander": "^12.1.0", - "exponential-sdk": "^1.30.0" + "exponential-sdk": "^1.34.0" }, "bin": { "exponential": "bin/exponential.js" @@ -1408,10 +1408,10 @@ } }, "node_modules/exponential-sdk": { - "version": "1.31.0", - "resolved": "https://registry.npmjs.org/exponential-sdk/-/exponential-sdk-1.31.0.tgz", - "integrity": "sha512-ZwrxC4CC+DsPxi2rRcA597s4Hbh/QBfCibkCpyQ3XwHGbepcc/oWKLH9Y6ISIHE/aAYXWO2I0p2fioOksHkKeQ==", - "license": "MIT", + "version": "1.34.0", + "resolved": "https://registry.npmjs.org/exponential-sdk/-/exponential-sdk-1.34.0.tgz", + "integrity": "sha512-W80PlJFLSx+WruyqZWuzz7G/3dW9weONw3hX14RL1xIZVjGzdv9PVWykjszRUZjpI1CxAe1sz5nSfmUklofRhA==", + "license": "AGPL-3.0-or-later", "dependencies": { "@trpc/client": "^11.0.0-rc.446", "conf": "^13.0.1", diff --git a/package.json b/package.json index f84eee3..02dcc46 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "dependencies": { "chalk": "^5.3.0", "commander": "^12.1.0", - "exponential-sdk": "^1.32.0" + "exponential-sdk": "^1.34.0" }, "devDependencies": { "@types/node": "^20.14.10",