@zleap-ai/sag-cli 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sag contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # SAG CLI
2
+
3
+ `@zleap-ai/sag-cli` 是运行中 SAG 实例的命令行客户端与诊断工具。除 Profile、
4
+ 认证、知识状态和检索外,v0.2 还可以验证本机 Docker SAG 的知识库 MCP,并自动
5
+ 接入 Codex 和 Claude Code。
6
+
7
+ ## 安装与运行
8
+
9
+ 需要 Node.js 20.19 或更高版本:
10
+
11
+ ```bash
12
+ npx @zleap-ai/sag-cli version
13
+ npm install --global @zleap-ai/sag-cli
14
+ sag --help
15
+ ```
16
+
17
+ ## 最短使用路径
18
+
19
+ 只验证和接入本机 Docker SAG MCP,不需要从 SAG Web 复制 Token:
20
+
21
+ ```bash
22
+ sag mcp test
23
+ sag agent connect codex
24
+ sag agent connect claude-code
25
+ sag agent status
26
+ ```
27
+
28
+ 需要先安装 Docker CLI,并运行包含 `sag_api.mcp.server` 的 SAG API 容器。
29
+ 接入某一个信源:
30
+
31
+ ```bash
32
+ sag mcp test --source-id <source-id>
33
+ sag agent connect codex --source-id <source-id>
34
+ ```
35
+
36
+ 原有 HTTP API 与知识检索路径:
37
+
38
+ ```bash
39
+ sag profile add local http://localhost:8000
40
+ sag auth login
41
+ sag doctor
42
+ sag source list
43
+ sag document status --source <source-id>
44
+ sag search "查询内容"
45
+ ```
46
+
47
+ `auth login` 会隐藏输入 SAG JWT,验证成功后优先保存到 macOS Keychain、
48
+ Windows Credential Manager 或 Linux Secret Service。无法使用系统凭据存储时,
49
+ Token 只保留在当前进程;自动化环境应使用 `SAG_TOKEN`。
50
+
51
+ ## 命令
52
+
53
+ ```text
54
+ sag version
55
+ sag auth login|status|logout
56
+ sag profile add|list|use|show|remove
57
+ sag doctor
58
+ sag source list|get|status
59
+ sag document list|get|status
60
+ sag search <query>
61
+ sag mcp test
62
+ sag agent list
63
+ sag agent connect <codex|claude-code>
64
+ sag agent status [codex|claude-code]
65
+ sag agent disconnect <codex|claude-code>
66
+ ```
67
+
68
+ 常用示例:
69
+
70
+ ```bash
71
+ sag profile list --json
72
+ sag source get <source-id>
73
+ sag source status [source-id]
74
+ sag document list --source <source-id>
75
+ sag document get <document-id> --source <source-id>
76
+ sag document status [document-id] --source <source-id>
77
+ sag search "MCP 如何接入" --source <source-id> --top-k 5 --strategy multi
78
+ sag mcp test --container sag-api-1 --timeout 15000
79
+ sag agent connect codex --dry-run
80
+ sag agent connect claude-code --name sag-knowledge-local
81
+ sag agent disconnect codex
82
+ ```
83
+
84
+ 全局参数:
85
+
86
+ ```text
87
+ --profile <name> 选择 Profile
88
+ --url <origin> 临时指定 SAG Origin
89
+ --json 输出稳定 JSON
90
+ --quiet 只输出核心值
91
+ --yes 确认安全的本地配置操作
92
+ ```
93
+
94
+ ## 环境变量
95
+
96
+ 配置优先级为:命令行参数 > 环境变量 > 当前 Profile > 本地默认探测。
97
+
98
+ ```bash
99
+ SAG_URL=http://localhost:8000
100
+ SAG_TOKEN=<jwt>
101
+ SAG_PROFILE=local
102
+ ```
103
+
104
+ Profile URL 只保存 `scheme://host[:port]`。CLI 自动为 API 添加 `/api/v1`,
105
+ 不要求用户手工填写接口前缀。
106
+
107
+ ## Agent MCP 接入行为
108
+
109
+ CLI 自动发现 Compose `api` 服务,优先选择项目名为 `sag` 的健康容器,并验证
110
+ 八个 SAG 只读 MCP 工具和 `list_sources` 调用。实际保存到 Agent 的命令是:
111
+
112
+ ```text
113
+ docker exec -i <container> python -m sag_api.mcp.server
114
+ ```
115
+
116
+ 默认 MCP 名称为 `sag-knowledge-<profile>`;没有 Profile 时为
117
+ `sag-knowledge-local`。`--dry-run` 只展示计划,`--yes` 跳过确认但不会跳过
118
+ 冲突和安全检查。
119
+
120
+ SAG CLI 不会把 JWT 写入 Agent 配置。它只删除自己创建且指纹未变化的 MCP
121
+ 条目;检测到同名用户配置或外部修改时会拒绝覆盖或删除。受管状态保存在平台配置
122
+ 目录的 `managed-connections.yaml` 中,权限为 `0600`。
123
+
124
+ ## JSON 契约
125
+
126
+ 成功与失败都包含固定 Schema:
127
+
128
+ ```json
129
+ { "schema": "sag.cli.v1", "ok": true, "data": {} }
130
+ ```
131
+
132
+ ```json
133
+ {
134
+ "schema": "sag.cli.v1",
135
+ "ok": false,
136
+ "error": { "code": "AUTH_REQUIRED", "message": "No SAG token is configured" }
137
+ }
138
+ ```
139
+
140
+ JSON、日志和错误输出不会包含 Token。退出码和错误分类见架构说明:
141
+ [中文](docs/architecture.zh-CN.md) / [English](docs/architecture.md)。
142
+
143
+ ## 开发
144
+
145
+ ```bash
146
+ npm install
147
+ npm run dev -- --help
148
+ npm run check
149
+ ```
150
+
151
+ 本地运行、认证、知识库搜索、断点调试、测试和 Docker MCP 验证见开发指南:
152
+ [中文](docs/development.zh-CN.md) / [English](docs/development.md)。
153
+
154
+ 贡献规则见 [CONTRIBUTING.md](CONTRIBUTING.md)。其他文档:
155
+
156
+ - 发布:[中文](docs/release.zh-CN.md) / [English](docs/release.md)
157
+ - 兼容性:[中文](docs/compatibility.zh-CN.md) /
158
+ [English](docs/compatibility.md)
159
+ - OAuth 与 MCP 授权:[中文](docs/oauth.zh-CN.md) /
160
+ [English](docs/oauth.md)
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }