@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.js CHANGED
@@ -65,6 +65,9 @@ function matchFromCodexPattern(codexFilePath, patterns, targetProject) {
65
65
  return false;
66
66
  }
67
67
  return patterns.some((pattern) => {
68
+ if (pattern.startsWith("projects/")) {
69
+ return matchPattern(pattern, codexFilePath);
70
+ }
68
71
  const projectSeparatorIndex = pattern.indexOf("/");
69
72
  if (projectSeparatorIndex === -1) {
70
73
  const fullPattern = `${targetProject}/${pattern}`;
@@ -2909,6 +2912,14 @@ async function scanCodexWithRouting(options) {
2909
2912
  function extractProjectFromPath(filePath, org) {
2910
2913
  const normalizedPath = filePath.replace(/\\/g, "/");
2911
2914
  const withoutOrg = normalizedPath.startsWith(`${org}/`) ? normalizedPath.slice(org.length + 1) : normalizedPath;
2915
+ if (withoutOrg.startsWith("projects/")) {
2916
+ const afterProjects = withoutOrg.slice("projects/".length);
2917
+ const firstSlash2 = afterProjects.indexOf("/");
2918
+ if (firstSlash2 === -1) {
2919
+ return afterProjects;
2920
+ }
2921
+ return afterProjects.slice(0, firstSlash2);
2922
+ }
2912
2923
  const firstSlash = withoutOrg.indexOf("/");
2913
2924
  if (firstSlash === -1) {
2914
2925
  return withoutOrg;
@@ -3095,16 +3106,19 @@ var SyncManager = class {
3095
3106
  };
3096
3107
  const plan = createSyncPlan(sourceFiles, targetFiles, planOptions, this.config);
3097
3108
  plan.estimatedTime = estimateSyncTime(plan);
3109
+ plan.source = codexDir;
3110
+ plan.target = ".fractary/codex/cache";
3098
3111
  return {
3099
3112
  ...plan,
3100
3113
  routingScan
3101
3114
  };
3102
3115
  }
3103
3116
  /**
3104
- * Execute a sync plan (dry run)
3117
+ * Execute a sync plan
3105
3118
  *
3106
- * In a real implementation, this would actually copy files.
3107
- * For the SDK, we provide the plan and let consumers execute.
3119
+ * Copies files from source to target based on the plan.
3120
+ * For from-codex syncs, files are copied to .fractary/codex/cache/ preserving full paths.
3121
+ * For to-codex syncs, files are copied to the codex repository.
3108
3122
  */
3109
3123
  async executePlan(plan, options) {
3110
3124
  const startTime = Date.now();
@@ -3130,7 +3144,30 @@ var SyncManager = class {
3130
3144
  if (options?.onProgress) {
3131
3145
  options.onProgress(i + 1, plan.totalFiles, file.path);
3132
3146
  }
3133
- synced++;
3147
+ if (file.operation === "create" || file.operation === "update") {
3148
+ const sourcePath = `${plan.source}/${file.path}`;
3149
+ const targetPath = `${plan.target}/${file.path}`;
3150
+ const fs4 = await import('fs/promises');
3151
+ const path6 = await import('path');
3152
+ const targetDir = path6.dirname(targetPath);
3153
+ await fs4.mkdir(targetDir, { recursive: true });
3154
+ await fs4.copyFile(sourcePath, targetPath);
3155
+ synced++;
3156
+ } else if (file.operation === "delete") {
3157
+ const targetPath = `${plan.target}/${file.path}`;
3158
+ const fs4 = await import('fs/promises');
3159
+ try {
3160
+ await fs4.unlink(targetPath);
3161
+ synced++;
3162
+ } catch (error) {
3163
+ if (error.code !== "ENOENT") {
3164
+ throw error;
3165
+ }
3166
+ synced++;
3167
+ }
3168
+ } else {
3169
+ synced++;
3170
+ }
3134
3171
  } catch (error) {
3135
3172
  failed++;
3136
3173
  errors.push({