@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
@@ -2,105 +2,49 @@
2
2
  "schema_version": "itp.agent_doc.v1",
3
3
  "role": "buyer",
4
4
  "topic": "cart-checkout",
5
- "title": "V3 Cart-First Checkout",
6
- "purpose": "Teach the agent to use the current V3 canonical server cart flow without treating local CLI state as business truth.",
5
+ "title": "Canonical Cart And Checkout Routing",
6
+ "purpose": "Use the canonical server Cart and route service-backed lines through Service Execution without hardcoded service logic.",
7
7
  "when_to_use": [
8
- "The user already chose a catalog item, variant, and offer.",
9
- "The agent needs to add a catalog item to a server cart before checkout.",
10
- "The agent wants to understand how service-backed cart items create or resume Service Execution."
8
+ "A catalog item or variant is ready to add.",
9
+ "An interrupted Cart or Checkout needs recovery."
11
10
  ],
12
- "required_state": {
13
- "needs": [
14
- "catalog_item_id",
15
- "catalog_variant_id",
16
- "offer_id"
17
- ],
18
- "optional": [
19
- "quantity",
20
- "contact email",
21
- "contact phone",
22
- "agent_device_id for service-backed items"
23
- ],
24
- "must_not_need": [
25
- "catalog search support from this CLI"
26
- ]
27
- },
28
11
  "commands": [
29
12
  {
30
- "intent": "add the first line to the canonical server cart",
31
- "command": "itpay cart add --item <catalog_item_id> --variant <catalog_variant_id> --offer <offer_id> --quantity 1 --host <client> --json",
32
- "success_signal": "JSON includes cart_id and cart_item_id; service-backed lines also include service_execution_id and top-level next_actions"
13
+ "intent": "add one published line",
14
+ "command": "itpay --agent-type <agent_type> cart add --item <catalog_item_id> --variant <catalog_variant_id> --offer <offer_id> --quantity 1 --json",
15
+ "success_signal": "result identifies the canonical cart line and next contains one executable recovery or service command"
33
16
  },
34
17
  {
35
- "intent": "recover the next step for the current cart",
36
- "command": "itpay cart next --json",
37
- "success_signal": "JSON includes next_actions derived from the canonical server cart and Service Execution read model"
18
+ "intent": "read the canonical Cart route",
19
+ "command": "itpay --agent-type <agent_type> cart next --json",
20
+ "success_signal": "service-backed lines route to services next; ordinary lines route to buy"
38
21
  },
39
22
  {
40
- "intent": "inspect the current canonical server cart before checkout",
41
- "command": "itpay cart show",
42
- "success_signal": "server cart lines, checkout readiness, and service refs are printed"
23
+ "intent": "create an ordinary Checkout",
24
+ "command": "itpay --agent-type <agent_type> buy --cart <cart_id> --json",
25
+ "success_signal": "status is human_checkout_required and handoff contains only fields usable by the current Host"
43
26
  },
44
27
  {
45
- "intent": "soft-remove one active line from the canonical server cart",
46
- "command": "itpay cart remove --line <cart_item_id>",
47
- "success_signal": "the line is removed from the server cart; quote-locked or checkout-bound lines return a conflict"
48
- },
49
- {
50
- "intent": "abandon the canonical server cart",
51
- "command": "itpay cart clear",
52
- "success_signal": "the server cart is abandoned, active lines are soft-removed, and local handles are cleared"
53
- },
54
- {
55
- "intent": "create checkout from a server cart that is ready for checkout",
56
- "command": "itpay buy --cart <cart_id> --host <client> [--contact-email <email>] [--contact-phone <phone>]",
57
- "success_signal": "the CLI either renders checkout_qr or emits an interaction request for missing contact data"
58
- },
59
- {
60
- "intent": "create quote lock and checkout for a service-backed cart item",
61
- "command": "itpay services checkout <service_execution_id> --capability <paid_capability_id> [--email <email>] --json",
62
- "success_signal": "the quote lock is bound to the original server cart item when present; JSON includes checkout_id and display_token"
63
- },
64
- {
65
- "intent": "read the next Service Execution action",
66
- "command": "itpay services next <service_execution_id> --json",
67
- "success_signal": "JSON includes next_actions such as invoke capability, select result item, or checkout"
28
+ "intent": "create or resume a service Checkout",
29
+ "command": "itpay --agent-type <agent_type> services checkout <service_execution_id> --capability <capability_id> [--input key=value] [--email <email>] --json",
30
+ "success_signal": "one Checkout handoff is returned; rerun with --resume after output or token loss"
68
31
  }
69
32
  ],
