Skip to content
Merged
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI

on:
pull_request:
push:
branches: [main]

# Read-only token; this workflow never sees secrets (pull_request, not
# pull_request_target), so it is safe to run on pull requests from forks.
permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: ['20', '22', '24']
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ matrix.node-version }}
package-manager-cache: false

- name: Install dependencies
run: npm ci --ignore-scripts

- name: Type check
run: npx tsc --noEmit

- name: Run tests
run: npm test

- name: Build
run: npm run build

- name: Audit production dependencies
run: npm audit --omit=dev --audit-level=moderate
54 changes: 46 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,59 @@ on:
release:
types: [published]

permissions:
contents: read
id-token: write
# Nothing at workflow level; the publish job asks only for what it needs.
permissions: {}

jobs:
publish:
runs-on: ubuntu-latest
# NPM_TOKEN is an environment secret of "release", which only v* tags may
# deploy to, and only admins may create tags. A workflow pushed on a
# branch cannot read it. Optionally add required reviewers to the
# environment so a release also needs an explicit approval to publish.
environment: release
permissions:
contents: read
id-token: write # npm trusted publishing (OIDC) and provenance
steps:
# Actions are pinned to full commit SHAs (tags can be moved).
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '20'
# Trusted publishing needs Node >= 22.14 and npm >= 11.5.1
node-version: '24'
registry-url: 'https://registry.npmjs.org'
# No dependency cache in the release job (cache-poisoning risk)
package-manager-cache: false

- name: Check npm version
run: |
node -e '
const [a, b, c] = process.argv[1].split(".").map(Number);
const ok = a > 11 || (a === 11 && (b > 5 || (b === 5 && c >= 1)));
if (!ok) { console.error(`::error::npm ${process.argv[1]} is too old for trusted publishing (need >= 11.5.1)`); process.exit(1); }
console.log(`npm ${process.argv[1]}`);
' "$(npm --version)"

- name: Check release tag matches package.json
env:
TAG: ${{ github.event.release.tag_name }}
run: |
PKG="$(node -p "require('./package.json').version")"
if [ "${TAG#v}" != "$PKG" ]; then
echo "::error::Release tag $TAG does not match package.json version $PKG"
exit 1
fi

- name: Install dependencies
run: npm ci
# No dependency needs install scripts; skipping them blocks a whole
# class of supply-chain attacks during the release build.
run: npm ci --ignore-scripts

- name: Run tests
run: npm test
Expand All @@ -31,6 +65,10 @@ jobs:
run: npm run build

- name: Publish to NPM
run: npm publish
# Uses OIDC trusted publishing once it is configured on npmjs.com
# (Minara-AI / minara-cli / publish.yml / environment release);
# until then npm falls back to NPM_TOKEN. --provenance links the
# published tarball to this workflow run.
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ minara discover trending
| Command | Description |
| ---------------- | ------------------------------------------- |
| `minara login` | Login via device code or email |
| `minara logout` | Logout and clear local credentials |
| `minara logout` | Logout: revoke the session, then clear local credentials (`--local` clears them even if the server is unreachable) |
| `minara account` | View your account info and wallet addresses |

```bash
Expand Down Expand Up @@ -119,6 +119,7 @@ minara swap # Interactive: side → token → amount
minara swap -s buy -t '$BONK' -a 100 # Buy by ticker (chain auto-detected)
minara swap -s sell -t '$NVDAx' -a all # Sell entire balance
minara swap --dry-run # Simulate without executing
minara swap -s buy -t '$BONK' -a 100 --max-slippage 15 # Accept a quote with up to 15% slippage tolerance

# Send tokens
minara send -c solana -t '$SOL' -a 5 --to <address> # Send SOL on Solana
Expand Down Expand Up @@ -164,7 +165,14 @@ minara perps close # Close a position: pick from list → market
minara perps close --all # Close all positions at once
```

> **Market orders:** `perps order -T market`, `perps close` and the `perps ask` quick order are sent as immediate-or-cancel (IOC) limit orders, priced 1% beyond the mark price (or at `--price` if you pass one). They fill immediately or are cancelled. They never sit as a pending trigger. The old `--tpsl` flag is no longer accepted.
> **Market orders:** `perps order -T market`, `perps close` and the `perps ask` quick order are sent as immediate-or-cancel (IOC) limit orders, priced 1% beyond the mark price (or at `--price` if you pass one). They fill immediately or are cancelled. They never sit as a pending trigger. The old `--tpsl` flag is no longer accepted. After submitting, the CLI reads Hyperliquid's per-order result. It shows the filled size and average price, warns about partial fills, and exits with an error if the order was rejected (for example, no liquidity within 1%).

