@fractary/codex 0.11.2 → 0.12.0

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/dist/index.cjs CHANGED
@@ -88,11 +88,14 @@ function matchToCodexPattern(filePath, patterns) {
88
88
  }
89
89
  return patterns.some((pattern) => matchPattern(pattern, filePath));
90
90
  }
91
- function matchFromCodexPattern(codexFilePath, patterns, targetProject) {
91
+ function matchFromCodexPattern(codexFilePath, patterns, targetProject, options) {
92
92
  if (!patterns || patterns.length === 0) {
93
93
  return false;
94
94
  }
95
95
  return patterns.some((pattern) => {
96
+ if (pattern.startsWith(CODEX_URI_PREFIX2)) {
97
+ return matchCodexUri(pattern, codexFilePath, targetProject, options);
98
+ }
96
99
  if (pattern.startsWith("projects/")) {
97
100
  return matchPattern(pattern, codexFilePath);
98
101
  }
@@ -110,6 +113,21 @@ function matchFromCodexPattern(codexFilePath, patterns, targetProject) {
110
113
  }
111
114
  });
112
115
  }
116
+ function matchCodexUri(uriPattern, codexFilePath, targetProject, options) {
117
+ let withoutPrefix = uriPattern.slice(CODEX_URI_PREFIX2.length);
118
+ withoutPrefix = withoutPrefix.replace(/{org}/g, options?.org || "").replace(/{project}/g, targetProject).replace(/{codex_repo}/g, options?.codexRepo || "");
119
+ const parts = withoutPrefix.split("/");
120
+ if (parts.length < 2) {
121
+ return false;
122
+ }
123
+ const project = parts[1];
124
+ const pathPattern = parts.slice(2).join("/");
125
+ if (!project) {
126
+ return false;
127
+ }
128
+ const fullPattern = pathPattern ? `projects/${project}/${pathPattern}` : `projects/${project}/**`;
129
+ return matchPattern(fullPattern, codexFilePath);
130
+ }
113
131
  function extractProjectFromCodexPath(codexFilePath) {
114
132
  const firstSlashIndex = codexFilePath.indexOf("/");
115
133
  if (firstSlashIndex === -1) {
@@ -124,15 +142,26 @@ function getRelativePath(codexFilePath) {
124
142
  }
125
143
  return codexFilePath.substring(firstSlashIndex + 1);
126
144
  }
127
- function expandPlaceholders(patterns, targetProject) {
145
+ function expandPlaceholders(patterns, targetProject, options) {
128
146
  if (!patterns) {
129
147
  return patterns;
130
148
  }
131
- return patterns.map((pattern) => pattern.replace(/{project}/g, targetProject));
149
+ return patterns.map((pattern) => {
150
+ let expanded = pattern.replace(/{project}/g, targetProject);
151
+ if (options?.org) {
152
+ expanded = expanded.replace(/{org}/g, options.org);
153
+ }
154
+ if (options?.codexRepo) {
155
+ expanded = expanded.replace(/{codex_repo}/g, options.codexRepo);
156
+ }
157
+ return expanded;
158
+ });
132
159
  }
160
+ var CODEX_URI_PREFIX2;
133
161
  var init_directional_patterns = __esm({
134
162
  "src/sync/directional-patterns.ts"() {
135
163
  init_matcher();
164
+ CODEX_URI_PREFIX2 = "codex://";
136
165
  }
137
166
  });
138
167
 
@@ -3530,6 +3559,7 @@ async function scanCodexWithRouting(options) {
3530
3559
  codexDir,
3531
3560
  targetProject,
3532
3561
  org,
3562
+ codexRepo,
3533
3563
  rules,
3534
3564
  storage,
3535
3565
  skipNoFrontmatter = false,
@@ -3548,7 +3578,10 @@ async function scanCodexWithRouting(options) {
3548
3578
  if (fromCodexPatterns && fromCodexPatterns.length > 0) {
3549
3579
  const module = await Promise.resolve().then(() => (init_directional_patterns(), directional_patterns_exports));
3550
3580
  matchFromCodexPattern2 = module.matchFromCodexPattern;
3551
- expandedFromCodexPatterns = module.expandPlaceholders(fromCodexPatterns, targetProject);
3581
+ expandedFromCodexPatterns = module.expandPlaceholders(fromCodexPatterns, targetProject, {
3582
+ org,
3583
+ codexRepo
3584
+ });
3552
3585
  }
3553
3586
  const allFiles = await listAllFilesRecursive(codexDir);
3554
3587
  for (const filePath of allFiles) {
@@ -3570,7 +3603,10 @@ async function scanCodexWithRouting(options) {
3570
3603
  let parseResult = null;
3571
3604
  const useFrontmatter = options.routing?.use_frontmatter === true;
3572
3605
  if (matchFromCodexPattern2 && expandedFromCodexPatterns && expandedFromCodexPatterns.length > 0) {
3573
- shouldSync = matchFromCodexPattern2(filePath, expandedFromCodexPatterns, targetProject);
3606
+ shouldSync = matchFromCodexPattern2(filePath, expandedFromCodexPatterns, targetProject, {
3607
+ org,
3608
+ codexRepo
3609
+ });
3574
3610
  parseResult = parseMetadata(content, { strict: false });
3575
3611
  } else if (useFrontmatter) {
3576
3612
  parseResult = parseMetadata(content, { strict: false });
@@ -3851,6 +3887,8 @@ var SyncManager = class {
3851
3887
  codexDir,
3852
3888
  targetProject: project,
3853
3889
  org,
3890
+ codexRepo: options?.codexRepo,
3891
+ // For codex:// URI {codex_repo} placeholder
3854
3892
  rules: void 0,
3855
3893
  // Use default routing rules (preventSelfSync, preventCodexSync, etc.)
3856
3894
  storage: this.localStorage,