@alphafox/cli 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/auth/browser-login.d.ts +30 -0
  2. package/dist/auth/browser-login.js +193 -0
  3. package/dist/auth/loopback-callback.d.ts +32 -0
  4. package/dist/auth/loopback-callback.js +175 -0
  5. package/dist/auth/open-browser.d.ts +15 -0
  6. package/dist/auth/open-browser.js +54 -0
  7. package/dist/auth/refresh.d.ts +27 -2
  8. package/dist/auth/refresh.js +52 -15
  9. package/dist/catalog/allowlist.d.ts +20 -4
  10. package/dist/catalog/allowlist.js +126 -25
  11. package/dist/catalog/command-tree.d.ts +34 -0
  12. package/dist/catalog/command-tree.js +117 -0
  13. package/dist/catalog/compatibility.d.ts +23 -0
  14. package/dist/catalog/compatibility.js +58 -0
  15. package/dist/catalog/generated/registry.json +6137 -0
  16. package/dist/catalog/generated/schemas.json +31036 -0
  17. package/dist/catalog/operations.d.ts +76 -3
  18. package/dist/catalog/operations.js +87 -213
  19. package/dist/commands/run.js +171 -153
  20. package/dist/config/profiles.js +3 -3
  21. package/dist/envelope.d.ts +3 -0
  22. package/dist/envelope.js +43 -3
  23. package/dist/http/client.js +18 -15
  24. package/dist/index.d.ts +12 -5
  25. package/dist/index.js +32 -1
  26. package/dist/keychain/linux-secret-service.d.ts +11 -0
  27. package/dist/keychain/linux-secret-service.js +93 -0
  28. package/dist/keychain/store.d.ts +20 -1
  29. package/dist/keychain/store.js +94 -6
  30. package/dist/keychain/windows-credential.d.ts +13 -0
  31. package/dist/keychain/windows-credential.js +176 -0
  32. package/dist/safety/confirmation.d.ts +10 -3
  33. package/dist/safety/confirmation.js +27 -4
  34. package/dist/version.d.ts +2 -2
  35. package/dist/version.js +3 -2
  36. package/docs/agents/domain.md +51 -0
  37. package/docs/agents/issue-tracker.md +156 -0
  38. package/docs/agents/triage-labels.md +18 -0
  39. package/docs/e2e-staging.md +76 -6
  40. package/docs/release-supply-chain.md +99 -26
  41. package/package.json +4 -2
  42. package/skills/account/SKILL.md +8 -6
  43. package/skills/admin/SKILL.md +9 -4
  44. package/skills/alphafox-shared/SKILL.md +23 -14
  45. package/skills/auth/SKILL.md +21 -6
  46. package/skills/exchange/SKILL.md +10 -3
  47. package/skills/market/SKILL.md +9 -4
  48. package/skills/notification/SKILL.md +8 -3
  49. package/skills/strategy/SKILL.md +15 -9
  50. package/skills/trading/SKILL.md +15 -5
@@ -1,49 +1,122 @@
1
1
  # Release: npm, Skills, supply chain (t101375)
2
2
 
3
+ **Status:** Frozen (G0)
4
+ **Date:** 2026-08-13
5
+ **Canonical package:** `@alphafox/cli` on the public npmjs.org registry.
6
+
7
+ This document freezes distribution policy. It supersedes the earlier draft that
8
+ named `@alphafoxai/cli` (that name was never published; npmjs returns 404).
9
+
3
10
  ## Package
4
11
 
