@fractary/codex 0.5.0 → 0.5.2

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
@@ -74,6 +74,9 @@ function matchFromCodexPattern(codexFilePath, patterns, targetProject) {
74
74
  return false;
75
75
  }
76
76
  return patterns.some((pattern) => {
77
+ if (pattern.startsWith("projects/")) {
78
+ return matchPattern(pattern, codexFilePath);
79
+ }
77
80
  const projectSeparatorIndex = pattern.indexOf("/");
78
81
  if (projectSeparatorIndex === -1) {
79
82
  const fullPattern = `${targetProject}/${pattern}`;
@@ -2918,6 +2921,14 @@ async function scanCodexWithRouting(options) {
2918
2921
  function extractProjectFromPath(filePath, org) {
2919
2922
  const normalizedPath = filePath.replace(/\\/g, "/");
2920
2923
  const withoutOrg = normalizedPath.startsWith(`${org}/`) ? normalizedPath.slice(org.length + 1) : normalizedPath;
2924
+ if (withoutOrg.startsWith("projects/")) {
2925
+ const afterProjects = withoutOrg.slice("projects/".length);
2926
+ const firstSlash2 = afterProjects.indexOf("/");
2927
+ if (firstSlash2 === -1) {
2928
+ return afterProjects;
2929
+ }
2930
+ return afterProjects.slice(0, firstSlash2);
2931
+ }
2921
2932
  const firstSlash = withoutOrg.indexOf("/");
2922
2933
  if (firstSlash === -1) {
2923
2934
  return withoutOrg;
@@ -3104,16 +3115,19 @@ var SyncManager = class {
3104
3115
  };
3105
3116
  const plan = createSyncPlan(sourceFiles, targetFiles, planOptions, this.config);
3106
3117
  plan.estimatedTime = estimateSyncTime(plan);
3118
+ plan.source = codexDir;
3119
+ plan.target = ".fractary/codex/cache";
3107
3120
  return {
3108
3121
  ...plan,
3109
3122
  routingScan
3110
3123
  };
3111
3124
  }
3112
3125
  /**
3113
- * Execute a sync plan (dry run)
3126
+ * Execute a sync plan
3114
3127
  *
3115
- * In a real implementation, this would actually copy files.
3116
- * For the SDK, we provide the plan and let consumers execute.
3128
+ * Copies files from source to target based on the plan.
3129
+ * For from-codex syncs, files are copied to .fractary/codex/cache/ preserving full paths.
3130
+ * For to-codex syncs, files are copied to the codex repository.
3117
3131
  */
3118
3132
  async executePlan(plan, options) {
3119
3133
  const startTime = Date.now();
@@ -3139,7 +3153,30 @@ var SyncManager = class {
3139
3153
  if (options?.onProgress) {
3140
3154
  options.onProgress(i + 1, plan.totalFiles, file.path);
3141
3155
  }
3142
- synced++;
3156
+ if (file.operation === "create" || file.operation === "update") {
3157
+ const sourcePath = `${plan.source}/${file.path}`;
3158
+ const targetPath = `${plan.target}/${file.path}`;
3159
+ const fs4 = await import('fs/promises');
3160
+ const path6 = await import('path');
3161
+ const targetDir = path6.dirname(targetPath);
3162
+ await fs4.mkdir(targetDir, { recursive: true });
3163
+ await fs4.copyFile(sourcePath, targetPath);
3164
+ synced++;
3165
+ } else if (file.operation === "delete") {
3166
+ const targetPath = `${plan.target}/${file.path}`;
3167
+ const fs4 = await import('fs/promises');
3168
+ try {
3169
+ await fs4.unlink(targetPath);
3170
+ synced++;
3171
+ } catch (error) {
3172
+ if (error.code !== "ENOENT") {
3173
+ throw error;
3174
+ }
3175
+ synced++;
3176
+ }
3177
+ } else {
3178
+ synced++;
3179
+ }
3143
3180
  } catch (error) {
3144
3181
  failed++;
3145
3182
  errors.push({