@thirdfy/agent-cli 0.4.3 → 0.5.1
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.
- package/CHANGELOG.md +52 -1
- package/README.md +4 -5
- package/package.json +2 -2
- package/src/cli/help.mjs +1 -0
- package/src/cli/manifest.mjs +4 -4
- package/src/cli/options/index.mjs +2 -0
- package/src/cli/options/onboarding/credentials.mjs +1 -7
- package/src/cli/options/onboarding/oauthLogin.mjs +8 -0
- package/src/commands/account/credits.mjs +9 -7
- package/src/commands/discovery.mjs +6 -5
- package/src/commands/doctor.mjs +7 -2
- package/src/commands/onboarding/bootstrap.mjs +35 -0
- package/src/commands/onboarding/credentials.mjs +0 -10
- package/src/commands/onboarding/oauthLogin.mjs +284 -0
- package/src/core/context.mjs +16 -6
- package/src/core/errorEnvelope.mjs +6 -0
- package/src/core/http.mjs +47 -2
- package/src/core/oauth/authServer.mjs +192 -0
- package/src/core/oauth/pkce.mjs +17 -0
- package/src/core/oauth/session.mjs +117 -0
- package/src/lib/creditsUsdSummary.mjs +128 -29
- package/src/runtime/certification/executionCertify.mjs +18 -1
- package/src/runtime/execution/payloads.mjs +6 -0
- package/src/runtime/handlers.mjs +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,58 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@thirdfy/agent-cli` are documented here. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## [0.5.1] - 2026-10-16
|
|
6
|
+
|
|
7
|
+
A patch release: `doctor certify execution` works for agents with a narrow allowlist.
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **`doctor certify execution` no longer fails on venue writes outside the agent's allowlist** (THI-201). With an agent key, the CLI reads the agent's own action list, so bare certification flagged every venue write the agent may not call (for example `place_hyperliquid_tp_sl` or `update_lighter_leverage`) as `CATALOG_SCHEMA_UNAVAILABLE` and failed. It now checks only the venue writes the agent may call and lists the rest in `skippedVenueActions`. An allowed action with a broken schema, a `--required-actions` entry the agent can't call, and a public catalog missing a venue write all still fail.
|
|
12
|
+
|
|
13
|
+
## [0.5.0] - 2026-10-15
|
|
14
|
+
|
|
15
|
+
`thirdfy-agent login` signs in with OAuth in the browser (auth.thirdfy.com, the same sign-in the MCP uses), as one agent with read access, plus trade with `--trade`. A minor version because `login` without a token flag now starts that sign-in instead of failing, and `credits balance` / `pricing quote` drop their credit counts for USD. `login email`, token flags and agent API keys work as before.
|
|
16
|
+
|
|
17
|
+
### Removed
|
|
18
|
+
|
|
19
|
+
- **The ignored Bitfinex flags of `credentials upsert`** (`--permission-profile`, `--verify-permissions`, `--skip-permissions-probe`, `--bitfinex-base-url`), as 0.4.3's warning announced (THI-86). Passing one is now an unknown-option error. Drop them from scripts.
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- **`thirdfy-agent login` signs in with OAuth** (THI-107, part of THI-104): auth.thirdfy.com, the same sign-in the MCP uses. With no token flag, `login` does this:
|
|
24
|
+
- opens the browser (`--no-browser` prints the URL);
|
|
25
|
+
- the owner picks one agent and approves read (plus trade with `--trade`);
|
|
26
|
+
- the browser returns to a one-time `127.0.0.1` listener;
|
|
27
|
+
- the CLI is a public client (registered once per server), and uses PKCE S256 and `resource` = the API.
|
|
28
|
+
|
|
29
|
+
How the sign-in is used:
|
|
30
|
+
- **Credential:** it's stored in `auth.oauth` and becomes the agent credential: after `--agent-api-key` and `THIRDFY_AGENT_API_KEY`, before config `agent.apiKey` and before stored owner auth for credits reads.
|
|
31
|
+
- **Agent:** its agent comes from the API (`GET /api/v1/agent/oauth/session`).
|
|
32
|
+
- **Requests:** they send `Authorization: Bearer`, refresh before expiry (rotation), and refresh and retry once after a 401.
|
|
33
|
+
- **Expiry:** a refused refresh is `OAUTH_SESSION_EXPIRED` (`nextAction: reauthenticate`).
|
|
34
|
+
- **`logout`** revokes the sign-in at the auth server.
|
|
35
|
+
- **`whoami`** shows `auth.oauth`.
|
|
36
|
+
- New next actions: `reauthenticate`, `reauthenticate_with_trade`.
|
|
37
|
+
|
|
38
|
+
Needs thirdfy/thirdfy-auth#15 (the API as a resource, token introspection) and the API change THI-106. Until both are live, `login` stops at `OAUTH_RESOURCE_NOT_SUPPORTED` and points to `login email`. `login email` and token flags work as before.
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
42
|
+
- **`credits balance` and `pricing quote` show balances in USD, never credits** (THI-123; same rules as thirdfy/thirdfy-mcp#279). Credits are Thirdfy's internal unit, and no price per action or request is stated.
|
|
43
|
+
- **Kept:** `availableUsd`, the free request counts (`freeDailyLimit`, `freeRequestsRemainingToday`, ...), `wouldBePaidBy` and `displayCurrency`.
|
|
44
|
+
- **Owner's fallback:** `ownerCreditsFallback` gets `availableUsd`, at the API's own `retailUsdPerCredit` from the same response, rounded to cents.
|
|
45
|
+
- **Dropped:** every credit count, per-credit rate and per-action price (`balanceCredits`, `balance`, `totalEarned`, `totalSpent`, `creditUsdValue`, `retailUsdPerCredit`, `quote.creditsCost`, `chargedUsd`, ...).
|
|
46
|
+
- **Text output:** without `--json`, `credits balance` reads `Balance loaded: $4.20 left; 8 of 20 free requests left today; then the owner's balance ($86.22) pays; then top up the balance.` The `note` says the same in USD. `pricing quote` reads `Action checked; would be paid by the owner's balance (owner_credits)`.
|
|
47
|
+
- **Unchanged:** the owner reports `credits transactions`, `credits usage`, `models list` and `models estimate` (credit ledger lines), as the MCP left its owner-token credits tools.
|
|
48
|
+
- **Owner ledger:** `totalAvailable` (a credit count) and `currency: 'credits'` are dropped too, and the owner route's free counts (`freeAllowance`, `freeRemainingToday`) are read, so owner auth also prints the free requests left.
|
|
49
|
+
- Before (0.4.3 and earlier) `credits balance` returned only `balanceCredits` and `ownerCreditsFallback.balanceCredits`, so a model answered in credits.
|
|
50
|
+
- **A proper "signed in" page after `thirdfy-agent login`.** The local listener used to answer the browser with a bare, unbranded page. Like Claude Code, GitHub CLI and Google Cloud CLI, it now:
|
|
51
|
+
- holds the browser until the CLI has its tokens and knows its agent;
|
|
52
|
+
- then sends it to the sign-in server's result page, `<issuer>/cli/signed-in`, with the agent, read or trade access, and the API (auth.thirdfy.com 0.5.1+);
|
|
53
|
+
- on a cancelled or failed sign-in, sends it to `<issuer>/cli/error`.
|
|
54
|
+
|
|
55
|
+
A sign-in server without those pages gets a built-in page in the same style.
|
|
56
|
+
- **A sign-in is used only on the API it was issued for**: an api-test sign-in is never sent to production, or the reverse. `whoami` shows `auth.oauth.resource` and `activeForThisApi`.
|
|
6
57
|
|
|
7
58
|
## [0.4.3] - 2026-10-14
|
|
8
59
|
|
package/README.md
CHANGED
|
@@ -39,12 +39,11 @@ Run without global install:
|
|
|
39
39
|
npx @thirdfy/agent-cli --help
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
## What's new in v0.
|
|
42
|
+
## What's new in v0.5.1
|
|
43
43
|
|
|
44
|
-
-
|
|
45
|
-
- **
|
|
46
|
-
-
|
|
47
|
-
- Older versions: see [CHANGELOG.md](./CHANGELOG.md).
|
|
44
|
+
- **`doctor certify execution` passes for agents with a narrow allowlist.** It now checks only the venue writes your agent may call, and lists the others under `skippedVenueActions` instead of failing. Runtimes that stop on a failed certify (Hermes, OpenClaw) start again.
|
|
45
|
+
- **Still fails closed:** an allowed action with a broken schema, a `--required-actions` entry the agent can't call, or a missing catalog.
|
|
46
|
+
- Browser sign-in (`thirdfy-agent login`, `--trade` for writes) arrived in 0.5.0. Older versions: see [CHANGELOG.md](./CHANGELOG.md).
|
|
48
47
|
|
|
49
48
|
## Quick start
|
|
50
49
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thirdfy/agent-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Thirdfy Agent CLI for onboarding, governance preflight, execute-intent, and status polling.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
25
|
"test": "node --test test/*/*.test.cjs test/*/*/*.test.cjs",
|
|
26
|
-
"lint": "node --check ./bin/thirdfy-agent.mjs && node --check ./src/core/*.mjs && node --check ./src/core/execution/*.mjs && node --check ./src/commands/*.mjs && node --check ./src/commands/venues/*.mjs && node --check ./src/commands/onboarding/*.mjs && node --check ./src/commands/account/*.mjs && node --check ./src/commands/signals/*.mjs && node --check ./src/cli/*.mjs && node --check ./src/cli/options/*.mjs && node --check ./src/cli/options/venues/*.mjs && node --check ./src/cli/options/onboarding/*.mjs && node --check ./src/cli/options/account/*.mjs && node --check ./src/runtime/*.mjs && node --check ./src/runtime/execution/*.mjs && node --check ./src/runtime/execution/runners/*.mjs && node --check ./src/runtime/actions/*.mjs && node --check ./src/runtime/validation/*.mjs && node --check ./src/runtime/certification/*.mjs && node --check ./src/runtime/providerHints/*.mjs && node --check ./src/runtime/risk/*.mjs",
|
|
26
|
+
"lint": "node --check ./bin/thirdfy-agent.mjs && node --check ./src/core/*.mjs && node --check ./src/core/execution/*.mjs && node --check ./src/core/oauth/*.mjs && node --check ./src/commands/*.mjs && node --check ./src/commands/venues/*.mjs && node --check ./src/commands/onboarding/*.mjs && node --check ./src/commands/account/*.mjs && node --check ./src/commands/signals/*.mjs && node --check ./src/cli/*.mjs && node --check ./src/cli/options/*.mjs && node --check ./src/cli/options/venues/*.mjs && node --check ./src/cli/options/onboarding/*.mjs && node --check ./src/cli/options/account/*.mjs && node --check ./src/runtime/*.mjs && node --check ./src/runtime/execution/*.mjs && node --check ./src/runtime/execution/runners/*.mjs && node --check ./src/runtime/actions/*.mjs && node --check ./src/runtime/validation/*.mjs && node --check ./src/runtime/certification/*.mjs && node --check ./src/runtime/providerHints/*.mjs && node --check ./src/runtime/risk/*.mjs",
|
|
27
27
|
"validate:cli-manifest-handlers": "node ./scripts/validate-cli-manifest-handlers.mjs",
|
|
28
28
|
"validate:runtime-boundaries": "node ./scripts/validate-runtime-boundaries.mjs",
|
|
29
29
|
"validate:npm-pack": "node ./scripts/validate-npm-pack.mjs",
|
package/src/cli/help.mjs
CHANGED
|
@@ -7,6 +7,7 @@ Core commands:
|
|
|
7
7
|
thirdfy-agent profile use --profile <name> [--run-mode thirdfy|self|hybrid|agent_wallet] [--custody-mode managed|external] [--json]
|
|
8
8
|
thirdfy-agent profile show [--json]
|
|
9
9
|
thirdfy-agent config set --key <path> --value <value> [--json]
|
|
10
|
+
thirdfy-agent login [--trade] [--no-browser] [--issuer <url>] [--json] (OAuth in the browser: one agent)
|
|
10
11
|
thirdfy-agent login [--auth-token <token> | --owner-session-token <token>] [--agent-api-key <key>] [--agent-key <key>] [--run-mode <mode>] [--custody-mode managed|external] [--wallet-address <addr>] [--json]
|
|
11
12
|
thirdfy-agent login email <address> [--code <otp>] [--accept-terms] [--key-name <name>] [--agent-key <key>] [--not-interactive|--ni] [--json]
|
|
12
13
|
thirdfy-agent logout [--all] [--clear-agent-key] [--json]
|
package/src/cli/manifest.mjs
CHANGED
|
@@ -47,8 +47,8 @@ export const CLI_MANIFEST = [
|
|
|
47
47
|
{
|
|
48
48
|
path: ['login'],
|
|
49
49
|
handler: 'commandLogin',
|
|
50
|
-
options: ['auth', 'bootstrap'],
|
|
51
|
-
description: '
|
|
50
|
+
options: ['auth', 'bootstrap', 'oauthLogin'],
|
|
51
|
+
description: 'Sign in with OAuth in the browser (one agent; --trade for writes), or with an auth token, owner session or agent API key',
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
54
|
path: ['login', 'email'],
|
|
@@ -212,7 +212,7 @@ export const CLI_MANIFEST = [
|
|
|
212
212
|
handler: 'commandCreditsBalance',
|
|
213
213
|
tier: 'online',
|
|
214
214
|
options: ['auth'],
|
|
215
|
-
description: '
|
|
215
|
+
description: 'Balance in USD, free requests today and who pays next',
|
|
216
216
|
},
|
|
217
217
|
{
|
|
218
218
|
path: ['credits', 'buy'],
|
|
@@ -254,7 +254,7 @@ export const CLI_MANIFEST = [
|
|
|
254
254
|
handler: 'commandPricingQuote',
|
|
255
255
|
tier: 'online',
|
|
256
256
|
options: ['auth', 'execution'],
|
|
257
|
-
description: '
|
|
257
|
+
description: 'Check who would pay for a catalog action now (never a price)',
|
|
258
258
|
},
|
|
259
259
|
{
|
|
260
260
|
path: ['chat', 'send'],
|
|
@@ -6,6 +6,7 @@ import { attachTrackingOptions } from './tracking.mjs';
|
|
|
6
6
|
import { attachWalletOptions } from './account/wallet.mjs';
|
|
7
7
|
import { attachBootstrapOptions, attachOnboardingHelpOptions } from './onboarding/bootstrap.mjs';
|
|
8
8
|
import { attachCredentialsOptions } from './onboarding/credentials.mjs';
|
|
9
|
+
import { attachOAuthLoginOptions } from './onboarding/oauthLogin.mjs';
|
|
9
10
|
import { attachAnalyticsOptions } from './analytics.mjs';
|
|
10
11
|
import { attachPolymarketOptions } from './venues/polymarket.mjs';
|
|
11
12
|
import { attachHummingbotOptions } from './venues/hummingbot.mjs';
|
|
@@ -27,6 +28,7 @@ const BUNDLES = {
|
|
|
27
28
|
tracking: attachTrackingOptions,
|
|
28
29
|
wallet: attachWalletOptions,
|
|
29
30
|
bootstrap: attachBootstrapOptions,
|
|
31
|
+
oauthLogin: attachOAuthLoginOptions,
|
|
30
32
|
onboardingHelp: attachOnboardingHelpOptions,
|
|
31
33
|
credentials: attachCredentialsOptions,
|
|
32
34
|
analytics: attachAnalyticsOptions,
|
|
@@ -7,11 +7,5 @@ export function attachCredentialsOptions(cmd) {
|
|
|
7
7
|
.option('--credential-type <type>', 'credential type')
|
|
8
8
|
.option('--passphrase <value>', 'exchange passphrase')
|
|
9
9
|
.option('--metadata <json>', 'credential metadata JSON')
|
|
10
|
-
.option('--policy <json>', 'credential policy JSON')
|
|
11
|
-
// Accepted and ignored since Bitfinex support was removed, so older scripts keep working; the
|
|
12
|
-
// command says so in meta.warnings. Drop them in the next minor version.
|
|
13
|
-
.option('--permission-profile <profile>', 'ignored (Bitfinex support was removed)')
|
|
14
|
-
.option('--verify-permissions', 'ignored (Bitfinex support was removed)')
|
|
15
|
-
.option('--skip-permissions-probe', 'ignored (Bitfinex support was removed)')
|
|
16
|
-
.option('--bitfinex-base-url <url>', 'ignored (Bitfinex support was removed)');
|
|
10
|
+
.option('--policy <json>', 'credential policy JSON');
|
|
17
11
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** `thirdfy-agent login` with OAuth (auth.thirdfy.com), the default when no token flag is passed. */
|
|
2
|
+
export function attachOAuthLoginOptions(cmd) {
|
|
3
|
+
return cmd
|
|
4
|
+
.option('--trade', 'also ask for trade access (writes that move funds); read-only otherwise')
|
|
5
|
+
.option('--no-browser', 'print the sign-in URL instead of opening the browser')
|
|
6
|
+
.option('--issuer <url>', 'sign-in server (default: paired with --api-base, https://auth.thirdfy.com)')
|
|
7
|
+
.option('--login-timeout <seconds>', 'how long to wait for the browser sign-in (default 300)');
|
|
8
|
+
}
|
|
@@ -6,7 +6,8 @@ import { toAvantisSpelling } from '../../core/venueBrand.mjs';
|
|
|
6
6
|
import {
|
|
7
7
|
formatCreditsEstimateSummary,
|
|
8
8
|
formatCreditsModelsSummary,
|
|
9
|
-
|
|
9
|
+
describeWouldBePaidBy,
|
|
10
|
+
toUsdFirst,
|
|
10
11
|
} from '../../lib/creditsUsdSummary.mjs';
|
|
11
12
|
|
|
12
13
|
function resolveToolCallsEstimate(flags) {
|
|
@@ -146,12 +147,13 @@ export function createCreditsCommands({ printEnvelope, getAuthToken, buildOwnerA
|
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
/**
|
|
149
|
-
* `pricing quote --action <id>`:
|
|
150
|
-
* (agent_credits | free_request | owner_credits | none) when the API can read the balances
|
|
150
|
+
* `pricing quote --action <id>`: whether one catalog action can run now and who pays for it:
|
|
151
|
+
* `wouldBePaidBy` (agent_credits | free_request | owner_credits | none) when the API can read the balances
|
|
151
152
|
* (thirdfy-api-v2#887). The ledger follows `resolveCreditsLedger`. Agent: `POST /agent/credits/quote`
|
|
152
153
|
* with the agent's key. Owner (session token or auth token): `/credits/pricing/quote`, for one of the
|
|
153
154
|
* owner's agents with --agent-key. An API without the agent route (404, before #887) is quoted
|
|
154
|
-
* through the owner route when owner auth is set and --agent-key names the key's agent.
|
|
155
|
+
* through the owner route when owner auth is set and --agent-key names the key's agent. Never a price:
|
|
156
|
+
* the quote's credit cost and USD figures are dropped (thirdfy-mcp quoteActionPricing, thirdfy-mcp#279).
|
|
155
157
|
*/
|
|
156
158
|
async function commandPricingQuote(ctx, flags) {
|
|
157
159
|
const action = requireFlag(flags, 'action', 'Missing --action for pricing quote');
|
|
@@ -210,9 +212,9 @@ export function createCreditsCommands({ printEnvelope, getAuthToken, buildOwnerA
|
|
|
210
212
|
success: true,
|
|
211
213
|
code: 'OK',
|
|
212
214
|
// wouldBePaidBy (agent_credits | free_request | owner_credits | none), when the API sends it.
|
|
213
|
-
message: response?.wouldBePaidBy ? `Action
|
|
214
|
-
//
|
|
215
|
-
data:
|
|
215
|
+
message: response?.wouldBePaidBy ? `Action checked; would be paid by ${describeWouldBePaidBy(response.wouldBePaidBy)}` : 'Action checked',
|
|
216
|
+
// No price per action or request: no credit cost, rate or USD figure (thirdfy-mcp quoteActionPricing).
|
|
217
|
+
data: toUsdFirst(response),
|
|
216
218
|
meta: {
|
|
217
219
|
apiBase: ctx.apiBase,
|
|
218
220
|
action,
|
|
@@ -2,7 +2,7 @@ import { requireFlag, parseJsonFlag } from '../core/args.mjs';
|
|
|
2
2
|
import { apiGet, apiPost } from '../core/http.mjs';
|
|
3
3
|
import { extractActions, getCachedActionsCatalogSnapshot, resolveCreditsLedger } from '../core/context.mjs';
|
|
4
4
|
import { getEffectiveRunMode } from '../core/runMode.mjs';
|
|
5
|
-
import { creditsFreeQuotaNote, formatCreditsBalanceSummary,
|
|
5
|
+
import { creditsFreeQuotaNote, formatCreditsBalanceSummary, toUsdFirst } from '../lib/creditsUsdSummary.mjs';
|
|
6
6
|
import { filterActionsByChain } from '../runtime/actions/chainFilter.mjs';
|
|
7
7
|
import { pageActionList, readActionListPaging } from '../runtime/actions/actionList.mjs';
|
|
8
8
|
import {
|
|
@@ -186,7 +186,8 @@ async function commandChains(ctx, flags, capabilities) {
|
|
|
186
186
|
* `credits balance`. Owner auth reads the owner's balance (`/credits/balance`). An explicit
|
|
187
187
|
* --agent-api-key, or no owner auth but an agent key in env or config, reads the agent's own ledger
|
|
188
188
|
* (`/agent/credits/balance`: its credits, free requests today and the owner-credits fallback), as
|
|
189
|
-
* thirdfy-mcp getCreditsBalance.
|
|
189
|
+
* thirdfy-mcp getCreditsBalance. In USD, never credits: `availableUsd` (the owner's fallback too, at the
|
|
190
|
+
* API's `retailUsdPerCredit`), free requests and who pays; no credit count, rate or price (thirdfy-mcp#279).
|
|
190
191
|
*/
|
|
191
192
|
async function commandCreditsBalance(ctx, flags, capabilities) {
|
|
192
193
|
const { ledger, agentApiKey } = resolveCreditsLedger(flags);
|
|
@@ -203,9 +204,9 @@ async function commandCreditsBalance(ctx, flags, capabilities) {
|
|
|
203
204
|
printEnvelope({
|
|
204
205
|
success: true,
|
|
205
206
|
code: 'OK',
|
|
206
|
-
message: flags.json ? '
|
|
207
|
-
//
|
|
208
|
-
data: { ...
|
|
207
|
+
message: flags.json ? 'Balance loaded' : `Balance loaded: ${summary}`,
|
|
208
|
+
// USD-first: balances in USD, no credit count, per-credit rate or price (thirdfy-mcp getCreditsBalance).
|
|
209
|
+
data: { ...toUsdFirst(response), ...(note ? { note } : {}) },
|
|
209
210
|
meta: {
|
|
210
211
|
apiBase: ctx.apiBase,
|
|
211
212
|
ledger: agentLedger ? 'agent' : 'owner',
|
package/src/commands/doctor.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import { requireFlag } from '../core/args.mjs';
|
|
3
3
|
import { apiGet, requestWithRouteFallback } from '../core/http.mjs';
|
|
4
|
-
import { loadProfileConfig, getProfileConfigPath,
|
|
4
|
+
import { loadProfileConfig, getProfileConfigPath, getCachedActionsCatalogSnapshot } from '../core/context.mjs';
|
|
5
5
|
import { DEFAULT_API_BASE, PROFILE_DEFAULTS } from '../core/constants.mjs';
|
|
6
6
|
import { DEFAULT_CHAIN_ID, describeChainGas, parseChainIdFlag, pinnedRpcProvider, resolveChainRpcUrl } from '../core/chainRegistry.mjs';
|
|
7
7
|
import { exitAfterOutput } from '../core/envelope.mjs';
|
|
@@ -333,9 +333,12 @@ async function commandManagedSetup(ctx, flags, capabilities) {
|
|
|
333
333
|
|
|
334
334
|
async function commandDoctorCertifyExecution(ctx, flags) {
|
|
335
335
|
let liveActions = null;
|
|
336
|
+
let catalogPolicyScoped = false;
|
|
336
337
|
let catalogError = null;
|
|
337
338
|
try {
|
|
338
|
-
|
|
339
|
+
const snapshot = await getCachedActionsCatalogSnapshot(ctx, flags);
|
|
340
|
+
liveActions = snapshot.actions;
|
|
341
|
+
catalogPolicyScoped = snapshot.policyScoped === true;
|
|
339
342
|
} catch (error) {
|
|
340
343
|
catalogError = {
|
|
341
344
|
message: error?.message || 'Actions catalog fetch failed',
|
|
@@ -356,6 +359,7 @@ async function commandDoctorCertifyExecution(ctx, flags) {
|
|
|
356
359
|
runMode,
|
|
357
360
|
expectedSchemaDigest,
|
|
358
361
|
requiredActions,
|
|
362
|
+
catalogPolicyScoped,
|
|
359
363
|
});
|
|
360
364
|
|
|
361
365
|
printEnvelope({
|
|
@@ -369,6 +373,7 @@ async function commandDoctorCertifyExecution(ctx, flags) {
|
|
|
369
373
|
catalog: {
|
|
370
374
|
fetched: Array.isArray(liveActions),
|
|
371
375
|
actionCount: Array.isArray(liveActions) ? liveActions.length : 0,
|
|
376
|
+
policyScoped: catalogPolicyScoped,
|
|
372
377
|
error: catalogError,
|
|
373
378
|
},
|
|
374
379
|
},
|
|
@@ -17,6 +17,9 @@ import {
|
|
|
17
17
|
} from '../../core/context.mjs';
|
|
18
18
|
import { apiGet, apiPost, requestWithRouteFallback } from '../../core/http.mjs';
|
|
19
19
|
import { isEvmAddress, isSolanaAddress } from '../../core/chainRegistry.mjs';
|
|
20
|
+
import { commandOAuthLogin } from './oauthLogin.mjs';
|
|
21
|
+
import { readOAuthSession } from '../../core/oauth/session.mjs';
|
|
22
|
+
import { revokeToken } from '../../core/oauth/authServer.mjs';
|
|
20
23
|
import { createRequire } from 'module';
|
|
21
24
|
|
|
22
25
|
const require = createRequire(import.meta.url);
|
|
@@ -35,6 +38,7 @@ export function createBootstrapCommands(deps) {
|
|
|
35
38
|
verifyOwnerWalletChallenge,
|
|
36
39
|
resolveEffectiveUserDid,
|
|
37
40
|
negotiateCapabilities,
|
|
41
|
+
CLI_VERSION,
|
|
38
42
|
commandAgentRegister,
|
|
39
43
|
} = deps;
|
|
40
44
|
|
|
@@ -232,6 +236,19 @@ async function commandWhoami(ctx, flags) {
|
|
|
232
236
|
hasOwnerSessionToken: Boolean(auth.ownerSessionToken),
|
|
233
237
|
ownerSessionToken: maskSecret(auth.ownerSessionToken),
|
|
234
238
|
ownerSessionExpiresAt: auth.ownerSessionExpiresAt || null,
|
|
239
|
+
oauth: readOAuthSession(config)
|
|
240
|
+
? {
|
|
241
|
+
issuer: auth.oauth.issuer || null,
|
|
242
|
+
// The API this sign-in is for; commands use it only on that API (--api-base).
|
|
243
|
+
resource: auth.oauth.resource || null,
|
|
244
|
+
activeForThisApi: String(auth.oauth.resource || '').replace(/\/+$/, '') === String(ctx.apiBase || '').replace(/\/+$/, ''),
|
|
245
|
+
agentKey: auth.oauth.agentKey || null,
|
|
246
|
+
scope: auth.oauth.scope || '',
|
|
247
|
+
canTrade: auth.oauth.canTrade === true,
|
|
248
|
+
expiresAt: auth.oauth.expiresAt || null,
|
|
249
|
+
accessToken: maskSecret(auth.oauth.accessToken),
|
|
250
|
+
}
|
|
251
|
+
: null,
|
|
235
252
|
},
|
|
236
253
|
agent: {
|
|
237
254
|
hasAgentApiKey: Boolean(agent.apiKey),
|
|
@@ -272,6 +289,12 @@ async function commandLogin(ctx, flags) {
|
|
|
272
289
|
);
|
|
273
290
|
let loginSource = 'token';
|
|
274
291
|
|
|
292
|
+
// No token and no wallet-signature inputs: sign in with OAuth in the browser (THI-104).
|
|
293
|
+
const hasChallengeInputs = Boolean(String(flags.challengeId || '').trim() && String(flags.signature || '').trim());
|
|
294
|
+
if (!authToken && !ownerSessionToken && !hasChallengeInputs) {
|
|
295
|
+
return commandOAuthLogin(ctx, flags, { printEnvelope, version: CLI_VERSION });
|
|
296
|
+
}
|
|
297
|
+
|
|
275
298
|
if (!authToken && !ownerSessionToken) {
|
|
276
299
|
const challengeId = String(flags.challengeId || '').trim();
|
|
277
300
|
const signature = String(flags.signature || '').trim();
|
|
@@ -611,6 +634,17 @@ async function commandLogout(ctx, flags) {
|
|
|
611
634
|
}
|
|
612
635
|
}
|
|
613
636
|
|
|
637
|
+
// An OAuth sign-in is revoked at the auth server (RFC 7009), so its tokens stop working
|
|
638
|
+
// everywhere, not only on this machine. Best effort: local credentials are cleared either way.
|
|
639
|
+
const oauthSession = readOAuthSession(current);
|
|
640
|
+
let oauthRevoked = null;
|
|
641
|
+
if (oauthSession) {
|
|
642
|
+
const revoke = (token) =>
|
|
643
|
+
revokeToken({ revocationEndpoint: oauthSession.revocationEndpoint, clientId: oauthSession.clientId, token }, ctx.timeoutMs || 30_000);
|
|
644
|
+
const [refresh, access] = await Promise.all([revoke(oauthSession.refreshToken), revoke(oauthSession.accessToken)]);
|
|
645
|
+
oauthRevoked = Boolean(refresh || access);
|
|
646
|
+
}
|
|
647
|
+
|
|
614
648
|
const next = { ...current };
|
|
615
649
|
delete next.auth;
|
|
616
650
|
if (flags.clearAgentKey) {
|
|
@@ -626,6 +660,7 @@ async function commandLogout(ctx, flags) {
|
|
|
626
660
|
revokeAttempted,
|
|
627
661
|
revokeSuccess,
|
|
628
662
|
revokeError,
|
|
663
|
+
...(oauthSession ? { oauthRevoked, oauthAgentKey: oauthSession.agentKey || null } : {}),
|
|
629
664
|
configPath: getProfileConfigPath(),
|
|
630
665
|
},
|
|
631
666
|
meta: { apiBase: ctx.apiBase },
|
|
@@ -5,14 +5,6 @@ import { createCliError } from '../../core/envelope.mjs';
|
|
|
5
5
|
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
7
7
|
const { normalizeCredentialStatus } = require('../../utils/cli/delegationNormalization.cjs');
|
|
8
|
-
/** `credentials upsert` flags of the removed Bitfinex permission probe: accepted, ignored, and named in a warning. */
|
|
9
|
-
const REMOVED_BITFINEX_FLAGS = [
|
|
10
|
-
['permissionProfile', '--permission-profile'],
|
|
11
|
-
['verifyPermissions', '--verify-permissions'],
|
|
12
|
-
['skipPermissionsProbe', '--skip-permissions-probe'],
|
|
13
|
-
['bitfinexBaseUrl', '--bitfinex-base-url'],
|
|
14
|
-
];
|
|
15
|
-
|
|
16
8
|
export function createCredentialsCommands({ printEnvelope, getAuthToken, buildOwnerAuthHeaders }) {
|
|
17
9
|
async function commandCredentialsUpsert(ctx, flags, capabilities) {
|
|
18
10
|
const authToken = getAuthToken(flags, 'Missing --auth-token (or THIRDFY_AUTH_TOKEN) for credentials upsert');
|
|
@@ -29,7 +21,6 @@ async function commandCredentialsUpsert(ctx, flags, capabilities) {
|
|
|
29
21
|
if (flags.policy) payload.policy = parseJsonFlag(flags, 'policy');
|
|
30
22
|
if (flags.agentKey) payload.agentKey = String(flags.agentKey).trim();
|
|
31
23
|
if (flags.chainId) payload.chainId = Number(flags.chainId);
|
|
32
|
-
const ignoredFlags = REMOVED_BITFINEX_FLAGS.filter(([key]) => flags[key] !== undefined).map(([, flag]) => flag);
|
|
33
24
|
const response = await requestWithRouteFallback(ctx, {
|
|
34
25
|
method: 'POST',
|
|
35
26
|
routes: ['/api/v1/agent/delegation/credentials/upsert', '/api/v1/agent/agent/delegation/credentials/upsert'],
|
|
@@ -46,7 +37,6 @@ async function commandCredentialsUpsert(ctx, flags, capabilities) {
|
|
|
46
37
|
meta: {
|
|
47
38
|
apiBase: ctx.apiBase,
|
|
48
39
|
capabilitiesVersion: capabilities?.contractVersion || null,
|
|
49
|
-
...(ignoredFlags.length ? { warnings: [`Ignored ${ignoredFlags.join(', ')}: Bitfinex support was removed. Drop these flags; they will stop being accepted in the next minor version.`] } : {}),
|
|
50
40
|
},
|
|
51
41
|
});
|
|
52
42
|
}
|