@itpay/cli 2.0.2 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +92 -142
  2. package/dist/src/client/backend.js +27 -9
  3. package/dist/src/commands/buy.js +84 -132
  4. package/dist/src/commands/cart.js +274 -169
  5. package/dist/src/commands/catalog.js +63 -38
  6. package/dist/src/commands/checkout.js +117 -78
  7. package/dist/src/commands/docs.js +97 -51
  8. package/dist/src/commands/guidance.js +87 -15
  9. package/dist/src/commands/install.js +50 -87
  10. package/dist/src/commands/next.js +45 -0
  11. package/dist/src/commands/order.js +44 -69
  12. package/dist/src/commands/orders.js +43 -15
  13. package/dist/src/commands/pay.js +51 -22
  14. package/dist/src/commands/readyz.js +8 -4
  15. package/dist/src/commands/refund.js +132 -14
  16. package/dist/src/commands/services.js +719 -148
  17. package/dist/src/main.js +711 -201
  18. package/dist/src/render/output.js +2 -3
  19. package/dist/src/state/cart_session.js +13 -17
  20. package/dist/src/state/client_context.js +4 -2
  21. package/dist/src/state/config.js +3 -5
  22. package/dist/src/state/device_authority.js +1 -1
  23. package/docs/agent/buyer/cart-checkout.json +27 -83
  24. package/docs/agent/buyer/install-and-setup.json +23 -67
  25. package/docs/agent/buyer/orders-refunds.json +31 -53
  26. package/docs/agent/buyer/payment-flow.json +24 -57
  27. package/docs/agent/buyer/quickstart.json +39 -162
  28. package/docs/agent/buyer/render-hosts.json +43 -57
  29. package/docs/cli-reference/agent-types.md +45 -0
  30. package/docs/cli-reference/commands/buy.md +167 -0
  31. package/docs/cli-reference/commands/cart/add.md +86 -0
  32. package/docs/cli-reference/commands/cart/clear.md +53 -0
  33. package/docs/cli-reference/commands/cart/index.md +30 -0
  34. package/docs/cli-reference/commands/cart/next.md +71 -0
  35. package/docs/cli-reference/commands/cart/remove.md +53 -0
  36. package/docs/cli-reference/commands/cart/show.md +65 -0
  37. package/docs/cli-reference/commands/catalog/index.md +26 -0
  38. package/docs/cli-reference/commands/catalog/list.md +45 -0
  39. package/docs/cli-reference/commands/checkout.md +74 -0
  40. package/docs/cli-reference/commands/docs/index.md +28 -0
  41. package/docs/cli-reference/commands/docs/list.md +51 -0
  42. package/docs/cli-reference/commands/docs/search.md +69 -0
  43. package/docs/cli-reference/commands/docs/show.md +68 -0
  44. package/docs/cli-reference/commands/install.md +112 -0
  45. package/docs/cli-reference/commands/next.md +87 -0
  46. package/docs/cli-reference/commands/order.md +92 -0
  47. package/docs/cli-reference/commands/orders.md +83 -0
  48. package/docs/cli-reference/commands/pay.md +103 -0
  49. package/docs/cli-reference/commands/readyz.md +39 -0
  50. package/docs/cli-reference/commands/refund/cancel.md +62 -0
  51. package/docs/cli-reference/commands/refund/create.md +85 -0
  52. package/docs/cli-reference/commands/refund/get.md +60 -0
  53. package/docs/cli-reference/commands/refund/index.md +33 -0
  54. package/docs/cli-reference/commands/refund/list.md +68 -0
  55. package/docs/cli-reference/commands/refund/watch.md +73 -0
  56. package/docs/cli-reference/commands/services/action.md +43 -0
  57. package/docs/cli-reference/commands/services/checkout.md +82 -0
  58. package/docs/cli-reference/commands/services/events.md +73 -0
  59. package/docs/cli-reference/commands/services/get.md +66 -0
  60. package/docs/cli-reference/commands/services/index.md +45 -0
  61. package/docs/cli-reference/commands/services/invoke.md +67 -0
  62. package/docs/cli-reference/commands/services/list.md +61 -0
  63. package/docs/cli-reference/commands/services/next.md +162 -0
  64. package/docs/cli-reference/commands/services/quote.md +59 -0
  65. package/docs/cli-reference/commands/services/read-result.md +98 -0
  66. package/docs/cli-reference/commands/services/start.md +53 -0
  67. package/docs/cli-reference/conventions.md +94 -0
  68. package/docs/cli-reference/index.md +64 -0
  69. package/package.json +1 -1
  70. package/skills/itpay-buyer/SKILL.md +47 -113
@@ -1,154 +1,88 @@
1
1
  ---
2
2
  name: itpay-buyer
3
3
  description: >
4
- Use the ItPay V3 CLI when a human asks an AI agent to discover services,
5
- use a free capability, buy a paid result, show an ItPay checkout QR, recover
6
- an interrupted purchase, or read a result covered by a temporary human grant.
4
+ Use the ItPay CLI when a human asks an Agent to discover services, use a
5
+ capability, buy a result, show a Checkout, recover an interrupted flow,
6
+ read a human-granted result, or manage a refund.
7
7
  ---
8
8
 
9
- # ItPay V3 Buyer
9
+ # ItPay Buyer
10
10
 
11
- Use the CLI as the control surface. Do not recreate ItPay API calls or invent a
12
- service-specific workflow. The backend returns the next valid actions for each
13
- catalog item and Service Execution.
11
+ Use the CLI as the only ItPay control surface. Do not recreate API calls or hardcode a service-specific sequence.
14
12
 
15
13
  ## Bootstrap
16
14
 
17
15
  ```bash
18
16
  npm install -g @itpay/cli
19
- itpay readyz
20
- itpay docs show quickstart
17
+ itpay install <agent_type> --json
18
+ itpay --agent-type <agent_type> readyz --json
19
+ itpay --agent-type <agent_type> docs show quickstart --json
21
20
  ```
22
21
 
23
- The CLI defaults to `https://api.itpay.ai`. Set `ITPAY_BACKEND_URL`
24
- only for an intentional override.
22
+ Supported types are `codex-desktop`, `codex-cli`, `claude-code-desktop`, `claude-code-cli`, and `workbuddy`. Use the real stable runtime type; Host is presentation only.
25
23
 
26
- Every commerce flow must identify the real runtime. Pass the global option
27
- immediately after `itpay`, or set `ITPAY_AGENT_TYPE` once:
24
+ ## Envelope Rule
28
25
 
29
- ```bash
30
- itpay --agent-type codex-desktop catalog list --json
31
- ```
26
+ For every JSON response:
32
27
 
33
- Examples include `codex-desktop`, `codex-cli`, `claude-code-desktop`,
34
- `claude-code-cli`, and the actual WorkBuddy/OpenClaw runtime name. Never rotate
35
- the type or local device files to obtain more free quota. The CLI enrolls one
36
- signed device under `~/.itpay-v3/device` and registers each runtime on it.
28
+ 1. Read `status` and `result` as current facts.
29
+ 2. Follow `instruction` when explaining or presenting those facts.
30
+ 3. Execute at most the one `next.command`, filling only explicit placeholders or required user data.
31
+ 4. Use `recovery` only when the normal next step cannot continue.
37
32
 
38
- ## Golden Flow
33
+ Do not print the whole envelope to the user. Return the useful result, a short explanation, and the next human action when needed.
39
34
 
40
- 1. Discover, then use IDs returned by the CLI:
35
+ ## Golden Flow
41
36
 
42
37
  ```bash
43
38
  itpay --agent-type <agent_type> catalog list --json
44
- itpay --agent-type <agent_type> services start <service_id>
45
- ```
46
-
47
- 2. Ask the server for the next step:
48
-
49
- ```bash
50
- itpay --agent-type <agent_type> services next <service_execution_id> --json
51
- ```
52
-
53
- 3. Execute the first applicable command from `next_actions` unchanged. Typical
54
- commands are `services invoke`, `services action`, or `services checkout`.
55
- Do not infer a capability ID or hardcode one service's sequence.
56
-
57
- 4. For a paid result, collect only contact fields requested by the CLI. Create
58
- the checkout with the exact server-selected capability:
59
-
60
- ```bash
61
- itpay --agent-type <agent_type> services checkout <service_execution_id> \
62
- --capability <capability_id> [--email <human_email>] --host <host> --json
63
- ```
64
-
65
- Include `--email` only when the CLI's `next_actions` command includes it. For a
66
- protected delivery, explain that the address receives the order claim link;
67
- never invent an address. Agent-visible paid results do not require email.
68
-
69
- 5. Show both handoff forms to the human:
70
-
71
- - Attach `brand_qr_local_path` when `brand_qr_status` is `downloaded`.
72
- - Print `checkout_url` as a clickable link.
73
- - Keep `checkout_id`, `display_token`, and `service_execution_id` for recovery.
74
- - Do not substitute a provider QR or call `itpay pay` in the normal buyer flow.
75
-
76
- 6. After the human pays, claims, or grants access, re-read server state:
77
-
78
- ```bash
79
- itpay --agent-type <agent_type> services next <service_execution_id> --json
80
- itpay --agent-type <agent_type> services get <service_execution_id> --json
39
+ itpay --agent-type <agent_type> services start <service_id> --json
81
40
  ```
82
41
 
83
- 7. Read protected output only when `next_actions` says the human grant is
84
- active:
42
+ Then execute the exact `next.command` returned by each step. It may invoke a capability, ask for a selection, create a Checkout, wait for human action, return an Agent-visible result, or read a protected result after grant.
85
43
 
86
- ```bash
87
- itpay --agent-type <agent_type> services read-result <service_execution_id>
88
- ```
44
+ Rules:
89
45
 
