@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
@@ -3,9 +3,6 @@ export function formatMoney(amountMinor, currency) {
3
3
  const major = (amountMinor / 100).toFixed(2);
4
4
  return `${major} ${currency}`;
5
5
  }
6
- export function renderReady(payload) {
7
- return `backend ${payload.status} (version ${payload.version})`;
8
- }
9
6
  export function renderOrder(order) {
10
7
  const lines = [];
11
8
  lines.push(`order ${order.order_id}`);
@@ -36,6 +33,8 @@ export function renderRefund(refund) {
36
33
  ` status: ${refund.status}`,
37
34
  ` amount: ${formatMoney(refund.amount_minor, refund.currency)}`,
38
35
  refund.reason ? ` reason: ${refund.reason}` : "",
36
+ ` access: ${refund.access_locked ? "locked" : "available"}`,
37
+ ` policy: ${refund.decision_mode === "automatic" ? "automatic" : "admin review"}`,
39
38
  ]
40
39
  .filter((line) => line.length > 0)
41
40
  .join("\n");
@@ -7,6 +7,7 @@ import { randomUUID } from "node:crypto";
7
7
  import { dirname } from "node:path";
8
8
  export class CartSession {
9
9
  state;
10
+ loadFailed = false;
10
11
  constructor(currency) {
11
12
  this.state = { currency, items: [] };
12
13
  }
@@ -23,8 +24,6 @@ export class CartSession {
23
24
  }
24
25
  });
25
26
  }
26
- if (persisted.agentDeviceID)
27
- session.state.agentDeviceID = persisted.agentDeviceID;
28
27
  if (persisted.lastCartID)
29
28
  session.state.lastCartID = persisted.lastCartID;
30
29
  if (persisted.lastCartItemID)
@@ -40,6 +39,7 @@ export class CartSession {
40
39
  }
41
40
  catch {
42
41
  session.state.items = [];
42
+ session.loadFailed = true;
43
43
  }
44
44
  }
45
45
  return session;
