@itpay/cli 0.2.16 → 2.0.0-rc.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/README.md +148 -447
- package/bin/itp +1 -150
- package/dist/src/client/backend.js +154 -0
- package/dist/src/client/http.js +76 -0
- package/dist/src/client/types.js +4 -0
- package/dist/src/commands/buy.js +351 -0
- package/dist/src/commands/cart.js +264 -0
- package/dist/src/commands/catalog.js +26 -0
- package/dist/src/commands/checkout.js +106 -0
- package/dist/src/commands/docs.js +61 -0
- package/dist/src/commands/guidance.js +422 -0
- package/dist/src/commands/install.js +95 -0
- package/dist/src/commands/order.js +78 -0
- package/dist/src/commands/orders.js +22 -0
- package/dist/src/commands/pay.js +26 -0
- package/dist/src/commands/readyz.js +8 -0
- package/dist/src/commands/refund.js +20 -0
- package/dist/src/commands/services.js +317 -0
- package/dist/src/main.js +606 -0
- package/dist/src/render/feishu.js +201 -0
- package/dist/src/render/ide.js +321 -0
- package/dist/src/render/index.js +57 -0
- package/dist/src/render/interaction.js +49 -0
- package/dist/src/render/markdown.js +83 -0
- package/dist/src/render/output.js +42 -0
- package/dist/src/render/plain_chat.js +60 -0
- package/dist/src/render/plan.js +31 -0
- package/dist/src/render/qr.js +32 -0
- package/dist/src/render/sink.js +6 -0
- package/dist/src/render/status.js +37 -0
- package/dist/src/render/telegram.js +172 -0
- package/dist/src/render/terminal.js +148 -0
- package/dist/src/render/terminal_image.js +19 -0
- package/dist/src/state/cart_session.js +151 -0
- package/dist/src/state/client_context.js +73 -0
- package/dist/src/state/config.js +82 -0
- package/dist/src/state/device_authority.js +217 -0
- package/dist/src/state/operation_journal.js +80 -0
- package/docs/agent/buyer/cart-checkout.json +56 -94
- package/docs/agent/buyer/catalog-list.json +47 -0
- package/docs/agent/buyer/install-and-setup.json +82 -0
- package/docs/agent/buyer/orders-refunds.json +76 -0
- package/docs/agent/buyer/payment-flow.json +77 -0
- package/docs/agent/buyer/quickstart.json +143 -75
- package/docs/agent/buyer/render-hosts.json +79 -0
- package/package.json +32 -13
- package/skills/itpay-buyer/SKILL.md +107 -238
- package/docs/agent/buyer/account-portal.json +0 -81
- package/docs/agent/buyer/catalog-search.json +0 -106
- package/docs/agent/buyer/human-claim-ui.json +0 -77
- package/docs/agent/buyer/payment-qr.json +0 -97
- package/docs/agent/buyer/payment-wait.json +0 -84
- package/docs/agent/buyer/product-recommendation.json +0 -80
- package/docs/agent/buyer/qr-refresh.json +0 -67
- package/docs/agent/buyer/recovery.json +0 -85
- package/docs/agent/buyer/safety-policy.json +0 -70
- package/docs/agent/buyer/secure-delivery.json +0 -90
- package/docs/agent/buyer/vault-agent-read.json +0 -95
- package/install.ps1 +0 -65
- package/install.sh +0 -66
- package/lib/account-status.js +0 -157
- package/lib/buyer.js +0 -2332
- package/lib/client-context.js +0 -126
- package/lib/docs.js +0 -200
- package/lib/env.js +0 -723
- package/lib/http.js +0 -151
- package/lib/ops.js +0 -135
- package/lib/render-human.js +0 -718
- package/lib/runtime.js +0 -1456
package/README.md
CHANGED
|
@@ -1,451 +1,152 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ItPay CLI
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
This repository is intentionally small. It contains only the public local tooling needed by users and agents:
|
|
6
|
-
|
|
7
|
-
- `itp` CLI
|
|
8
|
-
- npm package metadata
|
|
9
|
-
- install scripts
|
|
10
|
-
- smoke and local E2E scripts
|
|
11
|
-
- ItPay buyer skill prompt
|
|
12
|
-
- agent-readable CLI docs graph
|
|
13
|
-
|
|
14
|
-
It does not contain the closed-source SaaS backend, database files, payment keys, model provider keys, user credentials, or deployment secrets.
|
|
15
|
-
|
|
16
|
-
## What This CLI Does
|
|
17
|
-
|
|
18
|
-
`itp` lets a developer or coding agent discover ItPay services, create cart-first checkouts, show QR payments, wait for verified payment, report secure human delivery status, create one-time human account portal links, and read human-approved Vault grants without exposing raw keys or protected content to the agent.
|
|
19
|
-
|
|
20
|
-
Main flow:
|
|
21
|
-
|
|
22
|
-
```text
|
|
23
|
-
public catalog search -> explain/recommend -> UCP cart -> checkout -> QR payment -> wait verified -> redacted secure delivery status -> optional human account portal link
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Supported runtime targets:
|
|
27
|
-
|
|
28
|
-
```text
|
|
29
|
-
codex
|
|
30
|
-
claude-code
|
|
31
|
-
openclaw
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Default API endpoint:
|
|
35
|
-
|
|
36
|
-
```text
|
|
37
|
-
https://dev.api.itpay.ai
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Override it for local development, staging, or production:
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
export ITPAY_API_BASE=http://127.0.0.1:18080
|
|
44
|
-
export ITPAY_CORE_API_BASE=http://127.0.0.1:18080
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Production release will switch the package default to `https://api.itpay.ai`.
|
|
48
|
-
|
|
49
|
-
## Repository Layout
|
|
50
|
-
|
|
51
|
-
```text
|
|
52
|
-
.
|
|
53
|
-
├── bin/itp # Node.js CLI entrypoint
|
|
54
|
-
├── skills/itpay-buyer/SKILL.md # Buyer agent quick-start skill
|
|
55
|
-
├── docs/agent/buyer/*.json # Agent-readable docs graph
|
|
56
|
-
├── install.sh # Unix user-level installer
|
|
57
|
-
├── install.ps1 # Windows PowerShell installer
|
|
58
|
-
├── smoke.sh # Local CLI smoke test
|
|
59
|
-
├── e2e-local.sh # Local backend E2E test
|
|
60
|
-
├── package.json # npm package metadata
|
|
61
|
-
├── README.md # This maintenance guide
|
|
62
|
-
├── LICENSE # MIT
|
|
63
|
-
└── .gitignore
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Prerequisites
|
|
67
|
-
|
|
68
|
-
For local development:
|
|
69
|
-
|
|
70
|
-
```text
|
|
71
|
-
Node.js >= 18
|
|
72
|
-
npm
|
|
73
|
-
curl
|
|
74
|
-
git
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Optional native credential stores:
|
|
78
|
-
|
|
79
|
-
```text
|
|
80
|
-
macOS: security / Keychain
|
|
81
|
-
Linux: secret-tool
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Non-interactive agent hosts such as Codex automatically use file storage to
|
|
85
|
-
avoid OS keychain prompts. To force file storage anywhere:
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
ITP_CREDENTIAL_STORE=file itp buyer auth status --host <client> --json
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
If native credential storage is unavailable, the CLI falls back to:
|
|
92
|
-
|
|
93
|
-
```text
|
|
94
|
-
~/.itp/credentials.json
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
The fallback file is written with `0600` permissions.
|
|
98
|
-
|
|
99
|
-
## Human Account Portal Link
|
|
100
|
-
|
|
101
|
-
After a buyer has completed first-purchase auth and the CLI has a buyer account session, an agent can create a one-time link for the human to view the ItPay account/order portal:
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
itp account login-link --host <client> --json
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
The agent should give the returned `login_url` to the human and must not open or scrape it. The portal shows the same redacted order/vault state available through buyer APIs; raw artifact reveal remains a separate human Passkey/WebAuthn flow.
|
|
108
|
-
|
|
109
|
-
## Install From npm
|
|
3
|
+
The V3 terminal and agent-facing CLI for ItPay commerce.
|
|
110
4
|
|
|
111
5
|
```bash
|
|
112
6
|
npm install -g @itpay/cli
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
##
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
-
|
|
248
|
-
-
|
|
249
|
-
-
|
|
250
|
-
-
|
|
251
|
-
-
|
|
252
|
-
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
the artifact in the ItPay account portal with Passkey and choose "Give to
|
|
260
|
-
Agent". The agent then discovers the approved grant itself:
|
|
261
|
-
|
|
262
|
-
```bash
|
|
263
|
-
itp buyer vault grants list --checkout <checkout_id> --host <client> --json
|
|
264
|
-
itp buyer vault grants read <agent_read_grant_id> --host <client> --json
|
|
265
|
-
itp buyer vault read --order <order_id> --artifact <vault_artifact_id> --host <client> --json
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
Agents must not ask humans to paste claim links, claim tokens, raw API results,
|
|
269
|
-
provider keys, or grant ids into chat.
|
|
270
|
-
|
|
271
|
-
Order/account/refund commands require a server-verified buyer session, not a
|
|
272
|
-
vault grant. If they fail with a buyer session error, run:
|
|
273
|
-
|
|
274
|
-
```bash
|
|
275
|
-
itp status --refresh --host <client> --json
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
Then follow the returned `next.command`.
|
|
279
|
-
|
|
280
|
-
## Agent Skill And Docs
|
|
281
|
-
|
|
282
|
-
Installed agents can read the buyer skill and docs graph at any time:
|
|
283
|
-
|
|
284
|
-
```bash
|
|
285
|
-
itp skill show --role buyer --json
|
|
286
|
-
itp skill path --role buyer
|
|
287
|
-
itp docs list --role buyer --json
|
|
288
|
-
itp docs show quickstart --role buyer --json
|
|
289
|
-
itp docs search "<question>" --role buyer --json
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
Repository files:
|
|
293
|
-
|
|
294
|
-
```text
|
|
295
|
-
skills/itpay-buyer/SKILL.md
|
|
296
|
-
docs/agent/buyer/*.json
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
Agents should use the buyer skill when the user asks to search, buy, pay, or receive an ItPay service.
|
|
300
|
-
|
|
301
|
-
The skill rules are strict:
|
|
302
|
-
|
|
303
|
-
- Do not invent payment links.
|
|
304
|
-
- Do not ask users to paste API keys, claim links, claim tokens, redeem codes, or raw keys into chat.
|
|
305
|
-
- Use `--json` for agent-run commands.
|
|
306
|
-
- Use UCP cart-first checkout for CORE-028 buyer tests.
|
|
307
|
-
- Treat only `payment_intent.verified` as payment success.
|
|
308
|
-
- Report secure delivery as redacted status only.
|
|
309
|
-
|
|
310
|
-
## Local Backend E2E
|
|
311
|
-
|
|
312
|
-
When a local ItPay backend is running on `http://localhost:3000`:
|
|
313
|
-
|
|
314
|
-
```bash
|
|
315
|
-
ITPAY_API_BASE=http://localhost:3000 ./e2e-local.sh
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
The E2E script uses a temporary HOME, so it does not touch your real:
|
|
319
|
-
|
|
320
|
-
```text
|
|
321
|
-
~/.itp
|
|
322
|
-
~/.codex
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
The script covers the current buyer CLI smoke path and local backend contracts.
|
|
326
|
-
|
|
327
|
-
## Development Checks
|
|
328
|
-
|
|
329
|
-
Run before committing:
|
|
330
|
-
|
|
331
|
-
```bash
|
|
332
|
-
npm run check
|
|
333
|
-
npm pack --dry-run
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
Expected `npm pack --dry-run` files:
|
|
337
|
-
|
|
338
|
-
```text
|
|
339
|
-
LICENSE
|
|
340
|
-
README.md
|
|
341
|
-
bin/itp
|
|
342
|
-
e2e-local.sh
|
|
343
|
-
install.ps1
|
|
344
|
-
install.sh
|
|
345
|
-
package.json
|
|
346
|
-
skills/itpay-buyer/SKILL.md
|
|
347
|
-
docs/agent/buyer/*.json
|
|
348
|
-
smoke.sh
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
## npm Publish
|
|
352
|
-
|
|
353
|
-
Check login:
|
|
354
|
-
|
|
355
|
-
```bash
|
|
356
|
-
npm whoami
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
If needed:
|
|
360
|
-
|
|
361
|
-
```bash
|
|
362
|
-
npm login
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
Check package name:
|
|
366
|
-
|
|
367
|
-
```bash
|
|
368
|
-
npm view @itpay/cli name
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
If the package is not published yet, npm returns a not-found error.
|
|
372
|
-
|
|
373
|
-
Publish:
|
|
374
|
-
|
|
375
|
-
```bash
|
|
376
|
-
npm publish --access public
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
Post-publish install test:
|
|
380
|
-
|
|
381
|
-
```bash
|
|
382
|
-
TMP_PREFIX=$(mktemp -d)
|
|
383
|
-
npm install -g --prefix "$TMP_PREFIX" @itpay/cli
|
|
384
|
-
"$TMP_PREFIX/bin/itp" --version
|
|
385
|
-
"$TMP_PREFIX/bin/itp" skill show --role buyer --json
|
|
386
|
-
"$TMP_PREFIX/bin/itp" docs show quickstart --role buyer --json
|
|
387
|
-
"$TMP_PREFIX/bin/itpay" --version
|
|
388
|
-
"$TMP_PREFIX/bin/itpay_cli" --version
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
## Safety and Secrets
|
|
392
|
-
|
|
393
|
-
Never commit:
|
|
394
|
-
|
|
395
|
-
```text
|
|
396
|
-
.env
|
|
397
|
-
.npmrc with auth token
|
|
398
|
-
~/.itp
|
|
399
|
-
~/.codex
|
|
400
|
-
credentials.json
|
|
401
|
-
itpay.env
|
|
402
|
-
*.pem
|
|
403
|
-
*.key
|
|
404
|
-
*.p12
|
|
405
|
-
*.pfx
|
|
406
|
-
database files
|
|
407
|
-
npm tarballs
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
The repository `.gitignore` excludes these by default, including `**/.DS_Store`.
|
|
411
|
-
|
|
412
|
-
Before pushing or publishing, run:
|
|
413
|
-
|
|
414
|
-
```bash
|
|
415
|
-
git status --short
|
|
416
|
-
npm pack --dry-run
|
|
417
|
-
npm run check
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
## Maintainer Workflow
|
|
421
|
-
|
|
422
|
-
Typical update flow:
|
|
423
|
-
|
|
424
|
-
```bash
|
|
425
|
-
git pull
|
|
426
|
-
npm run check
|
|
427
|
-
# edit bin/itp, skills/itpay-buyer/SKILL.md, or docs/agent/buyer/*.json
|
|
428
|
-
npm run check
|
|
429
|
-
npm pack --dry-run
|
|
430
|
-
git status --short
|
|
431
|
-
git add .
|
|
432
|
-
git commit -m "Describe the CLI change"
|
|
433
|
-
git push
|
|
434
|
-
```
|
|
435
|
-
|
|
436
|
-
For behavior changes, update both:
|
|
437
|
-
|
|
438
|
-
```text
|
|
439
|
-
bin/itp
|
|
440
|
-
docs/agent/buyer/*.json
|
|
441
|
-
skills/itpay-buyer/SKILL.md
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
If the backend contract changes, update:
|
|
445
|
-
|
|
446
|
-
```text
|
|
447
|
-
README.md
|
|
448
|
-
e2e-local.sh
|
|
449
|
-
docs/agent/buyer/*.json
|
|
450
|
-
skills/itpay-buyer/SKILL.md
|
|
451
|
-
```
|
|
7
|
+
itpay readyz
|
|
8
|
+
itpay docs show quickstart
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This prerelease defaults to `https://test.itpay.ai`. Set
|
|
12
|
+
`ITPAY_BACKEND_URL` only when intentionally using another backend.
|
|
13
|
+
|
|
14
|
+
## Commands
|
|
15
|
+
|
|
16
|
+
- `itpay readyz` — `GET /v1/readyz`
|
|
17
|
+
- `itpay next [--json]` — show the next recommended agent action from remembered server handles
|
|
18
|
+
- `itpay cart add --item <id> --variant <id> --offer <id> [--quantity 1] [--input <json>] [--host <host>] [--json]` — create/update the canonical server cart; service-backed lines return `service_execution_id`
|
|
19
|
+
- `itpay cart next [--json]` — show the next recommended action for the remembered canonical server cart
|
|
20
|
+
- `itpay cart add --local ...` — explicit local draft compatibility mode only, not valid for service-backed flows
|
|
21
|
+
- `itpay cart remove --line <cart_item_id>` — soft-remove an active line from the canonical server cart; quote-locked or checkout-bound lines are rejected
|
|
22
|
+
- `itpay cart remove --local --variant <id> --offer <id>` — drop a local draft line
|
|
23
|
+
- `itpay cart show` — print the canonical server cart, or local draft fallback when no server cart handle exists
|
|
24
|
+
- `itpay cart clear` — abandon the canonical server cart and clear local handles
|
|
25
|
+
- `itpay cart clear --local` — clear local handles/draft only
|
|
26
|
+
- `itpay buy --cart <cart_id> --host <host> [--target <target>] [--qr-format ...] [--qr-file <path>]` — create checkout from a canonical server cart and render the branded checkout QR for the host
|
|
27
|
+
- `itpay buy --host <host> [--target <target>] [--item ... --variant ... --offer ...] [--quantity 1]` — compatibility one-shot cart + checkout path
|
|
28
|
+
- `itpay services start <service_id>` — start a generic Service Execution run
|
|
29
|
+
- `itpay services invoke <service_execution_id> --capability <capability_id> --input key=value` — invoke an agent-visible capability
|
|
30
|
+
- `itpay services action <service_execution_id> --action <action_type> [--result-item <id>]` — record a human/agent service action
|
|
31
|
+
- `itpay services checkout <service_execution_id> --capability <capability_id> --email <email> [--host <host>] [--json]` — create quote lock from Service Execution state, bind it to the server cart item when present, persist the handoff, and render the branded ItPay checkout
|
|
32
|
+
- `itpay services checkout <service_execution_id> --resume --json` — reissue a lost or expired handoff for the same unpaid checkout without asking for contact information again
|
|
33
|
+
- `itpay services next <service_execution_id> [--json]` — show the next recommended action from the Service Execution read model
|
|
34
|
+
- `itpay services get <service_execution_id>` / `itpay services events <service_execution_id>` — read the redacted Service Execution timeline
|
|
35
|
+
- `itpay checkout --id <checkout_id> --token <display_token>` — read canonical checkout presentation
|
|
36
|
+
- `itpay pay --checkout <id> --method alipay|wechatpay` — CLI escape hatch for operator/manual testing only; normal buyer flow opens the ItPay checkout page first
|
|
37
|
+
- `itpay order <order_id>` — read one V3 order
|
|
38
|
+
- `itpay orders [--limit 20] [--status <status>]` — list account-scoped orders (requires `ITPAY_BEARER_TOKEN`)
|
|
39
|
+
- `itpay refund --order <id> --payment-intent <id> --amount-minor <n> --currency <code>` — request a refund
|
|
40
|
+
|
|
41
|
+
## Hosts
|
|
42
|
+
|
|
43
|
+
The CLI dispatches to a per-host renderer based on `--host`:
|
|
44
|
+
|
|
45
|
+
| `--host` | Renderer | Native UI |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| `terminal` | `render/terminal.ts` | terminal QR + summary |
|
|
48
|
+
| `codex`, `claude-code` | `render/markdown.ts` | markdown image + links |
|
|
49
|
+
| `telegram` | `render/telegram.ts` | openclaw `message send` with inline buttons |
|
|
50
|
+
| `feishu`, `lark` | `render/feishu.ts` | Feishu/Lark interactive card (url + callback) |
|
|
51
|
+
| `discord`, `whatsapp`, `plain-chat` | `render/plain_chat.ts` | text + links, no native buttons |
|
|
52
|
+
|
|
53
|
+
Aliases: `tg` and `openclaw-telegram` map to `telegram`; `feishu_im` and `fs` map to `feishu`.
|
|
54
|
+
|
|
55
|
+
## Environment
|
|
56
|
+
|
|
57
|
+
- `ITPAY_BACKEND_URL` — optional backend override (prerelease default `https://test.itpay.ai`)
|
|
58
|
+
- `ITPAY_BEARER_TOKEN` — account-scoped session token (only needed for `orders`)
|
|
59
|
+
- `ITPAY_AGENT_DEVICE_ID` — agent device id, used for cart/service execution quota identity and `client_context`
|
|
60
|
+
- `ITPAY_CURRENCY` — checkout currency (default `CNY`)
|
|
61
|
+
- `ITPAY_IDEMPOTENCY_KEY` — `Idempotency-Key` for pay/refund requests (auto-generated if unset)
|
|
62
|
+
- `ITPAY_IDE_IMAGE_ATTACH` — set to `0` to disable the IDE image-attach contract (e.g. read-only runner FS). Default `1`.
|
|
63
|
+
- `ITPAY_IDE_IMAGE_DIR_OVERRIDE` — override the canonical IDE image directory instead of `$TMPDIR/itpay-v3-qr`. Useful when the IDE file panel only knows one path.
|
|
64
|
+
|
|
65
|
+
## Agent next actions
|
|
66
|
+
|
|
67
|
+
Service-backed flows return progressive guidance for agents:
|
|
68
|
+
|
|
69
|
+
- `itpay cart add --json`, `itpay services start`, `itpay services invoke`,
|
|
70
|
+
`itpay services action`, `itpay services get`, and
|
|
71
|
+
`itpay services checkout --json` include top-level `next_actions`.
|
|
72
|
+
- `itpay next`, `itpay cart next`, and `itpay services next <id>` print only
|
|
73
|
+
the next recommended command and recovery commands.
|
|
74
|
+
- The guidance is derived from server cart and Service Execution read models.
|
|
75
|
+
Local `~/.itpay-v3/cart.json` only stores handles such as `cart_id`,
|
|
76
|
+
`service_execution_id`, `checkout_id`, and `display_token`.
|
|
77
|
+
|
|
78
|
+
Agents should prefer `next_actions` over hardcoded service-specific flows.
|
|
79
|
+
For example, a service-backed cart add can return an invoke command for an
|
|
80
|
+
agent-visible free capability, while a quote-locked execution can return the
|
|
81
|
+
checkout handoff command.
|
|
82
|
+
|
|
83
|
+
## IDE image attach
|
|
84
|
+
|
|
85
|
+
Every `itpay buy`, `itpay services checkout` (and `itpay checkout`,
|
|
86
|
+
`itpay order`) downloads the
|
|
87
|
+
brand checkout QR from the backend and writes it to a stable local
|
|
88
|
+
file the agent can hand to the IDE image viewer (Trae `Read` tool,
|
|
89
|
+
Codex, Claude Code). The contract is:
|
|
90
|
+
|
|
91
|
+
- canonical file: `<os.tmpdir()>/itpay-v3-qr/itpay-v3-<kind>-<id>.png`
|
|
92
|
+
(override with `ITPAY_IDE_IMAGE_DIR_OVERRIDE`)
|
|
93
|
+
- when `/tmp/itpay-v3-qr` is a separate, writable location it gets a
|
|
94
|
+
mirror of the same file under the same name
|
|
95
|
+
- filename is stable per checkout, so re-runs overwrite the same
|
|
96
|
+
local file rather than scattering copies across the scratch dir
|
|
97
|
+
|
|
98
|
+
Outputs that carry the IDE image attach:
|
|
99
|
+
|
|
100
|
+
- `itpay buy --json` — fields `brand_qr_local_path`, `brand_qr_mirrors`,
|
|
101
|
+
`brand_qr_stable_name`, `brand_qr_status` (`downloaded` / `failed`
|
|
102
|
+
/ `disabled` / `fallback`), `brand_qr_error`, `brand_qr_data_url`,
|
|
103
|
+
`brand_qr_must_render_reason`, `brand_qr_render_action`. Read the
|
|
104
|
+
path with the IDE's `Read` tool so the human sees the picture.
|
|
105
|
+
- `itpay services checkout --json` — same brand QR fields, plus
|
|
106
|
+
`next_action: "open_human_checkout"` and the checkout-scoped
|
|
107
|
+
`display_token`. Agents must show this ItPay checkout QR/URL to the
|
|
108
|
+
human and must not call `itpay pay` for the normal buyer flow.
|
|
109
|
+
- Markdown (Trae / Codex / Claude Code) — inlines a `data:image/png;base64,...`
|
|
110
|
+
copy of the picture plus a `[ATTACH] IDE image` reference block that
|
|
111
|
+
points at the canonical local path and mirrors.
|
|
112
|
+
- Terminal — prints `Branded QR: /path/...png` and `QR mirrors: ...`;
|
|
113
|
+
iTerm inline image renders the same file when the session supports it.
|
|
114
|
+
- Telegram — the `ide_image_attach` block on `presentation.ide_image_attach`
|
|
115
|
+
carries `status`, `local_path`, `mirrors`, `mime_type`, `source`,
|
|
116
|
+
`caption`, `error` (when failed), `must_render_reason`, and a
|
|
117
|
+
step-by-step `instructions` array.
|
|
118
|
+
- Feishu / Lark — same `ide_image_attach` block on the
|
|
119
|
+
`message.ide_image_attach` envelope.
|
|
120
|
+
|
|
121
|
+
Disable the contract with `ITPAY_IDE_IMAGE_ATTACH=0` for runners on a
|
|
122
|
+
read-only filesystem. The plan carries `status: "disabled"` instead
|
|
123
|
+
of `status: "downloaded"` and no PNG is downloaded.
|
|
124
|
+
|
|
125
|
+
## Layout
|
|
126
|
+
|
|
127
|
+
- `src/main.ts` — `commander` entrypoint, command registration
|
|
128
|
+
- `src/client/` — HTTP/JSON client and DTOs
|
|
129
|
+
- `src/commands/` — one file per command family
|
|
130
|
+
- `src/render/` — terminal formatting
|
|
131
|
+
- `plan.ts` — `RenderPlan` contract shared by all renderers
|
|
132
|
+
- `qr.ts` — local QR + format selection
|
|
133
|
+
- `terminal.ts`, `markdown.ts`, `plain_chat.ts`, `telegram.ts`, `feishu.ts` — per-host renderers
|
|
134
|
+
- `index.ts` — `dispatchRender()` picks the right renderer
|
|
135
|
+
- `sink.ts` — `OutputSink` so tests can silence stdout
|
|
136
|
+
- `src/state/` — local CLI config, cart session, client context
|
|
137
|
+
- `tests/` — node:test smoke test + in-process mock backend
|
|
138
|
+
|
|
139
|
+
## Rules
|
|
140
|
+
|
|
141
|
+
- commands orchestrate user intent only
|
|
142
|
+
- render code must not issue HTTP calls
|
|
143
|
+
- keep API access under `src/client/`
|
|
144
|
+
- persist checkout-scoped `display_token` and last server handles only in the owner-only local cart session file
|
|
145
|
+
- the default `buy` command must not create a payment intent unless `--pay` is explicit
|
|
146
|
+
- the default `services checkout` command must render the ItPay
|
|
147
|
+
checkout handoff; provider payment intents are created by the human
|
|
148
|
+
checkout page, not by the agent
|
|
149
|
+
- a renderer must consume the brand QR the V3 backend hands back
|
|
150
|
+
(`qr_payload` / `qr_png_url` / `mobile_wallet_url`) and only
|
|
151
|
+
self-generate a QR for `auth_qr` / `checkout_qr` with the explicit
|
|
152
|
+
`--qr-file` opt-in
|