Metadata-Version: 2.5
Name: hookstride-cli
Version: 0.3.2
Summary: Manage Hookstride projects and destinations, inspect webhook activity and billing.
License: Proprietary
Requires-Python: >=3.11
Requires-Dist: click<9,>=8.1
Requires-Dist: httpx<1,>=0.28
Requires-Dist: prompt-toolkit<4,>=3.0.52
Requires-Dist: rich<15,>=14
Requires-Dist: typer<1,>=0.20
Description-Content-Type: text/markdown

# Hookstride CLI

Hookstride CLI lets you manage projects and webhook destinations, inspect delivery activity, and view billing records. It includes an interactive console with the same selected-project commands.

Version 0.3.2 adds queue metrics, redacted JSON exports and explicitly confirmed actions, and fixes missing-argument console exits. It also supports signed test-event sending, optional delivery-status polling, and project/destination management. Upgrade an older installation to use the new commands with a compatible backend. Billing and credential management remain outside the confirmed-action interface. Check [PyPI](https://pypi.org/project/hookstride-cli/) for package availability.

## Installation


Requires Python 3.11 or later.

```bash
uv tool install hookstride-cli
```

Alternatively, use `pipx install hookstride-cli`.

```bash
hookstride --version
hookstride status
hookstride console
```

Upgrade an existing installation with `uv tool upgrade hookstride-cli`.

## Authentication

Authenticated commands require a **Control API token** (`whrctl_`), available from your Hookstride dashboard. Project delivery API keys (`whrk_`) do not grant CLI access.

In an interactive console, run `auth login` and enter the token at the hidden prompt:

```bash
hookstride console
```

For one-off commands, set `HOOKSTRIDE_CONTROL_TOKEN` in your shell without entering it on the command line:

```bash
read -rs "HOOKSTRIDE_CONTROL_TOKEN?Control token: "
echo
export HOOKSTRIDE_CONTROL_TOKEN
hookstride auth status
```

The `read` example above works in **zsh**. In Bash, use `read -rs -p "Control token: " HOOKSTRIDE_CONTROL_TOKEN` followed by `echo` and `export HOOKSTRIDE_CONTROL_TOKEN`.

Tokens entered through `auth login` are retained only for the interactive console session. The CLI does not write tokens to its settings file.

## Commands

```bash
hookstride status
hookstride auth status
hookstride projects list
hookstride projects use PROJECT_UUID
hookstride projects create --account ACCOUNT_UUID --name "Staging" --slug staging
hookstride projects update PROJECT_UUID --name "Production EU"

hookstride destinations list
hookstride destinations create --name "Webhook receiver" --url "https://app.example.com/webhooks/hookstride"
hookstride destinations update DESTINATION_UUID --url "https://api.example.com/webhooks/hookstride"
hookstride destinations update DESTINATION_UUID --pause
hookstride destinations update DESTINATION_UUID --resume
hookstride keys list
hookstride events list --status failed
hookstride events show EVENT_UUID
hookstride events send DESTINATION_UUID --type webhook.test --wait
hookstride stats

hookstride incoming sources
hookstride incoming routes
hookstride incoming bindings
hookstride incoming registration-keys

hookstride billing status
hookstride billing history
hookstride config show
```

Replace the example UUIDs with identifiers from your account. Find your workspace's `account_id` with `hookstride --json projects list`; that ID is required for project creation. Project creation and renaming require an admin/owner role. Destination changes require developer access or higher.

Commands that operate on a project use the selected project. You can override the selection for an individual command:

```bash
hookstride --project PROJECT_UUID events list
```

### Interactive console

```bash
hookstride console
```

Use `help` to view commands, Tab for completion, and `exit` or Ctrl+D to leave. The console also supports `show projects`, `show events`, `show destinations`, `use PROJECT_UUID`, `back`, and `set env dev|production`. The same `projects create/update`, `destinations create/update`, and `events send` commands work inside the console. Commands with customer-provided names and URLs are not saved to console history.

### JSON output

Use `--json` before a command to retrieve structured data for scripts:

```bash
hookstride --json projects list
hookstride --project PROJECT_UUID --json events list --status failed
hookstride --env production --json billing history
```

Errors go to standard error; unsuccessful requests return a nonzero exit code. When creating a destination, the server returns a signing secret **once**. Save it securely immediately. Both terminal output and `--json` deliberately include that one-time secret, so avoid piping creation output into logs or public CI artifacts.

### Send a test event

Use an existing active destination from `hookstride destinations list`.
The command securely prompts for a project delivery API key (`whrk_`). It cannot use a
Control API token (`whrctl_`); these credentials have different permissions.

```bash
hookstride --env production projects use PROJECT_UUID
hookstride --env production events send DESTINATION_UUID --wait
hookstride --env production events show EVENT_UUID
```

The event type defaults to `webhook.test`, with a harmless JSON payload:
`{"message":"Hookstride CLI delivery test","source":"cli"}`.
To send a different JSON object without placing its contents in shell history:

```bash
hookstride --env production events send DESTINATION_UUID --type demo.delivery --payload-file ./demo-payload.json --wait
```

To avoid the hidden prompt, set `HOOKSTRIDE_PRODUCTION_API_KEY` or
`HOOKSTRIDE_DEV_API_KEY` for the matching environment only.
Never add keys to CLI arguments, commit them to Git, or paste them into a public CI log.
The CLI does not save delivery keys or their prompts in its configuration or history.
The `--wait` flag polls for a terminal status and exits nonzero if delivery fails.
A non-delivered event can be examined using `events show` with the usual Control token.

## Environments and local settings

The CLI connects to the production API by default: `https://api.hookstride.com`.
A new release must be published to PyPI before existing installations receive this change.

To inspect the development API explicitly, select it:

```bash
hookstride --env dev console
```

Development requests use `https://api-dev.hookstride.com`. Use a Control API token issued for the selected environment. A custom HTTPS API origin can be supplied with `--api-url`.

Project selections are stored separately by environment in `~/.config/hookstride/settings.json`. This file contains project identifiers, **not authentication tokens**. Console tokens and command history remain in memory and are discarded at exit.

## Documentation

Documentation: https://hookstride.com

## Capability boundaries

The CLI supports project/destination creation and updates, event submission and
inspection, incoming configuration inspection, billing history and statistics.
Version 0.3.2 adds JSON exports and confirmed configuration, replay, team and
alert actions. Use the dashboard for CSV exports, purchasing, credential
management, MFA/ownership controls and Support tickets. Billing output
preserves the actual recorded currency; it does not
convert historical payments into display estimates. `status` checks API and
dependency readiness. Version 0.3.2 adds `status --pipeline` for the
worker-readiness check. Neither mode proves signed delivery or historical uptime.

### Delivery metrics — version 0.3.2

Inspect the dashboard's queue-health measurements:

```bash
hookstride --project PROJECT_UUID metrics --days 1
hookstride --project PROJECT_UUID --json metrics --days 7
```

Windows are 1, 7 or 30 rolling UTC days. Completed delivery success excludes
waiting events; the current queue includes all accepted dates. `stats` retains
its existing lifetime response and labels its denominator as delivered/all,
including pending events. Neither command measures service uptime or quota usage.
The interactive console supports `metrics --days 7` and `show metrics` too.
This command needs version 0.3.2 or later and a backend with the delivery-metrics
endpoint. Select `--env dev` when using a separate development project/token.

### JSON event export — version 0.3.2

```bash
hookstride --project PROJECT_UUID --json events export --status failed > ./failed-events.json
```

This uses the dashboard's tenant-scoped redaction and export rules, including
recorded attempts. JSON is limited to 200 matching events; the response retains
`truncated` and `limit`, and the CLI reports truncation on stderr. Narrow status,
`--origin` or `--type` filters when needed. CSV remains available in the dashboard.

## Confirmed actions — version 0.3.2

The CLI exposes the same role-scoped, reviewed actions as Support,
without making AI calls. Inspect what this backend permits:

```bash
hookstride --project PROJECT_UUID actions list
hookstride actions workspaces
```

`actions context` shows authorized resource IDs, current settings, remaining
allowance and masked metadata for preparing inputs. It never retrieves raw
API keys or stored signing credentials. The response is scoped to your project
and role; payment history and team details keep their existing permissions.

| Action | Payload fields |
| --- | --- |
| `project.create` | `account_id`, `name`, optional `slug` (no project selection needed) |
| `project.configure` | `name` and/or `slug`, `expected_name`, `expected_slug` |
| `event.test` | `destination_id` |
| `event.replay` | `event_id` (delivered or failed) |
| `binding.create` | `source`, `endpoint`, `reference` |
| `destination.delivery` | `destination_id`, `payload_format`, `field_map`, `expected_payload_format`, `expected_field_map` |
| `team.invite` | `email`, `role` |
| `team.member` | `member_id`, `action` (`role` or `remove`), `expected_role`; `role` for role changes |
| `team.resend` / `team.revoke` | `invite_id`, `expected_email`, `expected_role` |
| `alerts.update` | `enabled`, `expected_enabled` (booleans) |
| `alerts.test` | Empty object |

Expected values come from the current context. Changes between preview and
confirmation are rechecked. Other existing destination/source/route operations
are also available when advertised by the backend; the dashboard remains the
guided interface for those resource-specific forms.

Write a non-secret JSON object to a private local file. For example, a replay
payload contains `{"event_id":"EVENT_UUID"}`. Then review and explicitly apply:

```bash
hookstride --env dev --project PROJECT_UUID actions preview event.replay --input-file ./replay.json
hookstride --env dev --project PROJECT_UUID actions apply event.replay --input-file ./replay.json
```

Apply obtains a fresh five-minute, single-use approval, displays the effect and
asks for confirmation. Scripts must provide `--confirm`; `--json` execution
requires that explicit flag. Cancellation never confirms or dispatches the
operation. First-project creation uses `project.create` with an `account_id`,
`name` and optional `slug` in the file and does not require a selected project.

Supported actions depend on the current role and backend: project setup,
destinations, incoming sources/routes, reference registration, delivery format,
test events/replay, workspace invitations/member access and failure alerts.
Billing and key-management actions are absent. Normal delivery actions still
consume the applicable event units; replay does not imply free processing.
Existing server validation, MFA, tenant isolation, quotas and email throttles
apply. No command can choose an arbitrary API path. Action payload files and
commands containing them are never retained in console history. Resource
creation can return a one-time signing secret outside chat: save it privately
and do not pipe creation output into logs or public artifacts.

## Server-gated preview: local webhook forwarding

Version 0.3.2 includes the opt-in listener from issue #163. **The server feature
remains disabled by default; inclusion of the command does not enable it in
production.** Use a separately configured development backend for verification.
Older installations must be upgraded to receive the command.

The backend requires the new ingress migration and both
`WEBHOOK_INGRESS_ENABLED=1` and `WEBHOOK_LOCAL_FORWARDING_ENABLED=1`. Local
forwarding is disabled by default. Enable it only after reviewing this change;
do not change production ingress/egress security gates to test it. An operator
must schedule `python manage.py prune_local_sessions` regularly (for example,
every minute); it removes at most 500 expired, revoked or idle sessions per run.
It does not delete incoming events, destinations, or billing records.

From a source checkout, install the CLI's locked development dependencies:

```bash
uv sync --frozen --group dev --project cli
uv run --project cli hookstride --env dev projects list
uv run --project cli hookstride --env dev projects use PROJECT_UUID
uv run --project cli hookstride --env dev incoming sources
```

Use an MFA-verified Control API token where the account role requires MFA, as
explained under Authentication above. Developer access or higher is required.
Select an existing incoming connection in a dedicated development project. Its
provider signing secret must already be configured through the existing source
setup; the CLI never fetches it. A production destination is not needed, and the
listener never adds or edits routing. A subscription to a source is an explicit
opt-in to preview all newly verified events accepted for that project/source,
independently of its production rule/reference destinations. Select a test
source if its payloads must not be copied to a development machine.

Start your local HTTP receiver on **127.0.0.1**, then run:

```bash
hookstride listen 8000 --path /webhooks
```

The project must have been explicitly selected already. An interactive terminal
lists incoming sources and asks for the source UUID; it never auto-selects a
source. For scripts or the interactive console, supply it explicitly:

```bash
hookstride --env dev --project PROJECT_UUID listen 8000 --path /webhooks --source SOURCE_UUID
```

For source-checkout testing, prefix these examples with `uv run --project cli`.
A custom development API may be selected with the existing global `--api-url`;
remote origins require HTTPS. The local receiver URL is always
`http://127.0.0.1:8000/webhooks`. Paths cannot select a different host, include
queries/fragments or contain traversal. Proxy environment variables are ignored
for the receiver, redirects are never followed, receiver requests time out after
five seconds, and receiver response bodies are never read or printed.

The console shows connection/reconnection state, stable event IDs, attempts,
forwarding results and bounded failure messages. It never prints provider
credentials, management tokens, request payloads, or receiver response bodies.
Listener commands/paths are not added to console command history. `--json` is
not supported for a continuous listener.

### Local delivery contract and duplicate handling

A forwarded POST contains a **new JSON envelope**, not the provider's original
signed request:

```json
{
  "id": "STABLE_INCOMING_MESSAGE_UUID",
  "source_id": "SOURCE_UUID",
  "type": "example.created",
  "received_at": "2026-11-09T00:00:00+00:00",
  "data": {"original": "parsed incoming JSON object"}
}
```

`X-Hookstride-Local-Event-Id` is the same stable `id` and
`X-Hookstride-Local-Session-Id` identifies the temporary session. No provider
signature or upstream authorization header is forwarded. Do not attempt provider
raw-body signature verification on this envelope or accept these local-only
headers as production authentication. The trust boundary is the authenticated
CLI and the explicitly selected loopback development receiver; another process
on the same machine can also send localhost requests.

Only newly accepted events that passed the existing provider signature and
project/source checks enter a session queue. History, provider duplicates,
redispatch, and ordinary outbound test events are not added. Each session has
its own queue, so multiple listeners can preview the same new event independently.
Normal ingress quota accounting still occurs once per new incoming event;
preview polling, local HTTP attempts and ACKs create no delivery jobs or charges.

Delivery is **at least once within the session's lifetime and resource limits**.
The CLI acknowledges only after a local HTTP 2xx. A 500, redirect, network error,
or timeout remains unacknowledged and becomes eligible again after a 60-second
lease. A lost ACK response is retried idempotently before another poll. A crash
or a timeout after your receiver has committed can still cause a duplicate:
receivers must atomically deduplicate by envelope `id` before applying side
effects. Do not claim exactly-once behavior.

Poll requests return immediately with up to five events; empty results are
paced client-side every two seconds so synchronous API workers remain free. The
CLI reconnects with capped backoff. A session lasts at most one hour (`--ttl 60` through
`--ttl 3600`), and expires after two idle minutes. The same creating Control token
is checked on every API request, and every poll rechecks token/MFA, membership,
role, project, source, revocation and expiry before returning events. Revocation
cannot recall bytes already returned to a client.

Ctrl+C revokes the session. If the process is killed before it can revoke, its
session expires automatically. You can resume that still-active session with the
same token, project, source and receiver before its two-minute idle timeout:

```bash
hookstride --env dev --project PROJECT_UUID listen 8000 --path /webhooks --source SOURCE_UUID --resume SESSION_UUID
```

The session UUID is shown on connection and is not an authentication credential.
Credentials and payloads are never saved locally. Resume does not extend the
original expiry or recover expired/revoked events, and does not create a
replacement session if the original is unavailable. Starting a fresh session
subscribes only to future events.

### Limits and troubleshooting

- Three active sessions per project, across all sources/users; one active poll
  per session; 120 requests/minute per user across local-session operations.
- 64 KiB maximum serialized envelope, 256 unacknowledged events per session,
  and 20 offers per event. Payload, backlog, or attempt overflow stops the
  session explicitly; it never silently evicts pending events. Normal incoming
  acceptance and production destination delivery continue unchanged.
- On a connection interruption, keep the listener running to reconnect. Long
  outages can exceed idle expiry; start a new session only if you accept that
  events during the gap will not be replayed.
- HTTP 401/403: check the environment's Control token, revocation/expiry, MFA and
  developer membership. Delivery API keys cannot create or read sessions.
- HTTP 404: check project/source selection and the backend's feature flags and
  migration. HTTP 410 means the temporary session stopped or expired.
- Queue full or retry-limit feedback: fix the receiver, then start a new session.
  Unforwarded events from the old session are not moved into a new one.
- Local connection errors: bind the receiver to `127.0.0.1`, confirm the port and
  path, and return a prompt 2xx. Redirects (including to another localhost URL)
  are failures. Check your receiver's own development logs; Hookstride does not
  display its response content.

Production release and remote Coolify staging verification remain separate
release gates. Do not send synthetic provider events to production/customer
sources or destinations to verify this preview.
