# agently-cli

Agent-first mail CLI for Agently.

## Install

```bash
npm install -g @tencent-qqmail/agently-cli
```

## Authenticate

Log in with OAuth:

```bash
agently-cli auth login
agently-cli auth status
```

## Workspaces

Workspace isolation is enabled by default. When the CLI detects an AI agent,
that agent can use its own mailbox identity and credentials under
`~/.agently-cli/agents/<agent>/`. Existing credentials in the shared `default`
workspace remain usable: read commands fall back to `default` until the detected
agent runs `agently-cli auth login`, which creates its dedicated workspace.

Use `AGENTLY_WORKSPACE=<name>` to pin a command to a specific workspace. A name
that does not exist stays pinned and is treated as not logged in; `auth login`
creates it. `AGENTLY_WORKSPACE=default` explicitly selects the shared identity.

`AGENTLY_CLI_CONFIG_DIR` has higher priority and always uses the unpartitioned
`default` layout. `AGENTLY_ACCESS_TOKEN` is workspace-independent and has the
highest authentication priority.

## Commands

```bash
# Current user
agently-cli +me

# List messages
agently-cli message +list --limit 10

# Read a message
agently-cli message +read --id msg_xxx

# Search messages
agently-cli message +search --q "report"

# Send a message
agently-cli message +send --to bob@example.com --to alice@example.com --subject "Hi" --body "Hello"
# Send a complex HTML body from a UTF-8 file under the current directory
agently-cli message +send --to bob@example.com --subject "Hi" --body-file ./body.html

# Reply to a message
agently-cli message +reply --id msg_xxx --cc carol@example.com --cc dan@example.com --body "Thanks"

# Forward a message
agently-cli message +forward --id msg_xxx --to bob@example.com --to alice@example.com --body "FYI"

# Move a message to trash (soft delete; storage is still used)
agently-cli message +trash --id msg_xxx

# Permanently delete from trash and release mailbox storage (irreversible)
agently-cli message +delete --id msg_xxx
# Explicitly empty trash
agently-cli message +delete --all

# Upload an attachment
agently-cli attachment +upload --file ./report.pdf

# Download an attachment
agently-cli attachment +download --msg msg_xxx --att att_xxx --output ./downloads
```

Send, reply, forward, and trash use two-step confirmation. First run returns
`data.confirmation_token`; rerun the same command with
`--confirmation-token <token>` to complete the operation.

Recipient flags are repeatable: use `--to` multiple times for multiple
recipients, and use repeated `--cc` / `--bcc` for copy and blind-copy recipients.
