@fractary/codex 0.1.2 → 0.1.3

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,385 +1,230 @@
1
- # @fractary/codex
2
-
3
- Core SDK for Fractary Codex - knowledge infrastructure for AI agents.
4
-
5
- [![npm version](https://img.shields.io/npm/v/@fractary/codex.svg)](https://www.npmjs.com/package/@fractary/codex)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
-
8
- ## Overview
9
-
10
- The Codex SDK provides foundational infrastructure for managing organizational knowledge across AI agents and projects. It implements a universal reference system (`codex://` URIs), multi-provider storage, intelligent caching, file synchronization, and MCP (Model Context Protocol) integration.
11
-
12
- ### Key Features
13
-
14
- - **Universal References**: `codex://` URI scheme for cross-project knowledge references
15
- - **Multi-Provider Storage**: Local filesystem, GitHub, and HTTP storage backends
16
- - **Intelligent Caching**: Multi-tier caching (L1 memory, L2 disk, L3 network) with LRU eviction
17
- - **File Synchronization**: Bidirectional sync with conflict detection
18
- - **MCP Integration**: Model Context Protocol server for AI agent integration
19
- - **Permission System**: Fine-grained access control (none/read/write/admin)
20
- - **Migration Tools**: Upgrade from v2.x to v3.0 configuration format
21
- - **Type-Safe**: Full TypeScript support with strict typing
22
-
23
- ## Installation
24
-
25
- ```bash
26
- npm install @fractary/codex
27
- ```
28
-
29
- ## Quick Start
30
-
31
- ```typescript
32
- import {
33
- parseReference,
34
- resolveReference,
35
- CacheManager,
36
- StorageManager,
37
- createMcpServer
38
- } from '@fractary/codex'
39
-
40
- // Parse a codex URI
41
- const ref = parseReference('codex://myorg/docs/api-guide.md')
42
- console.log(ref.org) // 'myorg'
43
- console.log(ref.path) // 'docs/api-guide.md'
44
-
45
- // Resolve to actual file location
46
- const resolved = resolveReference(ref, {
47
- cacheDir: '.codex-cache'
48
- })
49
-
50
- // Create storage and cache managers
51
- const storage = StorageManager.create()
52
- const cache = CacheManager.create({ cacheDir: '.codex-cache' })
53
-
54
- // Fetch content with caching
55
- const content = await cache.get('codex://myorg/docs/api-guide.md')
56
- ```
57
-
58
- ## Core Modules
59
-
60
- ### References
61
-
62
- Universal `codex://` URI system for cross-project knowledge references:
63
-
64
- ```typescript
65
- import {
66
- parseReference,
67
- buildUri,
68
- resolveReference,
69
- validateUri
70
- } from '@fractary/codex'
71
-
72
- // Parse URI
73
- const ref = parseReference('codex://fractary/codex/docs/api.md')
74
- // { org: 'fractary', project: 'codex', path: 'docs/api.md' }
75
-
76
- // Build URI
77
- const uri = buildUri('fractary', 'codex', 'docs/api.md')
78
- // 'codex://fractary/codex/docs/api.md'
79
-
80
- // Validate
81
- const isValid = validateUri('codex://org/project/path.md')
82
- ```
83
-
84
- ### Storage
85
-
86
- Multi-provider storage abstraction with priority-based fallback:
87
-
88
- ```typescript
89
- import {
90
- StorageManager,
91
- LocalStorage,
92
- GitHubStorage,
93
- HttpStorage
94
- } from '@fractary/codex'
95
-
96
- // Create storage manager with multiple providers
97
- const storage = StorageManager.create({
98
- providers: [
99
- { type: 'local', basePath: './knowledge' },
100
- { type: 'github', token: process.env.GITHUB_TOKEN },
101
- { type: 'http', baseUrl: 'https://codex.example.com' }
102
- ]
103
- })
104
-
105
- // Fetch content (tries providers in order)
106
- const result = await storage.fetch('codex://org/project/file.md')
107
- console.log(result.content)
108
- console.log(result.provider) // Which provider served the content
109
- ```
110
-
111
- ### Cache
112
-
113
- Multi-tier caching with LRU eviction and stale-while-revalidate:
114
-
115
- ```typescript
116
- import { CacheManager, createCacheManager } from '@fractary/codex'
117
-
118
- const cache = createCacheManager({
119
- cacheDir: '.codex-cache',
120
- maxMemorySize: 50 * 1024 * 1024, // 50MB L1 cache
121
- maxDiskSize: 500 * 1024 * 1024, // 500MB L2 cache
122
- defaultTtl: 3600 // 1 hour TTL
123
- })
124
-
125
- // Get with automatic caching
126
- const entry = await cache.get('codex://org/project/file.md')
127
-
128
- // Check cache status
129
- const status = cache.getStatus('codex://org/project/file.md')
130
- // 'fresh' | 'stale' | 'expired' | 'missing'
131
-
132
- // Invalidate specific entry
133
- await cache.invalidate('codex://org/project/file.md')
134
-
135
- // Clear all cache
136
- await cache.clear()
137
- ```
138
-
139
- ### MCP Server
140
-
141
- Model Context Protocol integration for AI agents:
142
-
143
- ```typescript
144
- import { createMcpServer } from '@fractary/codex'
145
-
146
- const server = createMcpServer({
147
- name: 'codex',
148
- version: '1.0.0',
149
- cacheDir: '.codex-cache'
150
- })
151
-
152
- // Available tools:
153
- // - codex_fetch: Fetch document by URI
154
- // - codex_search: Search across documents
155
- // - codex_list: List available documents
156
- // - codex_invalidate: Clear cache entries
157
-
158
- await server.start()
159
- ```
160
-
161
- ### Sync
162
-
163
- Bidirectional file synchronization:
164
-
165
- ```typescript
166
- import { SyncManager, createSyncPlan } from '@fractary/codex'
167
-
168
- const sync = new SyncManager({
169
- sourceDir: './local-docs',
170
- targetDir: './codex-repo'
171
- })
172
-
173
- // Create sync plan (dry run)
174
- const plan = await sync.plan({
175
- direction: 'bidirectional',
176
- include: ['**/*.md'],
177
- exclude: ['**/node_modules/**']
178
- })
179
-
180
- console.log(plan.operations) // List of copy/update/delete operations
181
-
182
- // Execute sync
183
- const result = await sync.execute(plan)
184
- ```
185
-
186
- ### Permissions
187
-
188
- Fine-grained access control:
189
-
190
- ```typescript
191
- import {
192
- PermissionManager,
193
- createRule,
194
- CommonRules
195
- } from '@fractary/codex'
196
-
197
- const permissions = new PermissionManager({
198
- config: { enforced: true }
199
- })
200
-
201
- // Add rules
202
- permissions.addRule(CommonRules.allowDocs()) // Allow read on docs/**
203
- permissions.addRule(CommonRules.denyPrivate()) // Deny .private/**
204
- permissions.addRule(createRule({
205
- pattern: 'admin/**',
206
- actions: ['fetch', 'sync'],
207
- level: 'admin'
208
- }))
209
-
210
- // Check permissions
211
- const allowed = permissions.isAllowed('docs/api.md', 'fetch')
212
- const hasAccess = permissions.hasPermission('admin/config.md', 'sync', 'admin')
213
-
214
- // Filter paths by permission
215
- const accessible = permissions.filterAllowed(paths, 'fetch')
216
- ```
217
-
218
- ### Migration
219
-
220
- Upgrade from v2.x to v3.0 configuration:
221
-
222
- ```typescript
223
- import {
224
- migrateConfig,
225
- detectVersion,
226
- convertLegacyReferences
227
- } from '@fractary/codex'
228
-
229
- // Detect config version
230
- const detection = detectVersion(oldConfig)
231
- console.log(detection.version) // '2.x' | '3.0' | 'unknown'
232
-
233
- // Migrate configuration
234
- const result = migrateConfig(oldConfig)
235
- if (result.success) {
236
- console.log(result.config) // Modern v3.0 config
237
- console.log(result.changes) // List of changes made
238
- }
239
-
240
- // Convert legacy references in content
241
- const converted = convertLegacyReferences(content, {
242
- defaultOrg: 'myorg',
243
- defaultProject: 'myproject'
244
- })
245
- ```
246
-
247
- ### Types
248
-
249
- Extensible artifact type system with TTL management:
250
-
251
- ```typescript
252
- import { TypeRegistry, BUILT_IN_TYPES } from '@fractary/codex'
253
-
254
- const types = new TypeRegistry()
255
-
256
- // Get TTL for a file
257
- const ttl = types.getTtl('docs/api.md') // Uses 'docs' type TTL
258
- const specTtl = types.getTtl('specs/v1.md') // Uses 'specs' type TTL
259
-
260
- // Register custom type
261
- types.register({
262
- name: 'templates',
263
- patterns: ['templates/**/*.md'],
264
- ttl: 86400, // 24 hours
265
- description: 'Document templates'
266
- })
267
- ```
268
-
269
- ## API Reference
270
-
271
- ### References Module
272
- - `parseReference(uri)` - Parse codex:// URI
273
- - `buildUri(org, project, path)` - Build codex:// URI
274
- - `resolveReference(ref, options)` - Resolve to file path
275
- - `validateUri(uri)` - Validate URI format
276
-
277
- ### Storage Module
278
- - `StorageManager` - Multi-provider storage coordinator
279
- - `LocalStorage` - Local filesystem provider
280
- - `GitHubStorage` - GitHub API/raw content provider
281
- - `HttpStorage` - Generic HTTP provider
282
-
283
- ### Cache Module
284
- - `CacheManager` - Multi-tier cache coordinator
285
- - `CachePersistence` - Disk persistence layer
286
- - `createCacheEntry(uri, content, options)` - Create cache entry
287
-
288
- ### MCP Module
289
- - `McpServer` - MCP protocol server
290
- - `CODEX_TOOLS` - Available tool definitions
291
- - `handleToolCall(name, args, context)` - Handle tool invocation
292
-
293
- ### Sync Module
294
- - `SyncManager` - Sync orchestration
295
- - `createSyncPlan(options)` - Create sync plan
296
- - `evaluatePath(path, rules)` - Evaluate sync rules
297
-
298
- ### Permissions Module
299
- - `PermissionManager` - Permission orchestration
300
- - `createRule(options)` - Create permission rule
301
- - `CommonRules` - Pre-built common rules
302
-
303
- ### Migration Module
304
- - `migrateConfig(config)` - Migrate v2.x to v3.0
305
- - `detectVersion(config)` - Detect config version
306
- - `convertLegacyReferences(content)` - Convert old references
307
-
308
- ## Configuration
309
-
310
- ### Environment Variables
311
-
312
- ```bash
313
- CODEX_CACHE_DIR=".codex-cache" # Cache directory
314
- CODEX_DEFAULT_TTL="3600" # Default TTL in seconds
315
- GITHUB_TOKEN="ghp_xxx" # GitHub API token (for GitHub storage)
316
- ```
317
-
318
- ### Cache Configuration
319
-
320
- ```typescript
321
- const cache = createCacheManager({
322
- cacheDir: '.codex-cache',
323
- maxMemorySize: 50 * 1024 * 1024, // 50MB
324
- maxDiskSize: 500 * 1024 * 1024, // 500MB
325
- defaultTtl: 3600, // 1 hour
326
- staleWhileRevalidate: true
327
- })
328
- ```
329
-
330
- ## Development
331
-
332
- ```bash
333
- # Install dependencies
334
- npm install
335
-
336
- # Build
337
- npm run build
338
-
339
- # Test
340
- npm test
341
-
342
- # Test with coverage
343
- npm run test:coverage
344
-
345
- # Type check
346
- npm run typecheck
347
-
348
- # Lint
349
- npm run lint
350
- ```
351
-
352
- ## Project Structure
353
-
354
- ```
355
- src/
356
- ├── references/ # codex:// URI parsing and resolution
357
- ├── types/ # Artifact type system
358
- ├── storage/ # Multi-provider storage
359
- ├── cache/ # Multi-tier caching
360
- ├── mcp/ # MCP server integration
361
- ├── sync/ # File synchronization
362
- ├── permissions/ # Access control
363
- ├── migration/ # v2.x to v3.0 migration
364
- ├── core/ # Core utilities
365
- │ ├── config/ # Configuration management
366
- │ ├── metadata/ # Frontmatter parsing
367
- │ ├── patterns/ # Glob pattern matching
368
- │ └── routing/ # Sync routing
369
- ├── schemas/ # Zod validation schemas
370
- ├── errors/ # Error classes
371
- └── index.ts # Public exports
372
- ```
373
-
374
- ## Related Projects
375
-
376
- - **forge-bundle-codex-github-core** - GitHub Actions workflows for codex sync
377
- - **forge-bundle-codex-claude-agents** - Claude Code agents for codex management
378
-
379
- ## License
380
-
381
- MIT © Fractary Engineering
382
-
383
- ## Contributing
384
-
385
- For issues or contributions, please visit the [GitHub repository](https://github.com/fractary/codex).
1
+ # @fractary/codex
2
+
3
+ JavaScript/TypeScript SDK for Fractary Codex - knowledge infrastructure for AI agents.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@fractary/codex.svg)](https://www.npmjs.com/package/@fractary/codex)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @fractary/codex
12
+ ```
13
+
14
+ ## Features
15
+
16
+ - **Universal References**: `codex://` URI scheme for cross-project knowledge references
17
+ - **Multi-Provider Storage**: Local filesystem, GitHub, and HTTP storage backends
18
+ - **Intelligent Caching**: Multi-tier caching (L1 memory, L2 disk, L3 network) with LRU eviction
19
+ - **File Synchronization**: Bidirectional sync with conflict detection
20
+ - **MCP Integration**: Model Context Protocol server for AI agent integration
21
+ - **Permission System**: Fine-grained access control (none/read/write/admin)
22
+ - **Migration Tools**: Upgrade from v2.x to v3.0 configuration format
23
+ - **Type-Safe**: Full TypeScript support with strict typing
24
+
25
+ ## Quick Start
26
+
27
+ ```typescript
28
+ import {
29
+ parseReference,
30
+ resolveReference,
31
+ CacheManager,
32
+ StorageManager,
33
+ createMcpServer
34
+ } from '@fractary/codex'
35
+
36
+ // Parse a codex URI
37
+ const ref = parseReference('codex://myorg/docs/api-guide.md')
38
+ console.log(ref.org) // 'myorg'
39
+ console.log(ref.path) // 'docs/api-guide.md'
40
+
41
+ // Create storage and cache managers
42
+ const storage = StorageManager.create()
43
+ const cache = CacheManager.create({ cacheDir: '.codex-cache' })
44
+
45
+ // Fetch content with caching
46
+ const content = await cache.get('codex://myorg/docs/api-guide.md')
47
+ ```
48
+
49
+ ## Core Modules
50
+
51
+ ### References
52
+
53
+ ```typescript
54
+ import { parseReference, buildUri, validateUri } from '@fractary/codex'
55
+
56
+ const ref = parseReference('codex://fractary/codex/docs/api.md')
57
+ const uri = buildUri('fractary', 'codex', 'docs/api.md')
58
+ const isValid = validateUri('codex://org/project/path.md')
59
+ ```
60
+
61
+ ### Storage
62
+
63
+ ```typescript
64
+ import { StorageManager } from '@fractary/codex'
65
+
66
+ const storage = StorageManager.create({
67
+ providers: [
68
+ { type: 'local', basePath: './knowledge' },
69
+ { type: 'github', token: process.env.GITHUB_TOKEN },
70
+ { type: 'http', baseUrl: 'https://codex.example.com' }
71
+ ]
72
+ })
73
+
74
+ const result = await storage.fetch('codex://org/project/file.md')
75
+ ```
76
+
77
+ ### Cache
78
+
79
+ ```typescript
80
+ import { createCacheManager } from '@fractary/codex'
81
+
82
+ const cache = createCacheManager({
83
+ cacheDir: '.codex-cache',
84
+ maxMemorySize: 50 * 1024 * 1024,
85
+ defaultTtl: 3600
86
+ })
87
+
88
+ const entry = await cache.get('codex://org/project/file.md')
89
+ ```
90
+
91
+ ### MCP Server
92
+
93
+ ```typescript
94
+ import { createMcpServer } from '@fractary/codex'
95
+
96
+ const server = createMcpServer({
97
+ name: 'codex',
98
+ version: '1.0.0',
99
+ cacheDir: '.codex-cache'
100
+ })
101
+
102
+ await server.start()
103
+ ```
104
+
105
+ ## Development
106
+
107
+ ```bash
108
+ # Install dependencies
109
+ npm install
110
+
111
+ # Build the package
112
+ npm run build
113
+
114
+ # Run tests
115
+ npm test
116
+
117
+ # Run tests in watch mode
118
+ npm run test:watch
119
+
120
+ # Type check
121
+ npm run typecheck
122
+
123
+ # Lint
124
+ npm run lint
125
+
126
+ # Format code
127
+ npm run format
128
+ ```
129
+
130
+ ## Publishing to npm
131
+
132
+ ### Prerequisites
133
+
134
+ 1. **npm Account**: Create an account on [npmjs.com](https://www.npmjs.com)
135
+ 2. **npm Login**: Run `npm login` to authenticate
136
+ 3. **Organization Access**: Ensure you have publish access to `@fractary` scope
137
+
138
+ ### Manual Publishing
139
+
140
+ ```bash
141
+ # Build and test
142
+ npm run build
143
+ npm test
144
+
145
+ # Check what will be published
146
+ npm pack --dry-run
147
+
148
+ # Publish to npm (the prepublishOnly script runs build & test automatically)
149
+ npm publish
150
+
151
+ # For first publish or after scope changes
152
+ npm publish --access public
153
+ ```
154
+
155
+ ### Automated Publishing (CI/CD)
156
+
157
+ For automated publishing via GitHub Actions:
158
+
159
+ 1. **npm Token**: Generate an Automation token on npmjs.com
160
+ 2. **GitHub Secret**: Add `NPM_TOKEN` to repository secrets
161
+ 3. **Workflow**: Create `.github/workflows/npm-publish.yml`:
162
+
163
+ ```yaml
164
+ name: Publish to npm
165
+ on:
166
+ release:
167
+ types: [published]
168
+
169
+ jobs:
170
+ publish:
171
+ runs-on: ubuntu-latest
172
+ steps:
173
+ - uses: actions/checkout@v4
174
+ - uses: actions/setup-node@v4
175
+ with:
176
+ node-version: '20'
177
+ registry-url: 'https://registry.npmjs.org'
178
+ - run: npm ci
179
+ - run: npm run build
180
+ - run: npm test
181
+ - run: npm publish --access public
182
+ env:
183
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
184
+ ```
185
+
186
+ ### Version Management
187
+
188
+ ```bash
189
+ # Bump patch version (0.1.2 -> 0.1.3)
190
+ npm version patch
191
+
192
+ # Bump minor version (0.1.2 -> 0.2.0)
193
+ npm version minor
194
+
195
+ # Bump major version (0.1.2 -> 1.0.0)
196
+ npm version major
197
+
198
+ # This automatically:
199
+ # - Updates package.json version
200
+ # - Creates a git commit
201
+ # - Creates a git tag
202
+ ```
203
+
204
+ To publish a new version:
205
+
206
+ ```bash
207
+ # 1. Ensure all changes are committed
208
+ # 2. Bump version
209
+ npm version patch # or minor/major
210
+
211
+ # 3. Push with tags
212
+ git push && git push --tags
213
+
214
+ # 4. Publish to npm
215
+ npm publish
216
+ ```
217
+
218
+ Follow [Semantic Versioning](https://semver.org/):
219
+ - **MAJOR**: Breaking API changes
220
+ - **MINOR**: New features, backward compatible
221
+ - **PATCH**: Bug fixes, backward compatible
222
+
223
+ ## License
224
+
225
+ MIT - see [LICENSE](LICENSE)
226
+
227
+ ## See Also
228
+
229
+ - [Python SDK](../python/) - `fractary-codex` on PyPI
230
+ - [Documentation](../../docs/)
package/dist/index.cjs CHANGED
@@ -1089,7 +1089,7 @@ function getCustomSyncDestinations(metadata) {
1089
1089
  try {
1090
1090
  const parsed = parseCustomDestination(destination);
1091
1091
  results.push(parsed);
1092
- } catch (error) {
1092
+ } catch (_error) {
1093
1093
  continue;
1094
1094
  }
1095
1095
  }