5
- | Field | Value |
6
- |-------|--------|
7
- | Name | `@alphafoxai/cli` |
8
- | Binary | `alphafox` |
9
- | Visibility | public npm (org `@alphafoxai`) |
10
- | Node | LTS 20 |
11
- | OS | macOS, Linux, Windows |
12
+ | Field | Frozen value |
13
+ |-------|----------------|
14
+ | Name | `@alphafox/cli` |
15
+ | Binary | `alphafox` (`bin/alphafox.js`) |
16
+ | Registry | `https://registry.npmjs.org/` |
17
+ | Visibility | **public** (`publishConfig.access=public`) |
18
+ | npm org / owner | `@alphafox` scope; maintainer `alphafox <joe@alphafox.app>` |
19
+ | License | MIT |
20
+ | Node | LTS **≥ 20** (`engines.node`) |
21
+ | OS | macOS, Linux, Windows (npm install; no standalone native binary in v1) |
22
+ | Package contents | `bin/`, `dist/`, `skills/`, `README.md`, `docs/`, `LICENSE` |
23
+
24
+ v1 does **not** ship independent GitHub Release binaries, so there is no extra
25
+ binary signing/checksum channel. Integrity is npm pack integrity plus
26
+ provenance (below).
27
+
28
+ Do **not** republish under `@alphafoxai/cli` without a new ADR. Skills and docs
29
+ that still mention that name are stale and must follow this freeze.
12
30
 
13
- ## Publish rules
31
+ ## Publish rules (normative)
14
32
 
15
- - Publish **only** from CI on protected tags (`v*`)
16
- - Prefer npm **trusted publishing / OIDC provenance** no long-lived npm tokens
17
- - 2FA required for org owners
18
- - Package contents: `dist/`, `skills/`, README, docs — **no** secrets, fixtures, private endpoints, or `.env`
33
+ 1. Publish **only** from CI on a protected git tag matching `v*` (example:
34
+ `v0.2.0`). Humans must not `npm publish` from a laptop for any release
35
+ after this freeze, except an explicit incident rollback documented in the
36
+ change ticket.
37
+ 2. CI MUST use npm **trusted publishing / OIDC provenance**. Long-lived npm
38
+ tokens are forbidden for publish.
39
+ 3. npm org owners MUST have 2FA. Publish permission is CI identity plus owners;
40
+ no shared user tokens in git or chat.
41
+ 4. Package tarball MUST NOT contain secrets, test fixtures with credentials,
42
+ `.env`, private endpoints, or internal-only hostnames.
43
+ 5. `prepublishOnly` builds from the tagged SHA. The published `CLI_VERSION`
44
+ (or equivalent) MUST equal the npm version.
45
+
46
+ ### Grandfathered 0.1.x
47
+
48
+ npmjs currently has `@alphafox/cli@0.1.0`–`0.1.5` (latest `0.1.5`). Those
49
+ tarballs have registry signatures and **no** provenance attestations
50
+ (`dist.attestations` is empty). They were published by the human npm user
51
+ `alphafox`. They remain installable but are **not** the compliance target.
52
+ The next minor/patch that this policy covers MUST be the first
53
+ OIDC-provenance release.
19
54
 
20
55
  ## Skills distribution
21
56
 
22
- - Co-versioned inside the npm package under `skills/`
23
- - Compatibility: Skills major aligns with CLI major; `contractVersion` must match API or CLI fails closed
57
+ - Skills ship **inside** the same npm tarball under `skills/` (co-versioned).
58
+ - Skills major aligns with CLI major. There is no separate Skills registry
59
+ in v1 and no silent download of a different Skills version at runtime.
60
+ - `contractVersion` on the CLI profile MUST match the Public API
61
+ `contractVersion` (or the documented compatible range). Mismatch → fail
62
+ closed; do not download an older contract or degrade quietly.
63
+
64
+ ## Compatibility / channels / deprecation
65
+
66
+ | Channel | npm dist-tag | Meaning |
67
+ |---------|--------------|---------|
68
+ | stable | `latest` | Supported release |
69
+ | prerelease | `next` | Opt-in only |
24
70
 
25
- ## Support matrix
71
+ - Breaking API/contract/minCLI/maxCLI changes: announce ≥ **30 days** before
72
+ `latest` moves; keep the previous compatible CLI installable on npm.
73
+ - Incompatible CLI ↔ API ↔ contract: CLI exits non-zero with a machine-readable
74
+ error. No silent skip, no automatic down-version.
75
+ - Emergency unpublish is a last resort (npm unpublish window). Preferred:
76
+ `npm deprecate @alphafox/cli@<bad> "<reason>; use <good>"` and tell
77
+ operators to install the last good version.
26
78
 
