kly 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/README.md +150 -0
- package/README.zh-CN.md +224 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +699 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/enrich-BHaZ2daX.mjs +3000 -0
- package/dist/enrich-BHaZ2daX.mjs.map +1 -0
- package/dist/index.d.mts +307 -0
- package/dist/index.mjs +2 -0
- package/package.json +82 -0
package/README.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# kly
|
|
2
|
+
|
|
3
|
+
Code repository file-level indexing tool for AI agents.
|
|
4
|
+
|
|
5
|
+
kly scans your codebase, extracts structural information via tree-sitter AST, and uses LLM to generate human-readable metadata for every file. The result is a structured index that lets agents find the right file with minimal tokens.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Tree-sitter AST parsing** — Extract imports, exports, and symbols from TypeScript, JavaScript, and Swift
|
|
10
|
+
- **Multi-provider LLM** — Generate metadata via OpenRouter, Anthropic, OpenAI, Google, Mistral, Groq, and more
|
|
11
|
+
- **Git-aware incremental builds** — Per-branch SQLite databases, only re-indexes changed files
|
|
12
|
+
- **FTS5 full-text search** — BM25 ranking with optional LLM rerank
|
|
13
|
+
- **Dependency graph** — File-level dependency tracking with reverse dependency queries
|
|
14
|
+
- **Error stack enrichment** — Enrich error stack frames with file context, dependencies, and git history
|
|
15
|
+
- **Agent-first CLI** — JSON output by default, `--pretty` for humans, stdin/pipe support
|
|
16
|
+
- **Post-commit hook** — Automatic indexing after every commit
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -g kly
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Initialize (non-interactive with flags, or interactive without)
|
|
28
|
+
kly init --provider openrouter --api-key sk-or-xxx
|
|
29
|
+
|
|
30
|
+
# Build the index
|
|
31
|
+
kly build
|
|
32
|
+
|
|
33
|
+
# Search files (JSON output by default)
|
|
34
|
+
kly query "authentication middleware"
|
|
35
|
+
|
|
36
|
+
# Human-readable output
|
|
37
|
+
kly query "authentication middleware" --pretty
|
|
38
|
+
|
|
39
|
+
# Show file details
|
|
40
|
+
kly show src/auth.ts
|
|
41
|
+
|
|
42
|
+
# Who imports this file?
|
|
43
|
+
kly dependents src/database.ts
|
|
44
|
+
|
|
45
|
+
# Recent git changes
|
|
46
|
+
kly history src/auth.ts
|
|
47
|
+
|
|
48
|
+
# Enrich error stack with code context
|
|
49
|
+
echo '[{"file":"src/auth.ts","line":42}]' | kly enrich
|
|
50
|
+
|
|
51
|
+
# Dependency graph
|
|
52
|
+
kly graph --focus src/auth.ts --depth 3
|
|
53
|
+
|
|
54
|
+
# Repository overview
|
|
55
|
+
kly overview
|
|
56
|
+
|
|
57
|
+
# Install post-commit hook
|
|
58
|
+
kly hook install
|
|
59
|
+
|
|
60
|
+
# Clean up databases for deleted branches
|
|
61
|
+
kly gc
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Commands
|
|
65
|
+
|
|
66
|
+
| Command | Description |
|
|
67
|
+
| ----------------------------- | -------------------------------------------------------------------- |
|
|
68
|
+
| `kly init` | Initialize kly (supports `--provider`, `--api-key`, `--model` flags) |
|
|
69
|
+
| `kly build` | Build or update the index (`--full` for rebuild, `--quiet` for CI) |
|
|
70
|
+
| `kly query <text>` | Search files by natural language (`--rerank`, `--limit`) |
|
|
71
|
+
| `kly show <path>` | Show indexed metadata for a file |
|
|
72
|
+
| `kly overview` | Repository summary with language breakdown |
|
|
73
|
+
| `kly graph` | File dependency graph (`--focus`, `--depth`) |
|
|
74
|
+
| `kly dependents <path>` | Show files that import the given file |
|
|
75
|
+
| `kly history <path>` | Show git modification history (`--limit`) |
|
|
76
|
+
| `kly enrich` | Enrich error stack frames (stdin or `--frames`) |
|
|
77
|
+
| `kly hook install\|uninstall` | Manage post-commit hook |
|
|
78
|
+
| `kly gc` | Remove databases for deleted branches |
|
|
79
|
+
|
|
80
|
+
All read commands support `--pretty` for human-readable output. Default is JSON.
|
|
81
|
+
|
|
82
|
+
## How It Works
|
|
83
|
+
|
|
84
|
+
In a git repository, kly maintains **per-branch SQLite databases** under `.kly/db/`:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
.kly/
|
|
88
|
+
config.yaml # LLM and glob settings
|
|
89
|
+
state.yaml # Tracks last indexed commit per branch
|
|
90
|
+
db/
|
|
91
|
+
main.db # main branch index
|
|
92
|
+
feature--auth.db # feature/auth branch (/ → --)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
After the first full build, subsequent builds use `git diff` to only re-index changed files — making incremental builds near-instant.
|
|
96
|
+
|
|
97
|
+
## Library Usage
|
|
98
|
+
|
|
99
|
+
kly is also a TypeScript library with clean exports:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import {
|
|
103
|
+
openDatabase,
|
|
104
|
+
searchFiles,
|
|
105
|
+
buildDependencyGraph,
|
|
106
|
+
enrichErrorStack,
|
|
107
|
+
getFileHistory,
|
|
108
|
+
buildIndex,
|
|
109
|
+
} from "kly";
|
|
110
|
+
|
|
111
|
+
// Search files
|
|
112
|
+
const db = openDatabase("/path/to/repo");
|
|
113
|
+
const results = searchFiles(db, "authentication", 10);
|
|
114
|
+
|
|
115
|
+
// Enrich error stack
|
|
116
|
+
const enriched = enrichErrorStack(db, "/path/to/repo", [
|
|
117
|
+
{ file: "src/auth.ts", line: 42, function: "validate" },
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
db.close();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Configuration
|
|
124
|
+
|
|
125
|
+
Edit `.kly/config.yaml` to customize:
|
|
126
|
+
|
|
127
|
+
```yaml
|
|
128
|
+
llm:
|
|
129
|
+
provider: openrouter
|
|
130
|
+
model: anthropic/claude-haiku-4.5
|
|
131
|
+
apiKey: sk-or-...
|
|
132
|
+
include:
|
|
133
|
+
- "**/*.ts"
|
|
134
|
+
- "**/*.tsx"
|
|
135
|
+
- "**/*.js"
|
|
136
|
+
- "**/*.jsx"
|
|
137
|
+
- "**/*.swift"
|
|
138
|
+
exclude:
|
|
139
|
+
- "**/node_modules/**"
|
|
140
|
+
- "**/dist/**"
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Documentation
|
|
144
|
+
|
|
145
|
+
- [Technical Documentation](docs/technical.md) ([中文](docs/technical.zh-CN.md)) — Architecture, data flow, core types, module breakdown
|
|
146
|
+
- [Testing Documentation](docs/testing.md) ([中文](docs/testing.zh-CN.md)) — Test strategy, coverage, manual test checklist
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# kly
|
|
2
|
+
|
|
3
|
+
[English](README.md) | **中文**
|
|
4
|
+
|
|
5
|
+
## 一句话介绍
|
|
6
|
+
|
|
7
|
+
kly 帮你的代码仓库建一份「目录」,让 AI Agent 和你自己都能快速找到想要的文件。
|
|
8
|
+
|
|
9
|
+
## 它解决什么问题?
|
|
10
|
+
|
|
11
|
+
一个项目有几百上千个文件,你想问 AI:「帮我改一下登录逻辑」——AI 怎么知道该看哪个文件?
|
|
12
|
+
|
|
13
|
+
传统做法是把所有代码塞给 AI 看,但这样 token 消耗巨大,而且 AI 还是会漏掉东西。
|
|
14
|
+
|
|
15
|
+
kly 的做法是:**先扫一遍你的代码,给每个文件生成一段简短的描述**。AI 拿到的不是几万行代码,而是一份简明的索引——像一本书的目录,直接翻到想看的章节。
|
|
16
|
+
|
|
17
|
+
## 它具体做了什么?
|
|
18
|
+
|
|
19
|
+
### 1. 解析代码结构
|
|
20
|
+
|
|
21
|
+
kly 用 [tree-sitter](https://tree-sitter.github.io/) 解析你的源码,提取出每个文件里有什么:
|
|
22
|
+
|
|
23
|
+
- **导入了什么**(import 哪些模块)
|
|
24
|
+
- **导出了什么**(export 哪些函数/类/变量)
|
|
25
|
+
- **有哪些符号**(函数名、类名、接口名、类型名)
|
|
26
|
+
|
|
27
|
+
支持 TypeScript、JavaScript、Swift 三种语言。
|
|
28
|
+
|
|
29
|
+
### 2. 用 AI 生成文件描述
|
|
30
|
+
|
|
31
|
+
光有代码结构还不够——`src/utils/helpers.ts` 里面到底干嘛的?kly 把代码交给 LLM,让它生成:
|
|
32
|
+
|
|
33
|
+
- **文件名称**(一个简短的人类可读名字,比如「认证中间件」)
|
|
34
|
+
- **文件描述**(一句话说清楚这个文件干什么)
|
|
35
|
+
- **文件摘要**(更详细的功能总结)
|
|
36
|
+
- **符号描述**(每个函数/类是做什么的)
|
|
37
|
+
|
|
38
|
+
支持 OpenRouter、Anthropic、OpenAI、Google、Mistral、Groq 等多家 LLM 服务商。
|
|
39
|
+
|
|
40
|
+
### 3. 存进数据库,支持搜索
|
|
41
|
+
|
|
42
|
+
所有索引信息存在 SQLite 数据库里,带 FTS5 全文搜索。你可以用自然语言搜索:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
kly query "处理用户登录的文件"
|
|
46
|
+
kly query "数据库连接配置"
|
|
47
|
+
kly query "错误处理中间件"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
搜索结果按相关性排序。还可以用 LLM 做二次排序(`--rerank`),结果更精准。
|
|
51
|
+
|
|
52
|
+
### 4. 跟踪文件依赖关系
|
|
53
|
+
|
|
54
|
+
kly 记录了文件之间的 import 关系:
|
|
55
|
+
|
|
56
|
+
- **正向依赖**:这个文件 import 了谁?
|
|
57
|
+
- **反向依赖**:谁 import 了这个文件?
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# 谁依赖了 types.ts?
|
|
61
|
+
kly dependents src/types.ts
|
|
62
|
+
|
|
63
|
+
# 整个依赖图
|
|
64
|
+
kly graph --focus src/auth.ts --depth 3
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
这对分析「改了这个文件会影响哪些模块」非常有用。
|
|
68
|
+
|
|
69
|
+
### 5. 查看文件修改历史
|
|
70
|
+
|
|
71
|
+
kly 可以查询每个文件最近被谁改过:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
kly history src/auth.ts
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
输出类似:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
abc1234 @alice 2026-03-25 fix: handle expired token
|
|
81
|
+
def5678 @bob 2026-03-20 feat: add refresh token
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 6. 错误栈增强(Error Stack Enrichment)
|
|
85
|
+
|
|
86
|
+
这是 kly 最强大的能力之一。当你的应用报错时,错误栈通常只有文件名和行号:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
TypeError: Cannot read property 'content' of undefined
|
|
90
|
+
at renderMessage (src/components/MessageList.tsx:142)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
kly 可以把这个错误栈「增强」——补上完整的代码上下文:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
echo '[{"file":"src/components/MessageList.tsx","line":142}]' | kly enrich
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
输出会告诉你:
|
|
100
|
+
|
|
101
|
+
- 📄 这个文件是做什么的(「聊天消息列表渲染组件」)
|
|
102
|
+
- 🔗 有哪些文件依赖它(影响范围)
|
|
103
|
+
- 📝 它 import 了哪些模块
|
|
104
|
+
- 👤 最近被谁改过(可能是谁引入的 bug)
|
|
105
|
+
|
|
106
|
+
### 7. Git 感知增量构建
|
|
107
|
+
|
|
108
|
+
首次构建需要扫描所有文件(调 LLM),但之后每次只处理变更的文件:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
kly build # 增量构建,只处理 git diff 里变了的文件
|
|
112
|
+
kly build --full # 强制全量重建
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
每个 git 分支有自己独立的数据库,分支之间互不影响。切换分支时,新分支会从 main 分支 fork 一份索引,再增量更新。
|
|
116
|
+
|
|
117
|
+
## 怎么用?
|
|
118
|
+
|
|
119
|
+
### 安装
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm install -g kly
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 初始化
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# 方式一:命令行参数(适合 CI 和 Agent)
|
|
129
|
+
kly init --provider openrouter --api-key sk-or-xxx
|
|
130
|
+
|
|
131
|
+
# 方式二:交互式引导(适合人类)
|
|
132
|
+
kly init
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 构建索引
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
kly build
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 搜索和查询
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# 搜索文件
|
|
145
|
+
kly query "用户认证"
|
|
146
|
+
|
|
147
|
+
# 查看文件详情
|
|
148
|
+
kly show src/auth.ts
|
|
149
|
+
|
|
150
|
+
# 仓库概览
|
|
151
|
+
kly overview
|
|
152
|
+
|
|
153
|
+
# 人类可读的输出(默认是 JSON,给 Agent 读的)
|
|
154
|
+
kly query "用户认证" --pretty
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 自动化
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# 安装 git hook,每次 commit 后自动更新索引
|
|
161
|
+
kly hook install
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 作为 TypeScript 库使用
|
|
165
|
+
|
|
166
|
+
kly 不只是命令行工具,也是一个导出干净的 TypeScript 库,可以直接 import:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { openDatabase, searchFiles, enrichErrorStack, buildIndex } from "kly";
|
|
170
|
+
|
|
171
|
+
const db = openDatabase("/path/to/repo");
|
|
172
|
+
|
|
173
|
+
// 搜索
|
|
174
|
+
const results = searchFiles(db, "authentication", 10);
|
|
175
|
+
|
|
176
|
+
// 错误栈增强
|
|
177
|
+
const enriched = enrichErrorStack(db, "/path/to/repo", [
|
|
178
|
+
{ file: "src/auth.ts", line: 42, function: "validate" },
|
|
179
|
+
]);
|
|
180
|
+
|
|
181
|
+
db.close();
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## 所有命令一览
|
|
185
|
+
|
|
186
|
+
| 命令 | 说明 |
|
|
187
|
+
| ----------------------------- | ------------------------------------------------------------- |
|
|
188
|
+
| `kly init` | 初始化(支持 `--provider`、`--api-key`、`--model` 参数) |
|
|
189
|
+
| `kly build` | 构建或更新索引(`--full` 全量重建,`--quiet` 静默模式) |
|
|
190
|
+
| `kly query <文本>` | 自然语言搜索文件(`--rerank` LLM 重排序,`--limit` 限制数量) |
|
|
191
|
+
| `kly show <路径>` | 查看文件的索引详情 |
|
|
192
|
+
| `kly overview` | 仓库总览(文件数、语言分布) |
|
|
193
|
+
| `kly graph` | 文件依赖图(`--focus` 聚焦,`--depth` 深度) |
|
|
194
|
+
| `kly dependents <路径>` | 查看谁 import 了这个文件 |
|
|
195
|
+
| `kly history <路径>` | 查看文件的 git 修改历史(`--limit` 限制条数) |
|
|
196
|
+
| `kly enrich` | 错误栈增强(通过 stdin 或 `--frames` 传入) |
|
|
197
|
+
| `kly hook install\|uninstall` | 管理 post-commit hook |
|
|
198
|
+
| `kly gc` | 清理已删除分支的数据库 |
|
|
199
|
+
|
|
200
|
+
所有查询命令默认输出 JSON(给 Agent 读),加 `--pretty` 输出人类可读格式。
|
|
201
|
+
|
|
202
|
+
## 配置
|
|
203
|
+
|
|
204
|
+
编辑 `.kly/config.yaml`:
|
|
205
|
+
|
|
206
|
+
```yaml
|
|
207
|
+
llm:
|
|
208
|
+
provider: openrouter
|
|
209
|
+
model: anthropic/claude-haiku-4.5
|
|
210
|
+
apiKey: sk-or-...
|
|
211
|
+
include:
|
|
212
|
+
- "**/*.ts"
|
|
213
|
+
- "**/*.tsx"
|
|
214
|
+
- "**/*.js"
|
|
215
|
+
- "**/*.jsx"
|
|
216
|
+
- "**/*.swift"
|
|
217
|
+
exclude:
|
|
218
|
+
- "**/node_modules/**"
|
|
219
|
+
- "**/dist/**"
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
MIT
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|