70
33
  "agent_rules": [
71
- "The current V3 CLI uses server cart as the business source of truth. Local ~/.itpay-v3/cart.json only caches last ids and explicit local drafts.",
72
- "Prefer top-level next_actions and itpay next/cart next/services next over hardcoded service-specific flows.",
73
- "Use cart add/show/remove/clear before checkout. Remove and clear are server-side soft state changes, not hard deletes.",
74
- "For service-backed items, use service_execution_id from cart add/show as the canonical handle for services invoke/action/checkout.",
75
- "Do not call buy --cart on a service-backed cart item until the required service action and quote lock are complete.",
76
- "Do not remove quote-locked or checkout-bound cart lines. Continue checkout/payment or use refund/cancel owner flow after payment.",
77
- "If required contact data is missing, prefer --require-contact so the CLI can emit a structured interaction request.",
78
- "Do not invent buyer email or phone values; let the human provide them when required.",
79
- "Only request --email when the selected capability declares delivery_email_required. Tell the buyer it sends the protected result claim link.",
80
- "The happy-path buy flow creates cart and checkout, then renders checkout_qr. It should not create a payment intent first."
34
+ "The Backend Cart is business truth; ~/.itpay-v3/cart.json only stores local recovery handles and explicit drafts.",
35
+ "Run the exact next.command returned by the CLI. Do not extract or invent a capability from a raw list.",
36
+ "One service intent uses one Service Execution. Start another execution for another independent intent.",
37
+ "Ask for email only when the selected capability requires protected delivery; never invent contact data.",
38
+ "A lost Checkout response is retried with the same Cart and persisted idempotency operation."
81
39
  ],
82
40
  "forbidden": [
83
- "Do not treat local cart files as durable business truth.",
84
- "Do not create duplicate checkout commands if the first handoff is still usable.",
85
- "Do not treat QR display as proof of payment."
41
+ "Do not call ordinary buy for a service-backed Cart line.",
42
+ "Do not create a second Checkout when the existing one can be resumed.",
43
+ "Do not treat QR display as payment verification."
86
44
  ],
87
45
  "next_docs": [
88
- {
89
- "condition": "Need host rendering details after checkout is created",
90
- "topic": "render-hosts",
91
- "file": "docs/agent/buyer/render-hosts.json"
92
- },
93
- {
94
- "condition": "Need order or refund follow-up after payment",
95
- "topic": "orders-refunds",
96
- "file": "docs/agent/buyer/orders-refunds.json"
97
- }
46
+ { "condition": "Checkout handoff is ready", "topic": "payment-flow" },
47
+ { "condition": "Host rendering needs clarification", "topic": "render-hosts" }
98
48
  ],
99
- "search_terms": [
100
- "cart",
101
- "checkout",
102
- "buy",
103
- "购物车",
104
- "结账"
105
- ]
49
+ "search_terms": ["cart", "checkout", "service execution", "resume", "contact"]
106
50
  }
@@ -27,7 +27,8 @@
27
27
  "Read the variant IDs and prices from the output; do not invent them.",
28
28
  "Explain the customer journey from service_flow instead of presenting every variant as an unrelated service.",
