Skip to content

Commit 76d395c

Browse files
committed
refactor: simplify codegraph-napi api
1 parent 235ad86 commit 76d395c

File tree

5 files changed

+79
-622
lines changed

5 files changed

+79
-622
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to the CodeGraph MCP Intelligence Platform will be documente
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Removed
11+
- Dropped the transactional/versioning/branch N-API bindings plus their documentation; the native TypeScript surface now focuses on semantic search, graph analysis, and cloud configuration so it matches the Surreal-only architecture.
12+
- Replaced the native addon example with a semantic-search walkthrough and removed CLI-centric integration snippets that referenced the deleted CodeGraph CLI.
13+
814
## [1.1.0] - 2025-11-18 - AutoAgents Integration & SurrealDB 2.x Compatibility
915

1016
### 🚀 **Added - AutoAgents Framework Integration (Experimental)**

crates/codegraph-napi/README.md

Lines changed: 14 additions & 306 deletions
Original file line numberDiff line numberDiff line change
@@ -163,38 +163,6 @@ for (const result of results.localResults) {
163163
}
164164
```
165165

166-
### Version Management
167-
168-
```typescript
169-
import {
170-
createVersion,
171-
listVersions,
172-
createBranch,
173-
mergeBranches,
174-
} from 'codegraph-napi';
175-
176-
// Create a version - direct function call!
177-
const version = await createVersion({
178-
name: 'v1.0.0',
179-
description: 'Initial release',
180-
author: 'user@example.com',
181-
parents: undefined,
182-
});
183-
184-
console.log(`Created: ${version.versionId}`);
185-
186-
// List versions
187-
const versions = await listVersions(50);
188-
versions.forEach(v => console.log(v.name));
189-
190-
// Create branch
191-
await createBranch({
192-
name: 'feature/api',
193-
from: version.versionId,
194-
author: 'user@example.com',
195-
});
196-
```
197-
198166
## API Reference
199167

200168
### Initialization
@@ -529,235 +497,6 @@ interface HubNode {
529497
}
530498
```
531499

532-
### Transaction Management
533-
534-
```typescript
535-
// Begin transaction
536-
const tx = await beginTransaction('serializable');
537-
// Options: 'read-uncommitted', 'read-committed', 'repeatable-read', 'serializable'
538-
539-
// Commit transaction
540-
await commitTransaction(tx.transactionId);
541-
542-
// Rollback transaction
543-
await rollbackTransaction(tx.transactionId);
544-
545-
// Get statistics
546-
const stats = await getTransactionStats();
547-
console.log(stats.activeTransactions);
548-
```
549-
550-
### Version Management
551-
552-
```typescript
553-
// Create version
554-
const version = await createVersion({
555-
name: 'v1.0.0',
556-
description: 'Release notes',
557-
author: 'user@example.com',
558-
parents: ['parent-id-1', 'parent-id-2'], // Optional
559-
});
560-
561-
// List versions
562-
const versions = await listVersions(50); // limit optional
563-
564-
// Get version by ID
565-
const version = await getVersion('version-id');
566-
567-
// Tag version
568-
await tagVersion('version-id', 'stable');
569-
570-
// Compare versions
571-
const diff = await compareVersions('from-id', 'to-id');
572-
console.log(`${diff.addedNodes} added, ${diff.modifiedNodes} modified`);
573-
```
574-
575-
### Branch Management
576-
577-
```typescript
578-
// Create branch
579-
const branch = await createBranch({
580-
name: 'feature/auth',
581-
from: 'version-id',
582-
author: 'user@example.com',
583-
description: 'Authentication feature', // Optional
584-
});
585-
586-
// List branches
587-
const branches = await listBranches();
588-
589-
// Get branch
590-
const branch = await getBranch('branch-name');
591-
592-
// Delete branch
593-
await deleteBranch('branch-name');
594-
595-
// Merge branches
596-
const result = await mergeBranches({
597-
source: 'feature/auth',
598-
target: 'main',
599-
author: 'user@example.com',
600-
message: 'Merge auth feature', // Optional
601-
});
602-
603-
if (result.success) {
604-
console.log('Merged!');
605-
} else {
606-
console.log(`${result.conflicts} conflicts`);
607-
}
608-
```
609-
610-
## Types
611-
612-
### TransactionResult
613-
614-
```typescript
615-
interface TransactionResult {
616-
transactionId: string;
617-
isolationLevel: string;
618-
status: string;
619-
}
620-
```
621-
622-
### VersionResult
623-
624-
```typescript
625-
interface VersionResult {
626-
versionId: string;
627-
name: string;
628-
description: string;
629-
author: string;
630-
createdAt: string; // ISO 8601 format
631-
}
632-
```
633-
634-
### BranchResult
635-
636-
```typescript
637-
interface BranchResult {
638-
name: string;
639-
head: string; // Version ID
640-
createdAt: string;
641-
createdBy: string;
642-
}
643-
```
644-
645-
### TransactionStats
646-
647-
```typescript
648-
interface TransactionStats {
649-
activeTransactions: number;
650-
committedTransactions: string; // u64 as string
651-
abortedTransactions: string; // u64 as string
652-
averageCommitTimeMs: number;
653-
}
654-
```
655-
656-
## Performance
657-
658-
### Benchmark: Native Addon vs CLI Spawning
659-
660-
```typescript
661-
// Native addon (direct function call)
662-
console.time('native');
663-
for (let i = 0; i < 1000; i++) {
664-
await getTransactionStats();
665-
}
666-
console.timeEnd('native');
667-
// ~150ms (0.15ms per call)
668-
669-
// CLI spawning
670-
console.time('cli');
671-
for (let i = 0; i < 1000; i++) {
672-
await exec('codegraph transaction stats');
673-
}
674-
console.timeEnd('cli');
675-
// ~45,000ms (45ms per call)
676-
```
677-
678-
**Native addon is ~300x faster** for high-frequency operations!
679-
680-
## Integration Examples
681-
682-
### Express API Server
683-
684-
```typescript
685-
import express from 'express';
686-
import { createVersion, listVersions } from 'codegraph-napi';
687-
688-
const app = express();
689-
app.use(express.json());
690-
691-
app.post('/api/versions', async (req, res) => {
692-
try {
693-
const version = await createVersion(req.body);
694-
res.json(version);
695-
} catch (error) {
696-
res.status(500).json({ error: error.message });
697-
}
698-
});
699-
700-
app.get('/api/versions', async (req, res) => {
701-
const versions = await listVersions(50);
702-
res.json(versions);
703-
});
704-
705-
app.listen(3000);
706-
```
707-
708-
### CLI Tool
709-
710-
```typescript
711-
#!/usr/bin/env node
712-
import { Command } from 'commander';
713-
import { createVersion, listVersions } from 'codegraph-napi';
714-
715-
const program = new Command();
716-
717-
program
718-
.command('version:create')
719-
.option('-n, --name <name>')
720-
.option('-d, --description <desc>')
721-
.action(async (options) => {
722-
const version = await createVersion({
723-
name: options.name,
724-
description: options.description,
725-
author: 'cli',
726-
parents: undefined,
727-
});
728-
console.log(`Created: ${version.versionId}`);
729-
});
730-
731-
program
732-
.command('version:list')
733-
.action(async () => {
734-
const versions = await listVersions(50);
735-
versions.forEach(v => console.log(`${v.name}: ${v.description}`));
736-
});
737-
738-
program.parse();
739-
```
740-
741-
### Background Worker
742-
743-
```typescript
744-
import { Queue, Worker } from 'bullmq';
745-
import { createVersion, mergeBranches } from 'codegraph-napi';
746-
747-
const worker = new Worker('codegraph-tasks', async job => {
748-
switch (job.name) {
749-
case 'create-version':
750-
return await createVersion(job.data);
751-
752-
case 'merge-branches':
753-
return await mergeBranches(job.data);
754-
755-
default:
756-
throw new Error('Unknown job type');
757-
}
758-
});
759-
```
760-
761500
## Cloud Features Usage Examples
762501

