@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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tu-Zhenzhao
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,617 @@
1
+ # ITPay CLI
2
+
3
+ Open-source command line client, buyer skill, and agent-readable docs for ItPay agent-native commerce.
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, and create one-time human account portal links without exposing raw keys or protected content to the agent. Legacy VoltaGent model-package setup remains available.
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 legacy API endpoint:
35
+
36
+ ```text
37
+ http://localhost:3000
38
+ ```
39
+
40
+ Override it for ItPay staging or production:
41
+
42
+ ```bash
43
+ export ITPAY_API_BASE=https://your-itpay-core.example.com
44
+ export ITPAY_CORE_BASE_URL=https://your-itpay-core.example.com
45
+ export VOLTAGENT_API_BASE=https://your-api.example.com
46
+ ```
47
+
48
+ ## Repository Layout
49
+
50
+ ```text
51
+ .
52
+ ├── bin/itp # Node.js CLI entrypoint
53
+ ├── skills/itpay-buyer/SKILL.md # Buyer agent quick-start skill
54
+ ├── skills/voltagent/SKILL.md # Legacy VoltaGent compatibility 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 setup --credits 100 --method alipay --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 --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
110
+
111
+ After publishing:
112
+
113
+ ```bash
114
+ npm install -g itpay_cli
115
+ ```
116
+
117
+ Verify all command aliases:
118
+
119
+ ```bash
120
+ itp --version
121
+ itpay --version
122
+ itpay_cli --version
123
+ ```
124
+
125
+ Run without installing globally:
126
+
127
+ ```bash
128
+ npx itpay_cli --version
129
+ ```
130
+
131
+ ## Agent First Step
132
+
133
+ If you are an AI agent, read the packaged buyer skill before searching,
134
+ creating carts, asking the user to pay, or reporting delivery:
135
+
136
+ ```bash
137
+ itp skill show --role buyer --json
138
+ ```
139
+
140
+ Then load the quickstart docs page:
141
+
142
+ ```bash
143
+ itp docs show quickstart --role buyer --json
144
+ ```
145
+
146
+ If confused, search the agent docs instead of guessing:
147
+
148
+ ```bash
149
+ itp docs search "<question>" --role buyer --json
150
+ ```
151
+
152
+ The skill is a quick-start directory and safety boundary. Detailed flow guidance
153
+ lives in `itp docs ... --role buyer --json`. Each docs page contains
154
+ `next_docs`, so an agent can read one small guide, act, then load the next guide
155
+ from the current state.
156
+
157
+ Before starting a new purchase, agents should inspect recoverable local state:
158
+
159
+ ```bash
160
+ itp status --json
161
+ ```
162
+
163
+ If an unfinished run exists, continue it:
164
+
165
+ ```bash
166
+ itp resume --run-id <run_id> --json
167
+ ```
168
+
169
+ ## Install From This Repo
170
+
171
+ ```bash
172
+ git clone <this-repo-url>
173
+ cd itpay_cli
174
+ npm run check
175
+ ```
176
+
177
+ User-level install:
178
+
179
+ ```bash
180
+ ./install.sh
181
+ ```
182
+
183
+ Or use the script directly:
184
+
185
+ ```bash
186
+ node ./bin/itp --version
187
+ ```
188
+
189
+ ## Basic User Flow
190
+
191
+ Set API endpoint if not using local backend:
192
+
193
+ ```bash
194
+ export VOLTAGENT_API_BASE=https://your-api.example.com
195
+ ```
196
+
197
+ For the agent-native one-command flow, let the CLI authenticate, create the
198
+ checkout, wait for verified payment, and deliver the grant/API credential to
199
+ the local `itp` credential store:
200
+
201
+ ```bash
202
+ itp setup --credits 100 --method alipay --json
203
+ ```
204
+
205
+ This returns `status=grant_ready` with `base_url`, `openai_base_url`, and the
206
+ local token helper command. It does not write Codex, Claude Code, or OpenClaw
207
+ config by default.
208
+
209
+ Runtime config writing is opt-in:
210
+
211
+ ```bash
212
+ itp setup --credits 100 --target codex --method alipay --install-runtime --json
213
+ ```
214
+
215
+ With `--no-wait`, setup returns `status=waiting_human_auth` before checkout if
216
+ the machine has no valid session, or `status=waiting_human_payment` after
217
+ checkout creation when a payment scan is still required.
218
+
219
+ QR display is automatic in terminals and machine-readable for chat agents:
220
+
221
+ ```bash
222
+ itp setup --credits 100 --method alipay --display auto --json
223
+ ITP_HOST=discord itp setup --credits 100 --method alipay --display json --json
224
+ ITP_HOST=telegram itp setup --credits 100 --method alipay --display json --json
225
+ ITP_HOST=whatsapp itp setup --credits 100 --method alipay --display json --json
226
+ ```
227
+
228
+ When interrupted, recover without creating a duplicate checkout:
229
+
230
+ ```bash
231
+ itp status --refresh --json
232
+ itp resume --json
233
+ ```
234
+
235
+ Local and sandbox payment tests use real Alipay sandbox credentials and
236
+ `--method alipay`. Fake/mock/offline flows are developer-only simulation hooks
237
+ and are intentionally omitted from the normal user flow.
238
+
239
+ For the ItPay sandbox buyer flow, agents should use the public buyer commands:
240
+
241
+ ```bash
242
+ itp buyer catalog search --query "吃鸡 情侣皮肤" --json
243
+ itp buyer cart create --variant var_pubg_couple_skin_cny20 --json
244
+ itp buyer cart create --variants var_itpay_enterprise_precise_lookup_cny05,var_itpay_enterprise_fuzzy_search_cny01 --quantities 1,1 --json
245
+ itp buyer cart show <cart_id> --json
246
+ itp buyer cart add <cart_id> --variant var_itpay_enterprise_fuzzy_search_cny01 --quantity 1 --json
247
+ itp buyer cart remove <cart_id> --line <cart_line_item_id> --json
248
+ itp buyer checkout create --cart <cart_id> --email buyer@example.com --phone +8613800000000 --json
249
+ itp buy var_pubg_couple_skin_cny20 --sandbox --email buyer@example.com --phone +8613800000000 --no-wait --json
250
+ itp buyer payment wait <payment_intent_id> --json
251
+ itp buyer checkout status <checkout_id> --json
252
+ ```
253
+
254
+ Alipay sandbox responses expose a stable `payment_entry_url` for browser/status
255
+ fallback and a tokenized `qr_image_url` for the human scanner. Render or download
256
+ `qr_image_url`; do not turn `payment_entry_url` into a QR code. If the Alipay
257
+ sandbox app reports "order not found", ask the API for a fresh display QR:
258
+
259
+ ```bash
260
+ itp buyer payment refresh-qr <payment_intent_id> --reason order-not-found --json
261
+ ```
262
+
263
+ `wait.timeout` from `/events/wait` is one long-poll cycle timing out, not a
264
+ payment failure. The CLI heartbeat reports this as `still_waiting` and continues
265
+ until the overall command timeout or a verified payment event. Ops-only sandbox
266
+ commands such as `itp ops sandbox worker run-once --json` require the sandbox ops
267
+ token and are not part of normal buyer/agent authority.
268
+
269
+ Live checkpoint on 2026-06-08: `itp buy ... --no-wait --json` created an Alipay
270
+ sandbox payment intent, the human scanned the `qr_image_url` SVG directly with
271
+ the Alipay sandbox app, public notify reached `/v1/alipay/sandbox/notify`, and
272
+ `itp buyer payment wait` returned `payment_intent.verified` without query
273
+ recovery.
274
+
275
+ Manual flow starts with Alipay-bound agent authentication:
276
+
277
+ ```bash
278
+ itp auth register --runtime codex --json
279
+ ```
280
+
281
+ The CLI prints the Alipay verification URL and code to stderr, waits for the
282
+ scan approval, stores the returned session, and then returns the saved account
283
+ metadata as JSON.
284
+
285
+ The response includes the actual saved `username`. Keep it if you plan to log in
286
+ later with a password.
287
+
288
+ Set the first Web login password:
289
+
290
+ ```bash
291
+ printf 'your-password\n' | itp account set-password --password-stdin --json
292
+ ```
293
+
294
+ Check auth and account state:
295
+
296
+ ```bash
297
+ itp auth status --json
298
+ itp account show --json
299
+ ```
300
+
301
+ List available plans:
302
+
303
+ ```bash
304
+ itp plans --json
305
+ ```
306
+
307
+ Create a checkout:
308
+
309
+ ```bash
310
+ itp checkout create --credits 100 --method alipay --json
311
+ ```
312
+
313
+ Wait for verified payment and grant delivery:
314
+
315
+ ```bash
316
+ itp payment wait <checkout_id> --timeout 120 --json
317
+ ```
318
+
319
+ Install the grant credential:
320
+
321
+ ```bash
322
+ itp grants install <grant_id> --target codex --json
323
+ ```
324
+
325
+ Optionally install runtime config:
326
+
327
+ ```bash
328
+ itp install codex --grant <grant_id> --json
329
+ ```
330
+
331
+ For local no-network config writing:
332
+
333
+ ```bash
334
+ itp install codex --grant <grant_id> --offline --no-test --json
335
+ ```
336
+
337
+ Check balance, usage, and orders:
338
+
339
+ ```bash
340
+ itp balance --json
341
+ itp usage --grant <grant_id> --json
342
+ itp checkout list --limit 20 --json
343
+ ```
344
+
345
+ Rotate or revoke a grant:
346
+
347
+ ```bash
348
+ itp keys rotate --grant <grant_id> --json
349
+ itp grants revoke <grant_id> --json
350
+ ```
351
+
352
+ ## Runtime Notes
353
+
354
+ ### Codex
355
+
356
+ The CLI writes:
357
+
358
+ ```text
359
+ ~/.codex/config.toml
360
+ ~/.itp/voltagent.env
361
+ ```
362
+
363
+ Codex reads `VOLTAGENT_API_KEY` from the process environment. If your launcher does not load the env file automatically, source it before starting Codex:
364
+
365
+ ```bash
366
+ source ~/.itp/voltagent.env
367
+ ```
368
+
369
+ ### Claude Code
370
+
371
+ The CLI writes the configured Anthropic-compatible base URL and credential through the target profile.
372
+
373
+ ### OpenClaw
374
+
375
+ The CLI supports `openclaw` as an install target. Use:
376
+
377
+ ```bash
378
+ itp grants install <grant_id> --target openclaw --json
379
+ itp install openclaw --grant <grant_id> --json
380
+ ```
381
+
382
+ ## Agent Skill And Docs
383
+
384
+ Installed agents can read the buyer skill and docs graph at any time:
385
+
386
+ ```bash
387
+ itp skill show --role buyer --json
388
+ itp skill path --role buyer
389
+ itp docs list --role buyer --json
390
+ itp docs show quickstart --role buyer --json
391
+ itp docs search "<question>" --role buyer --json
392
+ ```
393
+
394
+ Repository files:
395
+
396
+ ```text
397
+ skills/itpay-buyer/SKILL.md
398
+ skills/voltagent/SKILL.md
399
+ docs/agent/buyer/*.json
400
+ ```
401
+
402
+ Agents should use the buyer skill when the user asks to search, buy, pay, or receive an ItPay service. Use the legacy VoltaGent skill only for the older model-package setup flow:
403
+
404
+ ```bash
405
+ itp skill show --role voltagent --json
406
+ ```
407
+
408
+ The skill rules are strict:
409
+
410
+ - Do not invent payment links.
411
+ - Do not ask users to paste API keys, claim links, claim tokens, redeem codes, or raw keys into chat.
412
+ - Use `--json` for agent-run commands.
413
+ - Use UCP cart-first checkout for CORE-028 buyer tests.
414
+ - Treat only `payment_intent.verified` as payment success.
415
+ - Report secure delivery as redacted status only.
416
+
417
+ ## Local Backend E2E
418
+
419
+ When a local VoltaGent backend is running on `http://localhost:3000`:
420
+
421
+ ```bash
422
+ VOLTAGENT_API_BASE=http://localhost:3000 ./e2e-local.sh
423
+ ```
424
+
425
+ The E2E script uses a temporary HOME, so it does not touch your real:
426
+
427
+ ```text
428
+ ~/.itp
429
+ ~/.codex
430
+ ```
431
+
432
+ The script covers:
433
+
434
+ ```text
435
+ server health
436
+ plans
437
+ auth register
438
+ account password setup
439
+ Alipay checkout
440
+ payment wait
441
+ grant install
442
+ codex offline install
443
+ balance
444
+ checkout list
445
+ usage
446
+ key rotation
447
+ token issue
448
+ grant revoke
449
+ ```
450
+
451
+ ## Development Checks
452
+
453
+ Run before committing:
454
+
455
+ ```bash
456
+ npm run check
457
+ npm pack --dry-run
458
+ ```
459
+
460
+ Expected `npm pack --dry-run` files:
461
+
462
+ ```text
463
+ LICENSE
464
+ README.md
465
+ bin/itp
466
+ e2e-local.sh
467
+ install.ps1
468
+ install.sh
469
+ package.json
470
+ skills/voltagent/SKILL.md
471
+ smoke.sh
472
+ ```
473
+
474
+ ## npm Publish
475
+
476
+ Check login:
477
+
478
+ ```bash
479
+ npm whoami
480
+ ```
481
+
482
+ If needed:
483
+
484
+ ```bash
485
+ npm login
486
+ ```
487
+
488
+ Check package name:
489
+
490
+ ```bash
491
+ npm view itpay_cli name
492
+ ```
493
+
494
+ If the package is not published yet, npm returns a not-found error.
495
+
496
+ Publish:
497
+
498
+ ```bash
499
+ npm publish
500
+ ```
501
+
502
+ For a scoped package:
503
+
504
+ ```bash
505
+ npm publish --access public
506
+ ```
507
+
508
+ Post-publish install test:
509
+
510
+ ```bash
511
+ TMP_PREFIX=$(mktemp -d)
512
+ npm install -g --prefix "$TMP_PREFIX" itpay_cli
513
+ "$TMP_PREFIX/bin/itp" --version
514
+ "$TMP_PREFIX/bin/itp" skill show --role buyer --json
515
+ "$TMP_PREFIX/bin/itp" docs show quickstart --role buyer --json
516
+ "$TMP_PREFIX/bin/itpay" --version
517
+ "$TMP_PREFIX/bin/itpay_cli" --version
518
+ ```
519
+
520
+ ## Backend Contract
521
+
522
+ The CLI expects a VoltaGent-compatible backend that exposes:
523
+
524
+ ```text
525
+ GET /api/status
526
+ GET /api/itp/plans
527
+ POST /api/itp/auth/register
528
+ POST /api/itp/auth/login
529
+ POST /api/itp/auth/device/start
530
+ POST /api/itp/auth/device/:auth_id/poll
531
+ GET /api/itp/auth/status
532
+ GET /api/itp/account
533
+ POST /api/itp/account/password
534
+ POST /api/itp/checkout
535
+ GET /api/itp/checkout/:id
536
+ POST /api/itp/payments/alipay/notify
537
+ GET /api/itp/orders
538
+ GET /api/itp/balance
539
+ GET /api/itp/usage
540
+ GET /api/itp/grants
541
+ POST /api/itp/grants/:id/install
542
+ POST /api/itp/grants/:id/install-ack
543
+ POST /api/itp/grants/:id/rotate
544
+ POST /api/itp/grants/:id/revoke
545
+ ```
546
+
547
+ Relay base URLs returned by the backend:
548
+
549
+ ```text
550
+ /openai/v1
551
+ /anthropic/v1
552
+ /gemini/v1beta
553
+ ```
554
+
555
+ ## Safety and Secrets
556
+
557
+ Never commit:
558
+
559
+ ```text
560
+ .env
561
+ .npmrc with auth token
562
+ ~/.itp
563
+ ~/.codex
564
+ credentials.json
565
+ voltagent.env
566
+ *.pem
567
+ *.key
568
+ *.p12
569
+ *.pfx
570
+ database files
571
+ npm tarballs
572
+ ```
573
+
574
+ The repository `.gitignore` excludes these by default, including `**/.DS_Store`.
575
+
576
+ Before pushing or publishing, run:
577
+
578
+ ```bash
579
+ git status --short
580
+ npm pack --dry-run
581
+ npm run check
582
+ ```
583
+
584
+ ## Maintainer Workflow
585
+
586
+ Typical update flow:
587
+
588
+ ```bash
589
+ git pull
590
+ npm run check
591
+ # edit bin/itp, skills/itpay-buyer/SKILL.md, docs/agent/buyer/*.json, or skills/voltagent/SKILL.md
592
+ npm run check
593
+ npm pack --dry-run
594
+ git status --short
595
+ git add .
596
+ git commit -m "Describe the CLI change"
597
+ git push
598
+ ```
599
+
600
+ For behavior changes, update both:
601
+
602
+ ```text
603
+ bin/itp
604
+ docs/agent/buyer/*.json
605
+ skills/itpay-buyer/SKILL.md
606
+ skills/voltagent/SKILL.md
607
+ ```
608
+
609
+ If the backend contract changes, update:
610
+
611
+ ```text
612
+ README.md
613
+ e2e-local.sh
614
+ docs/agent/buyer/*.json
615
+ skills/itpay-buyer/SKILL.md
616
+ skills/voltagent/SKILL.md
617
+ ```