27
- | Platform | Install | Keychain |
28
- |----------|---------|----------|
29
- | macOS | npm global / npx | Keychain Access |
30
- | Linux | npm global / npx | Secret Service or file fallback 0600 |
31
- | Windows | npm global / npx | Credential Manager (file fallback until implemented) |
79
+ ## Support matrix (install / update / uninstall)
32
80
 
33
- ## Channels
81
+ | Platform | Install | Update | Uninstall | Secrets |
82
+ |----------|---------|--------|-----------|---------|
83
+ | macOS | `npm install -g @alphafox/cli` or `npx @alphafox/cli` | `npm update -g @alphafox/cli` or pin `@<version>` | `npm uninstall -g @alphafox/cli` | Keychain Access |
84
+ | Linux | same | same | same | Secret Service, or file fallback mode `0600` |
85
+ | Windows | same | same | same | Credential Manager (`CredWrite`/`CredRead`); file fallback mode `0600` if unavailable |
34
86
 
35
- - `latest` stable
36
- - `next` — prerelease
37
- - Deprecation window: ≥ 30 days for breaking contract changes
87
+ Fresh-machine acceptance (release checklist, not optional):
88
+
89
+ ```bash
90
+ npm install -g @alphafox/cli@<version>
91
+ npm view @alphafox/cli@<version> --json # attestations present after first OIDC release
92
+ alphafox version
93
+ alphafox doctor
94
+ alphafox schema me.whoami
95
+ ```
38
96
 
39
97
  ## Rollback
40
98
 
41
99
  ```bash
42
- npm install -g @alphafoxai/cli@<previous>
100
+ npm install -g @alphafox/cli@<previous-compatible>
43
101
  alphafox version
44
102
  alphafox doctor
45
103
  ```
46
104
 
105
+ Failed install leaves the previous global binary in place (npm does not
106
+ half-replace). If `doctor` fails after a successful install, roll back with
107
+ the command above. Do not point the CLI at a different environment to “make
108
+ it work”.
109
+
47
110
  ## SBOM / audit
48
111
 
49
- CI should generate SBOM (e.g. `cyclonedx` / `npm sbom`) and fail on critical vulns in runtime deps.
112
+ CI MUST emit an SBOM (`npm sbom` or CycloneDX) from the tagged SHA and fail
113
+ the release job on **critical** vulnerabilities in **runtime** dependencies.
114
+ Dev-only advisories do not block publish. SBOM is an artifact of the release
115
+ workflow, not a file committed to `main` by default.
116
+
117
+ ## Out of scope (v1)
118
+
119
+ - Private npm / GitHub Packages as the user install path
120
+ - Homebrew / scoop / standalone signed binaries
121
+ - Separate Skills marketplace
122
+ - Automation-token distribution (ADR 0004)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alphafox/cli",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "Alphafox CLI \u2014 Agent/Human entry for the public Application API.",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -18,8 +18,10 @@
18
18
  ],