763502
### Example 1: Semantic Code Search with Fallback
@@ -1005,49 +744,19 @@ COPY . .
1005744
CMD ["node", "server.js"]
1006745
```
1007746

1008-
### Serverless (AWS Lambda)
1009-
1010-
```typescript
1011-
// lambda/handler.ts
1012-
import { createVersion, listVersions } from 'codegraph-napi';
1013-
1014-
export const handler = async (event) => {
1015-
if (event.action === 'create') {
1016-
const version = await createVersion(JSON.parse(event.body));
1017-
return {
1018-
statusCode: 200,
1019-
body: JSON.stringify(version),
1020-
};
1021-
}
1022-
1023-
if (event.action === 'list') {
1024-
const versions = await listVersions(50);
1025-
return {
1026-
statusCode: 200,
1027-
body: JSON.stringify(versions),
1028-
};
1029-
}
1030-
};
1031-
```
1032-
1033747
## Error Handling
1034748

1035749
```typescript
1036750
try {
1037-
const version = await createVersion({
1038-
name: 'v1.0',
1039-
description: 'Release',
1040-
author: 'user',
1041-
});
751+
const results = await semanticSearch('non-existent symbol', { minSimilarity: 0.9 });
752+
console.log(results.totalCount);
1042753
} catch (error) {
1043-
if (error.message.includes('Invalid version ID')) {
1044-
console.error('Bad version ID format');
1045-
} else if (error.message.includes('Version not found')) {
1046-
console.error('Version does not exist');
1047-
} else if (error.message.includes('Failed to create version')) {
1048-
console.error('Creation failed:', error.message);
754+
if (error.message.includes('Failed to get node')) {
755+
console.error('Check that the repository has been indexed.');
756+
} else if (error.message.includes('invalid node ID')) {
757+
console.error('One of the IDs passed to searchSimilarFunctions is malformed.');
1049758
} else {
1050-
console.error('Unexpected error:', error);
759+
console.error('Unexpected search error:', error);
1051760
}
1052761
}
1053762
```
@@ -1137,22 +846,21 @@ await initialize();
1137846
### Concurrent Operations
1138847

1139848
```typescript
1140-
// Safe to call in parallel - uses internal locking
849+
// Safe to call in parallel - internal locking protects shared state
1141850
await Promise.all([
1142-
createVersion({ name: 'v1', ... }),
1143-
createVersion({ name: 'v2', ... }),
1144-
createVersion({ name: 'v3', ... }),
851+
semanticSearch('caching layers', { limit: 5 }),
852+
searchSimilarFunctions('node-id-1234', 5),
1145853
]);
1146854
```
1147855

1148856
### Memory Management
1149857

1150858
```typescript
1151-
// The addon uses Arc<Mutex<>> internally
1152-
// No manual cleanup needed - garbage collector handles it
859+
// The addon uses Arc<Mutex<>> internally - no manual cleanup required.
860+
// Large result sets are released once they drop out of scope.
1153861

1154-
const versions = await listVersions(1000000);
1155-
// Large arrays are properly freed when out of scope
862+
const largeQuery = await semanticSearch('serialization helpers', { limit: 500 });
863+
console.log(`Fetched ${largeQuery.localResults.length} entries`);
1156864
```
1157865

1158866
## Development

0 commit comments

Comments
 (0)