@itpay/cli 2.0.3 → 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 +26 -8
  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 -11
  16. package/dist/src/commands/services.js +719 -148
  17. package/dist/src/main.js +711 -193
  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 +2 -4
  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
@@ -0,0 +1,85 @@
1
+ # `itpay refund create`
2
+
3
+ ## 范围与意义
4
+
5
+ 为一笔订单提交退款意图。Refund Owner 从订单推导 Buyer、支付、金额、币种、消费事实和审核策略;Agent 只提交订单和用户原因。
6
+
7
+ **上游:** `order <id>` 或用户明确提出退款。
8
+ **下游:** `refund watch <refund_request_id>`,或在 `can_cancel=true` 时由用户选择取消。
9
+
10
+ 退款成功落库与交付冻结是同一事务;CLI 不自行锁单,也不预测自动退款结果。
11
+
12
+ ## 语法与参数
13
+
14
+ ```bash
15
+ itpay refund create --order <order_id> [--reason <reason>] [--json]
16
+ ```
17
+
18
+ | 参数 | 必填 | 说明 |
19
+ | --- | --- | --- |
20
+ | `--order <order_id>` | 是 | 当前 Buyer 或已绑定 Agent 可见的订单。 |
21
+ | `--reason <reason>` | 否 | 默认 `buyer_requested`;只记录用户原因,不决定政策。 |
22
+ | `--json` | 否 | 输出稳定 JSON 信封;未指定时输出相同事实的简洁文本。 |
23
+
24
+ CLI 使用 Device Authority 或已有 Buyer bearer,并用订单+原因生成稳定幂等操作 ID。不得提交退款金额、币种、支付 ID、消费状态或审核模式。
25
+
26
+ ## 标准输出
27
+
28
+ ```json
29
+ {
30
+ "status": "requested",
31
+ "result": {
32
+ "refund_request_id": "<refund_id>",
33
+ "order_id": "<order_id>",
34
+ "decision_mode": "automatic",
35
+ "refund_status": "accepted",
36
+ "consumption_state": "unconsumed",
37
+ "access_locked": true,
38
+ "can_cancel": true
39
+ },
40
+ "instruction": "退款处理中,交付已冻结;不要 reveal、授权或读取结果。",
41
+ "next": {
42
+ "command": "itpay refund watch <refund_id> --json",
43
+ "reason": "跟踪同一退款"
44
+ },
45
+ "recovery": []
46
+ }
47
+ ```
48
+
49
+ `decision_mode` 的服务器枚举为 `automatic|manual`。已消费交付通常返回 `manual` / `policy_review_required`;instruction 明确等待人工审核。`status` 表示提交动作已完成,`result.refund_status` 才是退款状态机当前状态。
50
+
51
+ 若服务器返回退款终态,`next` 为 `null`。文本输出依次显示 result 字段、instruction 和一个 next,不输出支付或 Provider 内部数据。
52
+
53
+ 重复提交同一活跃退款时 Backend 返回已有请求,不创建第二笔;CLI 继续跟踪该 `refund_request_id`。
54
+
55
+ ## 异常处理
56
+
57
+ 缺少 `--order` 时在 HTTP 前返回 `order_required`,要求恢复当前 Service Execution,不猜订单 ID。
58
+
59
+ 订单不可见、已退款、无可退款支付或状态不允许时 fail closed:
60
+
61
+ ```json
62
+ {
63
+ "status": "error",
64
+ "error": {
65
+ "code": "<server_error_code>",
66
+ "message": "<server reason>"
67
+ },
68
+ "instruction": "确认订单属于当前账号且可退款;不要修改金额、支付或消费事实。",
69
+ "next": null,
70
+ "recovery": [
71
+ {
72
+ "command": "itpay order <order_id> --json",
73
+ "reason": "检查订单和交付锁"
74
+ },
75
+ {
76
+ "command": "itpay refund list --order <order_id> --json",
77
+ "reason": "检查已有退款"
78
+ }
79
+ ]
80
+ }
81
+ ```
82
+
83
+ ## Agent Type / Host
84
+
85
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 五种 Agent Type 使用相同 Device Authority、退款政策和输出。未绑定订单时不得改用新 Device ID、Buyer ID 或开发者权限绕过 Owner 鉴权。
@@ -0,0 +1,60 @@
1
+ # `itpay refund get`
2
+
3
+ ## 范围与意义
4
+
5
+ 读取一笔当前身份可见退款的权威快照、交付锁和可取消性。它只请求一次,不轮询、不改变退款状态。
6
+
7
+ **上游:** `refund create`、`refund list` 或之前的 `refund watch`。
8
+ **下游:** 非终态进入 `refund watch`;终态结束;`can_cancel=true` 时用户可另行选择取消。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay refund get <refund_request_id> [--json]
14
+ ```
15
+
16
+ | 参数 | 必填 | 说明 |
17
+ | --- | --- | --- |
18
+ | `refund_request_id` | 是 | Refund Owner 返回的退款 ID。 |
19
+ | `--json` | 否 | 输出稳定 JSON 信封;未指定时输出相同事实的简洁文本。 |
20
+
21
+ ## 标准输出
22
+
23
+ ```json
24
+ {
25
+ "status": "shown",
26
+ "result": {
27
+ "refund_request_id": "<id>",
28
+ "order_id": "<order_id>",
29
+ "decision_mode": "automatic",
30
+ "refund_status": "accepted",
31
+ "consumption_state": "unconsumed",
32
+ "access_locked": true,
33
+ "can_cancel": true
34
+ },
35
+ "instruction": "退款处理中,交付已冻结;不要 reveal、授权或读取结果。",
36
+ "next": {
37
+ "command": "itpay refund watch <refund_id> --json",
38
+ "reason": "跟踪同一退款"
39
+ },
40
+ "recovery": []
41
+ }
42
+ ```
43
+
44
+ `decision_mode` 为 `automatic|manual`;`refund_status`、`consumption_state`、`access_locked` 和 `can_cancel` 均直接来自 Refund Owner。文本输出显示同一组字段、instruction 和最多一个 next。
45
+
46
+ ## 终态
47
+
48
+ - `succeeded`:instruction 明确“退款已成功;交付永久关闭”,`next=null`。
49
+ - `cancelled/rejected`:说明交付资格可恢复,但旧 grant 不复活,需要用户重新授权,`next=null`。
50
+ - `failed`:是否继续锁定以 `access_locked` 和 `failure_class` 的服务器裁定为准,`next=null`。
51
+
52
+ CLI 不因为退款终态自行修改订单或 grant。
53
+
54
+ ## 异常处理
55
+
56
+ 不存在和不属于当前账号的退款都返回不透明 `not_found`。错误 instruction 要求核对当前账号/Agent 绑定,唯一恢复入口为 `itpay services list --json`;不得通过错误差异探测其他账号退款。
57
+
58
+ ## Agent Type / Host
59
+
60
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 返回完全相同的退款事实、instruction 和 next。Host 不改变 Refund Owner 状态或访问锁。
@@ -0,0 +1,33 @@
1
+ # `itpay refund`
2
+
3
+ ## 命令范围
4
+
5
+ 创建、恢复、跟踪和取消退款申请。Refund Owner 决定政策和状态;CLI 只提交用户意图并展示服务端事实。
6
+
7
+ **上游:** 已归属当前 Buyer/Agent 的订单。
8
+ **下游:** 自动退款执行、Admin review、取消或终态。
9
+
10
+ ## 子命令
11
+
12
+ - [`refund create`](create.md)
13
+ - [`refund list`](list.md)
14
+ - [`refund get`](get.md)
15
+ - [`refund watch`](watch.md)
16
+ - [`refund cancel`](cancel.md)
17
+
18
+ 兼容别名 `itpay refund --order <id>` 等价于 `refund create`,文档和 instruction 统一推荐子命令形式。
19
+
20
+ 退款创建成功即锁定对应交付;旧 Agent grant 不得继续读取。直接运行无参数 `itpay refund` 显示 help,不创建请求。
21
+
22
+ ## 语法、参数与标准输出
23
+
24
+ ```bash
25
+ itpay refund --order <order_id> [--reason <reason>] [--json]
26
+ itpay refund --help
27
+ ```
28
+
29
+ 兼容别名的参数、输出、instruction 和异常合同与 [`refund create`](create.md) 完全相同。无 `--order` 时只显示 help 和推荐的 `refund create` 语法,不发送请求。
30
+
31
+ ## Agent Type / Host
32
+
33
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 五种类型使用同一签名 Device Authority 和退款状态机;Host 不影响退款资格。
@@ -0,0 +1,68 @@
1
+ # `itpay refund list`
2
+
3
+ ## 范围与意义
4
+
5
+ 列出指定订单的退款记录,按最新到最旧排序。
6
+
7
+ **上游:** `order_id`。
8
+ **下游:** `refund get/watch <refund_id>`。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay refund list --order <order_id> [--json]
14
+ ```
15
+
16
+ | 参数 | 必填 | 说明 |
17
+ |---|---:|---|
18
+ | `--order` | 是 | 用户订单 `order_id`,不可猜测。 |
19
+ | `--json` | 否 | 输出标准命令合同 JSON。 |
20
+
21
+ ## 标准输出
22
+
23
+ ```json
24
+ {
25
+ "status": "listed",
26
+ "result": {
27
+ "order_id": "<order_id>",
28
+ "refunds": [
29
+ {
30
+ "refund_request_id": "<id>",
31
+ "status": "<status>",
32
+ "amount": "<amount> <currency>",
33
+ "created_at": "<RFC3339>"
34
+ }
35
+ ]
36
+ },
37
+ "instruction": "已有活跃退款;继续跟踪同一笔,不要为该订单重复创建。",
38
+ "next": { "command": "itpay refund get <refund_id> --json", "reason": "读取活跃退款" },
39
+ "recovery": []
40
+ }
41
+ ```
42
+
43
+ 列表只返回选择退款所需的 ID、状态、金额和创建时间,不返回退款原因、消费证据、Admin 信息或支付渠道元数据。服务端按 `created_at DESC` 排序;CLI 优先引导至第一笔活跃退款,否则引导至最新记录。
44
+
45
+ 无记录时:
46
+
47
+ ```json
48
+ {
49
+ "status": "empty",
50
+ "result": { "order_id": "<order_id>", "refunds": [] },
51
+ "instruction": "该订单没有退款记录;确认用户确实要求退款后再创建。",
52
+ "next": {
53
+ "command": "itpay refund create --order <order_id> --json",
54
+ "reason": "为该订单创建退款"
55
+ },
56
+ "recovery": []
57
+ }
58
+ ```
59
+
60
+ ## 鉴权与异常处理
61
+
62
+ 允许订单 Owner 的 Buyer session、该订单的 order-scoped session,或绑定同一 Service Execution 的签名 Agent Device session。CLI 不自行判断归属;未知订单和无权访问统一按服务端不透明 `not_found` 处理。
63
+
64
+ 缺少 `--order` 必须在 HTTP 前返回 `order_required`。鉴权或归属失败时 instruction 要求核对订单,recovery 指向 `itpay services list --json`;不得通过错误差异泄露退款是否存在。
65
+
66
+ ## Agent Type / Host
67
+
68
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 五种 Agent Type 的业务字段、instruction 和 next 完全相同;本命令没有 Host 渲染差异。
@@ -0,0 +1,73 @@
1
+ # `itpay refund watch`
2
+
3
+ ## 范围与意义
4
+
5
+ 轮询同一退款直到终态或 timeout。命令内部可以读取多次,但对外只输出一个最终信封,不把无变化轮询刷入 Agent 上下文。中断后可无副作用重跑。
6
+
7
+ **上游:** active refund。
8
+ **下游:** `succeeded`、`failed`、`cancelled`、`rejected` 等终态,或稍后继续 watch。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay refund watch <refund_request_id> [--interval <seconds>] [--timeout <seconds>] [--json]
14
+ ```
15
+
16
+ | 参数 | 默认 | 约束 |
17
+ | --- | --- | --- |
18
+ | `refund_request_id` | 无 | 必填。 |
19
+ | `--interval <seconds>` | `2` | 必须至少 1 秒。 |
20
+ | `--timeout <seconds>` | `120` | 必须为正数;可使用小数。 |
21
+ | `--json` | 关闭 | 输出一个可直接解析的 JSON 信封。 |
22
+
23
+ 非法轮询参数在第一次 HTTP 请求前失败。
24
+
25
+ ## 终态输出
26
+
27
+ ```json
28
+ {
29
+ "status": "watch_complete",
30
+ "result": {
31
+ "refund_request_id": "<id>",
32
+ "order_id": "<order_id>",
33
+ "decision_mode": "automatic",
34
+ "refund_status": "succeeded",
35
+ "consumption_state": "unconsumed",
36
+ "access_locked": true,
37
+ "can_cancel": false
38
+ },
39
+ "instruction": "退款已成功;交付永久关闭。",
40
+ "next": null,
41
+ "recovery": []
42
+ }
43
+ ```
44
+
45
+ 其他终态使用与 `refund get` 相同的锁、恢复资格和旧 grant 规则。
46
+
47
+ ## Timeout 输出
48
+
49
+ Timeout 只表示本次 CLI 等待结束,不表示退款失败:
50
+
51
+ ```json
52
+ {
53
+ "status": "watch_timeout",
54
+ "result": {
55
+ "refund_request_id": "<id>",
56
+ "last_status": "<status>",
57
+ "access_locked": true,
58
+ "can_cancel": true
59
+ },
60
+ "instruction": "退款仍在处理,稍后继续跟踪同一退款;不要重复申请。",
61
+ "next": {
62
+ "command": "itpay refund watch <refund_id> --json",
63
+ "reason": "恢复轮询"
64
+ },
65
+ "recovery": []
66
+ }
67
+ ```
68
+
69
+ 网络、ID 或参数错误返回错误信封,并只建议 `itpay refund get <id> --json` 检查当前状态。
70
+
71
+ ## Agent Type / Host
72
+
73
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 返回相同退款事实。Desktop 不会把每次无变化轮询发送到用户对话;Host 不改变 timeout 或退款状态。
@@ -0,0 +1,43 @@
1
+ # `itpay services action`
2
+
3
+ ## 范围与意义
4
+
5
+ 记录用户或 Agent 对 Service Execution 的结构化动作,例如选择候选、批准、拒绝或取消。它不直接调用付费 Provider。
6
+
7
+ **上游:** `services invoke/next` 返回需要 action。
8
+ **下游:** 候选选择成功时直接进入服务端允许的下一动作;其他动作通过更新后的 `services next` 恢复。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay services action <service_execution_id> --action <action_type>
14
+ [--actor-type <actor_type>] [--actor-id <actor_id>]
15
+ [--status <pending|approved|rejected|expired|cancelled>]
16
+ [--candidate <rank> | --result-item <result_item_id>]
17
+ [--required-before <step>] [--input <key=value> ...] [--json]
18
+ ```
19
+
20
+ 普通 Agent 优先使用 `--candidate <rank>`。CLI 只从当前 Execution 的 `current_result_items` 解析 Result Item ID;Backend 再读取权威 Invocation 和 Stable Hash。Agent 不提交 Hash,也不能使用其他 Execution 或外部来源的候选。`--result-item` 只用于已持有当前 Execution 内部句柄的受控恢复,不应要求用户提供。
21
+
22
+ ## 标准输出
23
+
24
+ ```json
25
+ {
26
+ "status": "candidate_selected",
27
+ "result": {
28
+ "service_execution_id": "<id>",
29
+ "candidate": { "rank": 2, "title": "<title>" }
30
+ },
31
+ "instruction": "候选已绑定到来源 Execution;后续动作必须继续使用该 Execution。",
32
+ "next": { "command": "itpay services quote <id> --capability <capability_id> --email <email> --json", "reason": "为已确认候选准备报价" },
33
+ "recovery": [{ "command": "itpay services next <id> --json", "reason": "重新读取服务端允许的动作" }]
34
+ }
35
+ ```
36
+
37
+ `next` 来自 action 写入后重新读取的类型化 `allowed_actions`,不是 CLI 根据服务名猜测。若后续不是报价,CLI 渲染该动作对应的通用命令;没有合法动作时返回 `next: null`。非候选 action 仍返回 `action_recorded` 并引导 `services next`。
38
+
39
+ rank 不存在、属于旧结果集或其他 Execution、action 不允许、status 非法时均不写 action;返回结构化错误并引导同一 Execution 的 `services next`。相同候选重试幂等;同一结果集改选另一个候选返回冲突,不覆盖已批准事实。
40
+
41
+ ## Agent Type / Host
42
+
43
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 五种 Agent Type 行为相同。需要人确认时 instruction 必须明确“先询问用户”,不能因 Desktop Host 自动代替用户选择。
@@ -0,0 +1,82 @@
1
+ # `itpay services checkout`
2
+
3
+ ## 范围与意义
4
+
5
+ 为单个 Service Execution 快速创建或恢复 Checkout,并按 Host 向人交接付款入口。它是 `services quote -> cart add --quote -> buy --cart` 的单项快捷方式,必须复用相同的 Quote、Cart 和 Checkout Use Case。
6
+
7
+ **上游:** `services next` 返回的 `prepare_quote` capability 和已验证输入。
8
+ **下游:** 人完成 Checkout,随后 `checkout` 或 `services next`。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay services checkout <service_execution_id> --capability <capability_id>
14
+ [--input <key=value> ...] [--email <delivery_email>]
15
+ [--host <host>] [--target <target>] [--qr-format <format>] [--qr-file <path>] [--json]
16
+
17
+ itpay services checkout <service_execution_id> --resume
18
+ [--host <host>] [--target <target>] [--json]
19
+ ```
20
+
21
+ 创建时 `--capability` 必填。最终 locked input 必须满足 capability schema:显式输入来自 `--input`,服务端也可以按已发布 contract 从当前 Execution 的已批准 action 解析输入。解析后仍缺字段时,必须在创建 Quote、Cart 或 Checkout 前失败。只有 `delivery_email_required=true` 才要求 `--email`,并必须先向用户解释邮箱用于发送可 claim 的交付链接。`--resume` 复用同一个 Checkout 并轮换 handoff token,不再索取输入或邮箱。
22
+
23
+ ## 标准输出
24
+
25
+ ```json
26
+ {
27
+ "status": "human_checkout_required",
28
+ "result": {
29
+ "service_execution_id": "<id>",
30
+ "checkout_id": "<checkout_id>",
31
+ "capability_id": "<logical_capability_id>",
32
+ "locked_input": { "<required_key>": "<value>" },
33
+ "amount": "<amount> <currency>"
34
+ },
35
+ "handoff": { "url": "<checkout_url>", "qr_local_path": "<host_optional_path>", "markdown": "<host_optional_markdown>" },
36
+ "instruction": "把二维码和付款链接展示给用户;确认可见前不要查询状态,也不要创建新 Checkout。",
37
+ "next": { "command": "itpay checkout --id <checkout_id> --token <display_token>", "reason": "跟踪同一笔 Checkout" },
38
+ "recovery": []
39
+ }
40
+ ```
41
+
42
+ `capability_id` 是 service contract 中 Agent 可调用的逻辑 ID,不是 `scc_...` 数据库记录 ID。`locked_input` 是后端按 capability policy 最终解析并校验后的输入,不由 CLI 根据服务名称推断。
43
+
44
+ 普通文本输出保持同一事实顺序。桌面 Host 输出可直接转发的 `handoff.markdown`;终端 Host 额外渲染一个可扫码终端二维码;`--json` 不内嵌终端二维码或图片二进制。
45
+
46
+ 不得返回 quote lock、单独 token、重复 next actions、镜像路径数组或渲染器内部原因。缺输入、缺必填邮箱、phase 不允许时不得创建任何付款资源。恢复时 token 失效应重发同一 Checkout handoff,不创建第二个 Checkout。
47
+
48
+ ## 异常处理
49
+
50
+ 缺少付费 capability 输入:
51
+
52
+ ```json
53
+ {
54
+ "status": "error",
55
+ "error": { "code": "capability_input_invalid", "message": "missing required capability input: <field>" },
56
+ "instruction": "补齐付费 capability 的 required_input;本次没有创建 quote、Checkout 或订单。",
57
+ "next": null,
58
+ "recovery": [{ "command": "itpay services checkout <service_execution_id> --capability <capability_id> --input <field>=<value> --json", "reason": "提交完整且会被锁定的服务输入" }]
59
+ }
60
+ ```
61
+
62
+ 缺少交付邮箱:
63
+
64
+ ```json
65
+ {
66
+ "status": "error",
67
+ "error": { "code": "delivery_email_required", "message": "delivery email is required before creating this service checkout" },
68
+ "instruction": "该 capability 的交付链接会发送到用户邮箱;先向用户说明用途并询问邮箱,不要代填。",
69
+ "next": null,
70
+ "recovery": [{ "command": "itpay services checkout <service_execution_id> --capability <capability_id> --email <email> --json", "reason": "使用用户提供的邮箱创建 Checkout" }]
71
+ }
72
+ ```
73
+
74
+ ## Agent Type / Host
75
+
76
+ | Agent Type | Instruction |
77
+ |---|---|
78
+ | `codex-desktop` | `handoff={url,qr_local_path,markdown}`;把 `handoff.markdown` 原样发送到当前桌面对话。 |
79
+ | `codex-cli` | `handoff={url,qr_local_path}`;普通文本模式在用户可见终端渲染二维码。 |
80
+ | `claude-code-desktop` | `handoff={url,qr_local_path,markdown}`;把 `handoff.markdown` 原样发送到当前桌面对话。 |
81
+ | `claude-code-cli` | `handoff={url,qr_local_path}`;普通文本模式在用户可见终端渲染二维码。 |
82
+ | `workbuddy` | `handoff={url,qr_local_path,qr_image_url}`;发送链接和可用二维码附件,原生行为后续细化。 |
@@ -0,0 +1,73 @@
1
+ # `itpay services events`
2
+
3
+ ## 范围与意义
4
+
5
+ 按 sequence 升序读取一笔 Service Execution 的受限诊断事件。它只用于解释异常或支持排查,不是正常业务流程,不返回事件 ID、内部摘要、Provider 数据或受保护交付内容。
6
+
7
+ **上游:** `services get/next` 无法解释异常状态,并明确建议读取事件。
8
+
9
+ **下游:** 回到 `services next` 获取当前可执行动作;事件本身不能用于重放步骤。
10
+
11
+ ## 语法与参数
12
+
13
+ ```bash
14
+ itpay services events <service_execution_id> [--after-sequence <n>] [--limit <n>] [--json]
15
+ ```
16
+
17
+ | 参数 | 必填 | 默认 | 说明 |
18
+ | --- | --- | --- | --- |
19
+ | `service_execution_id` | 是 | - | 当前设备或账号可见的执行 ID。 |
20
+ | `--after-sequence` | 否 | `0` | 只返回 sequence 大于该非负整数的事件。 |
21
+ | `--limit` | 否 | `50` | 本页最多 `1..100` 条。 |
22
+ | `--json` | 否 | false | 返回标准命令 envelope。 |
23
+
24
+ CLI 在发起 HTTP 请求前校验数字参数。Backend 再执行归属鉴权和相同上限。
25
+
26
+ ## 标准输出
27
+
28
+ ```json
29
+ {
30
+ "status": "listed",
31
+ "result": {
32
+ "service_execution_id": "<id>",
33
+ "after_sequence": 0,
34
+ "returned_count": 2,
35
+ "events": [
36
+ {
37
+ "sequence": 1,
38
+ "type": "<public_event_type>",
39
+ "status": "<public_status>",
40
+ "phase": "<public_phase>",
41
+ "capability_id": "<optional_capability_id>",
42
+ "occurred_at": "<time>"
43
+ }
44
+ ]
45
+ },
46
+ "instruction": "事件仅用于诊断;不要从事件重放业务步骤,回到 services next 获取当前动作。",
47
+ "next": {
48
+ "command": "itpay services next <id> --json",
49
+ "reason": "恢复正常服务流程"
50
+ },
51
+ "recovery": []
52
+ }
53
+ ```
54
+
55
+ 当返回条数等于 limit 时,`recovery` 增加一条使用最后 sequence 的下一页命令。空页仍返回 `listed` 和 `returned_count: 0`。
56
+
57
+ ## 安全边界
58
+
59
+ CLI 只投影:`sequence`、`type`、`status`、`phase`、可选 `capability_id`、`occurred_at`。即使 Backend DTO 包含 `service_execution_event_id`、重复 execution ID 或 `redacted_summary`,CLI 也不输出。
60
+
61
+ 不得输出 AppCode、Provider headers、raw payload、payload ref/hash、Buyer PII、token、签名、候选 hash、correlation ID 或 Admin note。
62
+
63
+ ## 异常处理
64
+
65
+ | 错误 | 含义 | 恢复 |
66
+ | --- | --- | --- |
67
+ | `events_parameter_invalid` | sequence/limit 不是允许的整数。 | 查看本命令 help;未发 HTTP。 |
68
+ | `service_events_failed` | Backend 不可用或读取失败。 | 回到 `services next` 或当前身份的 `services list`。 |
69
+ | `not_found` | execution 不存在或不属于当前身份。 | 使用相同不透明错误,不区分两者。 |
70
+
71
+ ## Agent Type / Host
72
+
73
+ 五种正式 Agent Type 的事件字段、鉴权和 redaction 完全相同;Host 不影响可见性,也不产生 handoff。
@@ -0,0 +1,66 @@
1
+ # `itpay services get`
2
+
3
+ ## 范围与意义
4
+
5
+ 读取一笔 Service Execution 的紧凑状态、关键节点和当前首选动作。它面向恢复和用户解释,不是原始 event dump。
6
+
7
+ **上游:** execution ID。
8
+ **下游:** 当前首选命令;深度诊断才使用 `events`。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay services get <service_execution_id> [--json]
14
+ ```
15
+
16
+ | 参数 | 必填 | 说明 |
17
+ | --- | --- | --- |
18
+ | `<service_execution_id>` | 是 | `services start/list/next` 返回的 execution ID。 |
19
+ | `--json` | 否 | 输出单个标准 JSON envelope;默认输出相同事实的简洁文本。 |
20
+
21
+ 命令使用当前签名 Agent Device session;可见范围由 Backend 按设备和已绑定 Buyer account 决定。
22
+
23
+ ## 标准输出
24
+
25
+ ```json
26
+ {
27
+ "status": "shown",
28
+ "result": {
29
+ "service_execution_id": "<id>",
30
+ "service_id": "<service_id>",
31
+ "status": "<status>",
32
+ "phase": "<phase>",
33
+ "current_capability_id": "<optional capability>",
34
+ "updated_at": "<time>",
35
+ "timeline": [
36
+ {
37
+ "sequence": 1,
38
+ "step": "<public step>",
39
+ "status": "<status>",
40
+ "phase": "<phase>",
41
+ "occurred_at": "<time>"
42
+ }
43
+ ],
44
+ "delivery_mode": "<optional mode>"
45
+ },
46
+ "instruction": "时间线仅用于解释和恢复;按当前首选动作继续,不要重放已完成步骤。",
47
+ "next": { "command": "<state-derived command>", "reason": "继续当前首选动作" },
48
+ "recovery": [
49
+ { "command": "itpay services events <service_execution_id> --json", "reason": "仅在需要完整诊断事件时使用" }
50
+ ]
51
+ }
52
+ ```
53
+
54
+ 当 execution 为 `failed`、`refunded` 或 `cancelled` 时,`next` 必须是 `null`;只允许通过 `services events` 诊断终止原因,不得建议重放 capability 或创建 Checkout。
55
+
56
+ `timeline` 只保留最近 20 个公开节点;超过时增加 `timeline_truncated: true`。它不返回 event ID 或 `redacted_summary`。交付存在时可增加 `delivery_mode`;退款锁存在时增加 `access_locked` 和退款 ID/status,并优先返回锁定 instruction。
57
+
58
+ ## 异常处理
59
+
60
+ 默认不返回原始 events、Provider metadata、内部 bindings、graph projection、capability schema、candidate hash、client context 或完整 payload。需要完整但仍经服务端脱敏的事件时才运行 `services events`。
61
+
62
+ execution 不存在或不属于当前身份时保留不透明 `not_found`,只恢复到 `itpay services list --json`;不得通过错误差异探测其他账号。
63
+
64
+ ## Agent Type / Host
65
+
66
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 五种 Agent Type 的状态、timeline、instruction 和 next 相同。本命令没有二维码或 Host handoff。
@@ -0,0 +1,45 @@
1
+ # `itpay services`
2
+
3
+ ## 命令范围
4
+
5
+ 操作通用 Service Execution。CLI 不知道某个服务的业务流程;它读取服务合同中的 capability、input schema、价格、交付模式和服务端 next action。
6
+
7
+ **上游:** Catalog 的 `service_id`。
8
+ **下游:** 免费能力、人工动作、付费 Checkout、Agent-visible 交付或 Vault 授权交付。
9
+
10
+ ## 核心不变量
11
+
12
+ - 一个 Execution 表示一个独立服务意图;多个意图分别执行、分别交付,但各自的 Quote 可以进入同一 Cart。
13
+ - 任何 capability 输入都必须在状态写入、锁价、订单创建和 Provider 调用前通过 schema 校验。
14
+ - `invoke` 只运行当前阶段允许且不需付款的 Agent-visible capability。
15
+ - 依赖候选的付费 capability 必须继续来源 Execution;`action --candidate` 不能跨 Execution 搬运候选。
16
+ - `services quote` 只创建 Quote Lock;`cart add --quote` 聚合交易;`buy --cart` 创建一次 Checkout。
17
+ - `services checkout` 是单项快捷方式,内部复用 Quote、Cart 和 Checkout 的相同规则。
18
+ - `agent_visible_result` 从 `services next` 读取;`vault_artifact` 只有人授权后才能 `read-result`。
19
+
20
+ ## 子命令
21
+
22
+ - [`start`](start.md)
23
+ - [`invoke`](invoke.md)
24
+ - [`action`](action.md)
25
+ - [`quote`](quote.md)
26
+ - [`checkout`](checkout.md)
27
+ - [`list`](list.md)
28
+ - [`get`](get.md)
29
+ - [`next`](next.md)
30
+ - [`read-result`](read-result.md)
31
+ - [`events`](events.md)
32
+
33
+ 直接运行 `itpay services` 显示 help。
34
+
35
+ ## 语法、输出与异常
36
+
37
+ ```bash
38
+ itpay services --help
39
+ ```
40
+
41
+ 输出十个子命令及一句选择规则:正常推进使用 `next`,深度诊断才使用 `get/events`。未知子命令返回参数错误和本 help,不创建 Execution。
42
+
43
+ ## Agent Type / Host
44
+
45
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 五种 Agent Type 共享状态机;Agent Type 只影响身份归属和 Host instruction,不允许影响 quota 规则或服务能力。