> **Order rules:** prices and sizes follow Hyperliquid's [tick and lot sizes](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/tick-and-lot-size):
> - a price has at most 5 significant figures and at most 6 − szDecimals decimals (whole-number prices are always allowed);
> - a size has at most szDecimals decimals;
> - a new order must be worth at least $10.
>
> Orders that break these rules are refused before anything is sent, and an invalid `--price` gets the nearest valid price as a suggestion.

```bash
minara perps cancel # Cancel an order: pick from open orders list
Expand Down Expand Up @@ -319,7 +327,7 @@ Available settings:

| Setting | Default | Description |
| ------------------------ | ------- | ---------------------------------------------------- |
| Base URL | `https://api.minara.ai` | API endpoint — must be `https://*.minara.ai` (or localhost for development) |
| Base URL | `https://api.minara.ai` | API endpoint — must be `https://*.minara.ai` (localhost only with `MINARA_DEV=1` set, for development) |
| Touch ID | Off | Biometric verification for fund operations (macOS) |
| Transaction Confirmation | **On** | Mandatory second confirmation before fund operations |

Expand Down Expand Up @@ -348,9 +356,9 @@ The **transaction confirmation** shows chain, token, address, side, amount, and
? Are you sure you want to proceed? (y/N)
```

For `swap`, the expected output, fees, slippage and price impact are fetched and shown before this prompt.
For `swap`, the expected output, fees, slippage and price impact are fetched and shown before this prompt, also with `-y`. The swap request cannot carry a minimum output, so the CLI refuses quotes whose slippage tolerance or price impact is above 10% (raise with `--max-slippage` / `--max-price-impact`). With `-y` it also refuses to swap when no quote can be fetched.

**About `-y` / `--yes`:** on `swap`, `transfer`, `withdraw`, `deposit` (Spot → Perps), `limit-order create`, `perps order`, `perps close`, `perps sweep`, `perps transfer` and `perps leverage`, `-y` skips the transaction confirmation for scripting. `perps deposit`, `perps withdraw`, the `perps ask` quick order and autopilot changes always show it. Touch ID, when enabled, is never skipped. If you disable transaction confirmation via `minara config`, every skipped prompt prints a warning.
**About `-y` / `--yes`:** on `swap`, `transfer`, `withdraw`, `deposit` (Spot → Perps), `limit-order create`, `limit-order cancel`, `perps order`, `perps close`, `perps cancel`, `perps sweep`, `perps transfer` and `perps leverage`, `-y` skips the transaction confirmation for scripting. `perps deposit`, `perps withdraw`, the `perps ask` quick order and autopilot changes always show it. Touch ID, when enabled, is never skipped. If you disable transaction confirmation via `minara config`, every skipped prompt prints a warning.

### Touch ID (macOS)

Expand All @@ -360,9 +368,9 @@ Minara CLI supports macOS Touch ID to protect all fund-related operations. When
minara config # Select "Touch ID" to enable / disable
```

**Protected operations:** `withdraw`, `send` / `transfer`, `swap`, `receive` / `deposit` (Spot→Perps transfer), `perps deposit`, `perps withdraw`, `perps order`, `perps close`, `perps sweep`, `perps transfer`, `perps leverage`, `perps autopilot` (enable / update / create), `limit-order create`
**Protected operations:** `withdraw`, `send` / `transfer`, `swap`, `receive` / `deposit` (Spot→Perps transfer), `perps deposit`, `perps withdraw`, `perps order`, `perps close`, `perps cancel`, `perps sweep`, `perps transfer`, `perps leverage`, `perps autopilot` (enable / update / create), `limit-order create`, `limit-order cancel`. Cancelling counts because an order may be the stop-loss or take-profit protecting a position. `perps cancel` warns when it is.

> **Note:** Touch ID requires macOS with Touch ID hardware. The `--yes` flag does **not** bypass Touch ID. If Touch ID is enabled in your config but the current machine cannot use it (e.g. Linux), fund operations are cancelled instead of silently skipping the check. While Touch ID is on, turning off Touch ID or transaction confirmation in `minara config` also requires Touch ID verification.
> **Note:** Touch ID requires macOS with Touch ID hardware. The `--yes` flag does **not** bypass Touch ID. If Touch ID is enabled in your config but the current machine cannot use it (e.g. Linux), fund operations are cancelled instead of silently skipping the check. The same applies when `~/.minara/config.json` is damaged (for example truncated): fund operations are refused until it is fixed or rewritten with `minara config`. Config and credential files are written atomically. While Touch ID is on, turning off Touch ID or transaction confirmation in `minara config` also requires Touch ID verification.

