@itpay/cli 0.1.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.
@@ -0,0 +1,603 @@
1
+ ---
2
+ name: voltagent
3
+ description: >
4
+ Use VoltaGent when the user asks an AI agent to buy, recharge, configure,
5
+ install, test, diagnose, or use an ITPay/VoltaGent model package for Codex,
6
+ Claude Code, or OpenClaw. This skill is an executable runbook for the `itp`
7
+ CLI.
8
+ ---
9
+
10
+ # VoltaGent / ITPay Agent Runbook
11
+
12
+ Compatibility note: for current ItPay buyer commerce tests, prefer the
13
+ role-specific buyer skill:
14
+
15
+ ```bash
16
+ itp skill show --role buyer --json
17
+ itp docs show quickstart --role buyer --json
18
+ ```
19
+
20
+ This legacy VoltaGent runbook remains for model-package setup compatibility.
21
+
22
+ You are helping the user obtain and install a VoltaGent model package through
23
+ the `itp` CLI. Follow this file as a runbook. Do not improvise payment or
24
+ credential handling.
25
+
26
+ ## Non-Negotiable Rules
27
+
28
+ 1. Use `--json` for every `itp` command when acting as an agent.
29
+ 2. Never ask the user to paste API keys, session tokens, grant credentials, or
30
+ raw secrets into chat.
31
+ 3. Never print API keys, session tokens, grant credentials, or raw payment
32
+ payloads.
33
+ 4. Never pass passwords in command-line arguments. Use `--password-stdin`.
34
+ 5. Do not invent payment links, QR codes, checkout IDs, order IDs, or grant IDs.
35
+ 6. Do not modify, shorten, summarize, re-encode, or rewrite Alipay payment QR URLs.
36
+ For ItPay Core sandbox payment responses, render `local_qr_path` when present,
37
+ then `qr_png_url` / `preferred_qr_url`, and use `qr_image_url` only as fallback.
38
+ These are ItPay-hosted human QR images and may render native provider payment
39
+ codes for scanner reliability; do not request, decode, or expose the raw
40
+ provider payload. Do not turn `payment_entry_url` or `mobile_wallet_url` into
41
+ a QR code.
42
+ 7. Do not trust "I paid" as proof of payment.
43
+ 8. Only `itp setup --json` returning `status=grant_ready` / `status=installed`, or `itp payment wait
44
+ <checkout_id> --json` returning `status=grant_issued` / `status=grant_installed`
45
+ with a `grant_id`, means credential delivery may proceed.
46
+ 9. If a command fails, report the failed command and safe error message. Do not
47
+ dump local credential files.
48
+ 10. Prefer continuing from existing orders/grants over creating duplicate
49
+ checkouts.
50
+ 11. Always check recoverable local state with `itp status --json` before
51
+ starting a new setup.
52
+ 12. If `status` returns a `run_id` and a `next.command`, resume that run unless
53
+ the user explicitly asks to abandon it.
54
+ 13. Use `human_action.presentation`, `local_qr_path`, or `qr_png_url` to show
55
+ Alipay auth/payment QR codes in the current host. If the user is on mobile,
56
+ present `mobile_wallet_url` as a clickable human-only fallback. Do not ask
57
+ the user to copy checkout IDs or grant IDs.
58
+ 14. Showing a QR code is not completion. After showing auth or payment QR, keep
59
+ waiting by leaving `setup` running or immediately executing the returned
60
+ `next.command` until `status=grant_ready` / `status=installed` or a
61
+ terminal failure.
62
+ 15. Do not use `--method fake`, `--mock-approve`, or `--offline` for local,
63
+ sandbox, or live payment testing. "Local test", "sandbox", and "test with
64
+ Alipay sandbox" all still mean `--method alipay`. Only use fake/mock/offline
65
+ when the user literally asks for "fake", "mock", or "offline simulation".
66
+
67
+ ## Target Selection
68
+
69
+ For API-only purchase/setup, use the default `generic` target and do not ask
70
+ the user which runtime they use.
71
+
72
+ Choose a specific target only when the user explicitly wants runtime config
73
+ written by the CLI:
74
+
75
+ ```text
76
+ codex
77
+ claude-code
78
+ openclaw
79
+ ```
80
+
81
+ Selection rules:
82
+
83
+ - If the user names Codex, use `codex`.
84
+ - If the user names Claude Code, use `claude-code`.
85
+ - If the user names OpenClaw, use `openclaw`.
86
+ - If the environment clearly identifies the current agent runtime, use that.
87
+ - If unclear and runtime config writing was requested, ask one short question:
88
+ "安装到 Codex、Claude Code 还是 OpenClaw?"
89
+
90
+ ## API Endpoint
91
+
92
+ Use the existing environment if present:
93
+
94
+ ```bash
95
+ echo "$VOLTAGENT_API_BASE"
96
+ ```
97
+
98
+ If it is empty, use the CLI default. For local development this is:
99
+
100
+ ```text
101
+ http://localhost:3000
102
+ ```
103
+
104
+ For the current Oracle test deployment the endpoint is:
105
+
106
+ ```text
107
+ http://147.224.54.65:3000
108
+ ```
109
+
110
+ Do not hardcode the Oracle endpoint unless the user explicitly asks to use it
111
+ or the local context already exports `VOLTAGENT_API_BASE`.
112
+
113
+ ## Credential Storage
114
+
115
+ Do not trigger interactive OS keychain prompts while acting as an agent. In
116
+ non-interactive hosts the CLI defaults to file-backed storage. If the current
117
+ host still exposes a system keychain prompt, rerun with:
118
+
119
+ ```bash
120
+ ITP_CREDENTIAL_STORE=file itp setup --plan credit-300 --method alipay --json
121
+ ```
122
+
123
+ or set `ITP_CREDENTIAL_STORE=file` for all subsequent `itp` commands in the
124
+ same run.
125
+
126
+ ## Quick Health Check
127
+
128
+ ```bash
129
+ itp --version
130
+ itp status --json
131
+ itp auth status --json
132
+ itp plans --json
133
+ ```
134
+
135
+ If `itp` is missing, ask the user to install the npm package:
136
+
137
+ ```bash
138
+ npm install -g itpay_cli
139
+ ```
140
+
141
+ or use:
142
+
143
+ ```bash
144
+ npx itpay_cli --version
145
+ ```
146
+
147
+ ## One-Command Setup
148
+
149
+ Before creating a new checkout, inspect the current recoverable run:
150
+
151
+ ```bash
152
+ itp status --json
153
+ ```
154
+
155
+ If this returns an unfinished `run_id`, continue with:
156
+
157
+ ```bash
158
+ itp resume --run-id <run_id> --json
159
+ ```
160
+
161
+ Do not create a fresh checkout unless the previous run is done, failed beyond
162
+ recovery, or the user explicitly asks to start over.
163
+
164
+ For a normal purchase/API credential request, prefer the high-level setup
165
+ command:
166
+
167
+ ```bash
168
+ itp setup --credits <credits> --method alipay --json
169
+ ```
170
+
171
+ This command checks the current session, starts Alipay device authentication if
172
+ needed, creates the checkout, waits for verified payment, installs the grant
173
+ credential into the local `itp` credential store, and returns base URL fields.
174
+ It does not write Codex/Claude/OpenClaw config by default. If it returns
175
+ `status=grant_ready`, report the returned base URL fields and stop.
176
+
177
+ Use `--plan <plan_id>` instead of `--credits` only after the user chooses one
178
+ of the fixed credit plans below.
179
+
180
+ For Gemini CLI, Gemini terminal shell, or any host where the shell panel is
181
+ folded, jumpy, or hard for the user to scan, do not render the QR in the shell
182
+ panel. Ask the CLI to return a text QR in JSON, then paste
183
+ `human_action.agent_text_qr.fenced_text` verbatim in your normal assistant
184
+ message:
185
+
186
+ ```bash
187
+ itp setup --plan <plan_id> --method alipay --host gemini --display chat --json
188
+ ```
189
+
190
+ For authentication-only flows in Gemini CLI:
191
+
192
+ ```bash
193
+ itp auth register --host gemini --display chat --no-wait --json
194
+ ```
195
+
196
+ When using `--display chat`, the shell will not show a QR. You must copy every
197
+ byte of `human_action.agent_text_qr.fenced_text` into the normal chat reply,
198
+ then tell the user to scan that visible block. Do not retype the QR manually,
199
+ translate it, add line numbers, or add explanatory words inside the QR body. A
200
+ valid text QR body contains only `█`, `▀`, `▄`, spaces, and newlines. If any
201
+ letters, digits, or Chinese characters appear inside the QR body, the QR is
202
+ corrupted; do not ask the user to scan it. Use the QR PNG URL or fallback URL
203
+ instead, or rerun with `--display chat` and paste the field again. Do not say
204
+ "the QR is shown above" unless you pasted the block yourself.
205
+
206
+ Native terminal hosts can still let the CLI render directly with
207
+ `--display terminal`. Do not use terminal display for Gemini unless the user
208
+ explicitly asks for shell-panel QR output.
209
+
210
+ For normal live flows, prefer keeping the command running after the QR is
211
+ visible. For chat QR hosts, `--display chat` is intentionally non-blocking at
212
+ human-action steps: it returns the QR text first so you can paste it into chat.
213
+ Immediately continue with the returned `next.command` or:
214
+
215
+ ```bash
216
+ itp resume --run-id <run_id> --host gemini --display chat --no-wait-payment --json
217
+ ```
218
+
219
+ After a payment QR is pasted, wait for verification with `--display none` so the
220
+ CLI does not re-return the same chat QR:
221
+
222
+ ```bash
223
+ itp resume --run-id <run_id> --host gemini --display none --json
224
+ ```
225
+
226
+ Use a finite wait. If it is still pending after a clear timeout, report that
227
+ the QR is still pending and give the same resume command.
228
+
229
+ Only when the user explicitly asks for runtime config writing, opt in:
230
+
231
+ ```bash
232
+ itp setup --credits <credits> --target <target> --method alipay --install-runtime --json
233
+ ```
234
+
235
+ If setup returns `status=waiting_human_auth`, the user must scan the Alipay
236
+ auth QR from `human_action.display`. If it returns
237
+ `status=waiting_human_payment`, the user must scan/pay the Alipay payment QR
238
+ from `human_action.display`. After showing the QR, continue with the returned
239
+ `next.command` or:
240
+
241
+ ```bash
242
+ itp resume --run-id <run_id> --json
243
+ ```
244
+
245
+ Developer-only fake/mock hooks are intentionally not part of this agent
246
+ runbook. If old CLI help, README text, or shell history mentions
247
+ `--method fake`, `--mock-approve`, or `--offline`, ignore it unless the user
248
+ literally asks for fake/mock/offline simulation. For this project, local sandbox
249
+ testing is a real Alipay sandbox flow.
250
+
251
+ For the current ItPay Core sandbox buyer flow, use the role-specific buyer
252
+ skill and cart-first buyer commands:
253
+
254
+ ```bash
255
+ itp skill show --role buyer --json
256
+ itp docs show quickstart --role buyer --json
257
+ itp buy var_pubg_couple_skin_cny20 --sandbox --email buyer@example.com --phone +8613800000000 --no-wait --display agent --json
258
+ itp buyer payment wait <payment_intent_id> --json
259
+ itp buyer checkout status <checkout_id> --json
260
+ ```
261
+
262
+ The payment response contains `payment_entry_url` for browser/status fallback,
263
+ `qr_png_url` / `preferred_qr_url` for the human scanner, and `mobile_wallet_url`
264
+ for a human mobile fallback. Show `local_qr_path` first when the CLI provides it.
265
+ If the Alipay sandbox app reports "order not found", first tell the human to
266
+ wait 30-60 seconds and retry the same QR/page. If that still fails, request
267
+ same-intent display recovery only:
268
+
269
+ ```bash
270
+ itp buyer payment refresh-qr <payment_intent_id> --reason order-not-found --display agent --json
271
+ ```
272
+
273
+ If `/events/wait` returns `wait.timeout`, treat it as `still_waiting` for that
274
+ long-poll cycle and keep waiting until the overall command timeout or a verified
275
+ payment event. Do not use ops-only commands unless the user explicitly asks for
276
+ operator testing and provides the sandbox ops environment.
277
+
278
+ ## Login / Registration
279
+
280
+ Use this section only if setup needs to be performed manually.
281
+
282
+ Check auth:
283
+
284
+ ```bash
285
+ itp auth status --json
286
+ ```
287
+
288
+ If `authenticated=true`, continue.
289
+
290
+ If not authenticated, start the Alipay-bound device auth flow:
291
+
292
+ ```bash
293
+ itp auth register --runtime <target> --json
294
+ ```
295
+
296
+ The CLI prints the Alipay verification URL and user code to stderr, keeps
297
+ polling, and stores the returned session after the user scans and approves.
298
+ Do not ask the user to paste credentials. The returned JSON includes the saved
299
+ `username`; if the user wants password login later, tell them that username.
300
+
301
+ Do not use mock approval for local sandbox authentication. The user must scan
302
+ the Alipay sandbox auth QR.
303
+
304
+ If the user asks to log into an existing account:
305
+
306
+ ```bash
307
+ printf '<password>\n' | itp auth login --username <username> --password-stdin --runtime <target> --json
308
+ ```
309
+
310
+ Never use `--password`.
311
+
312
+ ## First Web Password
313
+
314
+ For a newly registered passwordless account, set the first Web login password
315
+ only if the user asks for Web login access:
316
+
317
+ ```bash
318
+ printf '<password>\n' | itp account set-password --password-stdin --json
319
+ ```
320
+
321
+ Then verify:
322
+
323
+ ```bash
324
+ itp account show --json
325
+ ```
326
+
327
+ Expected: `password_set=true`.
328
+
329
+ ## Plan Selection
330
+
331
+ List plans:
332
+
333
+ ```bash
334
+ itp plans --json
335
+ ```
336
+
337
+ Credit unit rule:
338
+
339
+ ```text
340
+ 1 credit = 1 CNY
341
+ ```
342
+
343
+ Custom recharge:
344
+
345
+ ```text
346
+ minimum 20 credits, integers only, no discount
347
+ ```
348
+
349
+ Fixed plans:
350
+
351
+ ```text
352
+ credit-100: pay 98 CNY, receive 100 credits
353
+ credit-300: pay 285 CNY, receive 300 credits (recommended)
354
+ credit-500: pay 460 CNY, receive 500 credits
355
+ ```
356
+
357
+ If the user says an exact CNY or credit amount, use `--credits <amount>` when
358
+ the amount is an integer >= 20. If the user asks for "a plan", "best value", or
359
+ does not specify an amount, summarize the three fixed plans and recommend
360
+ `credit-300`, then ask for confirmation before checkout.
361
+
362
+ Never use the disabled legacy `coding-100` plan.
363
+
364
+ ## Checkout
365
+
366
+ Production/default payment:
367
+
368
+ ```bash
369
+ itp checkout create --credits <credits> --method alipay --json
370
+ ```
371
+
372
+ Use a stable idempotency key when retrying the same user request. Do not create
373
+ multiple orders for the same request. Do not use fake payment for local or
374
+ sandbox Alipay testing.
375
+
376
+ If the checkout response contains `human_action.display`:
377
+
378
+ 1. Select the best display candidate for the current host.
379
+ 2. Discord: send the QR PNG as an attachment, preferably ephemeral or DM.
380
+ 3. Telegram: send the QR PNG with `sendPhoto`, with URL button fallback.
381
+ 4. WhatsApp: send the QR PNG as an image media message or media ID.
382
+ 5. Native terminal: let the CLI render the QR, or use `--display terminal`.
383
+ 6. Gemini CLI / folded agent shell: use `--host gemini --display chat`; paste
384
+ `human_action.agent_text_qr.fenced_text` exactly in the normal assistant
385
+ reply, not inside the shell panel. If the rendered QR body contains any
386
+ non-QR characters such as Chinese words, letters, digits, or line numbers,
387
+ treat it as corrupted and use the QR PNG URL or `fallback_text` visibly.
388
+ If `fenced_text` is absent, use the QR PNG URL and `fallback_text` visibly.
389
+ 7. Continue waiting through `itp resume --run-id <run_id> --json` or
390
+ `itp payment wait <checkout_id> --json`.
391
+
392
+ If an older checkout response only contains `payment.cashier_url`:
393
+
394
+ 1. Preserve the URL exactly.
395
+ 2. Show it as a legacy fallback. Do not rewrite it.
396
+ 3. Continue waiting through the backend status; never trust a manual "paid"
397
+ message.
398
+
399
+ If the checkout response already contains `grant_id` and `status=grant_issued`,
400
+ continue directly to grant install.
401
+
402
+ ## Payment Wait / Recovery
403
+
404
+ First prefer the run-aware resume command:
405
+
406
+ ```bash
407
+ itp resume --run-id <run_id> --json
408
+ ```
409
+
410
+ Wait for verified payment:
411
+
412
+ ```bash
413
+ itp payment wait <checkout_id> --timeout 120 --json
414
+ ```
415
+
416
+ If local state is lost or checkout ID is unknown:
417
+
418
+ ```bash
419
+ itp checkout list --limit 20 --json
420
+ ```
421
+
422
+ Pick the latest relevant checkout for the current account and continue waiting
423
+ or recovering. Do not create a duplicate checkout unless the user clearly asks.
424
+
425
+ Successful statuses:
426
+
427
+ ```text
428
+ grant_issued
429
+ grant_installed
430
+ ```
431
+
432
+ Failure or stop statuses:
433
+
434
+ ```text
435
+ expired
436
+ payment_failed
437
+ verify_failed
438
+ amount_mismatch
439
+ grant_failed
440
+ revoked
441
+ ```
442
+
443
+ If status is `grant_failed`, run:
444
+
445
+ ```bash
446
+ itp checkout recover <checkout_id> --json
447
+ itp payment wait <checkout_id> --timeout 120 --json
448
+ ```
449
+
450
+ If the agent loses local context, run:
451
+
452
+ ```bash
453
+ itp status --refresh --json
454
+ itp runs list --json
455
+ ```
456
+
457
+ Use the latest unfinished run or checkout instead of creating a duplicate.
458
+
459
+ ## Grant Install
460
+
461
+ Install the grant credential locally:
462
+
463
+ ```bash
464
+ itp grants install <grant_id> --target <target> --json
465
+ ```
466
+
467
+ Expected safe output includes:
468
+
469
+ ```text
470
+ grant_id
471
+ base_url
472
+ openai_base_url
473
+ anthropic_base_url
474
+ gemini_base_url
475
+ credential.stored=true
476
+ credential.credential_store
477
+ models
478
+ install_profiles
479
+ ```
480
+
481
+ Do not print the actual gateway key.
482
+
483
+ For Discord, Telegram, WhatsApp, or any persistent chat host, do not send the
484
+ raw gateway key into chat. Store it in the agent's vault if one exists, or
485
+ return the safe base URL and local credential status. Use
486
+ `itp token issue --grant <grant_id> --stdout` only as a local token helper for
487
+ the runtime that needs the key.
488
+
489
+ ## Optional Runtime Config Install
490
+
491
+ Install into the selected runtime only when the user explicitly asks:
492
+
493
+ ```bash
494
+ itp install <target> --grant <grant_id> --json
495
+ ```
496
+
497
+ By default this performs a `/models` connectivity check and reports an
498
+ install-ack to the backend.
499
+
500
+ Use offline mode only when the user explicitly wants local file writing without
501
+ network checks:
502
+
503
+ ```bash
504
+ itp install <target> --grant <grant_id> --offline --no-test --json
505
+ ```
506
+
507
+ Use no-test mode when the backend should record the installation but model
508
+ connectivity should be skipped:
509
+
510
+ ```bash
511
+ itp install <target> --grant <grant_id> --no-test --json
512
+ ```
513
+
514
+ ## Diagnosis
515
+
516
+ If install reports `model_check.ok=false` or the runtime cannot use the model:
517
+
518
+ ```bash
519
+ itp doctor --target <target> --grant <grant_id> --json
520
+ ```
521
+
522
+ Also check:
523
+
524
+ ```bash
525
+ itp balance --json
526
+ itp usage --grant <grant_id> --json
527
+ itp grants show <grant_id> --json
528
+ ```
529
+
530
+ ## Balance / Usage
531
+
532
+ Show safe account state:
533
+
534
+ ```bash
535
+ itp balance --json
536
+ itp usage --grant <grant_id> --json
537
+ ```
538
+
539
+ Do not expose raw tokens.
540
+
541
+ ## Key Rotation / Revoke
542
+
543
+ Rotate grant key:
544
+
545
+ ```bash
546
+ itp keys rotate --grant <grant_id> --json
547
+ ```
548
+
549
+ After rotation, reinstall runtime config if needed:
550
+
551
+ ```bash
552
+ itp install <target> --grant <grant_id> --json
553
+ ```
554
+
555
+ Revoke grant:
556
+
557
+ ```bash
558
+ itp grants revoke <grant_id> --json
559
+ ```
560
+
561
+ ## Final User Report
562
+
563
+ Report only safe fields:
564
+
565
+ ```text
566
+ target
567
+ account username if newly created
568
+ plan_id
569
+ checkout_id
570
+ grant_id
571
+ grant status
572
+ runtime install status if explicitly requested
573
+ model_check status
574
+ base_url
575
+ available model names
576
+ credits remaining
577
+ Web console URL
578
+ ```
579
+
580
+ Never include:
581
+
582
+ ```text
583
+ session_token
584
+ gateway API key
585
+ raw credential JSON
586
+ raw payment notify payload
587
+ local credential file contents
588
+ ```
589
+
590
+ ## Root/Admin Operations
591
+
592
+ Use these only when the user explicitly asks for root/admin troubleshooting and
593
+ provides a root access token through a safe local mechanism:
594
+
595
+ ```bash
596
+ itp admin orders --json --access-token <root_token> --new-api-user <id>
597
+ itp admin payment-events --json --access-token <root_token> --new-api-user <id>
598
+ itp admin outbox --json --access-token <root_token> --new-api-user <id>
599
+ itp admin process-outbox --json --access-token <root_token> --new-api-user <id>
600
+ itp admin recover-order <order_id> --json --access-token <root_token> --new-api-user <id>
601
+ ```
602
+
603
+ Do not expose raw payment payloads or credentials in troubleshooting output.