@@ -48,7 +48,6 @@ export class CartSession {
48
48
  const toSave = {
49
49
  currency: this.state.currency,
50
50
  items: this.state.items.map((item) => ({ ...item })),
51
- ...(this.state.agentDeviceID ? { agentDeviceID: this.state.agentDeviceID } : {}),
52
51
  ...(this.state.lastCartID ? { lastCartID: this.state.lastCartID } : {}),
53
52
  ...(this.state.lastCartItemID ? { lastCartItemID: this.state.lastCartItemID } : {}),
54
53
  ...(this.state.lastServiceExecutionID ? { lastServiceExecutionID: this.state.lastServiceExecutionID } : {}),
@@ -84,11 +83,7 @@ export class CartSession {
84
83
  }
85
84
  }
86
85
  clear() {
87
- this.state = {
88
- currency: this.state.currency,
89
- items: [],
90
- ...(this.state.agentDeviceID ? { agentDeviceID: this.state.agentDeviceID } : {}),
91
- };
86
+ this.state = { currency: this.state.currency, items: [] };
92
87
  }
93
88
  show() {
94
89
  return JSON.parse(JSON.stringify(this.state));
@@ -107,7 +102,8 @@ export class CartSession {
107
102
  }
108
103
  rememberCheckout(input) {
109
104
  this.state.items = [];
110
- this.state.lastCartID = input.cartID;
105
+ delete this.state.lastCartID;
106
+ delete this.state.lastCartItemID;
111
107
  this.state.lastCheckoutID = input.checkoutID;
112
108
  this.state.lastDisplayToken = input.displayToken;
113
109
  this.state.lastCheckoutURL = input.checkoutURL;
@@ -117,18 +113,15 @@ export class CartSession {
117
113
  rememberServerCart(input) {
118
114
  this.state.items = [];
119
115
  this.state.lastCartID = input.cartID;
116
+ delete this.state.lastCartItemID;
117
+ delete this.state.lastServiceExecutionID;
118
+ delete this.state.lastCheckoutID;
119
+ delete this.state.lastDisplayToken;
120
+ delete this.state.lastCheckoutURL;
120
121
  if (input.cartItemID)
121
122
  this.state.lastCartItemID = input.cartItemID;
122
123
  if (input.serviceExecutionID)
123
124
  this.state.lastServiceExecutionID = input.serviceExecutionID;
124
- if (input.agentDeviceID)
125
- this.state.agentDeviceID = input.agentDeviceID;
126
- }
127
- ensureAgentDeviceID(fallback) {
128
- if (!this.state.agentDeviceID) {
129
- this.state.agentDeviceID = fallback;
130
- }
131
- return this.state.agentDeviceID;
132
125
  }
133
126
  get lastCartID() {
134
127
  return this.state.lastCartID;
@@ -148,4 +141,7 @@ export class CartSession {
148
141
  get currency() {
149
142
  return this.state.currency;
150
143
  }
144
+ get stateLoadFailed() {
145
+ return this.loadFailed;
146
+ }
151
147
  }
@@ -56,10 +56,12 @@ export function hasDedicatedRenderer(host) {
56
56
  }
57
57
  export function defaultHostForAgentType(agentType) {
58
58
  const normalized = agentType?.trim().toLowerCase() ?? "";
59
- if (normalized.startsWith("codex"))
59
+ if (normalized === "codex-desktop")
60
60
  return "codex";
61
- if (normalized.startsWith("claude-code"))
61
+ if (normalized === "claude-code-desktop")
62
62
  return "claude-code";
63
+ if (normalized === "workbuddy")
64
+ return "plain-chat";
63
65
  return "terminal";
64
66
  }
65
67
  export function validateContext(host, target) {
@@ -8,9 +8,9 @@ import { HttpClient } from "../client/http.js";
8
8
  import { BackendClient } from "../client/backend.js";
9
9
  import { DeviceAuthority } from "./device_authority.js";
10
10
  import { OperationJournal } from "./operation_journal.js";
11
- export const DEFAULT_BASE_URL = "https://api.itpay.ai";
12
- export const CLI_VERSION = "2.0.2";
13
- export const API_CONTRACT_REVISION = "sha256:2c2829f4618c47bc505efc0ded853cf639d775585ba13aa23012197e39efa31f";
11
+ export const DEFAULT_BASE_URL = "https://app.itpay.ai";
12
+ export const CLI_VERSION = "2.0.5";
13
+ export const API_CONTRACT_REVISION = "sha256:3e6b650c62fa54eb8b9ea6b86857cfef594313871e2bf1b9f3ca4ff3cc6e1612";
14
14
  const CART_SESSION_DEFAULT_DIR = ".itpay-v3";
15
15
  const CART_SESSION_FILENAME = "cart.json";
16
16
  const OPERATION_JOURNAL_FILENAME = "operations.json";
@@ -25,7 +25,6 @@ export function cartSessionPath(env = process.env) {
25
25
  export function loadConfig(env = process.env) {
26
26
  const baseURL = env.ITPAY_BACKEND_URL || DEFAULT_BASE_URL;
27
27
  const bearerToken = env.ITPAY_BEARER_TOKEN || undefined;
28
- const agentDeviceID = env.ITPAY_AGENT_DEVICE_ID || "";
29
28
  const agentType = env.ITPAY_AGENT_TYPE || agentTypeFromArgv(process.argv);
30
29
  const checkoutCurrency = env.ITPAY_CURRENCY || "CNY";
31
30
  const idempotencyKey = env.ITPAY_IDEMPOTENCY_KEY || `cli_${shortRandom()}`;
@@ -33,7 +32,6 @@ export function loadConfig(env = process.env) {
33
32
  const ideImageDirOverride = env.ITPAY_IDE_IMAGE_DIR_OVERRIDE;
34
33
  return {
35
34
  baseURL,
36
- agentDeviceID,
37
35
  ...(agentType ? { agentType } : {}),
38
36
  checkoutCurrency,
39
37
  idempotencyKey,
@@ -2,7 +2,7 @@ import { createHash, createPrivateKey, generateKeyPairSync, randomUUID, sign, }
2
2
  import { chmodSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync, } from "node:fs";
3
3
  import { homedir } from "node:os";
4
4
  import { dirname, resolve } from "node:path";
5
- const PROTECTED_PATHS = ["/v1/carts", "/v1/service-executions", "/v1/agent-instances"];
5
+ const PROTECTED_PATHS = ["/v1/carts", "/v1/service-executions", "/v1/agent-instances", "/v1/orders", "/v1/refunds"];
6
6
  export class DeviceAuthority {
7
7
  baseURL;
8
8
  requestedAgentType;
@@ -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
  }
@@ -2,81 +2,37 @@
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 and select one of the five supported Agent Types without confusing Agent Type with Host.",
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": "list supported Agent Types",
14
+ "command": "itpay install --json",
15
+ "success_signal": "status is install_targets and exactly five agent_type/default_host pairs are returned"
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."
22
- },
23
- {
24
- "intent": "show install instructions for Codex / Trae",
25
- "command": "itpay install codex",
26
- "success_signal": "Step-by-step instructions for Codex/Trae setup."
18
+ "intent": "read setup for the real runtime",
19
+ "command": "itpay install <agent_type> --json",
20
+ "success_signal": "status is instructions_ready and next is a readyz command using that exact Agent Type"
27
21
  }
28
22
  ],
29
- "env_vars": {
30
- "ITPAY_BACKEND_URL": {
31
- "required": false,
32
- "description": "Optional V3 backend override. The CLI defaults to https://api.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."
47
- },
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"
55
- }
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
- },
65
23
  "agent_rules": [
66
- "Use the built-in https://api.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."
24
+ "Install with npm install -g @itpay/cli.",
25
+ "Use the default https://app.itpay.ai API unless an environment override is deliberate.",
26
+ "Use one exact type: codex-desktop, codex-cli, claude-code-desktop, claude-code-cli, or workbuddy.",
27
+ "Agent Type identifies the runtime and device instance. Host only controls human-facing rendering.",
28
+ "Do not change Agent Type to reset quota or recover a failed command."
29
+ ],
30
+ "forbidden": [
31
+ "Do not use codex, terminal, claude-code, or plain-chat as Agent Types.",
32
+ "Do not claim that install writes host configuration or registers a device; it only prints instructions."
33
+ ],
34
+ "next_docs": [
35
+ { "condition": "Installation is verified", "topic": "quickstart" }
71
36
  ],
72
- "search_terms": [
73
- "install",
74
- "setup",
75
- "configure",
76
- "first time",
77
- "setup",
78
- "安装",
79
- "配置",
80
- "environment"
81
- ]
37
+ "search_terms": ["install", "agent type", "host", "codex", "claude code", "workbuddy"]
82
38
  }
@@ -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
- "payment_intent_id for refund flows"
17
- ],
18
- "optional": [
19
- "ITPAY_BEARER_TOKEN for account order listing"
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 refund --order <order_id> --payment-intent <payment_intent_id> --amount-minor <n> --currency CNY --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
- "Refund amounts are minor units. For CNY, 100 means CNY 1.00.",
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,43 @@
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
+ "Payment is verified only by Backend Checkout or Order state, never by QR rendering, redirect, or user claim.",
32
+ "A terminal payment state must never display another payment handoff."
33
+ ],
34
+ "forbidden": [
35
+ "Do not render a provider QR in place of the ItPay Checkout handoff.",
36
+ "Do not mix a display token from another Checkout.",
37
+ "Do not create a replacement Checkout after an uncertain response; recover first."
51
38
  ],
52
39
  "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
- }
40
+ { "condition": "Payment is verified", "topic": "orders-refunds" },
41
+ { "condition": "The current Host cannot display the handoff", "topic": "render-hosts" }
63
42
  ],
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
- ]
43
+ "search_terms": ["payment", "checkout", "QR", "display token", "resume", "verified"]
77
44
  }