29
29
  "State free quota, paid continuation price, email requirement, and claim purpose exactly as published; do not exaggerate or omit conditions.",
30
- "If the buyer wants to search by keyword, filter the catalog output client-side (no backend search yet)."
30
+ "If the buyer wants to search by keyword, filter the catalog output client-side (no backend search yet).",
31
+ "After services start, submit service keywords only through the returned capability command's --input key=value options; --target is never a search keyword."
31
32
  ],
32
33
  "next_docs": [
33
34
  {
@@ -0,0 +1,64 @@
1
+ {
2
+ "schema_version": "itp.agent_doc.v1",
3
+ "role": "buyer",
4
+ "topic": "identity-and-sessions",
5
+ "title": "Device Identity And Session Recovery",
6
+ "purpose": "Explain stable local identity, Backend-scoped registrations, Agent Type instances, and bounded automatic session recovery.",
7
+ "when_to_use": [
8
+ "A different Agent window or runtime starts using an existing CLI installation.",
9
+ "The CLI reports device_state_unwritable, or the Backend reports agent_identity_required, agent_device_session_required, or agent_device_revoked.",
10
+ "The configured ITPAY_BACKEND_URL changes between dev, test, and app."
11
+ ],
12
+ "identity_model": {
13
+ "local_key": "One owner-only Ed25519 private key for the local installation.",
14
+ "backend_registration": "One independent server registration per normalized Backend API base URL.",
15
+ "agent_instance": "One instance per agent_type under each Backend registration; same-type windows and chats reuse it.",
16
+ "presentation": "Host and target route output only and never identify the Agent or provide business input."
17
+ },
18
+ "automatic_recovery": [
19
+ "The CLI reuses a valid cached device session.",
20
+ "On one HTTP 401 with code agent_device_session_required, it invalidates only the current Backend and Agent Type session, renews it, and retries the exact request once.",
21
+ "A second failure is returned to the Agent. The CLI does not loop, switch Agent Type, rotate the key, or create a replacement v2 device.",
22
+ "A revoked v2 registration requires explicit operator recovery; it is never silently replaced."
23
+ ],
24
+ "local_state_recovery": [
25
+ "Device state updates use an atomic directory lock and owner-only atomic file replacement; no lock file is opened with fs.open or fs.openSync.",
26
+ "On device_state_unwritable, use the reported operation and errno to diagnose the failing stage without exposing local paths; keep the same Agent Type and CLI/Node launcher, restore Host-approved persistent access to ~/.itpay-v3, then retry the original command.",
27
+ "Do not manually create a lock, switch Node runtimes, delete identity, or rotate Agent Type as a retry strategy."
28
+ ],
29
+ "commands": [
30
+ {
31
+ "intent": "reload the complete rules",
32
+ "command": "itpay --agent-type <agent_type> skill show itpay-buyer --json",
33
+ "success_signal": "the full Skill is returned and next keeps the same Agent Type"
34
+ },
35
+ {
36
+ "intent": "confirm the selected Backend is available",
37
+ "command": "itpay --agent-type <agent_type> readyz --json",
38
+ "success_signal": "Backend is available and onboarding returns to the Skill"
39
+ },
40
+ {
41
+ "intent": "recover after an operator-confirmed reset of the selected Backend registration database",
42
+ "command": "itpay --agent-type <agent_type> device recover --confirm-backend-reset --json",
43
+ "success_signal": "only the selected Backend registration is removed; the private key and other Backend registrations remain"
44
+ }
45
+ ],
46
+ "agent_rules": [
47
+ "Use the real runtime type and keep it stable across every command in the flow.",
48
+ "Keep the same CLI/Node launcher and Host-approved permission context for the whole flow.",
49
+ "Treat a new window, chat, task, or process of the same runtime as the same Agent Type, not a new identity.",
50
+ "Expect dev, test, and app to have separate device IDs, quota lineage, Agent instances, and sessions even on the same machine.",
51
+ "After automatic recovery fails, stop and report the exact code, Backend URL, Agent Type, and command family without exposing private keys or tokens."
52
+ ],
53
+ "forbidden": [
54
+ "Do not delete ~/.itpay-v3, rotate the key, switch Agent Type, or repeatedly retry to obtain fresh quota.",
55
+ "Do not use device recover for session expiry, revocation, quota recovery, or an unconfirmed Backend failure.",
56
+ "Do not copy a server device ID from one Backend registration into another.",
57
+ "Do not use --target as identity or service input."
58
+ ],
59
+ "next_docs": [
60
+ { "condition": "Identity is healthy", "topic": "quickstart" },
61
+ { "condition": "Need setup details", "topic": "install-and-setup" }
62
+ ],
63
+ "search_terms": ["identity", "device", "session", "login", "authentication", "agent type", "backend", "revoked", "recover", "unwritable", "lock", "window", "chat"]
64
+ }
@@ -2,81 +2,51 @@
2
2
  "schema_version": "itp.agent_doc.v1",
3
3
  "role": "buyer",
4
4
  "topic": "install-and-setup",
5
- "title": "Install and Configure ItPay V3 CLI for Agent Hosts",
6
- "purpose": "Guide the agent or runtime owner through installing and configuring the itpay CLI for different agent hosts.",
5
+ "title": "Install And Identify The ItPay Agent Runtime",
6
+ "purpose": "Install the CLI, load the complete Buyer Skill, and select one stable Agent Type without confusing identity, Backend, Host, target, or chat window.",
7
7
  "when_to_use": [
8
- "First-time setup of the itpay CLI.",
9
- "The agent needs to be configured for a specific host (Codex, Claude Code, etc.).",
10
- "The buyer wants to use itpay in a new environment."
8
+ "The CLI is being installed or upgraded.",
9
+ "The agent needs to confirm its stable runtime identity and default output Host."
11
10
  ],
12
11
  "commands": [
13
12
  {
14
- "intent": "list all supported install targets",
15
- "command": "itpay install",
16
- "success_signal": "Table of targets (claude-code, codex, terminal, telegram, feishu) with config file paths."
13
+ "intent": "verify the API and enter packaged onboarding",
14
+ "command": "itpay readyz --json",
15
+ "success_signal": "status is ready and next points to skill show itpay-buyer"
17
16
  },
18
17
  {
19
- "intent": "show install instructions for a specific target",
20
- "command": "itpay install claude-code",
21
- "success_signal": "Step-by-step instructions for Claude Code setup."
18
+ "intent": "read the complete packaged operating contract",
19
+ "command": "itpay skill show itpay-buyer --json",
20
+ "success_signal": "status is shown, result.content contains the complete Skill, and next selects Agent Type or Catalog"
22
21
  },
23
22
  {
24
- "intent": "show install instructions for Codex / Trae",
25
- "command": "itpay install codex",
26
- "success_signal": "Step-by-step instructions for Codex/Trae setup."
27
- }
28
- ],
29
- "env_vars": {
30
- "ITPAY_BACKEND_URL": {
31
- "required": false,
32
- "description": "Optional V3 backend override. The CLI defaults to https://app.itpay.ai.",
33
- "examples": ["http://localhost:18080", "https://test.itpay.ai"]
34
- },
35
- "ITPAY_BEARER_TOKEN": {
36
- "required": false,
37
- "description": "Bearer token for authenticated operations (orders list, vault, profile). Not needed for anonymous cart/checkout.",
38
- "acquired_from": "Sign in via web at /signin, then copy the session token."
39
- },
40
- "ITPAY_CART_SESSION_PATH": {
41
- "required": false,
42
- "description": "Custom path for the cart session file. Default: ~/.itpay-v3/cart.json"
43
- },
44
- "ITPAY_AGENT_DEVICE_ID": {
45
- "required": false,
46
- "description": "Legacy compatibility input. V3 enrolls a signed device identity under ~/.itpay-v3/device; agents should not rotate or invent this value."
23
+ "intent": "list supported Agent Types",
24
+ "command": "itpay install --json",
25
+ "success_signal": "status is install_targets and exactly five agent_type/default_host pairs are returned"
47
26
  },
48
- "ITPAY_AGENT_TYPE": {
49
- "required": false,
50
- "description": "Agent runtime type. Set this or pass --agent-type for commerce commands, for example codex-desktop or claude-code-cli."
51
- },
52
- "ITPAY_CURRENCY": {
53
- "required": false,
54
- "description": "Default currency for cart operations. Default: CNY"
27
+ {
28
+ "intent": "read setup for the real runtime",
29
+ "command": "itpay install <agent_type> --json",
30
+ "success_signal": "status is instructions_ready and next is a readyz command using that exact Agent Type"
55
31
  }
56
- },
57
- "host_requirements": {
58
- "terminal": "No special config needed. QR renders as ASCII in terminal or saved as PNG file.",
59
- "codex": "Use --host codex or --host trae. Markdown output with images and links.",
60
- "claude-code": "Use --host claude-code. Markdown format with image references.",
61
- "telegram": "Use --host telegram --target <chat_id>. Output includes openclaw_message payloads.",
62
- "feishu": "Use --host feishu --target <open_id>. Output is Feishu Interactive Card JSON.",
63
- "lark": "Use --host lark --target <open_id>. Same as feishu format."
64
- },
32
+ ],
65
33
  "agent_rules": [
66
- "Use the built-in https://app.itpay.ai production default; override ITPAY_BACKEND_URL only for another deliberate environment.",
67
- "Install globally with npm install -g @itpay/cli for all hosts.",
68
- "Identify the real runtime with --agent-type or ITPAY_AGENT_TYPE; do not invent a new type to obtain quota.",
69
- "Run `itpay install` without arguments to see all supported targets.",
70
- "Server cart facts persist in backend Postgres. ~/.itpay-v3/cart.json only caches last ids, checkout display token, and explicit local drafts."
34
+ "Install with npm install -g @itpay/cli.",
35
+ "Use the default https://app.itpay.ai API unless an environment override is deliberate.",
36
+ "Use one exact type: codex-desktop, codex-cli, claude-code-desktop, claude-code-cli, or workbuddy.",
37
+ "One local private key is reused, but each exact Backend API base URL has its own server registration and quota lineage.",
38
+ "Within one Backend registration, each Agent Type has one Agent Instance; all windows and chats of the same type reuse it.",
39
+ "Agent Type identifies the runtime. Host controls rendering and target only identifies a presentation destination.",
40
+ "Keep the exact Agent Type in every next or recovery command; do not fall back to a type previously used by another runtime.",
41
+ "Do not change Agent Type or rotate local identity to reset quota or recover a failed command."
42
+ ],
43
+ "forbidden": [
44
+ "Do not use codex, terminal, claude-code, or plain-chat as Agent Types.",
45
+ "Do not claim that install writes host configuration or registers a device; it only prints instructions.",
46
+ "Do not create a new identity for a different window, task, chat, or process of the same Agent Type."
47
+ ],
48
+ "next_docs": [
49
+ { "condition": "Installation is verified", "topic": "quickstart" }
71
50
  ],
72
- "search_terms": [
73
- "install",
74
- "setup",
75
- "configure",
76
- "first time",
77
- "setup",
78
- "安装",
79
- "配置",
80
- "environment"
81
- ]
51
+ "search_terms": ["install", "agent type", "host", "target", "device", "session", "identity", "backend", "codex", "claude code", "workbuddy"]
82
52
  }
@@ -2,75 +2,53 @@
2
2
  "schema_version": "itp.agent_doc.v1",
3
3
  "role": "buyer",
4
4
  "topic": "orders-refunds",
5
- "title": "Orders, Payment Escape Hatch, And Refund Requests",
6
- "purpose": "Teach the agent how to inspect orders and create refund requests with the current V3 CLI package.",
5
+ "title": "Order, Delivery And Refund Recovery",
6
+ "purpose": "Read owned orders and manage refunds through signed Agent authority without guessing payment or refund state.",
7
7
  "when_to_use": [
8
- "The user wants to inspect one order.",
9
- "The agent needs to list orders for an account-scoped bearer session.",
10
- "The user wants to request a refund.",
11
- "The checkout page is unavailable and the operator needs the payment-intent escape hatch."
8
+ "An order or Service Execution was interrupted after payment.",
9
+ "The buyer asks to request, track, or cancel a refund."
12
10
  ],
13
- "required_state": {
14
- "needs": [
15
- "order_id for order or refund flows",
16
- "ITPAY_BEARER_TOKEN for refund flows"
17
- ],
18
- "optional": [
19
- "refund reason; defaults to buyer_requested"
20
- ]
21
- },
22
11
  "commands": [
23
12
  {
24
- "intent": "read one canonical order by id",
25
- "command": "itpay order <order_id>",
26
- "success_signal": "order details and a status hint are printed"
13
+ "intent": "read one order",
14
+ "command": "itpay --agent-type <agent_type> order <order_id> --json",
15
+ "success_signal": "one compact owned-order summary and one current next step are returned"
27
16
  },
28
17
  {
29
- "intent": "list account-visible orders",
30
- "command": "ITPAY_BEARER_TOKEN=<account_scoped_token> itpay orders --limit 20",
31
- "success_signal": "orders are listed, or the CLI prints that no orders were found"
18
+ "intent": "request a refund",
19
+ "command": "itpay --agent-type <agent_type> refund create --order <order_id> --reason buyer_requested --json",
20
+ "success_signal": "the Refund Owner returns its request id, policy status, consumption state, and access lock"
32
21
  },
33
22
  {
34
- "intent": "create a payment intent only when the normal checkout page cannot do it",
35
- "command": "itpay pay --checkout <checkout_id> --method alipay",
36
- "success_signal": "payment_intent_id and current payment state are printed"
23
+ "intent": "recover one refund",
24
+ "command": "itpay --agent-type <agent_type> refund get <refund_request_id> --json",
25
+ "success_signal": "one authoritative refund snapshot is returned"
37
26
  },
38
27
  {
39
- "intent": "request a refund for an order",
40
- "command": "ITPAY_BEARER_TOKEN=<account_scoped_token> itpay refund --order <order_id> --reason buyer_requested",
41
- "success_signal": "refund request id and refund status are printed"
28
+ "intent": "wait through provider processing",
29
+ "command": "itpay --agent-type <agent_type> refund watch <refund_request_id> --json",
30
+ "success_signal": "one terminal refund envelope or one resumable timeout envelope is returned"
31
+ },
32
+ {
33
+ "intent": "cancel before provider submission",
34
+ "command": "itpay --agent-type <agent_type> refund cancel <refund_request_id> --json",
35
+ "success_signal": "the Refund Owner cancels the request and requires a new delivery authorization"
42
36
  }
43
37
  ],
44
38
  "agent_rules": [
45
- "Use itpay order when you already know the exact order id.",
46
- "Use itpay orders only with an account-scoped bearer token. Missing or wrong scope should be surfaced as an error, not guessed away.",
47
- "Treat itpay pay as an operator escape hatch. The checkout handoff remains the preferred path.",
48
- "Never ask the user or client to supply refund payment ids, amount, currency, buyer id, or actor; the backend derives them from the owned order.",
49
- "The refund response is the current source of truth; do not assume success locally."
39
+ "The Backend derives payment, amount, currency, Buyer and refund policy from the owned order.",
40
+ "A refund request freezes all delivery paths and revokes existing grants immediately.",
41
+ "Cancellation or rejection restores eligibility but never reactivates an old grant.",
42
+ "Use get or watch after interruption; do not infer success from elapsed time.",
43
+ "Account-wide orders requires an account-scoped Buyer bearer; exact order and refund routes support the bound signed Agent where documented."
50
44
  ],
51
45
  "forbidden": [
52
- "Do not fabricate bearer tokens.",
53
- "Do not create a payment intent first if normal checkout rendering is available.",
54
- "Do not claim a refund succeeded before the backend response says so."
46
+ "Do not fabricate Buyer sessions, Device IDs or payment references.",
47
+ "Do not read delivery while refund access_locked is true.",
48
+ "Do not claim a refund succeeded before the Refund Owner says succeeded."
55
49
  ],
56
50
  "next_docs": [
57
- {
58
- "condition": "Need the initial buyer flow",
59
- "topic": "quickstart",
60
- "file": "docs/agent/buyer/quickstart.json"
61
- },
62
- {
63
- "condition": "Need host-specific render behavior for checkout handoff",
64
- "topic": "render-hosts",
65
- "file": "docs/agent/buyer/render-hosts.json"
66
- }
51
+ { "condition": "Need the original purchase path", "topic": "quickstart" }
67
52
  ],
68
- "search_terms": [
69
- "order",
70
- "orders",
71
- "refund",
72
- "payment intent",
73
- "退款",
74
- "订单"
75
- ]
53
+ "search_terms": ["order", "refund", "cancel", "watch", "delivery lock", "grant"]
76
54
  }
