@itpay/cli 0.2.15 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -250,9 +250,9 @@ Payment QR rules:
250
250
  - Do not generate your own QR from payment URLs.
251
251
  - In OpenClaw Telegram, run root `agent_action.command` or `agent_action.argv` before replying; do not simulate buttons in normal prose.
252
252
  - Telegram native buttons require `presentation.blocks[].type="buttons"` with `text/url/callback_data`.
253
- - For Codex/Claude Code app clients, send root `agent_action.markdown` before any next ItPay command. If you can confirm it is visible to the human, you may then run `after_visible_action.command`; if unsure, stop.
253
+ - For Codex/Claude Code app clients, send root `agent_action.markdown` first; once it is visible in the current chat, run `after_visible_action.command` once by default. Stop only if visibility is uncertain.
254
254
  - For terminal clients, run root `agent_action.command` only when the human is directly watching that terminal. Do not use `--host terminal` merely because you invoke `itp` through shell.
255
- - If status is `payment_handoff_required`, `next` is the human reply step, not payment wait.
255
+ - If status is `payment_handoff_required`, follow `next.type`: Codex/Claude app clients normally send-to-human then wait once; plain chat stops for the human.
256
256
  - Treat only `payment_intent.verified` as payment success.
257
257
 
258
258
  If the human wants the agent to analyze delivered content, the human must reveal
@@ -49,10 +49,10 @@
49
49
  "response.agent_instruction is natural-language reinforcement for the agent; it does not replace response.agent_action.",
50
50
  "Telegram native buttons require openclaw message send --presentation; presentation.blocks[].type=\"buttons\" uses native text/url/callback_data. Do not simulate buttons in normal prose.",
51
51
  "If agent_instruction links/buttons include URLs, include the real URL. Do not only show the link label.",
52
- "In Codex or Claude Code app clients, send response.agent_action.markdown first. Do not start a hidden long wait before the human-visible message is sent.",
52
+ "In Codex or Claude Code app clients, send response.agent_action.markdown first. Once it is visible in the current chat, immediately run response.after_visible_action.command once; do not start a hidden wait before the human-visible message is sent.",
53
53
  "For Telegram-style message clients, send photo media first, include links, and expose native buttons for refresh/status when the adapter supports them.",
54
54
  "For plain chat clients, show response.agent_instruction.message/links and stop unless the human asks you to check status or returns with a payment question.",
55
- "When response.status is payment_handoff_required, response.next is the human reply step, not payment wait.",
55
+ "When response.status is payment_handoff_required, response.next describes the current client handoff. For Codex/Claude Code, send the markdown and then run after_visible_action once if visible; for plain chat, stop for the human.",
56
56
  "MUST show local_qr_path first when present. Many agent clients do not reliably render remote QR images; local_qr_path is the most reliable desktop/chat display artifact.",
57
57
  "If local_qr_path is not present, show qr_png_url or preferred_qr_url as the primary scannable QR. This is an ItPay-hosted human QR image; it may render the native provider payment code for scanner reliability, but the agent must not request or decode the raw provider payload.",
58
58
  "Use qr_image_url/SVG only as a fallback when PNG/local rendering is unavailable.",
@@ -60,8 +60,8 @@
60
60
  "payment_entry_url is the stable ItPay status/payment page. qr_png_url/local_qr_path is usually the better desktop scanner artifact.",
61
61
  "The provider can briefly show order not found even after precreate succeeded. Tell the human to wait 30-60 seconds and retry the same QR/page. Do not create a new checkout, do not create a new payment intent, and do not repeatedly refresh unless the ItPay page or CLI explicitly asks for recovery.",
62
62
  "Opening the payment page must not be treated as paid.",
63
- "Do not run payment wait before the QR/link has been sent to the human. If after_visible_action.command exists and you can confirm the handoff is visible, you may run it once; if unsure, stop and wait for the human.",
64
- "After the human says they paid or clicks a platform status button, run response.after_human_response.check_payment_command for the same payment_intent_id."
63
+ "Do not run payment wait before the QR/link has been sent to the human. If response.after_visible_action.command exists and you can confirm the handoff is visible, run it once by default; if unsure, stop and wait for the human.",
64
+ "If response.after_visible_action was not run, or after the human says they paid/clicks a platform status button later, run response.after_human_response.check_payment_command for the same payment_intent_id."
65
65
  ],
