@fractary/codex 0.1.1 → 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,280 +1,230 @@
1
- # @fractary/codex
2
-
3
- Core SDK for Fractary Codex - a centralized knowledge management and distribution platform for organizations.
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 the foundational business logic for the Fractary Codex system, which enables organizations to maintain a single source of truth for documentation, AI tools, and organizational knowledge across all projects.
11
-
12
- ### Key Features
13
-
14
- - **Metadata Parsing**: Extract and validate YAML frontmatter from markdown files
15
- - **Pattern Matching**: Glob-based pattern matching for intelligent file routing
16
- - **Smart Routing**: Determine which files should sync to which repositories
17
- - **Configuration Management**: Multi-source configuration with sensible defaults
18
- - **Organization-Agnostic**: Works for any organization, not just Fractary
19
- - **Type-Safe**: Full TypeScript support with strict typing
20
- - **Well-Tested**: Comprehensive unit test coverage
21
-
22
- ## Installation
23
-
24
- ```bash
25
- npm install @fractary/codex
26
- ```
27
-
28
- ## Quick Start
29
-
30
- ```typescript
31
- import {
32
- parseMetadata,
33
- shouldSyncToRepo,
34
- loadConfig
35
- } from '@fractary/codex'
36
-
37
- // 1. Load configuration
38
- const config = loadConfig({
39
- organizationSlug: 'fractary'
40
- })
41
-
42
- // 2. Parse frontmatter from a markdown file
43
- const fileContent = await readFile('docs/api-guide.md', 'utf-8')
44
- const { metadata, content } = parseMetadata(fileContent)
45
-
46
- // 3. Determine if file should sync to a target repository
47
- const shouldSync = shouldSyncToRepo({
48
- filePath: 'docs/api-guide.md',
49
- fileMetadata: metadata,
50
- targetRepo: 'api-gateway',
51
- sourceRepo: 'codex.fractary.com',
52
- rules: config.rules
53
- })
54
-
55
- console.log(`Sync to api-gateway: ${shouldSync}`)
56
- ```
57
-
58
- ## Core Concepts
59
-
60
- ### Metadata Parsing
61
-
62
- The SDK parses YAML frontmatter from markdown files to extract sync rules and metadata:
63
-
64
- ```yaml
65
- ---
66
- org: fractary
67
- system: api-gateway
68
- codex_sync_include: ['api-*', 'core-*']
69
- codex_sync_exclude: ['*-test', '*-dev']
70
- visibility: internal
71
- tags: [api, rest]
72
- ---
73
-
74
- # API Documentation
75
- ```
76
-
77
- ```typescript
78
- import { parseMetadata } from '@fractary/codex'
79
-
80
- const result = parseMetadata(markdown)
81
- console.log(result.metadata.codex_sync_include) // ['api-*', 'core-*']
82
- ```
83
-
84
- ### Pattern Matching
85
-
86
- Glob patterns determine which repositories receive which files:
87
-
88
- ```typescript
89
- import { matchPattern, matchAnyPattern } from '@fractary/codex'
90
-
91
- // Single pattern
92
- matchPattern('api-*', 'api-gateway') // true
93
- matchPattern('api-*', 'web-app') // false
94
-
95
- // Multiple patterns
96
- matchAnyPattern(['api-*', 'core-*'], 'api-gateway') // true
97
- matchAnyPattern(['api-*', 'core-*'], 'web-app') // false
98
-
99
- // Special: match all
100
- matchAnyPattern(['*'], 'anything') // true
101
- ```
102
-
103
- ### Sync Routing
104
-
105
- Determine which repositories should receive a file based on frontmatter rules:
106
-
107
- ```typescript
108
- import { shouldSyncToRepo } from '@fractary/codex'
109
-
110
- const shouldSync = shouldSyncToRepo({
111
- filePath: 'docs/api-guide.md',
112
- fileMetadata: {
113
- codex_sync_include: ['api-*', 'core-*'],
114
- codex_sync_exclude: ['*-test']
115
- },
116
- targetRepo: 'api-gateway',
117
- sourceRepo: 'codex.fractary.com'
118
- })
119
-
120
- // Returns: true (matches 'api-*' and not excluded)
121
- ```
122
-
123
- ### Configuration
124
-
125
- The SDK supports multi-source configuration:
126
-
127
- ```typescript
128
- import { loadConfig, resolveOrganization } from '@fractary/codex'
129
-
130
- // Auto-detect organization from repo name
131
- const org = resolveOrganization({
132
- repoName: 'codex.fractary.com'
133
- }) // Returns: 'fractary'
134
-
135
- // Load configuration
136
- const config = loadConfig({
137
- organizationSlug: 'fractary'
138
- })
139
-
140
- console.log(config)
141
- /*
142
- {
143
- organizationSlug: 'fractary',
144
- directories: {
145
- source: '.fractary',
146
- target: '.fractary',
147
- systems: '.fractary/systems'
148
- },
149
- rules: {
150
- preventSelfSync: true,
151
- preventCodexSync: true,
152
- allowProjectOverrides: true,
153
- autoSyncPatterns: []
154
- }
155
- }
156
- */
157
- ```
158
-
159
- ## API Reference
160
-
161
- ### Metadata Parsing
162
-
163
- - `parseMetadata(content, options?)` - Parse YAML frontmatter from markdown
164
- - `hasFrontmatter(content)` - Check if content has frontmatter
165
- - `validateMetadata(metadata)` - Validate metadata against schema
166
- - `extractRawFrontmatter(content)` - Extract raw frontmatter string
167
-
168
- ### Pattern Matching
169
-
170
- - `matchPattern(pattern, value)` - Match a single glob pattern
171
- - `matchAnyPattern(patterns, value)` - Match against multiple patterns
172
- - `filterByPatterns(patterns, values)` - Filter array by patterns
173
- - `evaluatePatterns({ value, include, exclude })` - Evaluate include/exclude rules
174
-
175
- ### Configuration
176
-
177
- - `loadConfig(options)` - Load configuration from all sources
178
- - `resolveOrganization(options)` - Resolve organization slug
179
- - `extractOrgFromRepoName(repoName)` - Extract org from repo name pattern
180
- - `getDefaultConfig(orgSlug)` - Get default configuration
181
-
182
- ### Routing
183
-
184
- - `shouldSyncToRepo(options)` - Determine if file should sync to repo
185
- - `getTargetRepos(options)` - Get all repos that should receive a file
186
-
187
- ## Configuration
188
-
189
- ### Environment Variables
190
-
191
- - `ORGANIZATION_SLUG` - Organization identifier
192
- - `CODEX_ORG_SLUG` - Alternative organization identifier
193
- - `CODEX_SOURCE_DIR` - Source directory (default: `.{org}`)
194
- - `CODEX_TARGET_DIR` - Target directory (default: `.{org}`)
195
- - `CODEX_PREVENT_SELF_SYNC` - Prevent self-sync (default: `true`)
196
- - `CODEX_ALLOW_PROJECT_OVERRIDES` - Allow project overrides (default: `true`)
197
-
198
- ### Auto-Sync Patterns
199
-
200
- Configure patterns that automatically sync to repositories:
201
-
202
- ```typescript
203
- const config = loadConfig({
204
- organizationSlug: 'fractary'
205
- })
206
-
207
- config.rules.autoSyncPatterns = [
208
- {
209
- pattern: '*/docs/schema/*.json',
210
- include: ['*'], // All repos
211
- exclude: []
212
- },
213
- {
214
- pattern: '*/security/**/*.md',
215
- include: ['*'],
216
- exclude: ['*-public']
217
- }
218
- ]
219
- ```
220
-
221
- ## Development
222
-
223
- ```bash
224
- # Install dependencies
225
- npm install
226
-
227
- # Build
228
- npm run build
229
-
230
- # Test
231
- npm test
232
-
233
- # Test with coverage
234
- npm run test:coverage
235
-
236
- # Type check
237
- npm run typecheck
238
- ```
239
-
240
- ## Project Structure
241
-
242
- ```
243
- src/
244
- ├── core/
245
- │ ├── metadata/ # Frontmatter parsing
246
- │ ├── patterns/ # Pattern matching
247
- │ ├── routing/ # Sync routing logic
248
- │ └── config/ # Configuration system
249
- ├── schemas/ # Zod schemas
250
- ├── errors/ # Error classes
251
- └── index.ts # Main exports
252
-
253
- tests/
254
- ├── unit/ # Unit tests
255
- └── fixtures/ # Test fixtures
256
- ```
257
-
258
- ## Specifications
259
-
260
- Detailed specifications are available in `/docs/specs/`:
261
-
262
- - [SPEC-00001: Core SDK Overview](./docs/specs/SPEC-00001-core-sdk-overview.md)
263
- - [SPEC-00002: Metadata Parsing](./docs/specs/SPEC-00002-metadata-parsing.md)
264
- - [SPEC-00003: Pattern Matching](./docs/specs/SPEC-00003-pattern-matching.md)
265
- - [SPEC-00004: Routing & Distribution](./docs/specs/SPEC-00004-routing-distribution.md)
266
- - [SPEC-00005: Configuration System](./docs/specs/SPEC-00005-configuration-system.md)
267
-
268
- ## Related Projects
269
-
270
- - **fractary-cli** - Unified CLI for all Fractary tools (coming soon)
271
- - **forge-bundle-codex-github-core** - GitHub Actions workflows for codex sync
272
- - **forge-bundle-codex-claude-agents** - Claude Code agents for codex management
273
-
274
- ## License
275
-
276
- MIT © Fractary Engineering
277
-
278
- ## Contributing
279
-
280
- This is part of the Fractary ecosystem. For issues or contributions, please refer to the [main 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
  }