Skip to content

feat(trader): add sphere trader command tree (mirrors trader-ctl)#5

Merged
vrogojin merged 1 commit intomainfrom
feat/sphere-trader
Apr 25, 2026
Merged

feat(trader): add sphere trader command tree (mirrors trader-ctl)#5
vrogojin merged 1 commit intomainfrom
feat/sphere-trader

Conversation

@vrogojin
Copy link
Copy Markdown
Contributor

Summary

Mirrors the canonical `trader-ctl` from vrogojin/trader-service as a built-in sphere-cli command tree. Same pattern as `sphere host` (HMCP). Operators using the canonical tool can keep using it; this is convenience parity.

7 subcommands

`create-intent` Submit a trading intent (--direction buy/sell, --base, --quote, --rate-min/max, --volume-min/total, --expiry-ms)
`cancel-intent` Cancel by --intent-id
`list-intents` --state filter + --limit
`list-deals` --state + --limit (wraps LIST_SWAPS)
`portfolio` Asset balances
`status` Uptime + adapter info
`set-strategy` --rate-strategy / --max-concurrent / --trusted-escrows

Shared globals (inherited): `--tenant`, `--json`, `--timeout` (with MIN_TIMEOUT_MS=100 floor).

Files added

  • `src/trader/trader-commands.ts` — createTraderCommand factory
  • `src/trader/acp-protocols.ts` — ACP-0 types + typed payload guards (mirrored from trader-service)
  • `src/trader/acp-envelope.ts` — parseAcpJson + isTimestampFresh + hasDangerousKeys + 64 KiB cap
  • `src/trader/acp-transport.ts` — ACP DM transport (correlates by `command_id` — distinct from HMCP transport that correlates by `in_reply_to`)
  • `src/trader/trader-commands.test.ts` — 18 unit tests
  • `src/shared/timeout-constants.ts` — `MIN_TIMEOUT_MS=100` shared with agentic-hosting tenant dispatcher

Why a separate transport

sphere-cli's existing `dm-transport.ts` is HMCP-shaped. ACP and HMCP envelopes + correlator keys differ enough to warrant separate files. The existing host transport is untouched.

Tests

  • Before: 50 (in main)
  • After: 94 (+44: trader-commands 18 + new protocol/envelope module tests)
  • `npm run lint` clean (warnings only, all pre-existing)
  • `npm run typecheck` clean
  • `npm run build` clean
  • `bin/sphere.mjs trader --help` lists all 7 subcommands

Cross-repo coordination

`trader-service` (vrogojin) owns the canonical command surface. If commands evolve there, this mirror needs an update.

The canonical trader-cli is bin/trader-ctl in vrogojin/trader-service.
sphere-cli ships this as a mirror so operators don't need to install
another tool; canonical trader-ctl users keep using their tool. Same
pattern as sphere host (HMCP).

## What
- src/trader/trader-commands.ts — createTraderCommand() commander tree
  with 7 subcommands: create-intent, cancel-intent, list-intents,
  list-deals, portfolio, set-strategy, status
- src/trader/acp-protocols.ts — ACP-0 types + typed payload guards
  (mirror of trader-service/src/protocols/acp.ts)
- src/trader/acp-envelope.ts — parseAcpJson + isTimestampFresh +
  hasDangerousKeys + 64KiB size cap
- src/trader/acp-transport.ts — ACP DM transport (correlates by
  command_id, distinct from HMCP's in_reply_to-correlated transport)
- src/shared/timeout-constants.ts — MIN_TIMEOUT_MS=100 shared with
  agentic-hosting tenant dispatcher
- src/index.ts — wire createTraderCommand() next to createHostCommand()
- README — add sphere trader to status table + quickstart examples

## Why a separate transport
sphere-cli's existing dm-transport.ts is HMCP-shaped (correlates by
in_reply_to, parses HMCP envelope). The trader uses ACP-0 (correlates
by command_id, parses ACP envelope). The two diverge enough to warrant
distinct files; the existing transport stays untouched.

## Tests
50 → 94 (+44 new across trader-commands + the protocol/envelope module
tests that come with the new files). All lint + typecheck + build clean.
`bin/sphere.mjs trader --help` lists all 7 subcommands.

## Cross-repo coordination
trader-service (vrogojin/trader-service) owns the canonical command
surface; this PR mirrors that surface. If trader-service's commands
evolve, this mirror needs an update; flag in PR description if you
change command shapes there.
@vrogojin vrogojin merged commit fa0e9bc into main Apr 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant