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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ exponential actions update --id <action-id> -n "New name" --priority "2nd Priori
exponential actions update --id <action-id> --scheduled-start 2026-08-05T09:00
exponential actions update --id <action-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 <x> leaves exactly <x>.
exponential actions create -n "Follow up" -p <project-id> --assignee ada@example.com
exponential actions update --id <action-id> --assignee <user-id> --assignee bob@example.com
exponential actions update --id <action-id> --unassign bob@example.com
exponential actions update --id <action-id> --clear-assignees

# What's actually on your plate: overdue + today + inbox
exponential actions today

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
84 changes: 84 additions & 0 deletions src/commands/actions.test.ts
Original file line number Diff line number Diff line change
@@ -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<typeof clientModule.getClient>,
);
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<string, unknown>;
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();
});
});
71 changes: 66 additions & 5 deletions src/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -280,6 +288,9 @@ export function createActionsCommand(): Command {
.option('--due <date>', 'Due date (YYYY-MM-DD or "null" to clear)')
.option('--scheduled-start <datetime>', '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 <datetime>', 'End of the time block (YYYY-MM-DD, ISO datetime, or "null" to clear)')
.option('--assignee <ref>', `Add an assignee (${ASSIGNEE_REF_HELP}). Additive: existing assignees stay. Must be assignable in the action's project or workspace`, collect)
.option('--unassign <ref>', `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;
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -351,6 +377,7 @@ export function createActionsCommand(): Command {
.option('--effort <minutes>', 'Effort estimate in minutes', parseInt)
.option('--ticket <id>', 'Link action to a product ticket (CUID) after creation')
.option('--epic <id>', 'Epic CUID to attach the action to')
.option('--assignee <ref>', `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;
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<typeof getClient>,
actionId: string,
options: { assignee?: string[]; unassign?: string[]; clearAssignees?: boolean },
): Promise<Action | undefined> {
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;
}
Loading