66
66
  "forbidden": [
67
67
  "Do not encode payment_entry_url into a new QR yourself when qr_png_url/local_qr_path is available.",
@@ -37,11 +37,11 @@
37
37
  "agent_rules": [
38
38
  "Every payment wait/status command must include the same client context as the handoff command. For OpenClaw Telegram, keep --host telegram --target <same chat_id>.",
39
39
  "If payment wait returns payment_handoff_required with response.agent_action, execute it before any later status check: command/argv for Telegram or terminal, markdown for Codex/Claude Code app clients. If only response.agent_instruction is present, follow it exactly before any later status check.",
40
- "Start payment status checks only after the QR image/link has already been sent to the human or the human asks to check status.",
40
+ "Start payment status checks only after the QR image/link has already been sent to the human. In Codex/Claude Code app clients, after_visible_action.command is the default one-round status check once the handoff is visible.",
41
41
  "If you run payment wait without a short timeout while payment is still pending, CLI returns payment_handoff_required and the human handoff instruction instead of long-polling.",
42
42
  "Payment wait/status check is a recovery loop around the same payment_intent_id, not a one-shot command.",
43
43
  "wait.timeout is a heartbeat, not a payment failure.",
44
- "In Codex or Claude Code app clients, after showing QR, use after_visible_action.command only if you can confirm the QR/link is visible. If the human still has not paid, explain that the same QR/link remains valid and pause for their reply.",
44
+ "In Codex or Claude Code app clients, after showing QR and confirming it is visible, run after_visible_action.command once. If it times out, explain that the same QR/link remains valid and pause for the human or continue only if they ask.",
45
45
  "Continue checking the same payment_intent_id unless the user explicitly cancels or asks you to pause.",
46
46
  "If the network drops, the process is interrupted, or there is no response, rerun payment wait with the same payment_intent_id or run checkout status/resume with the same checkout_id.",
47
47
  "If status is unclear, tell the human it is unclear and continue querying the same payment_intent_id/checkout_id. Do not create a new checkout.",
@@ -65,12 +65,12 @@
65
65
  "After showing auth_qr, keep running/resuming the same checkout unless the human explicitly asks you to pause. Do not stop merely because a QR was displayed.",
66
66
  "When a buyer command returns buyer_session.status=buyer_session_saved, the CLI has stored the buyer account session for this agent device. You may continue with checkout/payment or `buyer vault` commands without asking the human for a token.",
67
67
  "Vault grants are only for reading approved delivered artifacts. They are not buyer session credentials and do not authorize refunds or account/order management.",
68
- "Use high-level itp buy when possible, but in agent app clients split payment into two visible steps: first return and send the human handoff instruction, then only check status after the human responds or uses a platform button.",
68
+ "Use high-level itp buy when possible. In Codex/Claude Code app clients, the default payment flow is one round: send response.agent_action.markdown to the current chat, then immediately run response.after_visible_action.command once if the QR/link is visible.",
69
69
  "If response.agent_action is present, it is the mandatory execution path for the current client. Execute it before any normal prose reply: command/argv for Telegram or terminal, markdown for Codex/Claude Code app clients.",
70
70
  "In OpenClaw Telegram, response.agent_action is already the exact openclaw message send command. It includes target, QR media, exact message, and native button presentation.",
71
71
  "If response.agent_action cannot be executed or made visible to the human, stop and tell the human what capability is missing. Do not fall back to handwritten prose.",
72
72
  "response.agent_instruction is natural-language reinforcement for the agent; it does not replace response.agent_action.",
73
- "If response.status is payment_handoff_required, do not run payment wait from next.command; next is the human-visible reply. If after_visible_action.command exists and you can confirm the handoff is visible, you may run it once; if unsure, stop and wait for the human.",
73
+ "If response.status is payment_handoff_required, do not run payment wait before the QR/link is visible. If response.next.type is send_to_human_then_wait_once_if_visible, send agent_action first, then run after_visible_action.command once. Stop only when visibility is uncertain.",
74
74
  "Show the returned payment QR exactly as provided before starting payment wait.",
75
75
  "Payment truth comes only from payment_intent.verified.",
76
76
  "Secure delivery goes to the human first; report redacted delivery status only.",
package/lib/buyer.js CHANGED
@@ -1155,14 +1155,14 @@ function isTelegramBuyerHost(flags = {}) {
1155
1155
  }
1156
1156
 
1157
1157
  function paymentHandoffAgentNextActions() {
1158
- return ["send_agent_instruction_to_human"];
1158
+ return ["send_agent_instruction_to_human", "run_after_visible_action_once_if_visible"];
1159
1159
  }
1160
1160
 
1161
1161
  function paymentHandoffNext() {
1162
1162
  return {
1163
- type: "reply_to_human",
1164
- safe_for_agent: false,
1165
- instruction: "Send agent_instruction to the human now. Do not run payment wait until this message is visible to the human."
1163
+ type: "send_to_human_then_wait_once_if_visible",
1164
+ safe_for_agent: true,
1165
+ instruction: "Send agent_instruction to the human first. If it is visible, run after_visible_action once; otherwise stop and wait for the human."
1166
1166
  };
1167
1167
  }
1168
1168
 
@@ -1659,9 +1659,16 @@ function markdownBuyerInstruction(value = {}, flags = {}, platform = "codex_app"
1659
1659
  markdown
1660
1660
  }, summary, {
1661
1661
  instruction,
1662
+ preferred_flow: "send_agent_action_then_wait_once",
1662
1663
  agent_action: markdownAgentAction(platform, markdown),
1663
1664
  after_visible_action: afterVisibleAction(value, flags, summary),
1664
- agent_next_actions: ["send_agent_action_to_human"]
1665
+ after_human_response_fallback: true,
1666
+ agent_next_actions: ["send_agent_action_to_human", "run_after_visible_action_once_if_visible"],
1667
+ next: {
1668
+ type: "send_to_human_then_wait_once_if_visible",
1669
+ safe_for_agent: true,
1670
+ instruction: "先把 agent_action.markdown 原样发到当前聊天;确认二维码、摘要和链接可见后,立刻执行 after_visible_action.command 等一次。只有无法确认可见时才停下等人类。"
1671
+ }
1665
1672
  });
1666
1673
  }