## Supported Chains

Expand Down Expand Up @@ -390,7 +398,7 @@ minara --help

## Testing

Test suite built with [Vitest](https://vitest.dev/) — 362 tests covering unit, API, command integration, and formatter layers.
Test suite built with [Vitest](https://vitest.dev/) — 425 tests covering unit, API, command integration, and formatter layers.

```bash
npm test # Run all tests
Expand All @@ -403,15 +411,19 @@ npm run test:coverage # With v8 coverage report
- **Transaction Confirmation** — Mandatory second confirmation before all fund operations, showing full token details and contract addresses (default: enabled, configurable)
- **Touch ID** — Optional biometric protection for all fund operations (macOS only). A native Swift helper binary is compiled on first use and cached in `~/.minara/`
- **Token Verification** — Token ticker, name, and full contract address are always displayed before any transaction to prevent wrong-token mistakes. `$TICKER` lookups require an exact symbol match. When you have already chosen a chain (or passed `--chain`), only tokens on that chain are offered. If several tokens share a symbol, the picker shows each one's full contract address and market cap, lists the highest market cap first, and warns about same-chain lookalikes. Third-party token names are length-capped and stripped of control characters
- **Trusted API host only** — requests (including the session token and email login codes) are only sent to `https://*.minara.ai` or localhost; any other configured base URL is refused
- **Safe terminal output** — token names / symbols, API messages and chat output are stripped of terminal control sequences before display, so third-party metadata cannot rewrite or spoof confirmation screens
- **Trusted API host only** — requests (including the session token and email login codes) are only sent to `https://*.minara.ai` (localhost only when `MINARA_DEV=1` is set); any other configured base URL is refused
- **Safe terminal output** — every API response (including Hyperliquid market data) is stripped of terminal control sequences, C1 controls, bidi override characters and invisible characters (zero-width, soft hyphen, BOM, Unicode tags…) as it arrives. Chat output is cleaned the same way as it streams. Third-party metadata cannot rewrite or spoof confirmation screens
- **Recipient checks** — withdraw / send addresses are validated for the chain. A Solana address must decode to a 32-byte key, and one that is not a wallet public key (off the ed25519 curve) gets a warning, because Solana addresses have no checksum
- **Re-login safety** — after an expired session, the original request is only retried if you sign back in to the same account
- Credentials are stored in `~/.minara/credentials.json` with `0600` file permissions (re-applied on every write)
- The `~/.minara/` directory is kept at `0700` permissions
- Tokens are never logged or printed to the console
- OAuth login uses a temporary local server that shuts down after the callback
- **Pinned dependencies** — the package ships an `npm-shrinkwrap.json`, so `npm i -g minara` installs exactly the dependency versions that were tested
- **Release provenance** — releases are published from GitHub Actions with npm provenance, so you can check which commit and workflow built a version (`npm audit signatures`)
- Non-TTY environments (CI/pipes) skip interactive prompts and return errors directly

> **Limits of client-side protection:** transaction confirmation and Touch ID run inside the CLI on your machine. A process that already runs as your user (including an AI agent with shell access) can edit `~/.minara/config.json`, replace files in `~/.minara/`, or modify the installed CLI, so treat these checks as protection against mistakes and misleading prompts, not against code that already controls your account on this machine. Only give agents the access they need, and prefer running them in a sandbox.

## License

[MIT](LICENSE)
34 changes: 2 additions & 32 deletions package-lock.json → npm-shrinkwrap.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minara",
"version": "0.5.1",
"version": "0.5.2",
"description": "CLI client for Minara.ai — login, trade, deposit/withdraw, chat and more from your terminal.",
"type": "module",
"main": "dist/index.js",
Expand All @@ -10,7 +10,8 @@
},
"files": [
"dist",
"bin"
"bin",
"npm-shrinkwrap.json"
],
"scripts": {
"build": "tsc",
Expand Down
4 changes: 3 additions & 1 deletion src/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export function getCurrentUser(token: string) {

/** Logout */
export function logout(token: string) {
return post<void>('/auth/logout', { token });
// An expired session must not trigger the "log in again?" flow: that would
// log in and then immediately revoke the new session.
return post<void>('/auth/logout', { token, noReauth: true });
}

/** Get OAuth authorization URL */
Expand Down
Loading