ai-xray 0.0.1
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/PRD.md +372 -0
- package/README.md +10 -0
- package/package.json +18 -0
package/PRD.md
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
# ai-xray: X-Ray Vision for AI Coding Agents (PRD)
|
|
2
|
+
|
|
3
|
+
> **版本:** v1.0 Revised
|
|
4
|
+
> **日期:** 2026-03-06
|
|
5
|
+
> **一句话定位:** Give your AI coding agent x-ray vision into any codebase.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. 产品愿景
|
|
10
|
+
|
|
11
|
+
当 AI Agent 接手一个陌生项目时,它面对的是一间漆黑的房间——不知道技术栈、不知道目录结构、不知道怎么跑测试。
|
|
12
|
+
**`ai-xray` 就是那束穿透黑暗的 X 光。** 一条命令,瞬间看穿项目的骨骼结构。
|
|
13
|
+
|
|
14
|
+
- 不是 AI 助手(不帮你写代码)
|
|
15
|
+
- 不是 DevTools(不面向人类)
|
|
16
|
+
- 是 **AI 助手的眼睛**——专为 LLM 设计的、结构化的、Token 友好的本地环境探测器
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 2. 核心设计原则
|
|
21
|
+
|
|
22
|
+
### 2.1 Machine-First 协议
|
|
23
|
+
|
|
24
|
+
| 规则 | 含义 |
|
|
25
|
+
|---|---|
|
|
26
|
+
| **Pure JSON stdout** | 成功时 stdout 只包含一个合法 JSON 对象,无任何其他字符 |
|
|
27
|
+
| **Structured stderr** | 失败时 stderr 输出 `{"error": "...", "code": "..."}` + 非零 Exit Code |
|
|
28
|
+
| **Zero interactivity** | 绝不等待用户输入。所有选项必须通过参数传入 |
|
|
29
|
+
| **No ANSI escapes** | 输出中不含颜色码、进度条、emoji |
|
|
30
|
+
|
|
31
|
+
### 2.2 全局 Token 预算 `--budget`
|
|
32
|
+
|
|
33
|
+
**核心差异化特性。** 所有产生大量输出的命令都接受 `--budget <number>` 参数(近似 Token 数)。超出时自动截断并附加 `"truncated": true` 和下一步操作提示。
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 3. 技术栈
|
|
38
|
+
|
|
39
|
+
| 选型 | 选择 | 理由 |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| Language | TypeScript | 强类型保证 JSON Schema 严谨 |
|
|
42
|
+
| CLI Parsing | 手写 `process.argv` | 零依赖,启动极速 |
|
|
43
|
+
| Build | `tsup` → 单文件 `dist/cli.js` | 最小安装体积 |
|
|
44
|
+
| Runtime | Node.js ≥ 18 | 原生 `node:fs`, `node:child_process` |
|
|
45
|
+
| **运行时依赖** | **零** | 打包后完全自包含 |
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 4. 核心命令集
|
|
50
|
+
|
|
51
|
+
### 命令速查表
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
ai-xray scout [--budget=N] 一键全局侦察(env+tree+readme+rules+diff)
|
|
55
|
+
ai-xray env 项目画像
|
|
56
|
+
ai-xray tree [dir] [--depth=N] [--budget=N] 目录结构透视
|
|
57
|
+
ai-xray read <file...> [--lines=N-M] [--keys=a,b] [--budget=N] 精准文件读取
|
|
58
|
+
ai-xray diff [--full] [--file=path] Git 变更摘要
|
|
59
|
+
ai-xray init [--format=cursorrules|claude|agents] 注入/生成 AI rules 文件
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
通用参数:
|
|
63
|
+
- `--budget=<tokens>` 限制输出的近似 Token 数
|
|
64
|
+
- `--pretty` 仅供人类调试时使用
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### 4.1 ⭐ `ai-xray scout` — 一键全局侦察
|
|
69
|
+
|
|
70
|
+
**这是 README 里第一个展示的命令,也是使用频率最高的命令。**
|
|
71
|
+
|
|
72
|
+
**场景:** AI 刚 clone 了一个陌生项目(尤其是僵尸项目狩猎场景),需要一次性获取全部关键上下文。
|
|
73
|
+
|
|
74
|
+
**内置逻辑(用户不需要写条件,工具自动判断):**
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
1. 执行 env (总是)
|
|
78
|
+
2. 执行 tree --depth=2 (总是)
|
|
79
|
+
3. IF README.md 存在 THEN 读取前 60 行 (常见)
|
|
80
|
+
4. IF CLAUDE.md / .cursorrules / AGENTS.md 存在
|
|
81
|
+
THEN 读取其内容 (这些是 AI 约定文件,极重要)
|
|
82
|
+
5. IF 是 git 仓库 THEN 输出 diff stat (常见)
|
|
83
|
+
6. IF package.json 有 workspaces 字段
|
|
84
|
+
THEN 列出所有 workspace 包名和路径 (monorepo 场景)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Output:**
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"env": {
|
|
91
|
+
"packageManager": { "name": "pnpm", "version": "9.1.0" },
|
|
92
|
+
"node": { "version": "20.11.0", "engines": ">=18" },
|
|
93
|
+
"frameworks": ["next", "tailwindcss", "prisma"],
|
|
94
|
+
"scripts": { "dev": "next dev", "build": "next build", "test": "vitest" },
|
|
95
|
+
"testFramework": {
|
|
96
|
+
"name": "vitest",
|
|
97
|
+
"runCommand": "npx vitest run --reporter=json",
|
|
98
|
+
"parseHint": "Look for testResults[].assertionResults[].failureMessages"
|
|
99
|
+
},
|
|
100
|
+
"lintFramework": {
|
|
101
|
+
"name": "eslint",
|
|
102
|
+
"runCommand": "npx eslint . --format=json"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"tree": {
|
|
106
|
+
"src/": {
|
|
107
|
+
"components/": { "_files": ["Button.tsx", "Modal.tsx"], "_more": 9 },
|
|
108
|
+
"pages/": { "index.tsx": {}, "auth/": { "login.tsx": {} } },
|
|
109
|
+
"lib/": { "_files": ["db.ts", "auth.ts", "utils.ts"] }
|
|
110
|
+
},
|
|
111
|
+
"package.json": {},
|
|
112
|
+
"README.md": {}
|
|
113
|
+
},
|
|
114
|
+
"readme": "# My Project\nA Next.js application for...\n...(truncated at 60 lines)",
|
|
115
|
+
"agentRules": null,
|
|
116
|
+
"diff": {
|
|
117
|
+
"branch": "main",
|
|
118
|
+
"ahead": 0,
|
|
119
|
+
"behind": 2,
|
|
120
|
+
"staged": [],
|
|
121
|
+
"unstaged": [],
|
|
122
|
+
"untracked": []
|
|
123
|
+
},
|
|
124
|
+
"workspaces": null,
|
|
125
|
+
"_meta": {
|
|
126
|
+
"tokensEstimate": 1850,
|
|
127
|
+
"budget": 3000,
|
|
128
|
+
"truncated": false
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**价值:** 将 AI 接手陌生项目时的 5 轮工具调用压缩为 1 轮。在僵尸项目狩猎场景下,"每个项目 2 小时" → "每个项目 30 分钟"。
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### 4.2 `ai-xray env` — 项目画像
|
|
138
|
+
|
|
139
|
+
**场景:** 只需要技术栈信息,不需要目录结构。
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
ai-xray env
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"packageManager": { "name": "pnpm", "version": "9.1.0" },
|
|
148
|
+
"node": { "version": "20.11.0", "engines": ">=18" },
|
|
149
|
+
"workspaces": ["packages/*"],
|
|
150
|
+
"frameworks": ["next", "tailwindcss", "prisma"],
|
|
151
|
+
"scripts": {
|
|
152
|
+
"dev": "next dev",
|
|
153
|
+
"build": "next build",
|
|
154
|
+
"test": "vitest",
|
|
155
|
+
"lint": "eslint ."
|
|
156
|
+
},
|
|
157
|
+
"testFramework": {
|
|
158
|
+
"name": "vitest",
|
|
159
|
+
"runCommand": "npx vitest run --reporter=json",
|
|
160
|
+
"parseHint": "Look for testResults[].assertionResults[].failureMessages"
|
|
161
|
+
},
|
|
162
|
+
"lintFramework": {
|
|
163
|
+
"name": "eslint",
|
|
164
|
+
"runCommand": "npx eslint . --format=json",
|
|
165
|
+
"parseHint": "Each element has filePath and messages[]"
|
|
166
|
+
},
|
|
167
|
+
"git": {
|
|
168
|
+
"branch": "main",
|
|
169
|
+
"hasUncommitted": true,
|
|
170
|
+
"remoteUrl": "https://github.com/10iii/ai-xray.git"
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### 4.3 `ai-xray tree` — 结构透视
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
ai-xray tree # 整个项目,默认 depth=3
|
|
181
|
+
ai-xray tree src/ # 只看 src
|
|
182
|
+
ai-xray tree --depth=1 # 只看第一层
|
|
183
|
+
ai-xray tree --budget=300 # Token 预算限制
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
188
|
+
"root": ".",
|
|
189
|
+
"depth": 3,
|
|
190
|
+
"structure": {
|
|
191
|
+
"src/": {
|
|
192
|
+
"components/": {
|
|
193
|
+
"_files": ["Button.tsx", "Modal.tsx", "Header.tsx"],
|
|
194
|
+
"_more": 9
|
|
195
|
+
},
|
|
196
|
+
"pages/": {
|
|
197
|
+
"index.tsx": {},
|
|
198
|
+
"auth/": { "login.tsx": {}, "register.tsx": {} }
|
|
199
|
+
},
|
|
200
|
+
"lib/": {
|
|
201
|
+
"_files": ["db.ts", "auth.ts", "utils.ts"]
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
"tests/": { "_more": 8 },
|
|
205
|
+
"package.json": {},
|
|
206
|
+
"tsconfig.json": {}
|
|
207
|
+
},
|
|
208
|
+
"stats": {
|
|
209
|
+
"totalFiles": 47,
|
|
210
|
+
"displayed": 16,
|
|
211
|
+
"ignored": ["node_modules", "dist", ".next", ".git"]
|
|
212
|
+
},
|
|
213
|
+
"truncated": false
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**设计要点:**
|
|
218
|
+
- `_files` 数组:目录下只有文件时用扁平列表,极度节省 Token
|
|
219
|
+
- `_more: 9`:告诉 AI "还有 9 个文件被省略了",可据此决定是否深入
|
|
220
|
+
- `ignored`:明确告诉 AI 哪些目录被跳过,消除困惑
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
### 4.4 `ai-xray read` — 精准文件读取
|
|
225
|
+
|
|
226
|
+
支持四种模式:
|
|
227
|
+
|
|
228
|
+
**A. 读取整个文件**
|
|
229
|
+
```bash
|
|
230
|
+
ai-xray read src/auth.ts
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**B. 读取特定行范围**(AI 通常从报错信息中知道行号)
|
|
234
|
+
```bash
|
|
235
|
+
ai-xray read src/auth.ts --lines=40-65
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**C. 从 JSON 提取特定键**
|
|
239
|
+
```bash
|
|
240
|
+
ai-xray read package.json --keys=scripts,dependencies
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
**D. 批量读取多文件**(一次调用替代多次,减少 Agent 轮次)
|
|
244
|
+
```bash
|
|
245
|
+
ai-xray read src/auth.ts src/db.ts src/utils.ts --budget=2000
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Output 示例(批量模式):
|
|
249
|
+
```json
|
|
250
|
+
{
|
|
251
|
+
"files": [
|
|
252
|
+
{ "file": "src/auth.ts", "lines": 142, "content": "..." },
|
|
253
|
+
{ "file": "src/db.ts", "lines": 58, "content": "..." },
|
|
254
|
+
{ "file": "src/utils.ts", "lines": 31, "content": "...", "truncated": true }
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
### 4.5 `ai-xray diff` — 变更摘要
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
ai-xray diff # 默认:stat 模式
|
|
265
|
+
ai-xray diff --full # 含完整 diff 内容
|
|
266
|
+
ai-xray diff --file=src/auth.ts # 只看某个文件
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
**stat 模式输出:**
|
|
270
|
+
```json
|
|
271
|
+
{
|
|
272
|
+
"branch": "feature/auth",
|
|
273
|
+
"ahead": 2,
|
|
274
|
+
"behind": 0,
|
|
275
|
+
"staged": [
|
|
276
|
+
{ "file": "src/db.ts", "status": "M", "insertions": 5, "deletions": 1 }
|
|
277
|
+
],
|
|
278
|
+
"unstaged": [
|
|
279
|
+
{ "file": "src/auth.ts", "status": "M", "insertions": 15, "deletions": 2 }
|
|
280
|
+
],
|
|
281
|
+
"untracked": ["src/components/LoginForm.tsx"]
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
**`--full` 输出额外附带 `hunks` 字段包含实际变更内容。**
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
### 4.6 `ai-xray init` — 智能注入 AI Rules
|
|
290
|
+
|
|
291
|
+
**场景:** 让项目"AI-Ready"。在项目的 AI 规则文件中注入 ai-xray 的使用指南,使得后续任何 AI Agent 打开该项目时都会自动使用 ai-xray。
|
|
292
|
+
|
|
293
|
+
**核心行为(零参数智能默认):**
|
|
294
|
+
|
|
295
|
+
```
|
|
296
|
+
1. 按优先级搜索已有的 AI 规则文件:
|
|
297
|
+
AGENTS.md > CLAUDE.md > .cursorrules > .github/copilot-instructions.md
|
|
298
|
+
|
|
299
|
+
2. IF 找到了已有文件
|
|
300
|
+
THEN 将 ai-xray 使用指南注入到该文件末尾
|
|
301
|
+
(附加一个 <!-- ai-xray --> 标记,防止重复注入)
|
|
302
|
+
|
|
303
|
+
3. IF 没有找到任何已有文件
|
|
304
|
+
THEN 创建 AGENTS.md(最通用的格式)
|
|
305
|
+
|
|
306
|
+
4. 输出操作摘要到 stdout(JSON 格式)
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**注入的内容模板(自动根据当前项目技术栈定制):**
|
|
310
|
+
|
|
311
|
+
```markdown
|
|
312
|
+
<!-- ai-xray:start -->
|
|
313
|
+
## Project Context Protocol (powered by ai-xray)
|
|
314
|
+
|
|
315
|
+
Before modifying this project, gather context by running:
|
|
316
|
+
npx ai-xray scout --budget=2000
|
|
317
|
+
|
|
318
|
+
When debugging a failing test:
|
|
319
|
+
npx ai-xray read <file> --lines=<error-range>
|
|
320
|
+
|
|
321
|
+
Before committing changes:
|
|
322
|
+
npx ai-xray diff --full
|
|
323
|
+
<!-- ai-xray:end -->
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**可选参数:**
|
|
327
|
+
```bash
|
|
328
|
+
ai-xray init # 智能默认:找到就注入,没有就创建 AGENTS.md
|
|
329
|
+
ai-xray init --format=claude # 强制创建/注入 CLAUDE.md
|
|
330
|
+
ai-xray init --format=cursorrules # 强制创建/注入 .cursorrules
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
**Output:**
|
|
334
|
+
```json
|
|
335
|
+
{
|
|
336
|
+
"action": "injected",
|
|
337
|
+
"target": "AGENTS.md",
|
|
338
|
+
"linesAdded": 12,
|
|
339
|
+
"marker": "ai-xray:start"
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
**战略价值:** 这是 ai-xray 的**自我传播引擎**。用户运行 `ai-xray init` → 规则文件被提交到 Git → 其他开发者/AI 打开项目时读取规则 → 它们也开始用 `npx ai-xray` → 安装量自然增长。
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## 5. 未来考量 (v2.0+)
|
|
348
|
+
|
|
349
|
+
| 特性 | 描述 |
|
|
350
|
+
|---|---|
|
|
351
|
+
| **MCP 兼容** | 将 ai-xray 的命令暴露为 MCP Resources/Tools,使 Claude Desktop 等可原生调用 |
|
|
352
|
+
| **AST 感知 read** | `ai-xray read src/auth.ts --symbol=login` 只返回某个函数体 |
|
|
353
|
+
| **`search`** | 类 grep 但输出结构化 JSON(文件名 + 行号 + 上下文) |
|
|
354
|
+
| **多语言** | 支持 Python (pip/poetry)、Go、Rust (cargo) 项目 |
|
|
355
|
+
| **`run-test`** | 真正执行测试并提取精炼的失败摘要 |
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## 6. v1.0 路线图
|
|
360
|
+
|
|
361
|
+
| 里程碑 | 内容 |
|
|
362
|
+
|---|---|
|
|
363
|
+
| **M1** | `env` + `tree` + `scout` (core engine) |
|
|
364
|
+
| **M2** | `read` + `diff` |
|
|
365
|
+
| **M3** | `init` (self-propagation engine) |
|
|
366
|
+
| **M4** | `--budget` Token 预算系统 |
|
|
367
|
+
| **M5** | tsup 构建 → `ai-xray@1.0.0` 发布 |
|
|
368
|
+
|
|
369
|
+
M5 后进入**自我验证阶段**:用 ai-xray 自己去猎杀僵尸项目,根据实战体验反向优化 JSON 结构。
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
*PRD v1.0 Revised — 2026-03-06*
|
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# ai-xray
|
|
2
|
+
|
|
3
|
+
> Give your AI coding agent x-ray vision into any codebase.
|
|
4
|
+
|
|
5
|
+
This package is currently a placeholder for an upcoming CLI tool designed specifically for LLMs and AI Agents.
|
|
6
|
+
It aims to provide structured, token-efficient, and deterministic local environment context (env, tree, read, diff, scout, init) for AI tools like aider, Cursor, and Cline.
|
|
7
|
+
|
|
8
|
+
## Status
|
|
9
|
+
|
|
10
|
+
**Work in progress.** Stay tuned.
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai-xray",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Give your AI coding agent x-ray vision into any codebase.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"ai",
|
|
11
|
+
"llm",
|
|
12
|
+
"agent",
|
|
13
|
+
"context",
|
|
14
|
+
"cli"
|
|
15
|
+
],
|
|
16
|
+
"author": "10iii",
|
|
17
|
+
"license": "MIT"
|
|
18
|
+
}
|