@itpay/cli 2.0.3 → 2.0.7

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 (77) hide show
  1. package/README.md +96 -142
  2. package/dist/src/client/backend.js +26 -8
  3. package/dist/src/client/http.js +29 -23
  4. package/dist/src/commands/buy.js +84 -132
  5. package/dist/src/commands/cart.js +274 -169
  6. package/dist/src/commands/catalog.js +64 -38
  7. package/dist/src/commands/checkout.js +128 -79
  8. package/dist/src/commands/docs.js +97 -51
  9. package/dist/src/commands/guidance.js +112 -16
  10. package/dist/src/commands/install.js +50 -87
  11. package/dist/src/commands/next.js +45 -0
  12. package/dist/src/commands/order.js +44 -69
  13. package/dist/src/commands/orders.js +43 -15
  14. package/dist/src/commands/pay.js +51 -22
  15. package/dist/src/commands/readyz.js +8 -4
  16. package/dist/src/commands/refund.js +132 -11
  17. package/dist/src/commands/services.js +799 -147
  18. package/dist/src/commands/skill.js +55 -0
  19. package/dist/src/main.js +820 -193
  20. package/dist/src/render/output.js +2 -3
  21. package/dist/src/state/agent_type.js +19 -0
  22. package/dist/src/state/cart_session.js +13 -17
  23. package/dist/src/state/client_context.js +4 -2
  24. package/dist/src/state/config.js +5 -15
  25. package/dist/src/state/device_authority.js +175 -57
  26. package/docs/agent/buyer/cart-checkout.json +27 -83
  27. package/docs/agent/buyer/catalog-list.json +2 -1
  28. package/docs/agent/buyer/identity-and-sessions.json +64 -0
  29. package/docs/agent/buyer/install-and-setup.json +35 -65
  30. package/docs/agent/buyer/orders-refunds.json +31 -53
  31. package/docs/agent/buyer/payment-flow.json +28 -57
  32. package/docs/agent/buyer/quickstart.json +46 -161
  33. package/docs/agent/buyer/render-hosts.json +43 -57
  34. package/docs/cli-reference/agent-types.md +51 -0
  35. package/docs/cli-reference/commands/buy.md +167 -0
  36. package/docs/cli-reference/commands/cart/add.md +86 -0
  37. package/docs/cli-reference/commands/cart/clear.md +53 -0
  38. package/docs/cli-reference/commands/cart/index.md +30 -0
  39. package/docs/cli-reference/commands/cart/next.md +71 -0
  40. package/docs/cli-reference/commands/cart/remove.md +53 -0
  41. package/docs/cli-reference/commands/cart/show.md +65 -0
  42. package/docs/cli-reference/commands/catalog/index.md +26 -0
  43. package/docs/cli-reference/commands/catalog/list.md +45 -0
  44. package/docs/cli-reference/commands/checkout.md +74 -0
  45. package/docs/cli-reference/commands/device.md +13 -0
  46. package/docs/cli-reference/commands/docs/index.md +28 -0
  47. package/docs/cli-reference/commands/docs/list.md +51 -0
  48. package/docs/cli-reference/commands/docs/search.md +69 -0
  49. package/docs/cli-reference/commands/docs/show.md +68 -0
  50. package/docs/cli-reference/commands/install.md +114 -0
  51. package/docs/cli-reference/commands/next.md +87 -0
  52. package/docs/cli-reference/commands/order.md +92 -0
  53. package/docs/cli-reference/commands/orders.md +83 -0
  54. package/docs/cli-reference/commands/pay.md +103 -0
  55. package/docs/cli-reference/commands/readyz.md +38 -0
  56. package/docs/cli-reference/commands/refund/cancel.md +62 -0
  57. package/docs/cli-reference/commands/refund/create.md +85 -0
  58. package/docs/cli-reference/commands/refund/get.md +60 -0
  59. package/docs/cli-reference/commands/refund/index.md +33 -0
  60. package/docs/cli-reference/commands/refund/list.md +68 -0
  61. package/docs/cli-reference/commands/refund/watch.md +73 -0
  62. package/docs/cli-reference/commands/services/action.md +48 -0
  63. package/docs/cli-reference/commands/services/checkout.md +82 -0
  64. package/docs/cli-reference/commands/services/events.md +73 -0
  65. package/docs/cli-reference/commands/services/get.md +66 -0
  66. package/docs/cli-reference/commands/services/index.md +45 -0
  67. package/docs/cli-reference/commands/services/invoke.md +67 -0
  68. package/docs/cli-reference/commands/services/list.md +61 -0
  69. package/docs/cli-reference/commands/services/next.md +181 -0
  70. package/docs/cli-reference/commands/services/quote.md +63 -0
  71. package/docs/cli-reference/commands/services/read-result.md +98 -0
  72. package/docs/cli-reference/commands/services/start.md +55 -0
  73. package/docs/cli-reference/commands/skill.md +17 -0
  74. package/docs/cli-reference/conventions.md +97 -0
  75. package/docs/cli-reference/index.md +65 -0
  76. package/package.json +1 -1
  77. package/skills/itpay-buyer/SKILL.md +71 -110
@@ -0,0 +1,65 @@
1
+ # ItPay CLI Command Reference
2
+
3
+ 本目录是 ItPay CLI 的规范性命令合同。它定义命令应向人和 Agent 返回什么、如何指导下一步,以及失败后如何恢复。当前实现与本文档不一致时,以本文档作为后续校准目标。
4
+
5
+ 企知道可以作为示例数据出现,但任何命令、字段、状态和 instruction 都不得依赖某个服务。服务差异只能来自 Catalog、Service Contract、Capability metadata 和服务端状态。
6
+
7
+ ## 使用约定
8
+
9
+ - [输出与错误合同](conventions.md)
10
+ - [Agent Type 与 Host](agent-types.md)
11
+ - 所有示例中的 `<...>` 都是占位符,不得原样提交。
12
+ - 所有 commerce 命令必须使用真实的 `--agent-type`,不得为刷新额度伪造类型。
13
+ - 每条命令只返回当前步骤所需事实、一条 instruction、一个首选 next;异常时最多返回两个 recovery。
14
+
15
+ ## 命令目录
16
+
17
+ ### 环境与发现
18
+
19
+ - [`itpay readyz`](commands/readyz.md) - 检查后端是否可用
20
+ - [`itpay next`](commands/next.md) - 从本地保存的服务端句柄恢复下一步
21
+ - [`itpay catalog`](commands/catalog/index.md)
22
+ - [`itpay catalog list`](commands/catalog/list.md)
23
+ - [`itpay install`](commands/install.md) - 查看指定 Agent 的安装说明
24
+ - [`itpay skill show`](commands/skill.md) - 一次读取完整内置 Buyer Skill
25
+ - [`itpay docs`](commands/docs/index.md)
26
+ - [`itpay docs list`](commands/docs/list.md)
27
+ - [`itpay docs show`](commands/docs/show.md)
28
+ - [`itpay docs search`](commands/docs/search.md)
29
+
30
+ ### 购物与支付
31
+
32
+ - [`itpay cart`](commands/cart/index.md)
33
+ - [`itpay cart add`](commands/cart/add.md)
34
+ - [`itpay cart next`](commands/cart/next.md)
35
+ - [`itpay cart remove`](commands/cart/remove.md)
36
+ - [`itpay cart show`](commands/cart/show.md)
37
+ - [`itpay cart clear`](commands/cart/clear.md)
38
+ - [`itpay buy`](commands/buy.md)
39
+ - [`itpay checkout`](commands/checkout.md)
40
+ - [`itpay pay`](commands/pay.md)
41
+ - [`itpay order`](commands/order.md)
42
+ - [`itpay orders`](commands/orders.md)
43
+
44
+ ### 退款
45
+
46
+ - [`itpay refund`](commands/refund/index.md)
47
+ - [`itpay refund create`](commands/refund/create.md)
48
+ - [`itpay refund list`](commands/refund/list.md)
49
+ - [`itpay refund get`](commands/refund/get.md)
50
+ - [`itpay refund watch`](commands/refund/watch.md)
51
+ - [`itpay refund cancel`](commands/refund/cancel.md)
52
+
53
+ ### 通用服务执行
54
+
55
+ - [`itpay services`](commands/services/index.md)
56
+ - [`itpay services start`](commands/services/start.md)
57
+ - [`itpay services invoke`](commands/services/invoke.md)
58
+ - [`itpay services action`](commands/services/action.md)
59
+ - [`itpay services quote`](commands/services/quote.md)
60
+ - [`itpay services checkout`](commands/services/checkout.md)
61
+ - [`itpay services list`](commands/services/list.md)
62
+ - [`itpay services get`](commands/services/get.md)
63
+ - [`itpay services next`](commands/services/next.md)
64
+ - [`itpay services read-result`](commands/services/read-result.md)
65
+ - [`itpay services events`](commands/services/events.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itpay/cli",
3
- "version": "2.0.3",
3
+ "version": "2.0.7",
4
4
  "description": "ItPay CLI for V3 checkout, payment, order, refund, and agent-facing render flows.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,154 +1,115 @@
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.
12
+
13
+ ## Critical Rules
14
+
15
+ - Keep one honest Agent Type, one CLI/Node launcher, and one Host-approved permission context for the whole flow.
16
+ - Treat `next.command` as the preferred continuation, not an unconditional command. If the current result already satisfies the user's stated goal, present it and stop.
17
+ - Keep internal parsing, retries, sandbox diagnosis, and command translation out of the user response; report useful progress, results, and real human decisions only.
18
+ - If Device state is not writable, stop. Do not switch Node, manually create lock files, delete identity, or rotate Agent Type.
14
19
 
15
20
  ## Bootstrap
16
21
 
17
22
  ```bash
18
23
  npm install -g @itpay/cli
19
- itpay readyz
20
- itpay docs show quickstart
24
+ itpay readyz --json
25
+ itpay skill show itpay-buyer --json
26
+ itpay install --json
27
+ itpay install <agent_type> --json
28
+ itpay --agent-type <agent_type> readyz --json
21
29
  ```
22
30
 
23
- The CLI defaults to `https://app.itpay.ai`. Set `ITPAY_BACKEND_URL`
24
- only for an intentional override.
25
-
26
- Every commerce flow must identify the real runtime. Pass the global option
27
- immediately after `itpay`, or set `ITPAY_AGENT_TYPE` once:
28
-
29
- ```bash
30
- itpay --agent-type codex-desktop catalog list --json
31
- ```
31
+ Follow each returned `next.command`. `readyz` deliberately points back to this complete Skill. If the Skill was read without an Agent Type, choose the real runtime with `install`; after typed `readyz`, read the Skill again and continue to Catalog.
32
32
 
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.
33
+ Supported types are `codex-desktop`, `codex-cli`, `claude-code-desktop`, `claude-code-cli`, and `workbuddy`. State the real stable runtime type honestly. Do not identify a window, chat, task, process, or model session as a new Agent.
37
34
 
38
- ## Golden Flow
35
+ ## Identity And Sessions
39
36
 
40
- 1. Discover, then use IDs returned by the CLI:
37
+ - One local Ed25519 private key represents this ItPay installation. Never expose, copy, or rotate it to recover quota.
38
+ - Device registrations are scoped by exact Backend API base URL. `dev`, `test`, and `app` therefore have separate server device IDs, quota lineage, Agent instances, and sessions while using the same local key.
39
+ - Each Backend registration has one Agent Instance per `agent_type`. Different windows and chats of the same type reuse it; different types get separate instances under that registration.
40
+ - Every commerce command must keep the explicit `--agent-type` returned in `next` and `recovery`, or use one stable `ITPAY_AGENT_TYPE`. Never fall back to another type previously used on the machine.
41
+ - The CLI renews an expired or rejected device session and retries the same request exactly once. If that retry still fails, stop and report it; do not loop, create a new identity, or switch Agent Type.
42
+ - A revoked v2 device is not replaced automatically. It requires an explicit operator recovery path.
43
+ - If an operator confirms that one Backend registration database was reset, use `device recover --confirm-backend-reset` for that selected Backend only. This preserves the private key and every other Backend registration; never use it for ordinary session expiry or revocation.
44
+ - `--host` selects presentation. `--target` is only the destination chat/channel/open ID required by some Hosts. Neither is business input or identity.
41
45
 
42
- ```bash
43
- itpay --agent-type <agent_type> catalog list --json
44
- itpay --agent-type <agent_type> services start <service_id>
45
- ```
46
+ ## Envelope Rule
46
47
 
47
- 2. Ask the server for the next step:
48
+ For every JSON response:
48
49
 
49
- ```bash
50
- itpay --agent-type <agent_type> services next <service_execution_id> --json
51
- ```
50
+ 1. Read `status` and `result` as current facts.
51
+ 2. Follow `instruction` when explaining or presenting those facts.
52
+ 3. Execute at most the one `next.command`, filling only explicit placeholders or required user data.
53
+ 4. Use `recovery` only when the normal next step cannot continue.
52
54
 
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.
55
+ Do not print the whole envelope to the user. Return the useful result, a short explanation, and the next human action when needed.
56
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:
57
+ ## Golden Flow
59
58
 
60
59
  ```bash
61
- itpay --agent-type <agent_type> services checkout <service_execution_id> \
62
- --capability <capability_id> [--email <human_email>] --host <host> --json
60
+ itpay --agent-type <agent_type> catalog list --json
61
+ itpay --agent-type <agent_type> services start <service_id> --json
63
62
  ```
64
63
 
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:
64
+ 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.
70
65
 
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.
66
+ `services start` creates the Execution and returns the preferred capability plus its `required_input`. Put business values only in repeated `--input key=value` options on the returned `services invoke`, `services quote`, or `services checkout` command. For example, a company keyword belongs in `--input keyword=美团`; it never belongs in `--target`.
75
67
 
76
- 6. After the human pays, claims, or grants access, re-read server state:
68
+ Rules:
77
69
 
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
81
- ```
82
-
83
- 7. Read protected output only when `next_actions` says the human grant is
84
- active:
85
-
86
- ```bash
87
- itpay --agent-type <agent_type> services read-result <service_execution_id>
88
- ```
89
-
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.
70
+ - One independent service intent uses one Service Execution.
71
+ - 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.
72
+ - A normal single-Execution paid step uses the exact `services checkout` command returned by the CLI, but only after the instruction has made the price visible and the human explicitly agrees. The command internally uses the same Quote, Cart and Checkout rules.
73
+ - `services quote -> cart add --quote -> buy --cart` is only for a human who explicitly asks to combine Quotes from multiple independent Executions. Never use it as a fallback when `services checkout` fails.
74
+ - Ask for required email/contact fields; explain their delivery purpose and never invent them.
75
+ - When Checkout is ready, make the amount, ItPay QR/image and URL visible on the current human surface, then stop. Do not query until the human completes the action or asks for status.
76
+ - Normal payment happens on the ItPay Checkout page. `itpay pay` and `buy --pay` are operator escape hatches.
77
+ - Payment is confirmed only by Backend Checkout or Order state.
78
+ - Agent-visible results come from `services next`; do not call `read-result` for them.
79
+ - Quota exhaustion, candidate selection, Checkout pending, payment verified and delivery each remain on the same Execution. Never create a replacement Execution to escape one of those states.
80
+ - An Execution may have delivery history; always follow `services next` for the backend-selected current delivery instead of reusing an older result.
81
+ - 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.
82
+ - A pending refund locks every delivery path and revokes existing grants.
92
83
 
93
84
  ## Recovery
94
85
 
95
- Use server-backed recovery before creating anything again:
86
+ Before creating anything again:
96
87
 
97
88
  ```bash
98
89
  itpay --agent-type <agent_type> next --json
99
90
  itpay --agent-type <agent_type> services list --json
100
91
  itpay --agent-type <agent_type> services next <service_execution_id> --json
101
92
  itpay --agent-type <agent_type> services checkout <service_execution_id> --resume --json
102
- itpay checkout --id <checkout_id> --token <display_token>
93
+ itpay --agent-type <agent_type> checkout --id <checkout_id> --token <display_token> --json
94
+ itpay --agent-type <agent_type> refund get <refund_request_id> --json
95
+ itpay --agent-type <agent_type> device recover --confirm-backend-reset --json
103
96
  ```
104
97
 
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.
98
+ ## Safety
108
99
 
109
- ## Host Selection
100
+ - Never invent service, capability, item, Checkout, Order, grant, or refund IDs.
101
+ - Never expose Provider credentials, raw payloads, display tokens as standalone chat data, Buyer bearer tokens, or Device private keys.
102
+ - Never bypass ownership, compatibility, quota, grant, or refund-lock errors.
103
+ - Do not use `services events` in a normal flow; it is a bounded redacted diagnostic command.
104
+ - Do not rotate Agent Type or local identity to reset free quota.
110
105
 
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
106
+ ## Built-In Help
144
107
 
145
108
  ```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
109
+ itpay docs list --json
110
+ itpay docs search <term> --json
111
+ itpay docs show <topic> --json
112
+ itpay skill show itpay-buyer --json
154
113
  ```
114
+
115
+ The normative command contracts are packaged under `docs/cli-reference`.