@meritsandtree/mt-os-cli 0.1.2

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 ADDED
@@ -0,0 +1,223 @@
1
+ # `@meritsandtree/mt-os-cli`
2
+
3
+ `mt-os-cli` 是 MTOS 律所管理系统的本地安装、登录、诊断和 HTTP Tool 调用工具。常规调用链路是:
4
+
5
+ ```text
6
+ Codex / Claude Code -> MTOS MCP -> 业务 tools
7
+ ```
8
+
9
+ 不走 MCP 时,也可以直接通过 CLI 调用服务端 HTTP Tool:
10
+
11
+ ```text
12
+ mt-os-cli tool list/get/call/upload -> MTOS HTTP Tool 接口
13
+ ```
14
+
15
+ 默认环境是 `test`,默认服务地址是 `https://testlaw.meritsandtree.com`。
16
+
17
+ ## 安装
18
+
19
+ ```bash
20
+ npm i -g @meritsandtree/mt-os-cli
21
+ ```
22
+
23
+ 本地开发仓库调试时可直接执行:
24
+
25
+ ```bash
26
+ npm link /Users/june/IdeaProjects/e-mt-os-cli
27
+ ```
28
+
29
+ ## 自动更新
30
+
31
+ CLI 会按本地缓存轻量提醒新版本,不会在普通业务命令里静默替用户升级。真正安装新版本需要显式执行:
32
+
33
+ ```bash
34
+ mt-os-cli update --check
35
+ mt-os-cli update
36
+ ```
37
+
38
+ - `mt-os-cli update --check`:只检查 npm 最新版本,不执行安装,也不刷新本机 skill。
39
+ - `mt-os-cli update`:检测当前安装方式;如果当前命令来自 npm 全局安装且本机有 npm,会执行 `npm install -g @meritsandtree/mt-os-cli@<latest>`,成功后再执行 `mt-os-cli skills update`。
40
+ - JSON 输出会在有缓存命中新版本时附加 `_notice.update`,提示执行 `mt-os-cli update`;如需关闭提醒,可设置 `MT_OS_CLI_NO_UPDATE_NOTIFIER=1`。
41
+
42
+ ## 环境预设
43
+
44
+ `mt-os-cli` 内置 4 套环境预设:
45
+
46
+ - `local`:`http://localhost:8087`
47
+ - `dev`:`http://localhost:8087`
48
+ - `test`:`https://testlaw.meritsandtree.com`
49
+ - `prod`:`https://law.meritsandtree.com`
50
+
51
+ 默认就是 `test`,因此测试环境可直接执行:
52
+
53
+ ```bash
54
+ mt-os-cli auth login
55
+ mt-os-cli auth check
56
+ ```
57
+
58
+ 本地联调时先启动 `law-app`,再显式执行:
59
+
60
+ ```bash
61
+ mt-os-cli env use local
62
+ ```
63
+
64
+ 生产环境使用前需要显式切换:
65
+
66
+ ```bash
67
+ mt-os-cli env use prod
68
+ ```
69
+
70
+ ## 常用命令
71
+
72
+ ```bash
73
+ mt-os-cli env list
74
+ mt-os-cli env current
75
+ mt-os-cli env use test
76
+ mt-os-cli auth login
77
+ mt-os-cli auth login --no-wait --json
78
+ mt-os-cli auth login --device-code <device_code>
79
+ mt-os-cli auth token --env test --token <token>
80
+ mt-os-cli auth status
81
+ mt-os-cli auth check
82
+ mt-os-cli auth whoami
83
+ mt-os-cli auth refresh
84
+ mt-os-cli doctor
85
+ mt-os-cli skills
86
+ mt-os-cli skills update
87
+ mt-os-cli skill codex
88
+ mt-os-cli skill claude
89
+ mt-os-cli skill openclaw
90
+ mt-os-cli mcp
91
+ mt-os-cli mcp install
92
+ mt-os-cli mcp install openclaw
93
+ mt-os-cli tool list
94
+ mt-os-cli tool get query_customer --format json
95
+ mt-os-cli schema query_customer
96
+ mt-os-cli tool call query_customer --args-json '{}' --format json
97
+ mt-os-cli tool upload ./合同附件.pdf
98
+ mt-os-cli api GET /law/api/v1/cli/tools --query-json '{"domain":"customer"}'
99
+ mt-os-cli api GET /agent/api/v1/cli/skills
100
+ ```
101
+
102
+ ## 推荐使用流程
103
+
104
+ 首次使用:
105
+
106
+ ```bash
107
+ mt-os-cli auth login
108
+ ```
109
+
110
+ - 登录会创建设备授权码,在终端打印二维码和授权链接,用户在浏览器里确认授权后保存本地登录态。
111
+ - 登录成功后会安装 Codex、Claude、OpenClaw 可读取的本地技能/指令,并从 `/agent/api/v1/cli/skills` 拉取服务端最新 skill。
112
+ - 登录不会默认写入 MCP 配置;需要 MCP 时单独执行 `mt-os-cli mcp install [codex|claude|openclaw|all]`。
113
+ - Agent 代用户登录时,推荐用 `mt-os-cli auth login --no-wait --json`,把输出里的 `verification_url` 原样发给用户,再用 `mt-os-cli auth login --device-code <device_code>` 继续轮询授权结果。
114
+ - `mt-os-cli auth check` 只校验 token 是否有效,token 失效会以非 0 退出码返回结构化错误。
115
+ - `mt-os-cli doctor` 用来检查本地 session、客户端安装状态、MCP 配置是否完整。
116
+
117
+ ## 已安装内容
118
+
119
+ - Codex skill:`~/.codex/skills/mt-os/SKILL.md`
120
+ - Claude 入口指令:`~/.claude/CLAUDE.md`
121
+ - Claude skill:`~/.claude/skills/mt-os/SKILL.md`
122
+ - OpenClaw skill:`~/.openclaw/skills/mt-os/SKILL.md`
123
+ - 远程 MCP 服务名:`mt-os`
124
+ - 业务能力说明以 `mt-os-cli tool list/get/schema` 返回的实时 Tool 元数据为准。
125
+
126
+ ## Tool 调用
127
+
128
+ 先看服务端实时开放能力:
129
+
130
+ ```bash
131
+ mt-os-cli tool list --format table
132
+ mt-os-cli tool list --domain customer --format table
133
+ mt-os-cli schema query_customer
134
+ ```
135
+
136
+ 再调用具体 Tool:
137
+
138
+ ```bash
139
+ mt-os-cli tool call query_customer --args-json '{}' --format json
140
+ mt-os-cli tool call create_customer --args-json '{"customerName":"测试客户"}' --dry-run
141
+ ```
142
+
143
+ 如果命令返回 `confirmation_required`,需要确认参数和风险后再追加 `--confirm` 重试。
144
+
145
+ ## Raw API 调试
146
+
147
+ `mt-os-cli api` 用于排查 HTTP 层问题,默认只允许白名单路径前缀:
148
+
149
+ ```bash
150
+ mt-os-cli api GET /law/api/v1/cli/tools --query-json '{"domain":"customer"}'
151
+ mt-os-cli api GET /agent/api/v1/cli/skills
152
+ mt-os-cli api POST /law/api/v1/cli/tools/query_customer/invoke --data-json '{"arguments":{}}' --confirm
153
+ ```
154
+
155
+ - 允许前缀:`/law/api/v1/cli/tools`、`/agent/api/v1/cli/skills`、`/user/api/v1/token/check`、`/user/api/v1/token/refresh`、`/user/api/v1/cli-device-auth`。
156
+ - 非 GET 请求必须显式加 `--confirm`。
157
+ - 返回 HTTP 状态码、响应头和原始响应体,适合调试服务端协议差异。
158
+
159
+ ## Skill 更新流程
160
+
161
+ `mt-os-cli skills update` 默认先请求服务端 `/agent/api/v1/cli/skills`,把服务端动态 skill 写到 Codex、Claude 和 OpenClaw 的本机 skills 目录。只有远程不可用时,才写入 npm 包内置的 bootstrap skill 兜底。
162
+
163
+ 当前 npm 包只保留非业务 bootstrap 模板:
164
+
165
+ - `assets/agent-skill/SKILL.md`
166
+ - `assets/claude/CLAUDE.md`
167
+
168
+ 模板更新流程:
169
+
170
+ 1. 修改 `assets/agent-skill/SKILL.md` 或 `assets/claude/CLAUDE.md`。
171
+ 2. 执行 `npm run typecheck && npm test && npm run build`。
172
+ 3. 重新执行 `mt-os-cli skills update --source bundled`、`mt-os-cli auth login` 或 `mt-os-cli install codex/claude/openclaw`,把 bootstrap 覆盖到用户目录。
173
+ 4. 如果要对外发布,再升级 `package.json` 版本并发布 npm。
174
+
175
+ 服务端动态 skill 更新流程:
176
+
177
+ 1. 业务模块返回自己的 `CliSkillFileVO` 列表。
178
+ 2. 部署服务端后执行 `mt-os-cli skills update --source remote`,只拉远程 skill。
179
+ 3. 日常使用 `mt-os-cli skills update` 即可;远程成功时以服务端清单为准,远程不可用时写入 bootstrap 兜底。
180
+ 4. CLI 会在各客户端 skills 根目录记录 `.mt-os-cli-remote-skills.json`,并按服务端清单清理旧文件。
181
+
182
+ ## MCP 测试
183
+
184
+ Codex:
185
+
186
+ ```bash
187
+ mt-os-cli mcp install codex
188
+ codex exec --skip-git-repo-check "查一下我名下有多少个客户"
189
+ ```
190
+
191
+ Claude Code:
192
+
193
+ ```bash
194
+ mt-os-cli mcp install claude
195
+ claude mcp list
196
+ claude mcp get mt-os
197
+ claude -p --permission-mode bypassPermissions "查一下我参与的进行中项目,给我前5个"
198
+ ```
199
+
200
+ OpenClaw:
201
+
202
+ ```bash
203
+ mt-os-cli mcp install openclaw
204
+ openclaw mcp show mt-os --json
205
+ ```
206
+
207
+ ## 彻底卸载
208
+
209
+ 如果你要做一次完全干净的本机复测,推荐按下面两步执行:
210
+
211
+ ```bash
212
+ mt-os-cli uninstall
213
+ npm uninstall -g @meritsandtree/mt-os-cli
214
+ ```
215
+
216
+ - `mt-os-cli uninstall` 会清理 Keychain 中的本地登录态、Codex/Claude/OpenClaw 的 MTOS MCP 配置、由 `mt-os-cli` 安装或远程下发的 `mt-os`、`agent-*`、`tool-index` 等技能、Claude 托管指令区块,以及 `~/.config/mt-os-cli`。
217
+ - `npm uninstall -g @meritsandtree/mt-os-cli` 只会移除全局 `mt-os-cli` 命令;如果直接执行这一步,npm 不会替你清理 Keychain session 和本地配置,所以必须先执行 `mt-os-cli uninstall`。
218
+
219
+ ## 诊断建议
220
+
221
+ - `mt-os-cli doctor` 应至少看到 `session: present` 和 `api_check: ok`。
222
+ - `mt-os-cli auth check` 适合 Agent 在执行业务命令前轻量校验 token;失败时按返回的 JSON 错误 hint 重新登录。
223
+ - `mt-os-cli auth refresh` 适合在 token 即将过期时主动刷新;如果客户端 MCP Bearer 也需要更新,再执行 `mt-os-cli mcp install`。
@@ -0,0 +1,29 @@
1
+ ---
2
+ name: mt-os
3
+ description: 使用 mt-os-cli 或服务端已开放 Tool 处理 MTOS 律所管理系统客户、项目、审批、计时、附件、财务、报销和看板统计等业务请求时使用。
4
+ ---
5
+
6
+ # MTOS
7
+
8
+ ## 启动规则
9
+
10
+ - 首次安装或怀疑本机技能说明已更新时,先执行 `mt-os-cli skills update --source bundled codex`,刷新 `~/.codex/skills/mt-os/SKILL.md`。
11
+ - 业务能力以当前服务端开放的 Tool 清单为准;不要只凭历史工具名猜测 MTOS 工具名或参数。
12
+ - 先执行 `mt-os-cli tool list --format table` 查看可用 Tool,再用 `mt-os-cli schema <toolName>` 或 `mt-os-cli tool get <toolName>` 确认实时参数。
13
+ - 优先使用已开放的 MCP tools;MCP 不可用但本机已经登录时,用 `mt-os-cli tool list/get/call/upload` 做 HTTP 直调。
14
+ - 不要自行拼未开放 REST 接口,不要猜测工具名、参数名或返回结构。
15
+
16
+ ## 登录和刷新
17
+
18
+ - 登录态不确定时,先执行 `mt-os-cli auth check`。
19
+ - 需要代用户登录时,执行 `mt-os-cli auth login --no-wait --json`,把输出里的 `verification_url` 原样给用户,再执行 `mt-os-cli auth login --device-code <device_code>` 等待授权结果。
20
+ - token 失效时先执行 `mt-os-cli auth refresh`;refresh 失败再重新执行 `mt-os-cli auth login`。
21
+ - 如果当前宿主使用 MCP 且 Bearer 需要更新,再执行 `mt-os-cli mcp install`。
22
+
23
+ ## 安全边界
24
+
25
+ - `confirmPolicy` 为 `ALWAYS` 或 `confirmationRequired` 为 `true` 的工具必须等待用户明确确认。
26
+ - 命令返回 `confirmation_required` 且退出码为 `10` 时,不要当普通失败处理;先向用户确认风险和关键参数,再追加 `--confirm` 重试。
27
+ - 上传本地附件时,使用 `mt-os-cli tool upload <filePath>`,拿到真实文件地址后再用于后续工具。
28
+ - 结果为空、权限不足、同名歧义时,要明确告诉用户当前状态。
29
+ - 没有出现在 `mt-os-cli tool list`、`mt-os-cli schema` 或 MCP 工具列表里的能力,按暂未开放处理。
@@ -0,0 +1,10 @@
1
+ # Agent Skills Entry
2
+
3
+ 当用户在 Claude Code 中通过当前 CLI 处理 MTOS 业务数据时:
4
+
5
+ - 先查看 `~/.claude/skills/mt-os/SKILL.md`
6
+ - 首次安装或怀疑本机技能说明已更新时,先执行 `mt-os-cli skills update --source bundled claude`
7
+ - 优先使用已开放的 MCP tools,不要自行拼 REST 接口
8
+ - 如果 MCP 工具不可用,但本机已经执行过 `mt-os-cli auth login`,可以用 `mt-os-cli auth check`、`mt-os-cli schema`、`mt-os-cli tool list/get/call/upload` 做 HTTP 直调烟测
9
+ - 需要代用户登录时,用 `mt-os-cli auth login --no-wait --json` 发起授权,原样转发 `verification_url`,再用 `mt-os-cli auth login --device-code <device_code>` 等待结果
10
+ - token 过期时,先用 `mt-os-cli auth refresh` 刷新本机登录态;需要更新 Claude MCP Bearer 时再执行 `mt-os-cli mcp install claude`