@itpay/cli 2.0.3 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +96 -142
  2. package/dist/src/client/backend.js +26 -8
  3. package/dist/src/client/http.js +29 -23
  4. package/dist/src/commands/buy.js +84 -132
  5. package/dist/src/commands/cart.js +274 -169
  6. package/dist/src/commands/catalog.js +64 -38
  7. package/dist/src/commands/checkout.js +128 -79
  8. package/dist/src/commands/docs.js +97 -51
  9. package/dist/src/commands/guidance.js +112 -16
  10. package/dist/src/commands/install.js +50 -87
  11. package/dist/src/commands/next.js +45 -0
  12. package/dist/src/commands/order.js +44 -69
  13. package/dist/src/commands/orders.js +43 -15
  14. package/dist/src/commands/pay.js +51 -22
  15. package/dist/src/commands/readyz.js +8 -4
  16. package/dist/src/commands/refund.js +132 -11
  17. package/dist/src/commands/services.js +799 -147
  18. package/dist/src/commands/skill.js +55 -0
  19. package/dist/src/main.js +820 -193
  20. package/dist/src/render/output.js +2 -3
  21. package/dist/src/state/agent_type.js +19 -0
  22. package/dist/src/state/cart_session.js +13 -17
  23. package/dist/src/state/client_context.js +4 -2
  24. package/dist/src/state/config.js +5 -15
  25. package/dist/src/state/device_authority.js +175 -57
  26. package/docs/agent/buyer/cart-checkout.json +27 -83
  27. package/docs/agent/buyer/catalog-list.json +2 -1
  28. package/docs/agent/buyer/identity-and-sessions.json +64 -0
  29. package/docs/agent/buyer/install-and-setup.json +35 -65
  30. package/docs/agent/buyer/orders-refunds.json +31 -53
  31. package/docs/agent/buyer/payment-flow.json +28 -57
  32. package/docs/agent/buyer/quickstart.json +46 -161
  33. package/docs/agent/buyer/render-hosts.json +43 -57
  34. package/docs/cli-reference/agent-types.md +51 -0
  35. package/docs/cli-reference/commands/buy.md +167 -0
  36. package/docs/cli-reference/commands/cart/add.md +86 -0
  37. package/docs/cli-reference/commands/cart/clear.md +53 -0
  38. package/docs/cli-reference/commands/cart/index.md +30 -0
  39. package/docs/cli-reference/commands/cart/next.md +71 -0
  40. package/docs/cli-reference/commands/cart/remove.md +53 -0
  41. package/docs/cli-reference/commands/cart/show.md +65 -0
  42. package/docs/cli-reference/commands/catalog/index.md +26 -0
  43. package/docs/cli-reference/commands/catalog/list.md +45 -0
  44. package/docs/cli-reference/commands/checkout.md +74 -0
  45. package/docs/cli-reference/commands/device.md +13 -0
  46. package/docs/cli-reference/commands/docs/index.md +28 -0
  47. package/docs/cli-reference/commands/docs/list.md +51 -0
  48. package/docs/cli-reference/commands/docs/search.md +69 -0
  49. package/docs/cli-reference/commands/docs/show.md +68 -0
  50. package/docs/cli-reference/commands/install.md +114 -0
  51. package/docs/cli-reference/commands/next.md +87 -0
  52. package/docs/cli-reference/commands/order.md +92 -0
  53. package/docs/cli-reference/commands/orders.md +83 -0
  54. package/docs/cli-reference/commands/pay.md +103 -0
  55. package/docs/cli-reference/commands/readyz.md +38 -0
  56. package/docs/cli-reference/commands/refund/cancel.md +62 -0
  57. package/docs/cli-reference/commands/refund/create.md +85 -0
  58. package/docs/cli-reference/commands/refund/get.md +60 -0
  59. package/docs/cli-reference/commands/refund/index.md +33 -0
  60. package/docs/cli-reference/commands/refund/list.md +68 -0
  61. package/docs/cli-reference/commands/refund/watch.md +73 -0
  62. package/docs/cli-reference/commands/services/action.md +48 -0
  63. package/docs/cli-reference/commands/services/checkout.md +82 -0
  64. package/docs/cli-reference/commands/services/events.md +73 -0
  65. package/docs/cli-reference/commands/services/get.md +66 -0
  66. package/docs/cli-reference/commands/services/index.md +45 -0
  67. package/docs/cli-reference/commands/services/invoke.md +67 -0
  68. package/docs/cli-reference/commands/services/list.md +61 -0
  69. package/docs/cli-reference/commands/services/next.md +181 -0
  70. package/docs/cli-reference/commands/services/quote.md +63 -0
  71. package/docs/cli-reference/commands/services/read-result.md +98 -0
  72. package/docs/cli-reference/commands/services/start.md +55 -0
  73. package/docs/cli-reference/commands/skill.md +17 -0
  74. package/docs/cli-reference/conventions.md +97 -0
  75. package/docs/cli-reference/index.md +65 -0
  76. package/package.json +1 -1
  77. package/skills/itpay-buyer/SKILL.md +71 -110