1667
1674
 
@@ -1690,24 +1697,37 @@ function terminalBuyerInstruction(value = {}, flags = {}) {
1690
1697
  print_terminal_qr: true
1691
1698
  }, summary, {
1692
1699
  instruction,
1700
+ preferred_flow: "execute_agent_action_then_wait_once",
1693
1701
  agent_action: terminalAgentAction(summary, flags, plan.kind),
1694
1702
  after_visible_action: afterVisibleAction(value, flags, summary),
1695
- agent_next_actions: ["execute_agent_action"]
1703
+ after_human_response_fallback: true,
1704
+ agent_next_actions: ["execute_agent_action", "run_after_visible_action_once_if_visible"],
1705
+ next: {
1706
+ type: "execute_terminal_handoff_then_wait_once_if_visible",
1707
+ safe_for_agent: true,
1708
+ instruction: "先执行 agent_action.command,让人类正在看的终端显示二维码和链接;确认可见后,立刻执行 after_visible_action.command 等一次。若人类不是直接看终端,停止并用正确 --host 重跑。"
1709
+ }
1696
1710
  });
1697
1711
  }
1698
1712
 
1699
1713
  function handoffInstructionOutput(value = {}, flags = {}, agentInstruction = {}, summary = {}, extra = {}) {
1714
+ const afterHumanResponse = genericAfterHumanResponse(value, flags, summary);
1715
+ if (extra.after_human_response_fallback) {
1716
+ afterHumanResponse.fallback = true;
1717
+ afterHumanResponse.instruction = "Fallback only: use check_status_command when after_visible_action was not run, or when the human later replies/clicks status. User text is not proof.";
1718
+ }
1700
1719
  return compactObject({
1701
1720
  status: value.status,
1702
1721
  instruction: extra.instruction,
1703
1722
  must_send_to_human_before_next_command: true,
1723
+ preferred_flow: extra.preferred_flow,
1704
1724
  order_summary: summary,
1705
1725
  agent_action: extra.agent_action,
1706
1726
  agent_instruction: agentInstruction,
1707
- after_human_response: genericAfterHumanResponse(value, flags, summary),
1708
1727
  after_visible_action: extra.after_visible_action,
1728
+ after_human_response: afterHumanResponse,
1709
1729
  agent_next_actions: extra.agent_next_actions || ["send_agent_instruction_to_human"],
1710
- next: {
1730
+ next: extra.next || {
1711
1731
  type: "reply_to_human",
1712
1732
  safe_for_agent: false,
1713
1733
  instruction: extra.next_instruction || "先把 agent_instruction 发送给用户;用户点击按钮或回复后,再运行 after_human_response 里的命令。"
@@ -1717,7 +1737,7 @@ function handoffInstructionOutput(value = {}, flags = {}, agentInstruction = {},
1717
1737
 
1718
1738
  function markdownBuyerInstructionText(platform = "codex_app") {
1719
1739
  const label = platform === "claude_code" ? "Claude Code app" : "Codex desktop app";
1720
- return `你在 ${label}。必须先把顶层 agent_action.markdown 原样发到当前聊天,让人类真正看到二维码、订单摘要和链接;不要因为你用 shell 跑 itp 就改用 --host terminal。发出后,如果你能确认消息已经对人类可见,可以继续执行 after_visible_action.command 等 30 秒;如果不能确认,就停止等人类回复。`;
1740
+ return `你在 ${label}。必须先把顶层 agent_action.markdown 原样发到当前聊天,让人类真正看到二维码、订单摘要和链接;不要因为你用 shell 跑 itp 就改用 --host terminal。发出后,如果你能确认消息已经对人类可见,默认立刻执行 after_visible_action.command 等 30 秒;只有不能确认可见时才停止等人类回复。`;
1721
1741
  }
1722
1742
 
1723
1743
  function markdownAgentAction(platform = "codex_app", markdown = "") {
@@ -1750,14 +1770,14 @@ function terminalAgentAction(summary = {}, flags = {}, kind = "") {
1750
1770
  function afterVisibleAction(value = {}, flags = {}, summary = {}) {
1751
1771
  if (summary.payment_intent_id) {
1752
1772
  return {
1753
- optional: true,
1773
+ recommended: true,
1754
1774
  command: cliCommand("buyer", "payment", "wait", summary.payment_intent_id, "--timeout", "30", ...clientCommandArgs(flags), "--json"),
1755
1775
  instruction: "只有在二维码、订单摘要和链接已经对人类可见后才能执行。用户说已付款不算证明,只有 payment_intent.verified 算付款成功。"
1756
1776
  };
1757
1777
  }
1758
1778
  if (summary.checkout_id) {
1759
1779
  return {
1760
- optional: true,
1780
+ recommended: true,
1761
1781
  command: cliCommand("buyer", "checkout", "resume", summary.checkout_id, ...clientCommandArgs(flags), "--json"),
1762
1782
  instruction: "只有在授权入口已经对人类可见后才能执行;继续同一个 checkout,不要新建 checkout。"
1763
1783
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itpay/cli",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "ItPay CLI, buyer skill, and agent-readable docs for agent-native commerce.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -245,11 +245,11 @@ Codex or Claude Code app clients, send `agent_action.markdown` exactly to the
245
245
  current chat. In terminal, run `agent_action.command` only when the human is
246
246
  directly watching that terminal.
247
247
 
248
- If a response has `status=payment_handoff_required`, `next` is the user-visible
249
- reply step, not payment wait. Do not run `buyer payment wait` until the human
250
- has seen the QR/link. If `after_visible_action.command` exists and you can
251
- confirm the handoff is visible, you may run it once; if unsure, stop and wait
252
- for the human.
248
+ If a response has `status=payment_handoff_required`, follow `next.type`.
249
+ For Codex/Claude Code app clients, send `agent_action.markdown` first; once it
250
+ is visible in the current chat, run `after_visible_action.command` once by
251
+ default. Do not run payment wait before the human-visible QR/link is sent. If
252
+ visibility is uncertain, stop and wait for the human.
253
253
 
254
254
  For first-purchase auth, treat the returned ItPay authorization entry as a
255
255
  single human orchestration entry. It may open Alipay login/registration first