@fractary/codex 0.11.1 → 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 +56 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +56 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1745,6 +1745,12 @@ interface SyncOptions {
|
|
|
1745
1745
|
maxFiles?: number;
|
|
1746
1746
|
timeout?: number;
|
|
1747
1747
|
onProgress?: (current: number, total: number, file: string) => void;
|
|
1748
|
+
sourceFiles?: Array<{
|
|
1749
|
+
path: string;
|
|
1750
|
+
size: number;
|
|
1751
|
+
mtime: number;
|
|
1752
|
+
hash?: string;
|
|
1753
|
+
}>;
|
|
1748
1754
|
}
|
|
1749
1755
|
interface SyncRule {
|
|
1750
1756
|
pattern: string;
|
|
@@ -1859,7 +1865,9 @@ declare class SyncManager {
|
|
|
1859
1865
|
getOrCreateManifest(org: string, project: string): Promise<SyncManifest>;
|
|
1860
1866
|
listLocalFiles(directory: string): Promise<FileInfo[]>;
|
|
1861
1867
|
createPlan(_org: string, _project: string, sourceDir: string, targetFiles: FileInfo[], options?: SyncOptions): Promise<SyncPlan>;
|
|
1862
|
-
createRoutingAwarePlan(org: string, project: string, codexDir: string, options?: SyncOptions
|
|
1868
|
+
createRoutingAwarePlan(org: string, project: string, codexDir: string, options?: SyncOptions & {
|
|
1869
|
+
codexRepo?: string;
|
|
1870
|
+
}): Promise<SyncPlan & {
|
|
1863
1871
|
routingScan?: RoutingScanResult;
|
|
1864
1872
|
}>;
|
|
1865
1873
|
executePlan(plan: SyncPlan, options?: SyncOptions): Promise<SyncResult>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1745,6 +1745,12 @@ interface SyncOptions {
|
|
|
1745
1745
|
maxFiles?: number;
|
|
1746
1746
|
timeout?: number;
|
|
1747
1747
|
onProgress?: (current: number, total: number, file: string) => void;
|
|
1748
|
+
sourceFiles?: Array<{
|
|
1749
|
+
path: string;
|
|
1750
|
+
size: number;
|
|
1751
|
+
mtime: number;
|
|
1752
|
+
hash?: string;
|
|
1753
|
+
}>;
|
|
1748
1754
|
}
|
|
1749
1755
|
interface SyncRule {
|
|
1750
1756
|
pattern: string;
|
|
@@ -1859,7 +1865,9 @@ declare class SyncManager {
|
|
|
1859
1865
|
getOrCreateManifest(org: string, project: string): Promise<SyncManifest>;
|
|
1860
1866
|
listLocalFiles(directory: string): Promise<FileInfo[]>;
|
|
1861
1867
|
createPlan(_org: string, _project: string, sourceDir: string, targetFiles: FileInfo[], options?: SyncOptions): Promise<SyncPlan>;
|
|
1862
|
-
createRoutingAwarePlan(org: string, project: string, codexDir: string, options?: SyncOptions
|
|
1868
|
+
createRoutingAwarePlan(org: string, project: string, codexDir: string, options?: SyncOptions & {
|
|
1869
|
+
codexRepo?: string;
|
|
1870
|
+
}): Promise<SyncPlan & {
|
|
1863
1871
|
routingScan?: RoutingScanResult;
|
|
1864
1872
|
}>;
|
|
1865
1873
|
executePlan(plan: SyncPlan, options?: SyncOptions): Promise<SyncResult>;
|
package/dist/index.js
CHANGED
|
@@ -63,11 +63,14 @@ function matchToCodexPattern(filePath, patterns) {
|
|
|
63
63
|
}
|
|
64
64
|
return patterns.some((pattern) => matchPattern(pattern, filePath));
|
|
65
65
|
}
|
|
66
|
-
function matchFromCodexPattern(codexFilePath, patterns, targetProject) {
|
|
66
|
+
function matchFromCodexPattern(codexFilePath, patterns, targetProject, options) {
|
|
67
67
|
if (!patterns || patterns.length === 0) {
|
|
68
68
|
return false;
|
|
69
69
|
}
|
|
70
70
|
return patterns.some((pattern) => {
|
|
71
|
+
if (pattern.startsWith(CODEX_URI_PREFIX2)) {
|
|
72
|
+
return matchCodexUri(pattern, codexFilePath, targetProject, options);
|
|
73
|
+
}
|
|
71
74
|
if (pattern.startsWith("projects/")) {
|
|
72
75
|
return matchPattern(pattern, codexFilePath);
|
|
73
76
|
}
|
|
@@ -85,6 +88,21 @@ function matchFromCodexPattern(codexFilePath, patterns, targetProject) {
|
|
|
85
88
|
}
|
|
86
89
|
});
|
|
87
90
|
}
|
|
91
|
+
function matchCodexUri(uriPattern, codexFilePath, targetProject, options) {
|
|
92
|
+
let withoutPrefix = uriPattern.slice(CODEX_URI_PREFIX2.length);
|
|
93
|
+
withoutPrefix = withoutPrefix.replace(/{org}/g, options?.org || "").replace(/{project}/g, targetProject).replace(/{codex_repo}/g, options?.codexRepo || "");
|
|
94
|
+
const parts = withoutPrefix.split("/");
|
|
95
|
+
if (parts.length < 2) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
const project = parts[1];
|
|
99
|
+
const pathPattern = parts.slice(2).join("/");
|
|
100
|
+
if (!project) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const fullPattern = pathPattern ? `projects/${project}/${pathPattern}` : `projects/${project}/**`;
|
|
104
|
+
return matchPattern(fullPattern, codexFilePath);
|
|
105
|
+
}
|
|
88
106
|
function extractProjectFromCodexPath(codexFilePath) {
|
|
89
107
|
const firstSlashIndex = codexFilePath.indexOf("/");
|
|
90
108
|
if (firstSlashIndex === -1) {
|
|
@@ -99,15 +117,26 @@ function getRelativePath(codexFilePath) {
|
|
|
99
117
|
}
|
|
100
118
|
return codexFilePath.substring(firstSlashIndex + 1);
|
|
101
119
|
}
|
|
102
|
-
function expandPlaceholders(patterns, targetProject) {
|
|
120
|
+
function expandPlaceholders(patterns, targetProject, options) {
|
|
103
121
|
if (!patterns) {
|
|
104
122
|
return patterns;
|
|
105
123
|
}
|
|
106
|
-
return patterns.map((pattern) =>
|
|
124
|
+
return patterns.map((pattern) => {
|
|
125
|
+
let expanded = pattern.replace(/{project}/g, targetProject);
|
|
126
|
+
if (options?.org) {
|
|
127
|
+
expanded = expanded.replace(/{org}/g, options.org);
|
|
128
|
+
}
|
|
129
|
+
if (options?.codexRepo) {
|
|
130
|
+
expanded = expanded.replace(/{codex_repo}/g, options.codexRepo);
|
|
131
|
+
}
|
|
132
|
+
return expanded;
|
|
133
|
+
});
|
|
107
134
|
}
|
|
135
|
+
var CODEX_URI_PREFIX2;
|
|
108
136
|
var init_directional_patterns = __esm({
|
|
109
137
|
"src/sync/directional-patterns.ts"() {
|
|
110
138
|
init_matcher();
|
|
139
|
+
CODEX_URI_PREFIX2 = "codex://";
|
|
111
140
|
}
|
|
112
141
|
});
|
|
113
142
|
|
|
@@ -3505,6 +3534,7 @@ async function scanCodexWithRouting(options) {
|
|
|
3505
3534
|
codexDir,
|
|
3506
3535
|
targetProject,
|
|
3507
3536
|
org,
|
|
3537
|
+
codexRepo,
|
|
3508
3538
|
rules,
|
|
3509
3539
|
storage,
|
|
3510
3540
|
skipNoFrontmatter = false,
|
|
@@ -3523,7 +3553,10 @@ async function scanCodexWithRouting(options) {
|
|
|
3523
3553
|
if (fromCodexPatterns && fromCodexPatterns.length > 0) {
|
|
3524
3554
|
const module = await Promise.resolve().then(() => (init_directional_patterns(), directional_patterns_exports));
|
|
3525
3555
|
matchFromCodexPattern2 = module.matchFromCodexPattern;
|
|
3526
|
-
expandedFromCodexPatterns = module.expandPlaceholders(fromCodexPatterns, targetProject
|
|
3556
|
+
expandedFromCodexPatterns = module.expandPlaceholders(fromCodexPatterns, targetProject, {
|
|
3557
|
+
org,
|
|
3558
|
+
codexRepo
|
|
3559
|
+
});
|
|
3527
3560
|
}
|
|
3528
3561
|
const allFiles = await listAllFilesRecursive(codexDir);
|
|
3529
3562
|
for (const filePath of allFiles) {
|
|
@@ -3545,7 +3578,10 @@ async function scanCodexWithRouting(options) {
|
|
|
3545
3578
|
let parseResult = null;
|
|
3546
3579
|
const useFrontmatter = options.routing?.use_frontmatter === true;
|
|
3547
3580
|
if (matchFromCodexPattern2 && expandedFromCodexPatterns && expandedFromCodexPatterns.length > 0) {
|
|
3548
|
-
shouldSync = matchFromCodexPattern2(filePath, expandedFromCodexPatterns, targetProject
|
|
3581
|
+
shouldSync = matchFromCodexPattern2(filePath, expandedFromCodexPatterns, targetProject, {
|
|
3582
|
+
org,
|
|
3583
|
+
codexRepo
|
|
3584
|
+
});
|
|
3549
3585
|
parseResult = parseMetadata(content, { strict: false });
|
|
3550
3586
|
} else if (useFrontmatter) {
|
|
3551
3587
|
parseResult = parseMetadata(content, { strict: false });
|
|
@@ -3769,14 +3805,19 @@ var SyncManager = class {
|
|
|
3769
3805
|
* @param options - Sync options
|
|
3770
3806
|
*/
|
|
3771
3807
|
async createPlan(_org, _project, sourceDir, targetFiles, options) {
|
|
3772
|
-
let sourceFiles
|
|
3773
|
-
if (options?.
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
)
|
|
3808
|
+
let sourceFiles;
|
|
3809
|
+
if (options?.sourceFiles && options.sourceFiles.length > 0) {
|
|
3810
|
+
sourceFiles = options.sourceFiles;
|
|
3811
|
+
} else {
|
|
3812
|
+
sourceFiles = await this.listLocalFiles(sourceDir);
|
|
3813
|
+
if (options?.direction === "to-codex") {
|
|
3814
|
+
const toCodexPatterns = this.resolveToCodexPatterns();
|
|
3815
|
+
if (toCodexPatterns.length > 0) {
|
|
3816
|
+
const { matchToCodexPattern: matchToCodexPattern2 } = await Promise.resolve().then(() => (init_directional_patterns(), directional_patterns_exports));
|
|
3817
|
+
sourceFiles = sourceFiles.filter(
|
|
3818
|
+
(file) => matchToCodexPattern2(file.path, toCodexPatterns)
|
|
3819
|
+
);
|
|
3820
|
+
}
|
|
3780
3821
|
}
|
|
3781
3822
|
}
|
|
3782
3823
|
const plan = createSyncPlan(
|
|
@@ -3821,6 +3862,8 @@ var SyncManager = class {
|
|
|
3821
3862
|
codexDir,
|
|
3822
3863
|
targetProject: project,
|
|
3823
3864
|
org,
|
|
3865
|
+
codexRepo: options?.codexRepo,
|
|
3866
|
+
// For codex:// URI {codex_repo} placeholder
|
|
3824
3867
|
rules: void 0,
|
|
3825
3868
|
// Use default routing rules (preventSelfSync, preventCodexSync, etc.)
|
|
3826
3869
|
storage: this.localStorage,
|