@fractary/codex 0.12.16 → 0.12.18
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 +219 -52
- package/dist/index.cjs +607 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +109 -1
- package/dist/index.d.ts +109 -1
- package/dist/index.js +605 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,83 +11,250 @@ JavaScript/TypeScript SDK for Fractary Codex - knowledge infrastructure for AI a
|
|
|
11
11
|
npm install @fractary/codex
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## Quick Start
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
- **Multi-Provider Storage**: Local filesystem, GitHub, HTTP, and S3 storage backends
|
|
18
|
-
- **Intelligent Caching**: Multi-tier caching with LRU eviction
|
|
19
|
-
- **File Synchronization**: Bidirectional sync with conflict detection
|
|
20
|
-
- **MCP Integration**: Model Context Protocol server for AI agents
|
|
21
|
-
- **Permission System**: Fine-grained access control
|
|
22
|
-
- **Type-Safe**: Full TypeScript support
|
|
16
|
+
### Using CodexClient (recommended)
|
|
23
17
|
|
|
24
|
-
|
|
18
|
+
```typescript
|
|
19
|
+
import { CodexClient } from '@fractary/codex'
|
|
20
|
+
|
|
21
|
+
// Create client from project config (.fractary/config.yaml)
|
|
22
|
+
const client = await CodexClient.create()
|
|
23
|
+
|
|
24
|
+
// Fetch a document
|
|
25
|
+
const result = await client.fetch('codex://myorg/project/docs/api.md')
|
|
26
|
+
console.log(result.content.toString())
|
|
27
|
+
|
|
28
|
+
// Fetch with options
|
|
29
|
+
const fresh = await client.fetch('codex://myorg/project/docs/api.md', {
|
|
30
|
+
bypassCache: true,
|
|
31
|
+
ttl: 3600
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// Cache management
|
|
35
|
+
const stats = await client.getCacheStats()
|
|
36
|
+
await client.invalidateCache('codex://myorg/*')
|
|
37
|
+
|
|
38
|
+
// Health checks
|
|
39
|
+
const checks = await client.getHealthChecks()
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Using individual modules
|
|
25
43
|
|
|
26
44
|
```typescript
|
|
27
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
parseReference,
|
|
47
|
+
buildUri,
|
|
48
|
+
isValidUri,
|
|
49
|
+
CacheManager,
|
|
50
|
+
StorageManager,
|
|
51
|
+
TypeRegistry
|
|
52
|
+
} from '@fractary/codex'
|
|
28
53
|
|
|
29
|
-
// Parse a codex URI
|
|
30
|
-
const ref = parseReference('codex://myorg/docs/api
|
|
54
|
+
// Parse a codex:// URI
|
|
55
|
+
const ref = parseReference('codex://myorg/project/docs/api.md')
|
|
56
|
+
// { org: 'myorg', project: 'project', path: 'docs/api.md' }
|
|
31
57
|
|
|
32
|
-
//
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
cache.setStorageManager(storage)
|
|
58
|
+
// Build a URI
|
|
59
|
+
const uri = buildUri('myorg', 'project', 'docs/api.md')
|
|
60
|
+
// 'codex://myorg/project/docs/api.md'
|
|
36
61
|
|
|
37
|
-
//
|
|
38
|
-
|
|
62
|
+
// Validate
|
|
63
|
+
isValidUri('codex://myorg/project/docs/api.md') // true
|
|
39
64
|
```
|
|
40
65
|
|
|
41
|
-
##
|
|
66
|
+
## API Reference
|
|
42
67
|
|
|
43
|
-
|
|
68
|
+
### CodexClient
|
|
44
69
|
|
|
45
|
-
-
|
|
46
|
-
- [Authentication](../../docs/sdk/js/#authentication)
|
|
47
|
-
- [Troubleshooting](../../docs/sdk/js/#troubleshooting)
|
|
48
|
-
- [Configuration Guide](../../docs/configuration.md)
|
|
70
|
+
High-level facade for all codex operations.
|
|
49
71
|
|
|
50
|
-
|
|
72
|
+
```typescript
|
|
73
|
+
interface CodexClientOptions {
|
|
74
|
+
configPath?: string // Path to .fractary/config.yaml
|
|
75
|
+
cacheDir?: string // Override cache directory
|
|
76
|
+
organizationSlug?: string // Override organization
|
|
77
|
+
}
|
|
51
78
|
|
|
52
|
-
|
|
53
|
-
# Install dependencies
|
|
54
|
-
npm install
|
|
79
|
+
const client = await CodexClient.create(options?)
|
|
55
80
|
|
|
56
|
-
|
|
57
|
-
|
|
81
|
+
// Document operations
|
|
82
|
+
client.fetch(uri, options?) // Fetch document by URI
|
|
83
|
+
client.invalidateCache(pattern?) // Invalidate cache entries
|
|
84
|
+
client.invalidateCachePattern(regex) // Invalidate by regex
|
|
58
85
|
|
|
59
|
-
|
|
60
|
-
|
|
86
|
+
// Cache
|
|
87
|
+
client.getCacheStats() // Get cache statistics
|
|
88
|
+
client.listCacheEntries(options?) // List cached entries
|
|
61
89
|
|
|
62
|
-
|
|
63
|
-
|
|
90
|
+
// Health
|
|
91
|
+
client.getHealthChecks() // Run health diagnostics
|
|
64
92
|
|
|
65
|
-
|
|
66
|
-
|
|
93
|
+
// Accessors
|
|
94
|
+
client.getTypeRegistry() // Get type registry
|
|
95
|
+
client.getCacheManager() // Get cache manager
|
|
96
|
+
client.getStorageManager() // Get storage manager
|
|
97
|
+
client.getOrganization() // Get organization slug
|
|
67
98
|
```
|
|
68
99
|
|
|
69
|
-
|
|
100
|
+
### References
|
|
70
101
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
102
|
+
Parse, build, validate, and resolve `codex://` URIs.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
// Parsing and building
|
|
106
|
+
parseReference(uri: string): ParsedReference
|
|
107
|
+
buildUri(org: string, project: string, path: string): string
|
|
108
|
+
isValidUri(uri: string): boolean
|
|
109
|
+
validateUri(uri: string): boolean
|
|
74
110
|
|
|
75
|
-
|
|
76
|
-
|
|
111
|
+
// Resolution (adds filesystem paths, cache paths)
|
|
112
|
+
resolveReference(uri: string, options?): ResolvedReference
|
|
113
|
+
resolveReferences(uris: string[], options?): ResolvedReference[]
|
|
77
114
|
|
|
78
|
-
|
|
79
|
-
|
|
115
|
+
// Utilities
|
|
116
|
+
getExtension(uri: string): string
|
|
117
|
+
getFilename(uri: string): string
|
|
118
|
+
getDirectory(uri: string): string
|
|
119
|
+
isCurrentProjectUri(uri: string): boolean
|
|
80
120
|
|
|
81
|
-
|
|
82
|
-
|
|
121
|
+
// Legacy format support
|
|
122
|
+
isLegacyReference(ref: string): boolean
|
|
123
|
+
convertLegacyReference(ref: string): string
|
|
83
124
|
```
|
|
84
125
|
|
|
85
|
-
|
|
126
|
+
### StorageManager
|
|
127
|
+
|
|
128
|
+
Multi-provider storage with priority-based fallback.
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// Built-in providers
|
|
132
|
+
LocalStorage // Filesystem
|
|
133
|
+
GitHubStorage // GitHub repositories (needs GITHUB_TOKEN for private repos)
|
|
134
|
+
HttpStorage // HTTP/HTTPS endpoints
|
|
135
|
+
FilePluginStorage // File plugin integration
|
|
136
|
+
|
|
137
|
+
// Manager
|
|
138
|
+
const manager = StorageManager.create(config)
|
|
139
|
+
const result = await manager.fetch(ref, options?)
|
|
140
|
+
// result: { content: Buffer, contentType?: string, size: number }
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### CacheManager
|
|
144
|
+
|
|
145
|
+
TTL-based caching with disk persistence.
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const cache = CacheManager.create(config)
|
|
149
|
+
|
|
150
|
+
await cache.get(ref, options?) // Get from cache (or fetch)
|
|
151
|
+
await cache.set(uri, result) // Store in cache
|
|
152
|
+
await cache.clear() // Clear all entries
|
|
153
|
+
await cache.invalidate(pattern) // Invalidate by glob
|
|
154
|
+
await cache.invalidatePattern(regex) // Invalidate by regex
|
|
155
|
+
await cache.getStats() // Cache statistics
|
|
156
|
+
await cache.listEntries(options?) // List entries with filtering
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### TypeRegistry
|
|
160
|
+
|
|
161
|
+
Maps file paths to artifact types with TTL defaults.
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const registry = TypeRegistry.create()
|
|
165
|
+
|
|
166
|
+
registry.detectType('docs/api.md') // 'docs'
|
|
167
|
+
registry.getTtl('docs/api.md') // 86400 (1 day)
|
|
168
|
+
registry.register(customTypeConfig) // Add custom type
|
|
169
|
+
registry.list() // List all types
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Built-in types:**
|
|
173
|
+
|
|
174
|
+
| Type | Patterns | Default TTL |
|
|
175
|
+
|------|----------|-------------|
|
|
176
|
+
| `docs` | `docs/**`, `**/*.md` | 1 day |
|
|
177
|
+
| `specs` | `specs/**`, `**/SPEC-*.md` | 7 days |
|
|
178
|
+
| `config` | `**/*.yaml`, `**/*.json` | 1 hour |
|
|
179
|
+
| `logs` | `logs/**`, `**/*.log` | 1 hour |
|
|
180
|
+
| `schemas` | `schemas/**`, `**/*.schema.json` | 7 days |
|
|
86
181
|
|
|
87
|
-
|
|
182
|
+
### SyncManager
|
|
88
183
|
|
|
89
|
-
|
|
184
|
+
Bidirectional file synchronization.
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const sync = SyncManager.create(config)
|
|
188
|
+
|
|
189
|
+
const plan = await sync.createPlan(org, project, targetDir, patterns)
|
|
190
|
+
// plan: { direction, operations[], stats, conflicts[] }
|
|
191
|
+
|
|
192
|
+
const result = await sync.executePlan(plan, options?)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### PermissionManager
|
|
196
|
+
|
|
197
|
+
Fine-grained access control.
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const permissions = PermissionManager.create(config)
|
|
201
|
+
|
|
202
|
+
permissions.isAllowed(context) // Check if action allowed
|
|
203
|
+
permissions.hasPermission(context, level) // Check permission level
|
|
204
|
+
|
|
205
|
+
// Permission levels: none < read < write < admin
|
|
206
|
+
// Actions: fetch, cache, sync, invalidate, manage
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### ConfigManager
|
|
210
|
+
|
|
211
|
+
Configuration management (used by CLI internally).
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
const result = await ConfigManager.init(options) // Initialize config
|
|
215
|
+
const result = await ConfigManager.update(options) // Update config
|
|
216
|
+
const result = await ConfigManager.validate(options) // Validate config
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### HealthChecker
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
const checker = HealthChecker.create(options)
|
|
223
|
+
const results = await checker.runAll()
|
|
224
|
+
// Checks: config, storage, client, cache, type registry
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Errors
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import {
|
|
231
|
+
CodexError, ConfigurationError, ValidationError, PermissionDeniedError
|
|
232
|
+
} from '@fractary/codex'
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
await client.fetch(uri)
|
|
236
|
+
} catch (err) {
|
|
237
|
+
// PermissionDeniedError extends Error directly, not CodexError - check it first
|
|
238
|
+
if (err instanceof PermissionDeniedError) { /* access denied */ }
|
|
239
|
+
if (err instanceof ConfigurationError) { /* config issue */ }
|
|
240
|
+
if (err instanceof ValidationError) { /* validation issue */ }
|
|
241
|
+
if (err instanceof CodexError) { /* other SDK error */ }
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Configuration
|
|
246
|
+
|
|
247
|
+
The SDK reads from `.fractary/config.yaml`. See the [Configuration Guide](../../docs/configuration.md).
|
|
248
|
+
|
|
249
|
+
## Development
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
npm install
|
|
253
|
+
npm run build
|
|
254
|
+
npm test
|
|
255
|
+
npm run typecheck
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## License
|
|
90
259
|
|
|
91
|
-
|
|
92
|
-
- [CLI](../../cli/) - Command-line interface
|
|
93
|
-
- [MCP Server](../../mcp/server/) - AI agent integration
|
|
260
|
+
MIT
|