@easbot/codebase 0.1.11

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 houjallen
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.en.md ADDED
@@ -0,0 +1,187 @@
1
+ # @easbot/codebase
2
+
3
+ Code Knowledge Graph SDK - A code indexing and querying system based on the Property Graph model
4
+
5
+ ## Features
6
+
7
+ - **Property Graph Model**: Store code entities and their relationships using nodes and edges
8
+ - **Multi-language Support**: TypeScript, JavaScript, Python, Rust, Go, C/C++, C#, Java, Scala, Ruby, PHP, Zig
9
+ - **Hybrid Search**: FTS full-text search + structured queries
10
+ - **Incremental Updates**: Smart incremental indexing based on file content hashes
11
+ - **Tree-sitter Parsing**: High-performance AST parsing
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add @easbot/codebase
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```typescript
22
+ import { createCodebase } from '@easbot/codebase';
23
+
24
+ // Create graph instance
25
+ const graph = await createCodebase({
26
+ workspaceDir: '/path/to/your/project',
27
+ });
28
+
29
+ // Index project
30
+ const result = await graph.indexDirectory();
31
+ console.log(`Indexed: ${result.filesProcessed} files, ${result.nodesCreated} nodes`);
32
+
33
+ // Search code
34
+ const results = await graph.search('UserService');
35
+ for (const r of results) {
36
+ console.log(`${r.name} (${r.astType}) - ${r.filePath}:${r.startLine}`);
37
+ }
38
+
39
+ // Query nodes
40
+ const classes = await graph.queryNodes({ astType: 'class_declaration' });
41
+
42
+ // Query call graph
43
+ const callGraph = await graph.queryCallGraph('ts:src/service.ts:function_declaration:UserService');
44
+
45
+ // Close graph
46
+ await graph.close();
47
+ ```
48
+
49
+ ## API Documentation
50
+
51
+ ### CodeKnowledgeGraph
52
+
53
+ Main class providing complete code knowledge graph functionality.
54
+
55
+ #### Constructor Options
56
+
57
+ ```typescript
58
+ interface CodeKnowledgeGraphConfig {
59
+ workspaceDir: string; // Workspace directory
60
+ database?: {
61
+ path: string; // Database path
62
+ walMode?: boolean; // WAL mode
63
+ };
64
+ parser?: {
65
+ languages?: Language[]; // Supported languages
66
+ lazyLoad?: boolean; // Lazy loading
67
+ };
68
+ indexer?: {
69
+ batchSize: number; // Batch size
70
+ ignorePatterns: string[]; // Ignore patterns
71
+ incremental: boolean; // Incremental updates
72
+ };
73
+ }
74
+ ```
75
+
76
+ #### Main Methods
77
+
78
+ | Method | Description |
79
+ |--------|-------------|
80
+ | `initialize()` | Initialize graph |
81
+ | `indexFile(path)` | Index single file |
82
+ | `indexDirectory(dir?)` | Index directory |
83
+ | `sync()` | Incremental sync |
84
+ | `search(query, options?)` | Hybrid search |
85
+ | `queryNodes(filter)` | Query nodes |
86
+ | `queryEdges(filter)` | Query edges |
87
+ | `queryNeighbors(nodeId, options?)` | Query neighbors |
88
+ | `queryCallGraph(nodeId, depth?)` | Query call graph |
89
+ | `queryInheritance(nodeId)` | Query inheritance |
90
+ | `getStatus()` | Get status |
91
+ | `healthCheck()` | Health check |
92
+ | `close()` | Close graph |
93
+
94
+ ### Search Options
95
+
96
+ ```typescript
97
+ interface SearchOptions {
98
+ maxResults?: number; // Max results
99
+ minScore?: number; // Min score
100
+ language?: Language; // Language filter
101
+ filePath?: string; // File path filter
102
+ astType?: string; // AST type filter
103
+ enableFts?: boolean; // Enable FTS
104
+ ftsWeight?: number; // FTS weight
105
+ }
106
+ ```
107
+
108
+ ## Data Model
109
+
110
+ ### Node
111
+
112
+ | Field | Type | Description |
113
+ |-------|------|-------------|
114
+ | id | string | Unique identifier |
115
+ | name | string | Name |
116
+ | ast_type | string | AST type |
117
+ | language | string | Language |
118
+ | file_path | string | File path |
119
+ | start_line | number | Start line |
120
+ | start_col | number | Start column |
121
+ | end_line | number | End line |
122
+ | end_col | number | End column |
123
+ | text | string | Code text |
124
+
125
+ ### Edge
126
+
127
+ | Field | Type | Description |
128
+ |-------|------|-------------|
129
+ | id | string | Unique identifier |
130
+ | source | string | Source node ID |
131
+ | target | string | Target node ID |
132
+ | relation | string | Relation type |
133
+
134
+ ### Relation Types
135
+
136
+ | Relation | Description |
137
+ |----------|-------------|
138
+ | CONTAINS | Parent-child AST relationship |
139
+ | CALLS | Function call relationship |
140
+ | INHERITS_FROM | Class inheritance |
141
+ | IMPLEMENTS | Interface implementation |
142
+ | IMPORTS | Module import |
143
+ | REFERENCES | Variable/identifier reference |
144
+
145
+ ## Architecture
146
+
147
+ ```
148
+ src/
149
+ ├── types.ts # Type definitions
150
+ ├── errors.ts # Error classes
151
+ ├── index.ts # Entry file
152
+ ├── code-knowledge-graph.ts # Main class
153
+ ├── database/
154
+ │ └── database-manager.ts # Database management
155
+ ├── parser/
156
+ │ └── parser-manager.ts # Parser management
157
+ ├── extractor/
158
+ │ ├── node-extractor.ts # Node extraction
159
+ │ └── edge-extractor.ts # Edge extraction
160
+ ├── indexer/
161
+ │ └── indexer.ts # Indexer
162
+ └── query/
163
+ └── query-interface.ts # Query interface
164
+ ```
165
+
166
+ ## Development
167
+
168
+ ```bash
169
+ # Install dependencies
170
+ pnpm install
171
+
172
+ # Build
173
+ pnpm build
174
+
175
+ # Test
176
+ pnpm test
177
+
178
+ # Type check
179
+ pnpm type-check
180
+
181
+ # Lint
182
+ pnpm lint
183
+ ```
184
+
185
+ ## License
186
+
187
+ MIT
package/README.md ADDED
@@ -0,0 +1,187 @@
1
+ # @easbot/codebase
2
+
3
+ 代码知识图谱 SDK - 基于 Property Graph 模型的代码索引与查询系统
4
+
5
+ ## 特性
6
+
7
+ - **Property Graph 模型**: 使用节点和边存储代码实体及其关系
8
+ - **多语言支持**: TypeScript、JavaScript、Python、Rust、Go、C/C++、C#、Java、Scala、Ruby、PHP、Zig
9
+ - **混合搜索**: FTS 全文搜索 + 结构化查询
10
+ - **增量更新**: 基于文件内容哈希的智能增量索引
11
+ - **Tree-sitter 解析**: 高性能 AST 解析
12
+
13
+ ## 安装
14
+
15
+ ```bash
16
+ pnpm add @easbot/codebase
17
+ ```
18
+
19
+ ## 快速开始
20
+
21
+ ```typescript
22
+ import { createCodebase } from '@easbot/codebase';
23
+
24
+ // 创建图谱实例
25
+ const graph = await createCodebase({
26
+ workspaceDir: '/path/to/your/project',
27
+ });
28
+
29
+ // 索引项目
30
+ const result = await graph.indexDirectory();
31
+ console.log(`索引完成: ${result.filesProcessed} 文件, ${result.nodesCreated} 节点`);
32
+
33
+ // 搜索代码
34
+ const results = await graph.search('UserService');
35
+ for (const r of results) {
36
+ console.log(`${r.name} (${r.astType}) - ${r.filePath}:${r.startLine}`);
37
+ }
38
+
39
+ // 查询节点
40
+ const classes = await graph.queryNodes({ astType: 'class_declaration' });
41
+
42
+ // 查询调用图
43
+ const callGraph = await graph.queryCallGraph('ts:src/service.ts:function_declaration:UserService');
44
+
45
+ // 关闭图谱
46
+ await graph.close();
47
+ ```
48
+
49
+ ## API 文档
50
+
51
+ ### CodeKnowledgeGraph
52
+
53
+ 主类,提供完整的代码知识图谱功能。
54
+
55
+ #### 构造选项
56
+
57
+ ```typescript
58
+ interface CodeKnowledgeGraphConfig {
59
+ workspaceDir: string; // 工作区目录
60
+ database?: {
61
+ path: string; // 数据库路径
62
+ walMode?: boolean; // WAL 模式
63
+ };
64
+ parser?: {
65
+ languages?: Language[]; // 支持的语言
66
+ lazyLoad?: boolean; // 延迟加载
67
+ };
68
+ indexer?: {
69
+ batchSize: number; // 批处理大小
70
+ ignorePatterns: string[]; // 忽略模式
71
+ incremental: boolean; // 增量更新
72
+ };
73
+ }
74
+ ```
75
+
76
+ #### 主要方法
77
+
78
+ | 方法 | 说明 |
79
+ |------|------|
80
+ | `initialize()` | 初始化图谱 |
81
+ | `indexFile(path)` | 索引单个文件 |
82
+ | `indexDirectory(dir?)` | 索引目录 |
83
+ | `sync()` | 增量同步 |
84
+ | `search(query, options?)` | 混合搜索 |
85
+ | `queryNodes(filter)` | 查询节点 |
86
+ | `queryEdges(filter)` | 查询边 |
87
+ | `queryNeighbors(nodeId, options?)` | 查询邻居 |
88
+ | `queryCallGraph(nodeId, depth?)` | 查询调用图 |
89
+ | `queryInheritance(nodeId)` | 查询继承关系 |
90
+ | `getStatus()` | 获取状态 |
91
+ | `healthCheck()` | 健康检查 |
92
+ | `close()` | 关闭图谱 |
93
+
94
+ ### 搜索选项
95
+
96
+ ```typescript
97
+ interface SearchOptions {
98
+ maxResults?: number; // 最大结果数
99
+ minScore?: number; // 最小分数
100
+ language?: Language; // 语言过滤
101
+ filePath?: string; // 文件路径过滤
102
+ astType?: string; // AST 类型过滤
103
+ enableFts?: boolean; // 启用 FTS
104
+ ftsWeight?: number; // FTS 权重
105
+ }
106
+ ```
107
+
108
+ ## 数据模型
109
+
110
+ ### 节点 (Node)
111
+
112
+ | 字段 | 类型 | 说明 |
113
+ |------|------|------|
114
+ | id | string | 唯一标识 |
115
+ | name | string | 名称 |
116
+ | ast_type | string | AST 类型 |
117
+ | language | string | 语言 |
118
+ | file_path | string | 文件路径 |
119
+ | start_line | number | 起始行 |
120
+ | start_col | number | 起始列 |
121
+ | end_line | number | 结束行 |
122
+ | end_col | number | 结束列 |
123
+ | text | string | 代码文本 |
124
+
125
+ ### 边 (Edge)
126
+
127
+ | 字段 | 类型 | 说明 |
128
+ |------|------|------|
129
+ | id | string | 唯一标识 |
130
+ | source | string | 源节点 ID |
131
+ | target | string | 目标节点 ID |
132
+ | relation | string | 关系类型 |
133
+
134
+ ### 关系类型
135
+
136
+ | 关系 | 说明 |
137
+ |------|------|
138
+ | CONTAINS | 包含关系(类包含方法) |
139
+ | CALLS | 调用关系(函数调用) |
140
+ | INHERITS_FROM | 继承关系 |
141
+ | IMPLEMENTS | 实现接口 |
142
+ | IMPORTS | 导入模块 |
143
+ | REFERENCES | 引用关系 |
144
+
145
+ ## 架构
146
+
147
+ ```
148
+ src/
149
+ ├── types.ts # 类型定义
150
+ ├── errors.ts # 错误类
151
+ ├── index.ts # 入口文件
152
+ ├── code-knowledge-graph.ts # 主类
153
+ ├── database/
154
+ │ └── database-manager.ts # 数据库管理
155
+ ├── parser/
156
+ │ └── parser-manager.ts # 解析器管理
157
+ ├── extractor/
158
+ │ ├── node-extractor.ts # 节点提取
159
+ │ └── edge-extractor.ts # 边提取
160
+ ├── indexer/
161
+ │ └── indexer.ts # 索引器
162
+ └── query/
163
+ └── query-interface.ts # 查询接口
164
+ ```
165
+
166
+ ## 开发
167
+
168
+ ```bash
169
+ # 安装依赖
170
+ pnpm install
171
+
172
+ # 构建
173
+ pnpm build
174
+
175
+ # 测试
176
+ pnpm test
177
+
178
+ # 类型检查
179
+ pnpm type-check
180
+
181
+ # 代码检查
182
+ pnpm lint
183
+ ```
184
+
185
+ ## 许可证
186
+
187
+ MIT