@@ -0,0 +1,67 @@
1
+ # `itpay services invoke`
2
+
3
+ ## 范围与意义
4
+
5
+ 调用当前 phase 允许的非付费 Agent-visible capability。输入先按 capability schema 校验,校验失败不得迁移 execution 或记录 Provider 已调用。
6
+
7
+ **上游:** `services start/next` 明确返回 invoke。
8
+ **下游:** 候选结果、人工 action、付费 Quote 或新 execution。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay services invoke <service_execution_id> --capability <capability_id>
14
+ [--input <key=value> ...] [--json]
15
+ ```
16
+
17
+ `--input` 可重复;必填 key 来自 `input_schema.required`,值按 schema 类型解析。Agent 不猜字段名。
18
+
19
+ ## 有结果输出
20
+
21
+ ```json
22
+ {
23
+ "status": "result_ready",
24
+ "result": {
25
+ "service_execution_id": "<id>",
26
+ "capability_id": "<capability_id>",
27
+ "items": [{ "rank": 1, "title": "<title>", "safe_payload": {} }],
28
+ "quota": { "remaining": 2, "limit": 3 }
29
+ },
30
+ "instruction": "向用户展示编号和 safe_payload;若候选列表已满足用户目标,在此停止。仅在用户明确选择并希望继续时,才在当前 Execution 提交对应 rank。",
31
+ "next": { "command": "itpay services action <id> --action <action_type> --actor-type human --status approved --candidate <rank> --json", "reason": "记录用户选择" },
32
+ "recovery": []
33
+ }
34
+ ```
35
+
36
+ ## 无结果与额度耗尽
37
+
38
+ 无结果时明确说明 Provider 已返回空结果,并根据服务端 graph 决定重试同一 execution 或启动新 execution。额度耗尽时,普通单 Execution 流程返回完整的 `services checkout` 单项快捷命令;`services quote -> cart add --quote -> buy --cart` 只用于用户明确要求把多个独立 Execution 合并付款的高级流程。
39
+
40
+ ```json
41
+ {
42
+ "status": "quota_exhausted",
43
+ "result": {
44
+ "service_execution_id": "<id>",
45
+ "capability_id": "<capability_id>",
46
+ "items": [],
47
+ "quota": { "remaining": 0, "limit": 3 },
48
+ "checkout": {
49
+ "capability_id": "<paid_capability_id>",
50
+ "price": { "amount_minor": 10, "currency": "CNY" },
51
+ "delivery_email_required": false
52
+ }
53
+ },
54
+ "instruction": "免费额度已用完,本次没有调用 Provider,也尚未创建 Quote 或 Checkout。现在只向用户说明:‘继续当前请求需要支付 0.10 CNY,是否购买?’然后停止并等待用户明确回复。用户明确同意前,不要执行 next.command,不要新建 Execution,不要尝试其他 capability、quote、cart、buy、checkout 或 pay 命令。",
55
+ "next": {
56
+ "command": "itpay services checkout <id> --capability <paid_capability_id> --input <key=value> --json",
57
+ "reason": "仅在用户明确同意支付 0.10 CNY 后执行;否则停止"
58
+ },
59
+ "recovery": []
60
+ }
61
+ ```
62
+
63
+ 缺少 required input 时返回 `capability_input_invalid`,recovery 给出带占位符的同一 invoke 命令;CLI 和 Backend 都必须在 Provider 调用前拒绝,Backend 还必须在 execution/event/quota/invocation 写入前拒绝。错误调用付费 capability 时不得给出购买旁路,只能回到同一 Execution 的 `services next`;execution 状态、event、ProviderCalled 均保持不变。
64
+
65
+ ## Agent Type / Host
66
+
67
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 五种 Agent Type 的 safe result 一致。instruction 可以适配对话表述,但不得隐藏 quota、价格或 schema 错误。
@@ -0,0 +1,61 @@
1
+ # `itpay services list`
2
+
3
+ ## 范围与意义
4
+
5
+ 恢复当前已登记设备或账号可见的 Service Execution 摘要。它不是批量 timeline 导出。
6
+
7
+ **上游:** 本地句柄丢失、404 recovery 或用户要求查看历史任务。
8
+ **下游:** `services next <selected_id>`。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay services list [--limit <number>] [--json]
14
+ ```
15
+
16
+ | 参数 | 必填 | 说明 |
17
+ | --- | --- | --- |
18
+ | `--limit <number>` | 否 | 返回数量,默认 10;必须是 1 到 100 的整数。只有最近结果找不到目标时才扩大。 |
19
+ | `--json` | 否 | 输出单个标准 JSON envelope;默认输出每条一行的简洁文本。 |
20
+
21
+ 命令使用签名 Agent Device session。Backend 按 `updated_at DESC` 返回当前设备或已绑定 Buyer account 可见的执行;CLI 保留该顺序,不在本地推断归属。
22
+
23
+ ## 标准输出
24
+
25
+ ```json
26
+ {
27
+ "status": "listed",
28
+ "result": {
29
+ "executions": [
30
+ { "service_execution_id": "<id>", "service_id": "<service_id>", "status": "<status>", "phase": "<phase>", "updated_at": "<time>" }
31
+ ]
32
+ },
33
+ "instruction": "结果按最新到最旧排列,默认只列最近 10 条;找不到目标时再扩大 limit。",
34
+ "next": { "command": "itpay services next <latest_service_execution_id> --json", "reason": "默认恢复最新执行" },
35
+ "recovery": []
36
+ }
37
+ ```
38
+
39
+ 不得为每条 execution 附加完整 guidance、capabilities、result items、events、candidate hash、client context 或内部 binding。若用户指定了另一条,Agent 应用该行 ID 替换默认最新 ID 后运行 `services next`。
40
+
41
+ 无结果时返回 `no_executions`、空数组和 `itpay catalog list --json`。
42
+
43
+ 非法 limit 在请求 Backend 前返回:
44
+
45
+ ```json
46
+ {
47
+ "status": "error",
48
+ "error": { "code": "limit_invalid", "message": "--limit must be an integer from 1 to 100" },
49
+ "instruction": "使用 1 到 100 的整数 limit;本次未读取服务端列表。",
50
+ "next": null,
51
+ "recovery": [
52
+ { "command": "itpay services list --limit 10 --json", "reason": "使用默认上限重试" }
53
+ ]
54
+ }
55
+ ```
56
+
57
+ 身份或 Backend 错误保留服务端错误码,只建议 `readyz` 和重新读取列表;不得猜测 ID。
58
+
59
+ ## Agent Type / Host
60
+
61
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 五种 Agent Type 返回相同列表格式;Agent instance 权限决定可见范围。本命令没有 Host handoff。
@@ -0,0 +1,181 @@
1
+ # `itpay services next`
2
+
3
+ ## 范围与意义
4
+
5
+ 读取一笔 Service Execution 的当前状态,并只返回一个首选下一步。若交付模式允许 Agent 直接读取,本命令同时返回完整 safe result。
6
+
7
+ **上游:** `services start`、`invoke`、`action`、`checkout`,或一次中断恢复。
8
+ **下游:** 一个可执行命令、需要用户完成的候选选择或授权,或 Graph 真正到达终态。
9
+
10
+ 本命令不返回原始 Backend DTO、capability 列表、内部 result ID/hash、graph、binding 或重复 guidance。
11
+
12
+ Backend 会根据当前 capability 选择 `current_delivery`;完整 `delivery_bindings` 仅是历史记录。CLI 不按数组位置猜测当前交付,同一 Execution 后续产生的新交付会取代旧交付成为默认结果。
13
+
14
+ ## 语法与参数
15
+
16
+ ```bash
17
+ itpay services next <service_execution_id> [--json]
18
+ ```
19
+
20
+ | 参数 | 必填 | 说明 |
21
+ | --- | --- | --- |
22
+ | `service_execution_id` | 是 | `services start` 或后续命令返回的 execution ID。 |
23
+ | `--json` | 否 | 输出稳定 JSON 信封;未指定时输出相同事实的简洁文本。 |
24
+
25
+ 需要有效 Agent Device session。命令不接受 Buyer token、capability 或服务输入。
26
+
27
+ ## 候选选择
28
+
29
+ 免费或付费候选已经产生、Graph 允许继续选择时,恢复输出必须包含当前 Result Set 的安全候选:
30
+
31
+ ```json
32
+ {
33
+ "status": "candidate_selection_available",
34
+ "result": {
35
+ "service_execution_id": "<id>",
36
+ "items": [
37
+ { "rank": 1, "title": "<title>", "safe_payload": { "<public_field>": "<value>" } }
38
+ ]
39
+ },
40
+ "instruction": "向用户展示编号和 safe_payload;若候选列表已满足用户目标,在此停止。仅在用户明确选择并希望继续时,才在当前 Execution 提交对应 rank。",
41
+ "next": {
42
+ "command": "itpay services action <id> --action select_candidate --actor-type human --status approved --candidate <rank> --json",
43
+ "reason": "仅在用户明确选择后锁定来源候选"
44
+ },
45
+ "recovery": []
46
+ }
47
+ ```
48
+
49
+ 该列表来自 Backend 的 `current_result_items`,CLI 不缓存或合并其他 Execution 的候选。
50
+
51
+ ## Agent-visible 结果
52
+
53
+ ```json
54
+ {
55
+ "status": "result_ready",
56
+ "result": {
57
+ "service_execution_id": "<id>",
58
+ "capability_id": "<capability_id>",
59
+ "delivery_mode": "agent_visible_result",
60
+ "items": [
61
+ {
62
+ "rank": 1,
63
+ "title": "<title>",
64
+ "safe_payload": { "<public_field>": "<value>" }
65
+ }
66
+ ]
67
+ },
68
+ "instruction": "付费模糊搜索已完成。现在把 items 中的编号、title 和 safe_payload 展示给用户,然后停止。本结果是 agent-visible,不要调用 read-result。若用户的目标只是搜索候选企业,任务已经完成;只有用户之后明确选择某个候选并要求继续时,才执行 next.command。不要自动购买后续报告。",
69
+ "next": {
70
+ "command": "itpay services action <id> --action select_candidate --actor-type human --status approved --candidate <rank> --json",
71
+ "reason": "仅在用户明确选择候选并要求继续时执行"
72
+ },
73
+ "recovery": []
74
+ }
75
+ ```
76
+
77
+ 只有 Graph 允许继续选择时才返回上述 `next`。若结果本身就是最终交付,则 instruction 为“只使用 safe_payload,不调用 read-result”,且 `next: null`。文本输出依次显示 `status`、Execution、`delivery_mode`、候选及 instruction,不暴露 Result Item ID、Invocation ID 或 Hash。
78
+
79
+ ## Vault 交付
80
+
81
+ 未授权时不返回 result item 或 protected payload:
82
+
83
+ ```json
84
+ {
85
+ "status": "human_authorization_required",
86
+ "result": {
87
+ "service_execution_id": "<id>",
88
+ "capability_id": "<capability_id>",
89
+ "delivery_mode": "vault_artifact",
90
+ "grant_status": "none"
91
+ },
92
+ "instruction": "这是当前 Graph 步骤对应的交付;请用户在订单页面授权,未授权前不要读取或猜测内容。",
93
+ "next": {
94
+ "command": "itpay services read-result <id> --json",
95
+ "reason": "仅在用户确认授权后执行"
96
+ },
97
+ "recovery": []
98
+ }
99
+ ```
100
+
101
+ 有效 grant 存在时:
102
+
103
+ ```json
104
+ {
105
+ "status": "grant_active",
106
+ "result": {
107
+ "service_execution_id": "<id>",
108
+ "capability_id": "<capability_id>",
109
+ "delivery_mode": "vault_artifact",
110
+ "grant_status": "active",
111
+ "grant_expires_at": "<RFC3339 time>"
112
+ },
113
+ "instruction": "这是当前 Graph 步骤对应的交付;用户授权有效,立即读取并遵守字段范围与到期时间。",
114
+ "next": {
115
+ "command": "itpay services read-result <id> --json",
116
+ "reason": "读取当前有效 grant 的结果"
117
+ },
118
+ "recovery": []
119
+ }
120
+ ```
121
+
122
+ 额度耗尽或候选已确认并进入付费 continuation 时,`services next` 必须重复价格、用户确认原话、停止条件和禁止动作;普通单 Execution 的 next 使用 `services checkout`,不暴露 Quote/Cart/Buy 编排。
123
+
124
+ 已有 Checkout 时,Backend 返回 `resume_checkout`,CLI 只能恢复同一 Checkout:
125
+
126
+ ```json
127
+ {
128
+ "status": "checkout_pending",
129
+ "result": {
130
+ "service_execution_id": "<id>",
131
+ "service_id": "<service_id>",
132
+ "phase": "checkout",
133
+ "allowed_actions": [{ "type": "resume_checkout", "requires_human": true }]
134
+ },
135
+ "instruction": "当前 Execution 已经有一笔 Checkout。不要创建新的 Quote、Cart、Checkout 或 Execution。现在只执行 next.command,恢复并展示同一 Checkout 的付款入口。",
136
+ "next": { "command": "itpay services checkout <id> --resume --json", "reason": "恢复同一 Checkout,不创建第二笔" },
137
+ "recovery": []
138
+ }
139
+ ```
140
+
141
+ 付款已确认但 Provider 尚在履约时只能等待并再次读取同一 Execution;不得新建 Execution、Checkout 或再次付款。其他执行阶段只返回 Execution、service、phase、类型化 `allowed_actions` 和一个服务端状态导出的命令。CLI 只把 Backend 的动作类型渲染成命令,不执行 Publication 中的任意 shell 文本。完成或空结果后不得建议重放已失效的 invoke。
142
+
143
+ ## 退款访问锁
144
+
145
+ 订单存在 active 或永久退款锁时,该状态优先于 Agent-visible、Vault 和 grant guidance,不返回交付结果,也不再要求用户授权:
146
+
147
+ ```json
148
+ {
149
+ "status": "delivery_locked",
150
+ "result": {
151
+ "service_execution_id": "<id>",
152
+ "access_locked": true,
153
+ "refund": {
154
+ "refund_request_id": "<refund_id>",
155
+ "status": "<refund_status>"
156
+ }
157
+ },
158
+ "instruction": "退款处理中,交付已冻结;不要 reveal、创建 grant 或读取结果。",
159
+ "next": {
160
+ "command": "itpay refund get <refund_id> --json",
161
+ "reason": "读取退款权威状态"
162
+ },
163
+ "recovery": []
164
+ }
165
+ ```
166
+
167
+ `succeeded` 退款改为“交付永久关闭”,并返回 `next: null`。取消、拒绝或确定未产生资金影响的失败退款不再阻塞,但旧 grant 不会复活;用户必须重新授权。
168
+
169
+ ## 异常处理
170
+
171
+ execution 不存在或不属于当前设备/账号时返回错误信封,并仅建议:
172
+
173
+ ```text
174
+ itpay services get <service_execution_id> --json
175
+ ```
176
+
177
+ 不要创建替代 execution 来掩盖归属或状态错误。
178
+
179
+ ## Agent Type / Host
180
+
181
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 返回完全相同的状态、safe payload、instruction 和 next。本命令不渲染二维码,也不包含 Host handoff。
@@ -0,0 +1,63 @@
1
+ # `itpay services quote`
2
+
3
+ ## 范围与意义
4
+
5
+ 为当前 Service Execution 的一个付费 Capability 准备 Quote Lock。它只锁定可信输入、候选来源、价格、币种和有效期,不创建 Cart、Checkout、订单或 Provider 调用。
6
+
7
+ 本命令是多 Execution 合并付款的高级入口。普通单 Execution 流程应使用 `services checkout`,不要把 `services quote` 当作 Checkout 失败后的替代路径。
8
+
9
+ **上游:** 用户明确要求合并多个独立 Execution,且每个 Execution 的 Graph 当前都允许 `prepare_quote`。
10
+
11
+ **下游:** `cart add --quote`。多个独立 Execution 的 Quote 可以加入同一 Cart。
12
+
13
+ ## 语法与参数
14
+
15
+ ```bash
16
+ itpay services quote <service_execution_id> --capability <capability_id>
17
+ [--input <key=value> ...] [--email <delivery_email>] [--json]
18
+ ```
19
+
20
+ | 参数 | 必填 | 说明 |
21
+ |---|---:|---|
22
+ | `service_execution_id` | 是 | 候选或输入所属的来源 Execution。 |
23
+ | `--capability` | 是 | 当前 `allowed_actions` 明确允许报价的付费 Capability。 |
24
+ | `--input` | 条件必填 | 不依赖已批准候选时,提供 schema 要求的输入;可重复。 |
25
+ | `--email` | 条件必填 | 仅 `delivery_email_required=true` 时需要,必须来自用户;随 Quote Lock 持久化。 |
26
+ | `--json` | 否 | 输出紧凑机器合同。 |
27
+
28
+ 若 Capability 依赖候选,Backend 只从当前 Execution 的 approved Candidate Action 读取 Result Item、Invocation 和 Stable Hash;CLI 不重新提交公司名、候选 ID 或 Hash。
29
+
30
+ 交付联系信息属于 Quote 的锁定事实。多个 Quote 合并付款时,Checkout Owner 汇总它们的联系信息;相同字段值冲突时拒绝创建 Checkout,不由 CLI 选择或覆盖。
31
+
32
+ ## 标准输出
33
+
34
+ ```json
35
+ {
36
+ "status": "quote_ready",
37
+ "result": {
38
+ "service_quote_lock_id": "<quote_id>",
39
+ "service_execution_id": "<execution_id>",
40
+ "capability_id": "<capability_id>",
41
+ "price": "<amount> <currency>",
42
+ "expires_at": "<RFC3339>"
43
+ },
44
+ "instruction": "报价已锁定当前 Execution 的可信输入和价格;可单独付款,也可与其他独立 Execution 的报价合并。",
45
+ "next": { "command": "itpay cart add --quote <quote_id> --json", "reason": "加入 canonical Cart" },
46
+ "recovery": [{ "command": "itpay services next <execution_id> --json", "reason": "重新读取当前 Execution 状态" }]
47
+ }
48
+ ```
49
+
50
+ 不得返回 locked input、Candidate Hash、Provider 元数据或完整 Execution DTO。
51
+
52
+ ## 异常处理
53
+
54
+ - `capability_not_quoteable`:Capability 不存在、免费或当前不可报价;回到同一 Execution 的 `services next`。
55
+ - `capability_input_invalid`:缺少 required input;不创建 Quote、Cart 或 Checkout。
56
+ - `delivery_email_required`:先说明邮箱用于交付 claim link,再询问用户;禁止代填。
57
+ - 候选未确认、来自其他 Execution、Quote 已存在冲突:Backend 拒绝且不改变 Execution。
58
+ - `service_quote_not_allowed`:当前 Graph 不允许从当前 Execution 状态购买该 capability;不得换 capability、新建 Execution 或尝试其他购买命令,只回到同一 Execution 的 `services next`。
59
+ - Backend 不支持当前交易合同时返回 `backend_contract_incompatible`,必须停止,不能改用 `services checkout`、`cart`、`buy` 或 `pay` 绕过。
60
+
61
+ ## Agent Type / Host
62
+
63
+ `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 返回相同 Quote 事实、instruction 和 next。本命令不显示二维码;Agent Type 只作为设备与审计上下文,不改变价格或候选规则。
@@ -0,0 +1,98 @@
1
+ # `itpay services read-result`
2
+
3
+ ## 范围与意义
4
+
5
+ 使用当前 Agent Device Authority,在用户创建的有效、未过期且范围匹配的 grant 内读取 Vault 保护结果。它不适用于 `agent_visible_result`。
6
+
7
+ **上游:** `services next` 返回 `vault_artifact`,且用户已在订单页面授权。
8
+ **下游:** Agent 仅在 grant scope 和 TTL 内使用返回字段;没有自动后续命令。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay services read-result <service_execution_id> [--json]
14
+ ```
15
+
16
+ | 参数 | 必填 | 说明 |
17
+ | --- | --- | --- |
18
+ | `service_execution_id` | 是 | Vault 交付对应的 execution ID。 |
19
+ | `--json` | 否 | 输出稳定 JSON 信封;未指定时输出相同事实的简洁文本。 |
20
+
21
+ CLI 使用已登记设备的签名 session,不接受 Checkout token、Buyer token、`agent_device_id` 参数或开发者凭证。
22
+
23
+ CLI 直接请求 Backend 的当前有效 Grant。历史 `delivery_bindings` 不作为访问判断;Backend 负责验证当前 Vault、Agent instance、Buyer、scope、TTL 和退款锁。
24
+
25
+ ## 标准输出
26
+
27
+ ```json
28
+ {
29
+ "status": "granted_result_ready",
30
+ "result": {
31
+ "service_execution_id": "<id>",
32
+ "grant_expires_at": "<RFC3339 time>",
33
+ "granted_fields": ["<field>"],
34
+ "payload": { "<granted_field>": "<value>" }
35
+ },
36
+ "instruction": "结果来自当前有效 Vault Grant;只使用本次授权字段,过期后停止读取并重新请求用户同意。",
37
+ "next": null,
38
+ "recovery": []
39
+ }
40
+ ```
41
+
42
+ 文本输出显示相同的 execution、到期时间、字段名和 payload,不附带 Vault ID、grant ID 或原始 scope。
43
+
44
+ ## 异常处理
45
+
46
+ 没有当前有效 Vault Grant(包括只有 Agent-visible 历史交付、未授权、过期、撤销或 wrong-scope)时,Backend 返回 `agent_access_denied`。CLI 指向:
47
+
48
+ ```text
49
+ itpay services next <id> --json
50
+ ```
51
+
52
+ 不要从历史 Delivery Binding 推断当前模式,也不要使用数据库、Admin API 或新 Device ID 绕过授权。
53
+
54
+ 退款访问锁由 Backend 在读取 Vault payload 的同一事务中拒绝:
55
+
56
+ ```json
57
+ {
58
+ "status": "error",
59
+ "error": {
60
+ "code": "delivery_locked_by_refund",
61
+ "message": "delivery is locked by refund <refund_id>"
62
+ },
63
+ "instruction": "退款访问锁已生效;不要 reveal、创建 grant 或读取交付结果。",
64
+ "next": null,
65
+ "recovery": [
66
+ {
67
+ "command": "itpay refund get <refund_id> --json",
68
+ "reason": "读取退款权威状态"
69
+ }
70
+ ]
71
+ }
72
+ ```
73
+
74
+ 其他 `agent_access_denied` 返回:
75
+
76
+ ```json
77
+ {
78
+ "status": "error",
79
+ "error": {
80
+ "code": "agent_access_denied",
81
+ "message": "<server reason>"
82
+ },
83
+ "instruction": "请用户在订单页面重新授权;不要使用开发者权限绕过授权或退款锁。",
84
+ "next": null,
85
+ "recovery": [
86
+ {
87
+ "command": "itpay services next <id> --json",
88
+ "reason": "检查交付模式和 grant 状态"
89
+ }
90
+ ]
91
+ }
92
+ ```
93
+
94
+ 一个 grant 只允许读取对应订单、execution、Agent instance 和批准字段。拒绝时不得改用数据库、Admin API 或新 Device ID 绕过。
95
+
96
+ ## Agent Type / Host
97
+
98
+ 同一 Buyer account 下已登记的 `codex-desktop`、`codex-cli`、`claude-code-desktop`、`claude-code-cli`、`workbuddy` 可按政策领取同一订单授权;每个类型仍需自己的有效 Device Authority。五种类型返回相同字段、TTL 和错误,不因 Host 扩大 grant scope。
@@ -0,0 +1,55 @@
1
+ # `itpay services start`
2
+
3
+ ## 范围与意义
4
+
5
+ 按 Catalog 中的 `service_id` 启动一次 Service Execution,并返回当前可执行的唯一首选动作。不会调用 Provider、创建 Checkout 或订单。
6
+
7
+ **上游:** `catalog list` 或服务端明确要求新 execution。
8
+ **下游:** `services invoke`、`action`、`checkout` 或 `next`。
9
+
10
+ ## 语法与参数
11
+
12
+ ```bash
13
+ itpay --agent-type <agent_type> services start <service_id>
14
+ [--host <host>] [--target <target>] [--json]
15
+ ```
16
+
17
+ `service_id` 必须来自 Catalog。`--target` 只用于需要稳定消息目标的 Host,例如 chat/channel/open ID;它不是搜索词或其他业务输入。Buyer、Device 和 Agent instance 均来自签名 Agent session,不接受请求参数覆盖。
18
+
19
+ 本命令不接收 capability 业务输入。它返回 `required_input` 和一条 `services invoke`(或其他当前合法动作)命令;把真实值填入那条命令的重复 `--input key=value`。例如企业关键词是 `--input keyword=美团`,不是 `--target 美团`。
20
+
21
+ ## 标准输出
22
+
23
+ ```json
24
+ {
25
+ "status": "ready",
26
+ "result": {
27
+ "service_execution_id": "<execution_id>",
28
+ "service_id": "<service_id>",
29
+ "phase": "<phase>",
30
+ "capability": {
31
+ "capability_id": "<capability_id>",
32
+ "required_input": ["<field>"],
33
+ "free_quota_limit": 3
34
+ }
35
+ },
36
+ "instruction": "填写首选 capability 的 required_input;一次只提交当前 execution 所代表的服务意图。",
37
+ "next": {
38
+ "command": "itpay --agent-type <agent_type> services invoke <execution_id> --capability <capability_id> --input <key=value> --json",
39
+ "reason": "执行当前允许的能力"
40
+ },
41
+ "recovery": []
42
+ }
43
+ ```
44
+
45
+ Start API 只提供免费额度上限,不提供当前剩余额度,因此本命令不得虚构 `remaining`。不得输出全部 capability DTO、contract version、graph ID、buyer/device ID 或重复 guidance。若服务不存在,recovery 为 `catalog list`。设备 session 由 CLI 自动登记或刷新;401 `agent_device_session_required` 仅续期并重试一次,仍失败时返回错误,不循环。
46
+
47
+ ## Agent Type / Host
48
+
49
+ | Agent Type | 默认行为 |
50
+ |---|---|
51
+ | `codex-desktop` | 登记该类型并使用 `codex` Host instruction。 |
52
+ | `codex-cli` | 登记该类型并使用 terminal instruction。 |
53
+ | `claude-code-desktop` | 登记该类型并使用 `claude-code` Host instruction。 |
54
+ | `claude-code-cli` | 登记该类型并使用 terminal instruction。 |
55
+ | `workbuddy` | 登记该类型并使用 plain-chat instruction。 |
@@ -0,0 +1,17 @@
1
+ # `itpay skill show`
2
+
3
+ ## 范围与意义
4
+
5
+ 读取 npm 包内置的完整 Agent Skill。与按 topic 渐进读取的 `docs` 不同,本命令故意一次返回完整 `SKILL.md`,用于首次 onboarding 和身份/session 规则恢复;不访问 Backend,不修改宿主配置或本地身份。
6
+
7
+ ```bash
8
+ itpay [--agent-type <agent_type>] skill show itpay-buyer [--json]
9
+ ```
10
+
11
+ 当前只内置 `itpay-buyer`。`--json` 时完整 Markdown 位于 `result.content`;文本模式直接输出完整内容。
12
+
13
+ 未声明 Agent Type 时,`next` 是 `itpay install --json`。已声明时,`next` 是保留同一类型的 `catalog list --json`。未知名称返回 `skill_not_found`;包内文件缺失或损坏返回 `skill_unavailable` 并要求重装同版本 CLI。
14
+
15
+ Skill 是操作和安全合同,不是服务端业务状态。执行时仍以每个命令当前 envelope 的 `result`、`instruction` 和 `next` 为准。
16
+
17
+ 所有 Agent Type 使用相同的 JSON 外壳、字段和命令参数。`workbuddy` 只在 `instruction` 中额外强调保持同一 Node/CLI launcher、持久写权限和减少内部诊断转述;它不改变输入或输出 schema。
@@ -0,0 +1,97 @@
1
+ # Output And Error Contract
2
+
3
+ ## 目标
4
+
5
+ CLI 输出是给 Agent 执行的协议,不是后端 DTO 的调试转储。默认输出适合人阅读;`--json` 使用同一语义的稳定机器合同。调试事实只由明确的诊断命令返回。
6
+
7
+ ## 标准 JSON 外壳
8
+
9
+ ```json
10
+ {
11
+ "status": "<command_state>",
12
+ "result": {},
13
+ "instruction": "<one concise instruction>",
14
+ "next": {
15
+ "command": "itpay <next-command>",
16
+ "reason": "<why this is next>"
17
+ },
18
+ "recovery": []
19
+ }
20
+ ```
21
+
22
+ 规则:
23
+
24
+ - `status`:当前命令的业务结果,不是 HTTP 状态。
25
+ - `result`:仅包含当前步骤必须使用或向用户说明的事实。
26
+ - `instruction`:一条可直接当作 Agent prompt 使用的自然语言指令,不复述 `result`。
27
+ - `next`:最多一个首选动作;流程结束时为 `null`。
28
+ - `next.command` 是状态机允许的首选延续,不是无条件执行指令;当前结果已满足用户目标时,Agent 应展示结果并停止。
29
+ - `recovery`:成功时通常为空;失败或中断时最多两个动作。
30
+ - 一旦命令声明 `--agent-type` 或 `ITPAY_AGENT_TYPE`,所有 ItPay `next.command` 和 `recovery.command` 都保留同一类型。
31
+ - 相同事实不得同时出现在顶层、`agent_guidance`、`next_actions` 等多个位置。
32
+ - 默认隐藏 buyer、device、contract version、compiled graph、quote lock、内部 event ID 等实现细节。
33
+ - token、付款 URL 和本地二维码路径只在确实需要交给用户时返回,并不得写入日志型命令。
34
+
35
+ ## 默认文本输出
36
+
37
+ 文本输出与 JSON 字段一一对应,最多四段:
38
+
39
+ ```text
40
+ <status summary>
41
+ <necessary result lines>
42
+ instruction: <what the agent must do>
43
+ next: <one command>
44
+ ```
45
+
46
+ 无下一步时省略 `next`;无异常时省略 `recovery`。
47
+
48
+ ## 标准错误
49
+
50
+ ```json
51
+ {
52
+ "status": "error",
53
+ "error": {
54
+ "code": "<stable_error_code>",
55
+ "message": "<human-readable reason>"
56
+ },
57
+ "instruction": "<what not to do and what to correct>",
58
+ "next": null,
59
+ "recovery": [
60
+ { "command": "itpay <recovery-command>", "reason": "<reason>" }
61
+ ]
62
+ }
63
+ ```
64
+
65
+ 错误必须满足:
66
+
67
+ - 参数和前置条件在产生订单、锁价、扣费、Provider 调用或状态迁移前验证。
68
+ - 不得只返回 `invalid_state`;必须说明当前状态和合法恢复入口。
69
+ - 重试应复用同一 cart、checkout、execution、order 或 refund ID,不得默认创建新资源。
70
+ - 用户口头说“已付款”不是支付事实;仅服务端 `verified` 状态有效。
71
+ - `agent_device_session_required` 只触发一次 session 续期和同请求重试;第二次失败必须返回,不得循环或换身份。
72
+ - `device_state_unwritable` 表示当前运行环境不能可靠持久化 `~/.itpay-v3`;保持同一 Agent Type 与 CLI/Node launcher,恢复 Host 写权限后重试原命令,不得手工造 lock、删除身份或换运行时碰运气。
73
+
74
+ ## Instruction 模板
75
+
76
+ Instruction 只回答当前最重要的一件事:
77
+
78
+ ```text
79
+ 说明结果的意义 + 明确 Agent 现在必须做或禁止做的动作。
80
+ ```
81
+
82
+ 示例:
83
+
84
+ ```text
85
+ 把付款二维码和链接展示给用户;确认用户可见前不要查询付款状态,也不要创建新 Checkout。
86
+ ```
87
+
88
+ 不得使用空洞 instruction,例如“继续下一步”“按需处理”“查看详情”。
89
+
90
+ ## 通用性边界
91
+
92
+ - CLI 不识别企知道、企业查询、某个 capability 名称或某个字段名。
93
+ - 必填输入来自 `input_schema.required`。
94
+ - 是否收费来自 `requires_payment` 和价格元数据。
95
+ - 是否需要邮箱来自 `delivery_email_required`。
96
+ - 是否可直接给 Agent 来自 `agent_visible` / `delivery_mode`。
97
+ - 下一步来自 Service Execution read model,不由 CLI 猜业务流程。