90
- The grant is scoped to one Service Execution and expires after 15 minutes. It
91
- does not expose the buyer's other Vault artifacts, orders, or executions.
46
+ - One independent service intent uses one Service Execution.
47
+ - Every candidate list belongs to its source Service Execution. After a human selects a rank, submit the selection on that same Execution; never copy it into a new Execution or construct a candidate.
48
+ - A paid step is `services quote -> cart add --quote -> buy --cart`. Quote locks service input and price; Cart may combine Quotes from separate Executions without merging their delivery.
49
+ - `services checkout` is the one-item shortcut for the same Quote, Cart and Checkout rules.
50
+ - Ask for required email/contact fields; explain their delivery purpose and never invent them.
51
+ - When Checkout is ready, make both the ItPay QR/image and URL visible on the current human surface.
52
+ - Normal payment happens on the ItPay Checkout page. `itpay pay` and `buy --pay` are operator escape hatches.
53
+ - Payment is confirmed only by Backend Checkout or Order state.
54
+ - Agent-visible results come from `services next`; do not call `read-result` for them.
55
+ - An Execution may have delivery history; always follow `services next` for the backend-selected current delivery instead of reusing an older result.
56
+ - Protected results require a current human grant. The grant is scoped to one delivery, approved fields and frozen Agent audience, and expires after 15 minutes.
57
+ - A pending refund locks every delivery path and revokes existing grants.
92
58
 
93
59
  ## Recovery
94
60
 
95
- Use server-backed recovery before creating anything again:
61
+ Before creating anything again:
96
62
 
97
63
  ```bash
98
64
  itpay --agent-type <agent_type> next --json
99
65
  itpay --agent-type <agent_type> services list --json
100
66
  itpay --agent-type <agent_type> services next <service_execution_id> --json
101
67
  itpay --agent-type <agent_type> services checkout <service_execution_id> --resume --json
102
- itpay checkout --id <checkout_id> --token <display_token>
68
+ itpay checkout --id <checkout_id> --token <display_token> --json
69
+ itpay --agent-type <agent_type> refund get <refund_request_id> --json
103
70
  ```
104
71
 
105
- `--resume` reissues the handoff for the existing unpaid checkout. It must not
106
- create a second order. Local files cache recovery handles; canonical cart,
107
- quota, execution, checkout, delivery, and grant state comes from the backend.
72
+ ## Safety
108
73
 
109
- ## Host Selection
74
+ - Never invent service, capability, item, Checkout, Order, grant, or refund IDs.
75
+ - Never expose Provider credentials, raw payloads, display tokens as standalone chat data, Buyer bearer tokens, or Device private keys.
76
+ - Never bypass ownership, compatibility, quota, grant, or refund-lock errors.
77
+ - Do not use `services events` in a normal flow; it is a bounded redacted diagnostic command.
78
+ - Do not rotate Agent Type or local identity to reset free quota.
110
79
 
111
- `--agent-type` identifies the agent runtime. `--host` identifies where the
112
- human sees the output. They are separate.
113
-
114
- | Human surface | CLI options |
115
- | --- | --- |
116
- | Codex | `--host codex` |
117
- | Claude Code | `--host claude-code` |
118
- | Terminal | `--host terminal` |
119
- | Telegram | `--host telegram --target <chat_id>` |
120
- | Feishu/Lark | `--host feishu --target <id>` or `--host lark --target <id>` |
121
-
122
- Run `itpay install <host>` for host-specific setup.
123
-
124
- ## Progressive Disclosure
125
-
126
- - Run one state-changing command at a time.
127
- - Return the useful result, a short explanation, and the next executable step.
128
- - Ask the human only for a missing required field such as delivery email.
129
- - When checkout is ready, visibly attach the QR and print the payment link.
130
- - Prefer CLI `next_actions`; do not dump internal timelines unless diagnosing.
131
- - Use `--json` for agent parsing and normal rendering for the human handoff.
132
-
133
- ## Safety Rules
134
-
135
- 1. Never invent catalog, service, capability, result-item, checkout, or order IDs.
136
- 2. Never expose provider credentials, raw provider metadata, bearer tokens, or device private keys.
137
- 3. Do not treat QR rendering or a human statement as payment confirmation.
138
- 4. Do not call `itpay pay` or use `buy --pay` for a normal checkout; those are operator escape hatches.
139
- 5. Do not create a new execution or checkout until recovery confirms the prior one is unusable.
140
- 6. Do not claim protected access before `services read-result` succeeds.
141
- 7. Do not invent admin, account, grant-creation, or provider-specific CLI commands.
142
-
143
- ## Built-in Docs
80
+ ## Built-In Help
144
81
 
145
82
  ```bash
146
- itpay docs list
147
- itpay docs search <term>
148
- itpay docs show catalog-list
149
- itpay docs show cart-checkout
150
- itpay docs show payment-flow
151
- itpay docs show orders-refunds
152
- itpay docs show render-hosts
153
- itpay docs show install-and-setup
83
+ itpay docs list --json
84
+ itpay docs search <term> --json
85
+ itpay docs show <topic> --json
154
86
  ```
87
+
88
+ The normative command contracts are packaged under `docs/cli-reference`.