@@ -2,76 +2,47 @@
2
2
  "schema_version": "itp.agent_doc.v1",
3
3
  "role": "buyer",
4
4
  "topic": "payment-flow",
5
- "title": "ItPay V3 Payment Flow — From Checkout to Verified Payment",
6
- "purpose": "Teach the agent how to hand a checkout to the human, let the ItPay checkout page create provider payment, and verify payment state.",
5
+ "title": "Human Checkout Handoff And Payment Verification",
6
+ "purpose": "Show the ItPay Checkout to the human and recover authoritative payment state without creating duplicate payment resources.",
7
7
  "when_to_use": [
8
- "The agent has created a checkout and needs to hand it to the human.",
9
- "The buyer wants to pay via Alipay or WeChat Pay.",
10
- "The agent needs to wait for payment verification before confirming success."
8
+ "buy or services checkout returned human_checkout_required.",
9
+ "The agent restarted or lost the Checkout output before payment was confirmed."
11
10
  ],
12
11
  "commands": [
13
12
  {
14
- "intent": "create checkout from a canonical server cart and render ItPay checkout page handoff",
15
- "command": "itpay buy --cart <cart_id> --host <client> --contact-email <email>",
16
- "success_signal": "ItPay checkout QR/URL is rendered for the human; payment intent is not created by the agent."
13
+ "intent": "present the Checkout handoff",
14
+ "command": "<execute the exact command returned by buy or services checkout>",
15
+ "success_signal": "the human can see both the ItPay Checkout QR or image and the Checkout URL"
17
16
  },
18
17
  {
19
- "intent": "create service-execution quote lock and render ItPay checkout page handoff",
20
- "command": "itpay services checkout <service_execution_id> --capability <paid_capability_id> [--email <email>]",
21
- "success_signal": "The quote lock is bound to the original server cart item when present; ItPay checkout QR/URL is rendered for the human; the checkout page handles authorization and provider payment."
18
+ "intent": "read authoritative Checkout state",
19
+ "command": "itpay checkout --id <checkout_id> --token <display_token> --json",
20
+ "success_signal": "pending returns one human handoff; completed returns no payment handoff and routes to delivery"
22
21
  },
23
22
  {
24
- "intent": "create service-execution checkout with machine-readable handoff",
25
- "command": "itpay services checkout <service_execution_id> --capability <paid_capability_id> [--email <email>] --json",
26
- "success_signal": "JSON with kind='checkout_handoff_required', next_action='open_human_checkout', checkout_url, display_token, qr_png_url, and brand_qr_local_path."
27
- },
28
- {
29
- "intent": "recover a service checkout after output loss, process restart, or token expiry",
23
+ "intent": "recover a service Checkout handoff",
30
24
  "command": "itpay services checkout <service_execution_id> --resume --json",
31
- "success_signal": "The existing checkout is reused and a fresh handoff is persisted before rendering."
32
- },
33
- {
34
- "intent": "inspect checkout state after payment",
35
- "command": "itpay checkout --id <checkout_id> --token <display_token>",
36
- "success_signal": "Current checkout status, any payment intents, and buyer session state."
25
+ "success_signal": "the same unpaid Checkout is reused with a fresh short-lived handoff"
37
26
  }
38
27
  ],
