@webneat/codewiki 0.0.3 → 0.0.6

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 CHANGED
@@ -1,14 +1,20 @@
1
1
  # @webneat/codewiki
2
2
 
3
- Core library for parsing, analyzing, and documenting TypeScript codebases.
3
+ Core library for parsing, analyzing, and documenting TypeScript codebases with dependency tracking and topological ordering.
4
+
5
+ ## Overview
6
+
7
+ `@webneat/codewiki` is a TypeScript codebase analysis engine that builds a comprehensive knowledge graph of your code. It extracts symbols, files, directories, and dependencies, then provides topological ordering to enable AI tools to generate contextual documentation with maximum context for each entity.
4
8
 
5
9
  ## Features
6
10
 
7
- - 🔍 **TypeScript AST Parsing** - Extract elements, imports, and exports
8
- - 📊 **Dependency Analysis** - Build complete dependency graphs
9
- - 🗄️ **SQLite Storage** - Fast, portable database for codebase metadata
10
- - 🤖 **AI-Powered Descriptions** - Generate contextual documentation
11
+ - 🔍 **TypeScript AST Parsing** - Extract symbols, imports, exports, and file structure
12
+ - 📊 **Dependency Analysis** - Build complete dependency graphs between files, symbols, and external packages
13
+ - 🗄️ **SQLite Storage** - Fast, portable database with Drizzle ORM for codebase metadata
14
+ - 📝 **Description Management** - Store and manage contextual documentation with smart ordering
11
15
  - ⚡ **Incremental Updates** - Git-based change detection for fast re-indexing
16
+ - 🎯 **Topological Ordering** - Intelligent entity ordering to enable optimal AI context
17
+ - 🔗 **Relationship Tracking** - Complete import/export relationships and internal symbol links
12
18
 
13
19
  ## Installation
14
20
 
@@ -16,44 +22,187 @@ Core library for parsing, analyzing, and documenting TypeScript codebases.
16
22
  pnpm add @webneat/codewiki
17
23
  ```
18
24
 
19
- ## Usage
25
+ ## Quick Start
20
26
 
21
27
  ```typescript
22
- import { index_project, queries } from '@webneat/codewiki'
28
+ import { create, load } from '@webneat/codewiki'
23
29
 