19
19
  "scripts": {
20
20
  "build": "tsc -p tsconfig.build.json && node scripts/postbuild.cjs",
21
+ "generate:catalog": "node scripts/generate-catalog.mjs",
22
+ "check:catalog-drift": "node scripts/generate-catalog.mjs --check",
21
23
  "typecheck": "tsc -p tsconfig.json --noEmit",
22
- "test": "npm run build && node scripts/build-mvp-web-bundle.mjs && tsc -p tsconfig.test.json && node --test dist-test/**/*.test.js",
24
+ "test": "npm run check:catalog-drift && npm run build && node scripts/build-mvp-web-bundle.mjs && tsc -p tsconfig.test.json && node --test dist-test/**/*.test.js",
23
25
  "test:mvp": "node scripts/build-mvp-web-bundle.mjs && tsc -p tsconfig.test.json && node --test dist-test/tests/mvp-oauth-web-handlers.test.js",
24
26
  "alphafox": "node dist/cli.js",
25
27
  "prepublishOnly": "npm run build"
@@ -1,21 +1,23 @@
1
1
  ---
2
2
  name: alphafox-account
3
3
  description: Account, wallet, and subscription read paths.
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  ---
6
6
 
7
7
  # Account / wallet
8
8
 
9
+ Always `--format json --no-input`. These paths are read-first. Wallet mutations are write/high-risk — `--dry-run` then `--yes`; never auto-retry.
10
+
9
11
  ```bash
10
- alphafox api GET /api/v1/wallet
11
- alphafox api GET /api/v1/account/exchange-uids
12
- alphafox api GET /api/v1/subscriptions/me
13
- alphafox api GET /api/v1/managed-wallets
12
+ alphafox api GET /api/v1/wallet --format json --no-input
13
+ alphafox api GET /api/v1/account/exchange-uids --format json --no-input
14
+ alphafox api GET /api/v1/subscriptions/me --format json --no-input
15
+ alphafox api GET /api/v1/managed-wallets --format json --no-input
14
16
  ```
15
17
 
16
18
  ## operationIds
17
19
 
18
20
  - `wallet.get`
19
21
  - `account.exchange_uids.list`
20
- - `subscriptions.me.get`
22
+ - `subscriptions.me.get` (facade `GET /api/v1/subscriptions/me`)
21
23
  - `managed_wallets.list`
@@ -1,18 +1,23 @@
1
1
  ---
2
2
  name: alphafox-admin
3
3
  description: Admin-only operations reusing Web role authorization.
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  ---
6
6
 
7
7
  # Admin
8
8
 
9
- Requires admin role on the server. CLI confirmation does not grant privilege.
9
+ Requires admin role on the server. CLI confirmation does not grant privilege. Not available to automation (v1 deferred). Always `--format json --no-input`.
10
10
 
11
11
  ```bash
12
- alphafox api GET /api/v1/admin/users
12
+ alphafox api GET /api/v1/admin/users --format json --no-input
13
13
  ```
14
14
 
15
- High-risk admin writes: `--dry-run` then `--yes`. Not available to automation (v1 deferred).
15
+ High-risk admin writes: `--dry-run` then `--yes`. If the operator is not admin, expect `403` and stop.
16
+
17
+ ## Recovery
18
+
19
+ - `401`: re-auth. `403`: not admin — do not escalate by switching profiles.
20
+ - Uncataloged admin POST/PATCH/DELETE still require `--yes` (unknown risk).
16
21
 
17
22
  ## operationIds
18
23
 
@@ -1,20 +1,22 @@
1
1
  ---
2
2
  name: alphafox-shared
3
3
  description: Shared Alphafox CLI rules for Agents — auth, profiles, envelopes, risk gates, and public operationIds only.
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  ---
6
6
 
7
7
  # Alphafox shared Agent contract
8
8
 
9
+ Co-versioned with `@alphafox/cli`. Query compatibility with `alphafox version --format json` (`version`, `contractVersion`, `catalogVersion`) and `alphafox catalog`.
10
+
9
11
  ## Install / identity
10
12
 
11
13
  ```bash
12
- npx @alphafoxai/cli version
13
- npx @alphafoxai/cli doctor
14
+ npx @alphafox/cli version --format json --no-input
15
+ npx @alphafox/cli doctor --format json --no-input
14
16
  ```
15
17
 
16
18
  - Default profile: `production`. Use `--profile staging|local` explicitly.
17
- - Tokens: OS keychain only. Never pass `--token`. Never read tokens from config JSON.
19
+ - Tokens: OS keychain only (macOS Keychain, Linux Secret Service, Windows Credential Manager). Never pass `--token`. Never read tokens from config JSON.
18
20
  - Automation tokens are **not supported in v1** (interactive Device Flow / PKCE only).
19
21
 
20
22
  ## Output
@@ -25,35 +27,42 @@ Always use:
25
27
  alphafox … --format json --no-input
26
28
  ```
27
29
 
28
- Parse the JSON envelope: `ok === true` for success. Errors land on **stderr** with `ok: false` and may include HTTP `status` + `requestId`.
30
+ Optional: `--jq '<filter>'` requires the `jq` binary; missing jq fails closed (does not print the unfiltered envelope).
31
+
32
+ Parse the JSON envelope: `ok === true` for success. Errors land on **stderr** with `ok: false` and may include HTTP `status` + `requestId`. Stream watch uses JSONL. Do not parse human tables.
29
33
 
30
34
  ## Auth
31
35
 
32
36
  ```bash
33
- alphafox auth login --no-wait
34
- # show verification_uri to the user, then:
35
- alphafox auth login --device-code <device_code>
36
- alphafox auth status --verify
37
- alphafox whoami
37
+ alphafox auth login --no-wait --format json --no-input
38
+ # show verification_uri / user_code to the human, then:
39
+ alphafox auth login --device-code <device_code> --format json --no-input
40
+ alphafox auth status --verify --format json --no-input
41
+ alphafox whoami --format json --no-input
38
42
  ```
39
43
 
44
+ Local browser: `alphafox auth login --browser --format json --no-input` (loopback 127.0.0.1). If the browser cannot open, copy `authorizeUrl` from the error; do not invent a Device Flow retry unless the operator is headless.
45
+
46
+ Wrong environment / missing permission / missing `--yes`: stop. Do not retry with a different profile.
47
+
40
48
  ## Commands
41
49
 
42
50
  1. Prefer typed catalog: `alphafox schema <operationId>` then invoke domain commands.
43
51
  2. Raw escape hatch only for allowlisted facade:
44
52
 
45
53
  ```bash
46
- alphafox api GET /api/v1/me
54
+ alphafox api GET /api/v1/me --format json --no-input
47
55
  ```
48
56
 
49
- Forbidden: `/backend`, `/control-plane`, `/signal-center`, internal secrets, non-`/api/v1` product routes.
57
+ Forbidden: `/backend`, `/control-plane`, `/signal-center`, internal secrets, non-`/api/v1` product routes, `--token`.
50
58
 
51
59
  ## Risk
52
60
 
53
- - `high-risk-write` requires `--yes` (exit code `10` if missing).
61
+ - `high-risk-write` and uncataloged mutations (`unknown`) require `--yes` (exit code `10` if missing).
54
62
  - Prefer `--dry-run` first for trader start/stop, withdrawals, admin writes.
55
63
  - Never auto-retry unknown write outcomes.
64
+ - CLI `--yes` is UX only; the server still enforces role, ownership, and scopes.
56
65
 
57
66
  ## Public operationIds only
58
67
 
59
- Skills must reference registry `operationId`s (see `alphafox schema` / `alphafox catalog`). Do not hardcode internal service URLs.
68
+ Skills must reference registry `operationId`s (see `alphafox schema` / `alphafox catalog`). Shortcuts may only compose those operationIds. Do not hardcode internal service URLs or invent a second catalog.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: alphafox-auth
3
3
  description: Login, status, logout, whoami, and environment isolation for Alphafox CLI.
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  ---
6
6
 
7
7
  # Auth Skill
@@ -10,24 +10,39 @@ version: 0.1.0
10
10
 
11
11
  User needs to sign in, verify session, switch profile, or revoke tokens.
12
12
 
13
+ Always `--format json --no-input`. Never `--token`.
14
+
13
15
  ## Workflows
14
16
 
15
17
  ### Device Flow (headless / Agent)
16
18
 
17
- 1. `alphafox auth login --no-wait --format json`
19
+ 1. `alphafox auth login --no-wait --format json --no-input`
18
20
  2. Present `verification_uri` / `user_code` to the human.
19
- 3. After approval: `alphafox auth login --device-code <device_code>`
20
- 4. `alphafox whoami` / `alphafox auth status --verify`
21
+ 3. After approval: `alphafox auth login --device-code <device_code> --format json --no-input`
22
+ 4. `alphafox whoami --format json --no-input` / `alphafox auth status --verify --format json --no-input`
23
+
24
+ ### Browser loopback (human, local machine)
25
+
26
+ 1. `alphafox auth login --browser --format json --no-input`
27
+ 2. CLI binds `127.0.0.1` and opens the system browser. Do not copy codes or verifiers.
28
+ 3. After the localhost callback, `alphafox whoami` / `alphafox auth status --verify`
29
+ 4. If the browser cannot open, the error includes a copyable `authorizeUrl`. Do not retry as Device Flow unless the human is headless.
21
30
 
22
31
  ### Status / logout
23
32
 
24
- - `alphafox auth status --verify`
25
- - `alphafox auth logout` (server revoke + local keychain clear)
33
+ - `alphafox auth status --verify --format json --no-input`
34
+ - `alphafox auth logout --format json --no-input` (server revoke + local keychain clear). If `remoteRevoke` is `failed`, local tokens are still cleared but exit is non-zero — do not claim a full logout.
35
+
36
+ ### Recovery
37
+
38
+ - `401` / `expired_token`: re-run Device Flow or browser login. Do not reuse a token from another profile.
39
+ - Cross-env: production tokens are rejected on staging/local. Switch `--profile` only with explicit operator intent.
26
40
 
27
41
  ## Safety
28
42
 
29
43
  - Fail closed on cross-environment tokens (prod token never hits staging).
30
44
  - Do not copy refresh tokens into CI (automation deferred — ADR 0004).
45
+ - Scopes: `openid` `profile` `offline_access` at grant time.
31
46
 
32
47
  ## operationIds
33
48
 
@@ -1,16 +1,23 @@
1
1
  ---
2
2
  name: alphafox-exchange
3
3
  description: Exchange connectors list and connection management via Public API.
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  ---
6
6
 
7
7
  # Exchange connectors
8
8
 
9
+ Always `--format json --no-input`. List is `exchange-connectors:read`.
10
+
9
11
  ```bash
10
- alphafox api GET /api/v1/exchange-connectors
12
+ alphafox api GET /api/v1/exchange-connectors --format json --no-input
11
13
  ```
12
14
 
13
- Writes that create/disable connectors may be `high-risk-write` — use `--dry-run` / `--yes`.
15
+ Writes that create/disable connectors may be `high-risk-write` — use `--dry-run` / `--yes`. Uncataloged connector POST is treated as unknown risk and still needs `--yes`.
16
+
17
+ ## Recovery
18
+
19
+ - `403` / wrong resource: stop. Do not retry with production tokens on staging.
20
+ - Never log connector secrets from request bodies.
14
21
 
15
22
  ## operationIds
16
23
 
@@ -1,14 +1,19 @@
1
1
  ---
2
2
  name: alphafox-market
3
3
  description: Market data and spread-radar readonly queries.
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  ---
6
6
 
7
7
  # Market
8
8
 
9
+ Always `--format json --no-input`. Prefer readonly scopes. No mock success if upstream fails.
10
+
9
11
  ```bash
10
- alphafox api GET /api/v1/market/symbols
11
- alphafox api GET /api/v1/spread-radar/pairs
12
+ alphafox api GET /api/v1/spread-radar/pairs --format json --no-input
13
+ alphafox api GET /api/v1/market/symbols --format json --no-input
12
14
  ```
13
15
 
14
- Prefer readonly scopes. No mock success if upstream fails.
16
+ ## operationIds
17
+
18
+ - `spread_radar.pairs.list`
19
+ - `market.symbols.list`
@@ -1,16 +1,21 @@
1
1
  ---
2
2
  name: alphafox-notification
3
3
  description: Notification channels and subscriptions.
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  ---
6
6
 
7
7
  # Notification
8
8
 
9
+ Always `--format json --no-input`. List is `notification:read`. Channel create/replace/delete may be write or high-risk — `--dry-run` / `--yes`.
10
+
9
11
  ```bash
10
- alphafox api GET /api/v1/notification/channels
11
- alphafox api GET /api/v1/notification/subscriptions
12
+ alphafox api GET /api/v1/notification/channels --format json --no-input
13
+ alphafox api GET /api/v1/notification/subscriptions --format json --no-input
12
14
  ```
13
15
 
16
+ If a path is not allowlisted, stop with the structured error. Do not call notification internals.
17
+
14
18
  ## operationIds
15
19
 
16
20
  - `notification.channels.list`
21
+ - `notification.subscriptions.list`
@@ -1,35 +1,41 @@
1
1
  ---
2
2
  name: alphafox-strategy
3
3
  description: Strategy definitions, chats, and backtests via public operationIds.
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  ---
6
6
 
7
7
  # Strategy / Chat / Backtest
8
8
 
9
+ Always `--format json --no-input`. Read scopes `trading:read` / `backtests:read`; writes `chats:write` / `backtests:write`.
10
+
9
11
  ## Read
10
12
 
11
13
  ```bash
12
- alphafox schema trading.strategy_definitions.list
13
- alphafox api GET /api/v1/trading/strategy-definitions
14
+ alphafox schema trading.strategy_definitions.list --format json --no-input
15
+ alphafox api GET /api/v1/trading/strategy-definitions --format json --no-input
14
16
  ```
15
17
 
16
18
  ## Write (ordinary)
17
19
 
18
20
  ```bash
19
- alphafox api POST /api/v1/chats --body '{"strategyGenerationMode":"simple"}'
21
+ alphafox api POST /api/v1/chats --body '{"strategyGenerationMode":"simple"}' --format json --no-input
20
22
  ```
21
23
 
22
- Requires auth. Sends `Idempotency-Key` when available.
24
+ Requires auth. Sends `Idempotency-Key` when available. Duplicate key → `409`; do not invent a new key unless the operator asks to create another chat.
23
25
 
24
26
  ## Long-running backtest
25
27
 
26
28
  ```bash
27
- alphafox api POST /api/v1/backtests --body '{...}'
28
- alphafox api GET /api/v1/backtests/{backtestId}
29
- alphafox api GET /api/v1/backtests/{backtestId}/stream
30
- alphafox api POST /api/v1/backtests/{backtestId}/cancel --body '{}'
29
+ alphafox api POST /api/v1/backtests --body '{"chatId":"<chat-id>"}' --format json --no-input
30
+ alphafox api GET /api/v1/backtests/{backtestId} --format json --no-input
31
+ alphafox api GET /api/v1/backtests/{backtestId}/stream --format jsonl --no-input
32
+ alphafox api POST /api/v1/backtests/{backtestId}/cancel --body '{}' --format json --no-input
31
33
  ```
32
34
 
35
+ `backtests.create` requires `chatId`. `strategyId` is optional: the facade resolves a compiled strategy on that chat. A chat with no compiled strategy returns `CHAT_HAS_NO_COMPILED_STRATEGY` (not `JOB_NOT_FOUND`). Optional `backtestSettings` overlays chat settings when it is a settingsJson object.
36
+
37
+ If the stream drops, `GET` the backtest by id — do not assume success. Cancel is explicit; interruption must remain queryable.
38
+
33
39
  ## operationIds
34
40
 
35
41
  - `trading.strategy_definitions.list`
@@ -1,25 +1,35 @@
1
1
  ---
2
2
  name: alphafox-trading
3
3
  description: Traders list and high-risk start/stop with confirmation gates.
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  ---
6
6
 
7
7
  # Trading
8
8
 
9
+ Always `--format json --no-input`. Read first. Writes need scopes `trading:write`; start/stop also `trading:high-risk`.
10
+
9
11
  ## Read
10
12
 
11
13
  ```bash
12
- alphafox api GET /api/v1/trading/traders
14
+ alphafox api GET /api/v1/trading/traders --format json --no-input
13
15
  ```
14
16
 
15
17
  ## High-risk write
16
18
 
17
19
  ```bash
18
- alphafox api POST /api/v1/trading/traders/{traderId}/start --body '{}' --dry-run
19
- alphafox api POST /api/v1/trading/traders/{traderId}/start --body '{}' --yes
20
+ alphafox api POST /api/v1/trading/traders/{traderId}/start --body '{}' --dry-run --format json --no-input
21
+ alphafox api POST /api/v1/trading/traders/{traderId}/start --body '{}' --yes --format json --no-input
20
22
  ```
21
23
 
22
- Without `--yes`, CLI exits `10` with `confirmation_required`.
24
+ Without `--yes`, CLI exits `10` with `confirmation_required`. Server still checks role/ownership.
25
+
26
+ Stop: `POST /api/v1/trading/traders/{traderId}/stop` with the same `--dry-run` then `--yes` sequence.
27
+
28
+ ## Recovery
29
+
30
+ - `403`: missing scope or not owner — stop, do not retry `--yes`.
31
+ - `409`: trader already in the requested state — report, do not loop start/stop.
32
+ - Unknown HTTP after a write: do not auto-retry.
23
33
 
24
34
  ## operationIds
25
35