39
- "payment_flow_states": {
40
- "quote_bound": "Checkout created, no payment intent yet. Show the ItPay checkout QR/URL to the human.",
41
- "payment_pending": "Payment intent created, waiting for buyer to complete payment.",
42
- "payment_succeeded": "Payment verified via SSE event payment_intent.verified.",
43
- "completed": "Order delivered."
44
- },
45
28
  "agent_rules": [
46
- "Do not call itpay pay or use --pay for the normal buyer flow; those are operator escape hatches.",
47
- "The human opens the ItPay checkout page first; the page handles authorization and creates the Alipay/WeChat payment intent.",
48
- "For JSON output, render brand_qr_local_path or qr_png_url to the human; do not render provider qr.alipay.com directly.",
49
- "After timeout, re-run checkout --id ... --token ... to check current state before retrying.",
50
- "Payment success is confirmed ONLY by backend events, not by QR display or buyer claim."
29
+ "Normal buyer flow opens the ItPay Checkout page; itpay pay and buy --pay are operator escape hatches.",
30
+ "Use only handoff fields returned for the current Host and make them actually visible to the human.",
31
+ "Before creating a single-Service Checkout, send the exact price confirmation requested by the current instruction, stop, and wait for explicit human agreement.",
32
+ "After presenting a Checkout, stop. Run the returned next.command only after the human completes the payment action or asks to query the same Checkout.",
33
+ "Payment is verified only by Backend Checkout or Order state, never by QR rendering, redirect, or user claim.",
34
+ "A terminal payment state must never display another payment handoff."
35
+ ],
36
+ "forbidden": [
37
+ "Do not render a provider QR in place of the ItPay Checkout handoff.",
38
+ "Do not mix a display token from another Checkout.",
39
+ "Do not create a replacement Checkout after an uncertain response; recover first.",
40
+ "Do not use services quote, cart, buy, or pay as a fallback when the single-Service checkout flow fails.",
41
+ "Do not start another Service Execution to bypass quota, candidate, quote, checkout, or delivery state."
51
42
  ],
52
43
  "next_docs": [
53
- {
54
- "condition": "Payment verified, need to check order state",
55
- "topic": "orders-refunds",
56
- "file": "docs/agent/buyer/orders-refunds.json"
57
- },
58
- {
59
- "condition": "Need to understand render behavior per host",
60
- "topic": "render-hosts",
61
- "file": "docs/agent/buyer/render-hosts.json"
62
- }
44
+ { "condition": "Payment is verified", "topic": "orders-refunds" },
45
+ { "condition": "The current Host cannot display the handoff", "topic": "render-hosts" }
63
46
  ],
64
- "search_terms": [
65
- "payment",
66
- "pay",
67
- "alipay",
68
- "wechat",
69
- "QR",
70
- "payment intent",
71
- "wait",
72
- "SSE",
73
- "verified",
74
- "支付",
75
- "扫码"
76
- ]
47
+ "search_terms": ["payment", "checkout", "QR", "display token", "resume", "verified"]
77
48
  }