24
- // Index a TypeScript project
25
- await index_project('/path/to/project', {
30
+ // Create a new wiki instance
31
+ const wiki = await create({
26
32
  db_path: './codewiki.db',
27
- excluded_paths: ['node_modules', 'dist'],
28
- progress_callback: (status) => {
29
- console.log(`${status.phase}: ${status.current}/${status.total}`)
30
- },
33
+ project_path: './my-typescript-project',
34
+ description: 'My awesome TypeScript project'
31
35
  })
32
36
 
33
- // Query the database
34
- const element = await queries.find_element(db, 'MyFunction')
35
- const deps = await queries.element_dependencies(db, element.id)
37
+ // Or load an existing wiki database
38
+ const wiki = await load('./codewiki.db')
39
+
40
+ // Update the wiki with latest changes
41
+ await wiki.update()
42
+
43
+ // Get counts of entities in different states
44
+ const counts = wiki.counts()
45
+ console.log(`Ready: ${counts.symbols.ready} symbols, ${counts.files.ready} files`)
46
+
47
+ // Get next entities to describe (in topological order)
48
+ const toDescribe = wiki.to_describe(10)
49
+ if (toDescribe.type === 'symbols') {
50
+ console.log(`Next symbols to describe: ${toDescribe.items.map(s => s.name).join(', ')}`)
51
+ }
36
52
  ```
37
53
 
38
- ## Architecture
54
+ ## Core API
55
+
56
+ ### CodeWiki Interface
57
+
58
+ The main interface provides access to all entity types:
59
+
60
+ ```typescript
61
+ interface CodeWiki {
62
+ readonly config: Config
63
+ update(): Promise<void> // Re-index the project
64
+ counts(): WikiCounts // Get entity counts by state
65
+ to_describe(limit: number): EntitiesToDescribe // Get next entities for AI description
66
+
67
+ files: FilesWiki // File operations
68
+ symbols: SymbolsWiki // Symbol/function/class operations
69
+ directories: DirectoriesWiki // Directory operations
70
+ dependencies: DependenciesWiki // External dependency operations
71
+ }
72
+ ```
73
+
74
+ ### Entity Operations
75
+
76
+ Each entity type provides a consistent API:
77
+
78
+ ```typescript
79
+ // Search and retrieve
80
+ const files = wiki.files.search({ where: { state: 'ready' }, limit: 10 })
81
+ const file = wiki.files.get(fileId)
82
+
83
+ // Set AI-generated descriptions
84
+ wiki.files.set_description(fileId, 'This file contains utility functions...')
85
+
86
+ // Query relationships
87
+ const importedFiles = wiki.files.imported_by_file(fileId)
88
+ const usingSymbols = wiki.symbols.using_dependency(dependencyId)
89
+ ```
90
+
91
+ ## Entity Types
92
+
93
+ ### Files
94
+ - **States**: `to_scan` → `to_describe` → `ready`
95
+ - **Tracks**: File metadata, imports, exports, symbols
96
+ - **Relationships**: Import relationships with other files and external dependencies
97
+
98
+ ### Symbols
99
+ - **States**: `to_link` → `to_describe` → `ready`
100
+ - **Tracks**: Functions, classes, variables, types
101
+ - **Relationships**: Internal symbol references and external dependency usage
102
+
103
+ ### Directories
104
+ - **States**: `to_describe` → `ready`
105
+ - **Tracks**: Directory structure and contents
106
+ - **Relationships**: Parent-child relationships and contained files
107
+
108
+ ### External Dependencies
109
+ - **States**: `to_describe` → `ready`
110
+ - **Tracks**: npm packages, built-in modules
111
+ - **Relationships**: Usage by files and symbols
112
+
113
+ ## Topological Description Order
39
114
 
40
- This is the core library used by:
41
- - **codewiki-cli** - Command-line interface with MCP server
42
- - **codewiki-vscode** - VSCode extension
115
+ The `to_describe()` method returns entities in an intelligent order that maximizes AI context:
116
+
117
+ 1. **External Dependencies** (no dependencies)
118
+ - Built-in packages first, then by usage count
119
+ 2. **Symbols** (depend on other symbols and dependencies)
120
+ - Fewest missing dependencies first, then by complexity
121
+ 3. **Files** (contain symbols and have imports)
122
+ - Fewest missing descriptions first, then by file size
123
+ 4. **Directories** (contain files and subdirectories)
124
+ - Fewest missing content first, then by total size
125
+
126
+ This ensures that when describing an entity, all its dependencies are already described.
127
+
128
+ ## CLI Usage
129
+
130
+ The package includes a comprehensive CLI:
131
+
132
+ ```bash
133
+ # Initialize and index a project
134
+ codewiki update
135
+
136
+ # Show current status
137
+ codewiki status
138
+
139
+ # Search entities
140
+ codewiki files search --where.state=ready
141
+ codewiki symbols search --where.name="myFunction"
142
+
143
+ # Set descriptions
144
+ codewiki symbols set-description 123 "This function does X..."
145
+
146
+ # Query relationships
147
+ codewiki files imported-by-file 456
148
+ codewiki dependencies used-by-file 456
149
+ ```
150
+
151
+ ## Database Schema
152
+
153
+ Uses SQLite with Drizzle ORM. Key tables:
154
+ - `files` - File metadata and state
155
+ - `symbols` - Function/class/variable definitions
156
+ - `directories` - Directory structure
157
+ - `external_dependencies` - npm packages and built-ins
158
+ - `imports` - File-to-file import relationships
159
+ - `symbol_*_links` - Symbol dependency relationships
160
+
161
+ ## Configuration
162
+
163
+ ```typescript
164
+ type Config = {
165
+ db_path: string // SQLite database file path
166
+ project_path: string // Root directory of TypeScript project
167
+ description?: string // Optional project description
168
+ package_json_path?: string // Optional package.json location
169
+ node_modules_paths?: string[] // Optional node_modules directories
170
+ }
171
+ ```
43
172
 
44
173
  ## Development
45
174
 
46
175
  ```bash
47
- # Build
176
+ # Install dependencies
177
+ pnpm install
178
+
179
+ # Build the library
48
180
  pnpm build
49
181
 
50
- # Test
182
+ # Run tests
51
183
  pnpm test
52
184
 
53
- # Type check
185
+ # Type checking
54
186
  pnpm typecheck
187
+
188
+ # Database operations
189
+ pnpm db:generate # Generate migrations
190
+ pnpm db:push # Push schema changes
191
+ pnpm db:studio # Open Drizzle Studio
55
192
  ```
56
193
 
194
+ ## Architecture
195
+
196
+ This is the core library that powers:
197
+ - **codewiki-cli** - Command-line interface and MCP server
198
+ - **codewiki-vscode** - VSCode extension (planned)
199
+
200
+ The library is designed to be:
201
+ - **Incremental** - Only processes changed files
202
+ - **Performant** - Uses SQLite and efficient AST parsing
203
+ - **Extensible** - Clean separation between parsing, storage, and API layers
204
+ - **Type-safe** - Full TypeScript support throughout
205
+
57
206
  ## License
58
207
 
59
- MIT
208
+ MIT © [Amine Ben hammou](https://github.com/webNeat)