@itpay/cli 2.0.13 → 2.0.15
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 +15 -7
- package/dist/src/commands/docs.js +1 -0
- package/dist/src/commands/guidance.js +8 -12
- package/dist/src/commands/install.js +2 -2
- package/dist/src/commands/readyz.js +7 -3
- package/dist/src/commands/skill.js +10 -10
- package/dist/src/main.js +22 -18
- package/dist/src/state/config.js +41 -6
- package/docs/agent/buyer/cart-checkout.json +16 -3
- package/docs/agent/buyer/catalog-list.json +1 -0
- package/docs/agent/buyer/identity-and-sessions.json +34 -13
- package/docs/agent/buyer/install-and-setup.json +25 -8
- package/docs/agent/buyer/orders-refunds.json +13 -2
- package/docs/agent/buyer/payment-flow.json +17 -3
- package/docs/agent/buyer/quickstart.json +49 -13
- package/docs/agent/buyer/render-hosts.json +14 -2
- package/docs/cli-reference/agent-types.md +2 -0
- package/docs/cli-reference/commands/buy.md +2 -0
- package/docs/cli-reference/commands/cart/add.md +2 -0
- package/docs/cli-reference/commands/cart/clear.md +2 -0
- package/docs/cli-reference/commands/cart/index.md +2 -0
- package/docs/cli-reference/commands/cart/next.md +2 -0
- package/docs/cli-reference/commands/cart/remove.md +3 -1
- package/docs/cli-reference/commands/cart/show.md +2 -0
- package/docs/cli-reference/commands/catalog/index.md +2 -0
- package/docs/cli-reference/commands/catalog/list.md +2 -0
- package/docs/cli-reference/commands/checkout.md +2 -0
- package/docs/cli-reference/commands/device.md +3 -1
- package/docs/cli-reference/commands/docs/index.md +2 -0
- package/docs/cli-reference/commands/docs/list.md +2 -0
- package/docs/cli-reference/commands/docs/search.md +2 -0
- package/docs/cli-reference/commands/docs/show.md +2 -0
- package/docs/cli-reference/commands/install.md +4 -2
- package/docs/cli-reference/commands/next.md +2 -0
- package/docs/cli-reference/commands/order.md +2 -0
- package/docs/cli-reference/commands/orders.md +2 -0
- package/docs/cli-reference/commands/pay.md +2 -0
- package/docs/cli-reference/commands/readyz.md +40 -11
- package/docs/cli-reference/commands/refund/cancel.md +2 -0
- package/docs/cli-reference/commands/refund/create.md +2 -0
- package/docs/cli-reference/commands/refund/get.md +2 -0
- package/docs/cli-reference/commands/refund/index.md +2 -0
- package/docs/cli-reference/commands/refund/list.md +2 -0
- package/docs/cli-reference/commands/refund/watch.md +2 -0
- package/docs/cli-reference/commands/services/action.md +2 -0
- package/docs/cli-reference/commands/services/checkout.md +2 -0
- package/docs/cli-reference/commands/services/events.md +2 -0
- package/docs/cli-reference/commands/services/get.md +2 -0
- package/docs/cli-reference/commands/services/index.md +2 -0
- package/docs/cli-reference/commands/services/invoke.md +2 -0
- package/docs/cli-reference/commands/services/list.md +2 -0
- package/docs/cli-reference/commands/services/next.md +2 -0
- package/docs/cli-reference/commands/services/quote.md +2 -0
- package/docs/cli-reference/commands/services/read-result.md +2 -0
- package/docs/cli-reference/commands/services/start.md +2 -0
- package/docs/cli-reference/commands/skill.md +5 -3
- package/docs/cli-reference/conventions.md +2 -0
- package/docs/cli-reference/index.md +3 -1
- package/docs/skill-bundle-rollout/01-mcp-authentication.md +256 -0
- package/docs/skill-bundle-rollout/02-platform-bundle-repositories.md +282 -0
- package/docs/skill-bundle-rollout/03-platform-publishing.md +270 -0
- package/docs/skill-bundle-rollout/README.md +98 -0
- package/package.json +6 -3
- package/skills/{itpay-buyer → itpay}/SKILL.md +39 -17
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay refund watch`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
7
|
轮询同一退款直到终态或 timeout。命令内部可以读取多次,但对外只输出一个最终信封,不把无变化轮询刷入 Agent 上下文。中断后可无副作用重跑。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay services action`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
7
|
记录用户或 Agent 对 Service Execution 的结构化动作,例如选择候选、批准、拒绝或取消。它不直接调用付费 Provider。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay services checkout`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
7
|
为单个 Service Execution 快速创建或恢复 Checkout,并按 Host 向人交接付款入口。它是 `services quote -> cart add --quote -> buy --cart` 的单项快捷方式,必须复用相同的 Quote、Cart 和 Checkout Use Case。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay services events`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
7
|
按 sequence 升序读取一笔 Service Execution 的受限诊断事件。它只用于解释异常或支持排查,不是正常业务流程,不返回事件 ID、内部摘要、Provider 数据或受保护交付内容。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay services get`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
7
|
读取一笔 Service Execution 的紧凑状态、关键节点和当前首选动作。它面向恢复和用户解释,不是原始 event dump。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay services`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 命令范围
|
|
4
6
|
|
|
5
7
|
操作通用 Service Execution。CLI 不知道某个服务的业务流程;它读取服务合同中的 capability、input schema、价格、交付模式和服务端 next action。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay services invoke`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
7
|
调用当前 phase 允许的非付费 Agent-visible capability。输入先按 capability schema 校验,校验失败不得迁移 execution 或记录 Provider 已调用。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay services list`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
7
|
恢复当前已登记设备或账号可见的 Service Execution 摘要。它不是批量 timeline 导出。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay services next`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
7
|
读取一笔 Service Execution 的当前状态,并只返回一个首选下一步。若交付模式允许 Agent 直接读取,本命令同时返回完整 safe result。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay services quote`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
7
|
为当前 Service Execution 的一个付费 Capability 准备 Quote Lock。它只锁定可信输入、候选来源、价格、币种和有效期,不创建 Cart、Checkout、订单或 Provider 调用。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay services read-result`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
7
|
使用当前 Agent Device Authority,在用户创建的有效、未过期且范围匹配的 grant 内读取 Vault 保护结果。它不适用于 `agent_visible_result`。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `itpay services start`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
7
|
按 Catalog 中的 `service_id` 启动一次 Service Execution,并返回当前可执行的唯一首选动作。不会调用 Provider、创建 Checkout 或订单。
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
# `itpay skill show`
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 范围与意义
|
|
4
6
|
|
|
5
|
-
读取 npm 包内置的完整 Agent Skill。与按 topic 渐进读取的 `docs` 不同,本命令故意一次返回完整 `SKILL.md`,用于首次 onboarding 和身份/session 规则恢复;不访问 Backend,不修改宿主配置或本地身份。
|
|
7
|
+
读取 npm 包内置的完整 ItPay Agent Skill。与按 topic 渐进读取的 `docs` 不同,本命令故意一次返回完整 `SKILL.md`,用于首次 onboarding 和身份/session 规则恢复;不访问 Backend,不修改宿主配置或本地身份。
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
|
-
itpay [--agent-type <agent_type>] skill show itpay
|
|
10
|
+
itpay [--agent-type <agent_type>] skill show itpay [--json]
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
当前只内置 `itpay
|
|
13
|
+
当前只内置 `itpay`。该 Skill 是 Buyer 与未来 Seller 的共同入口,不再按角色拆分名称。`--json` 时完整 Markdown 位于 `result.content`;文本模式直接输出完整内容。
|
|
12
14
|
|
|
13
15
|
未声明 Agent Type 时,`next` 是 `itpay install --json`。已声明时,`next` 是保留同一类型的 `catalog list --json`。未知名称返回 `skill_not_found`;包内文件缺失或损坏返回 `skill_unavailable` 并要求重装同版本 CLI。
|
|
14
16
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Output And Error Contract
|
|
2
2
|
|
|
3
|
+
> **Product boundary:** `itpay` is the single public CLI entry point, and `$itpay` is its user-facing Skill invocation. Under that one product entry point, the two top-level commerce actions are `buy` and `sell`: Buyer workflows are available now; Seller workflows will use the same entry point and are not implemented yet.
|
|
4
|
+
|
|
3
5
|
## 目标
|
|
4
6
|
|
|
5
7
|
CLI 输出是给 Agent 执行的协议,不是后端 DTO 的调试转储。默认输出适合人阅读;`--json` 使用同一语义的稳定机器合同。调试事实只由明确的诊断命令返回。
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
本目录是 ItPay CLI 的规范性命令合同。它定义命令应向人和 Agent 返回什么、如何指导下一步,以及失败后如何恢复。当前实现与本文档不一致时,以本文档作为后续校准目标。
|
|
4
4
|
|
|
5
|
+
> **统一产品边界:** `itpay` 是唯一公开的 CLI 入口,`$itpay` 是对应的用户侧 Skill 调用方式。在同一个产品入口下,两个顶层 commerce 动作是 `buy` 和 `sell`:Buyer 流程当前可用;Seller 流程未来仍使用同一入口,当前尚未实现。不得拆分出独立 Buyer 或 Seller 产品入口。
|
|
6
|
+
|
|
5
7
|
企知道可以作为示例数据出现,但任何命令、字段、状态和 instruction 都不得依赖某个服务。服务差异只能来自 Catalog、Service Contract、Capability metadata 和服务端状态。
|
|
6
8
|
|
|
7
9
|
## 使用约定
|
|
@@ -21,7 +23,7 @@
|
|
|
21
23
|
- [`itpay catalog`](commands/catalog/index.md)
|
|
22
24
|
- [`itpay catalog list`](commands/catalog/list.md)
|
|
23
25
|
- [`itpay install`](commands/install.md) - 查看指定 Agent 的安装说明
|
|
24
|
-
- [`itpay skill show`](commands/skill.md) - 一次读取完整内置
|
|
26
|
+
- [`itpay skill show`](commands/skill.md) - 一次读取完整内置 ItPay Skill
|
|
25
27
|
- [`itpay docs`](commands/docs/index.md)
|
|
26
28
|
- [`itpay docs list`](commands/docs/list.md)
|
|
27
29
|
- [`itpay docs show`](commands/docs/show.md)
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# 核心任务一:MCP 专用认证系统
|
|
2
|
+
|
|
3
|
+
状态:待实施
|
|
4
|
+
|
|
5
|
+
## 1. Current State
|
|
6
|
+
|
|
7
|
+
### CLI Device Authority
|
|
8
|
+
|
|
9
|
+
当前 `src/state/device_authority.ts`:
|
|
10
|
+
|
|
11
|
+
- 每个本地安装生成一把 Ed25519 私钥。
|
|
12
|
+
- 私钥和 Device 状态存放在 `~/.itpay-v3/device`,owner-only 权限。
|
|
13
|
+
- 一个 production Device registration 下按 `agent_type` 建立 Agent Instance。
|
|
14
|
+
- CLI 通过 challenge 签名取得短期 Device session。
|
|
15
|
+
- 受保护请求使用 `Authorization: ItPayDevice ...` 加请求签名。
|
|
16
|
+
- session 失效只续期一次;已撤销的 v2 registration 不会静默替换。
|
|
17
|
+
|
|
18
|
+
这套系统回答的是“哪个本地 Agent 设备在调用”,不是“哪个付费用户连接了 MCP”。
|
|
19
|
+
|
|
20
|
+
### Buyer Bearer
|
|
21
|
+
|
|
22
|
+
`src/state/config.ts` 可以从 `ITPAY_BEARER_TOKEN` 读取账号 Bearer token,供 `orders` 等账号范围命令使用。它是外部注入能力,不是平台 OAuth 连接系统,不应直接扩展成把 token 写进 Skill bundle。
|
|
23
|
+
|
|
24
|
+
### 问题
|
|
25
|
+
|
|
26
|
+
云端 Chat 平台不能稳定访问用户电脑上的 `~/.itpay-v3`。即使 Skill 在沙箱里写出同名目录,那也是平台执行容器的临时身份,不是用户本机身份,也不能作为订阅、订单或支付权限的长期主键。
|
|
27
|
+
|
|
28
|
+
## 2. Target Behavior
|
|
29
|
+
|
|
30
|
+
新增远程 MCP OAuth 通道:
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
Platform -> OAuth authorize -> ItPay login/consent
|
|
34
|
+
<- authorization code
|
|
35
|
+
Platform -> token endpoint (code + PKCE)
|
|
36
|
+
<- access token + refresh token
|
|
37
|
+
Platform -> MCP tool + Bearer access token
|
|
38
|
+
MCP -> validate issuer/audience/scope/expiry
|
|
39
|
+
MCP -> principal.user_id
|
|
40
|
+
Backend -> account/entitlement/order authorization
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
完成后:
|
|
44
|
+
|
|
45
|
+
- MCP 通过 ItPay 用户身份追踪收费、套餐、订单与权限。
|
|
46
|
+
- CLI 继续通过 Device Authority 追踪本地 Agent 设备和 Agent Instance。
|
|
47
|
+
- 用户可以显式把 Device 关联到同一 ItPay account,但关联不改变认证方式。
|
|
48
|
+
- 两套 token 具有不同 issuer/audience、Header scheme、存储位置和撤销域。
|
|
49
|
+
- 后端授权逻辑接收统一 principal,但不混淆 principal 类型。
|
|
50
|
+
|
|
51
|
+
不应该改变:
|
|
52
|
+
|
|
53
|
+
- 现有 CLI 私钥位置、Device 注册协议、签名格式和一次性 session 恢复规则。
|
|
54
|
+
- 默认 `https://app.itpay.ai`,且仅允许准确 `https://dev.itpay.ai` 测试 override 的官方 Backend 规则。
|
|
55
|
+
- Checkout 外部人类确认和服务端支付状态权威性。
|
|
56
|
+
|
|
57
|
+
## 3. Scope
|
|
58
|
+
|
|
59
|
+
### In scope
|
|
60
|
+
|
|
61
|
+
- ItPay OAuth Authorization Server 所需的 authorize、token、refresh、revoke 和 metadata。
|
|
62
|
+
- MCP resource server 的 Bearer token 验证。
|
|
63
|
+
- PKCE、state、精确 redirect URI、scope、audience、过期和撤销。
|
|
64
|
+
- OAuth subject 到现有 ItPay `user_id` 的映射。
|
|
65
|
+
- 平台 OAuth client/connection 记录。
|
|
66
|
+
- MCP 工具级 scope 与敏感写操作确认策略。
|
|
67
|
+
- CLI Device 与用户账号的可选显式关联。
|
|
68
|
+
- 审计日志、最小化返回、测试账号和平台审核所需演示凭据。
|
|
69
|
+
|
|
70
|
+
### Out of scope
|
|
71
|
+
|
|
72
|
+
- 重写 CLI Device Authority。
|
|
73
|
+
- 让 MCP 读取或迁移本地 Device 私钥。
|
|
74
|
+
- 让平台 Access Token 代替支付确认。
|
|
75
|
+
- 在聊天内容中采集支付卡、支付密码、验证码、钱包私钥。
|
|
76
|
+
- 为每个平台建立独立 ItPay 用户表。
|
|
77
|
+
|
|
78
|
+
## 4. 认证边界
|
|
79
|
+
|
|
80
|
+
### Principal 类型
|
|
81
|
+
|
|
82
|
+
后端至少明确区分:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
type Principal =
|
|
86
|
+
| { kind: "device"; deviceId: string; agentInstanceId: string; agentType: string }
|
|
87
|
+
| { kind: "user"; userId: string; oauthClientId: string; scopes: string[] };
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
不要求实际代码使用这个 TypeScript 类型,但授权层必须保留等价区分。禁止根据“有 Authorization Header”就把两者当成同一种账号。
|
|
91
|
+
|
|
92
|
+
### Header 与 audience
|
|
93
|
+
|
|
94
|
+
| 通道 | Header | audience | 用途 |
|
|
95
|
+
| --- | --- | --- | --- |
|
|
96
|
+
| CLI | `Authorization: ItPayDevice <session>` + 签名 Headers | Device API | 本地设备、Agent Instance、设备额度与执行 |
|
|
97
|
+
| MCP | `Authorization: Bearer <oauth_access_token>` | ItPay MCP resource | 用户账号、套餐、订单和 MCP 工具 |
|
|
98
|
+
|
|
99
|
+
Bearer token 不能被 CLI Device middleware 接受;Device session 不能被 MCP middleware 接受。鉴权失败返回 401,授权不足返回 403,不做静默降级。
|
|
100
|
+
|
|
101
|
+
### 服务端身份关系
|
|
102
|
+
|
|
103
|
+
建议关系而非第二套用户系统:
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
itpay_users
|
|
107
|
+
id
|
|
108
|
+
|
|
109
|
+
oauth_clients
|
|
110
|
+
client_id
|
|
111
|
+
platform
|
|
112
|
+
redirect_uris
|
|
113
|
+
status
|
|
114
|
+
|
|
115
|
+
oauth_grants
|
|
116
|
+
user_id -> itpay_users.id
|
|
117
|
+
client_id -> oauth_clients.client_id
|
|
118
|
+
scopes
|
|
119
|
+
revoked_at
|
|
120
|
+
|
|
121
|
+
agent_devices
|
|
122
|
+
optional_linked_user_id -> itpay_users.id
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Access token 的 `sub` 是稳定、不可猜测的 ItPay 用户 subject。若需要减少跨客户端关联,应使用 pairwise subject,并在服务端映射回同一 `user_id`;不要把 email、ChatGPT 用户名或平台会话 ID 当主键。
|
|
126
|
+
|
|
127
|
+
## 5. Implementation Steps
|
|
128
|
+
|
|
129
|
+
### Step 1:冻结现有 CLI 认证合同
|
|
130
|
+
|
|
131
|
+
依赖:无。
|
|
132
|
+
|
|
133
|
+
- 为现有 Device enrollment、session、请求签名、401 单次恢复补齐合同测试。
|
|
134
|
+
- 记录 Device API 可访问的路由集合。
|
|
135
|
+
- 确认 MCP 改动不会修改 `src/state/device_authority.ts` 的持久化 schema。
|
|
136
|
+
|
|
137
|
+
完成条件:加入 MCP 中间件前后,现有 CLI 测试结果和本地身份文件保持一致。
|
|
138
|
+
|
|
139
|
+
### Step 2:定义 OAuth issuer 和 MCP resource
|
|
140
|
+
|
|
141
|
+
依赖:Step 1。
|
|
142
|
+
|
|
143
|
+
- 选择正式 issuer,例如 `https://auth.itpay.ai`;若沿用 `app.itpay.ai`,也必须保持独立 OAuth 路径和密钥用途。
|
|
144
|
+
- 发布标准 Authorization Server metadata 和 MCP Protected Resource metadata。
|
|
145
|
+
- 明确 production MCP URL、resource audience、redirect URI 注册规则和允许的平台 client。
|
|
146
|
+
- Authorization Code 必须使用 PKCE;禁止 implicit flow 和 Resource Owner Password flow。
|
|
147
|
+
|
|
148
|
+
完成条件:平台可以发现授权端点,redirect URI 不能通配,code 只能使用一次且短期有效。
|
|
149
|
+
|
|
150
|
+
### Step 3:实现登录、同意和 token 生命周期
|
|
151
|
+
|
|
152
|
+
依赖:Step 2。
|
|
153
|
+
|
|
154
|
+
- 用户在 ItPay 页面完成登录;平台不能代收 ItPay 密码。
|
|
155
|
+
- consent 页面展示 client、scope、数据用途和撤销入口。
|
|
156
|
+
- access token 短期有效;refresh token 轮换并检测重放。
|
|
157
|
+
- 支持单 grant 撤销、全设备/全连接撤销和用户主动断开平台。
|
|
158
|
+
- 密钥轮换保留合理验证窗口;日志不记录原始 token 或 authorization code。
|
|
159
|
+
|
|
160
|
+
完成条件:登录、刷新、过期、撤销、重放和错误 redirect URI 均有自动测试。
|
|
161
|
+
|
|
162
|
+
### Step 4:在 MCP 服务建立认证和工具授权
|
|
163
|
+
|
|
164
|
+
依赖:Step 3。
|
|
165
|
+
|
|
166
|
+
- MCP 入口只接受匹配 issuer、audience、签名、有效期和未撤销 grant 的 Bearer token。
|
|
167
|
+
- 每个工具声明并验证最小 scope。
|
|
168
|
+
- 只读工具与创建 Checkout、退款等写工具分开。
|
|
169
|
+
- 敏感写工具保留平台确认和 ItPay 服务端幂等键。
|
|
170
|
+
- 工具响应去掉 token、内部用户 ID、Device ID、调试 payload 和不必要个人数据。
|
|
171
|
+
|
|
172
|
+
建议第一版 scope:
|
|
173
|
+
|
|
174
|
+
| Scope | 能力 |
|
|
175
|
+
| --- | --- |
|
|
176
|
+
| `catalog:read` | 浏览公开目录 |
|
|
177
|
+
| `checkout:write` | 创建或恢复当前用户的 Checkout handoff |
|
|
178
|
+
| `orders:read` | 读取当前用户订单摘要 |
|
|
179
|
+
| `refunds:write` | 按既有退款政策发起退款请求 |
|
|
180
|
+
|
|
181
|
+
不要第一版就增加通配 scope。
|
|
182
|
+
|
|
183
|
+
完成条件:越权工具返回 403;不能通过参数替换其他用户 ID;写操作保持幂等。
|
|
184
|
+
|
|
185
|
+
### Step 5:关联账号而不合并凭据
|
|
186
|
+
|
|
187
|
+
依赖:Step 3、Step 4。
|
|
188
|
+
|
|
189
|
+
- MCP OAuth grant 直接绑定 ItPay `user_id`。
|
|
190
|
+
- 本地 Device 若需要账号能力,通过网页显式关联到同一 `user_id`。
|
|
191
|
+
- 关联只写服务端关系,不把 OAuth refresh token 写入 `~/.itpay-v3/device`,也不把 Device 私钥传到服务端或 MCP。
|
|
192
|
+
- 解除关联不删除 Device 身份;撤销 OAuth 不删除 Device registration。
|
|
193
|
+
|
|
194
|
+
完成条件:分别撤销任一通道不会破坏另一通道;同一用户的订单权限由服务端政策决定。
|
|
195
|
+
|
|
196
|
+
### Step 6:平台审核材料与运维
|
|
197
|
+
|
|
198
|
+
依赖:Step 4。
|
|
199
|
+
|
|
200
|
+
- 建立无 MFA、无短信/邮件确认、无内网依赖的审核测试账号,仅含固定测试数据和限额。
|
|
201
|
+
- 准备 privacy policy、terms、support、数据删除和撤销说明。
|
|
202
|
+
- 记录 client、user、tool、scope、结果和 request ID;不记录 secret。
|
|
203
|
+
- 对 token 签发、失败登录、撤销、敏感工具建立告警。
|
|
204
|
+
|
|
205
|
+
完成条件:审核者可以独立完成正向和负向测试;运营可以按 user/client 撤销连接。
|
|
206
|
+
|
|
207
|
+
## 6. API / Data / Type Changes
|
|
208
|
+
|
|
209
|
+
预计涉及,具体路由名在服务端仓库调研后确定:
|
|
210
|
+
|
|
211
|
+
- OAuth metadata、authorize、token、revoke 端点。
|
|
212
|
+
- MCP protected resource metadata。
|
|
213
|
+
- OAuth client、grant、refresh-token family、consent/audit 数据。
|
|
214
|
+
- 统一但保留 `device`/`user` 区分的 principal 类型。
|
|
215
|
+
- MCP tool scope 和平台 action annotation。
|
|
216
|
+
|
|
217
|
+
CLI 公共命令和 `~/.itpay-v3/device` schema:无计划变更。
|
|
218
|
+
|
|
219
|
+
## 7. Tests / Verification
|
|
220
|
+
|
|
221
|
+
### 单元测试
|
|
222
|
+
|
|
223
|
+
- PKCE verifier、redirect URI、state、code 单次消费。
|
|
224
|
+
- issuer/audience/scope/expiry/signature/revocation。
|
|
225
|
+
- refresh rotation 和旧 token 重放。
|
|
226
|
+
- Device/Bearer scheme 互相拒绝。
|
|
227
|
+
|
|
228
|
+
### 集成测试
|
|
229
|
+
|
|
230
|
+
- 完整 OAuth 登录、MCP 调用、刷新、撤销。
|
|
231
|
+
- 同一 ItPay 用户从两个平台 client 登录。
|
|
232
|
+
- MCP OAuth 登录后,本地 CLI Device ID 和私钥 hash 不变。
|
|
233
|
+
- Device 撤销后 MCP grant 仍按自身状态工作;反向亦然。
|
|
234
|
+
- 订单、Checkout、退款的跨用户越权测试。
|
|
235
|
+
|
|
236
|
+
### 手动验证
|
|
237
|
+
|
|
238
|
+
- ChatGPT Connect/Disconnect。
|
|
239
|
+
- 另一个支持远程 MCP OAuth 的平台连接。
|
|
240
|
+
- 本地 CLI 同时运行并完成 `readyz`、目录、Checkout 恢复。
|
|
241
|
+
|
|
242
|
+
## 8. Risks / Uncertainties
|
|
243
|
+
|
|
244
|
+
- MCP 服务端代码不在当前 CLI 仓库,本文件定义合同,实施前必须在对应服务端仓库重新追踪现有用户/session 模块。
|
|
245
|
+
- 各平台对动态 client registration、redirect URI 和 token metadata 的细节可能不同;以平台实际连接测试为准。
|
|
246
|
+
- OpenAI 对金融交易和 PCI 数据有额外限制。MCP 只编排外部 Checkout,不把 OAuth 登录等同于付款授权。
|
|
247
|
+
- `ITPAY_BEARER_TOKEN` 的长期定位需要服务端确认;第一版不删除、不重命名,也不让 MCP 依赖该环境变量。
|
|
248
|
+
|
|
249
|
+
## 9. Checkpoint
|
|
250
|
+
|
|
251
|
+
本任务不需要改动当前 CLI 身份即可开始。实施时只有以下情况停下确认:
|
|
252
|
+
|
|
253
|
+
- 现有服务端没有可复用的 ItPay 用户主表;
|
|
254
|
+
- 必须改变 Device principal 或 quota 归属;
|
|
255
|
+
- 需要引入新的支付授权行为;
|
|
256
|
+
- 平台要求与这里冲突的 token 传递方式。
|