@fractary/codex-cli 0.10.26 → 0.10.28
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/cli.cjs +44 -8
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +45 -9
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -150,10 +150,13 @@ async function isValidGitRepo(repoPath) {
|
|
|
150
150
|
return false;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
function getCodexRepoUrl(config) {
|
|
153
|
+
function getCodexRepoUrl(config, token) {
|
|
154
154
|
const codexRepo = config.codex_repo || "codex";
|
|
155
155
|
validateGitHubName(config.organization, "organization");
|
|
156
156
|
validateGitHubName(codexRepo, "repository");
|
|
157
|
+
if (token) {
|
|
158
|
+
return `https://x-access-token:${encodeURIComponent(token)}@github.com/${config.organization}/${codexRepo}.git`;
|
|
159
|
+
}
|
|
157
160
|
return `https://github.com/${config.organization}/${codexRepo}.git`;
|
|
158
161
|
}
|
|
159
162
|
async function execGit(repoPath, args) {
|
|
@@ -217,6 +220,10 @@ async function ensureCodexCloned(config, options) {
|
|
|
217
220
|
const branch = options?.branch || "main";
|
|
218
221
|
if (await isValidGitRepo(tempPath) && !options?.force) {
|
|
219
222
|
try {
|
|
223
|
+
if (options?.token) {
|
|
224
|
+
const repoUrl2 = getCodexRepoUrl(config, options.token);
|
|
225
|
+
await execGit(tempPath, ["remote", "set-url", "origin", repoUrl2]);
|
|
226
|
+
}
|
|
220
227
|
await gitFetch(tempPath, branch);
|
|
221
228
|
await gitCheckout(tempPath, branch);
|
|
222
229
|
await gitPull(tempPath);
|
|
@@ -227,7 +234,7 @@ async function ensureCodexCloned(config, options) {
|
|
|
227
234
|
await fs2__namespace.rm(tempPath, { recursive: true, force: true });
|
|
228
235
|
}
|
|
229
236
|
}
|
|
230
|
-
const repoUrl = getCodexRepoUrl(config);
|
|
237
|
+
const repoUrl = getCodexRepoUrl(config, options?.token);
|
|
231
238
|
try {
|
|
232
239
|
await fs2__namespace.rm(tempPath, { recursive: true, force: true });
|
|
233
240
|
} catch (error) {
|
|
@@ -977,6 +984,23 @@ function syncCommand() {
|
|
|
977
984
|
const cmd = new commander.Command("sync");
|
|
978
985
|
cmd.description("Sync single project with codex repository").argument("[name]", "Project name (auto-detected if not provided)").option("--env <env>", "Target environment (dev/test/staging/prod)", "prod").option("--dry-run", "Show what would sync without executing").option("--direction <dir>", "Sync direction (to-codex/from-codex/bidirectional)", "bidirectional").option("--include <pattern>", "Include files matching pattern (can be used multiple times)", (val, prev) => prev.concat([val]), []).option("--exclude <pattern>", "Exclude files matching pattern (can be used multiple times)", (val, prev) => prev.concat([val]), []).option("--force", "Force sync without checking timestamps").option("--json", "Output as JSON").option("--work-id <id>", "GitHub issue number or URL to scope sync to").action(async (name, options) => {
|
|
979
986
|
try {
|
|
987
|
+
const envFilePath = path3__namespace.join(process.cwd(), ".fractary", "env", ".env");
|
|
988
|
+
try {
|
|
989
|
+
const { readFile } = await import('fs/promises');
|
|
990
|
+
const envContent = await readFile(envFilePath, "utf-8");
|
|
991
|
+
for (const line of envContent.split("\n")) {
|
|
992
|
+
const trimmed = line.trim();
|
|
993
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
994
|
+
const eqIdx = trimmed.indexOf("=");
|
|
995
|
+
if (eqIdx === -1) continue;
|
|
996
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
997
|
+
const val = trimmed.slice(eqIdx + 1).trim().replace(/^["']|["']$/g, "");
|
|
998
|
+
if (key && !process.env[key]) {
|
|
999
|
+
process.env[key] = val;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
} catch {
|
|
1003
|
+
}
|
|
980
1004
|
const configPath = path3__namespace.join(process.cwd(), ".fractary", "config.yaml");
|
|
981
1005
|
let config;
|
|
982
1006
|
try {
|
|
@@ -1008,6 +1032,7 @@ function syncCommand() {
|
|
|
1008
1032
|
}
|
|
1009
1033
|
const direction = options.direction;
|
|
1010
1034
|
const targetBranch = getEnvironmentBranch(config, options.env);
|
|
1035
|
+
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN || void 0;
|
|
1011
1036
|
const localStorage = createLocalStorage({
|
|
1012
1037
|
baseDir: process.cwd()
|
|
1013
1038
|
});
|
|
@@ -1047,14 +1072,19 @@ function syncCommand() {
|
|
|
1047
1072
|
console.error(chalk10__default.default.yellow(`Warning: Invalid pattern "${pattern}": ${error.message}`));
|
|
1048
1073
|
}
|
|
1049
1074
|
}
|
|
1075
|
+
const fsModuleLocal = await import('fs/promises');
|
|
1050
1076
|
const targetFiles = await Promise.all(
|
|
1051
1077
|
Array.from(matchedFilePaths).map(async (filePath) => {
|
|
1052
1078
|
const fullPath = path3__namespace.join(sourceDir, filePath);
|
|
1053
|
-
const stats = await
|
|
1079
|
+
const [stats, content] = await Promise.all([
|
|
1080
|
+
fsModuleLocal.stat(fullPath),
|
|
1081
|
+
fsModuleLocal.readFile(fullPath)
|
|
1082
|
+
]);
|
|
1054
1083
|
return {
|
|
1055
1084
|
path: filePath,
|
|
1056
1085
|
size: stats.size,
|
|
1057
|
-
mtime: stats.mtimeMs
|
|
1086
|
+
mtime: stats.mtimeMs,
|
|
1087
|
+
hash: codex.calculateContentHash(content)
|
|
1058
1088
|
};
|
|
1059
1089
|
})
|
|
1060
1090
|
);
|
|
@@ -1077,7 +1107,8 @@ function syncCommand() {
|
|
|
1077
1107
|
console.log(chalk10__default.default.blue("\u2139 Cloning/updating codex repository..."));
|
|
1078
1108
|
}
|
|
1079
1109
|
codexRepoPath = await ensureCodexCloned2(config, {
|
|
1080
|
-
branch: targetBranch
|
|
1110
|
+
branch: targetBranch,
|
|
1111
|
+
token
|
|
1081
1112
|
});
|
|
1082
1113
|
if (!options.json) {
|
|
1083
1114
|
console.log(chalk10__default.default.dim(` Codex cloned to: ${codexRepoPath}`));
|
|
@@ -1133,7 +1164,8 @@ function syncCommand() {
|
|
|
1133
1164
|
console.log(chalk10__default.default.blue("\u2139 Cloning/updating codex repository..."));
|
|
1134
1165
|
}
|
|
1135
1166
|
codexRepoPath = await ensureCodexCloned2(config, {
|
|
1136
|
-
branch: targetBranch
|
|
1167
|
+
branch: targetBranch,
|
|
1168
|
+
token
|
|
1137
1169
|
});
|
|
1138
1170
|
if (!options.json) {
|
|
1139
1171
|
console.log(chalk10__default.default.dim(` Codex cloned to: ${codexRepoPath}`));
|
|
@@ -1155,11 +1187,15 @@ function syncCommand() {
|
|
|
1155
1187
|
existingCodexFiles = await Promise.all(
|
|
1156
1188
|
codexGlobMatches.map(async (filePath) => {
|
|
1157
1189
|
const fullPath = path3__namespace.join(codexProjectDir, filePath);
|
|
1158
|
-
const stats = await
|
|
1190
|
+
const [stats, content] = await Promise.all([
|
|
1191
|
+
fsPromises.stat(fullPath),
|
|
1192
|
+
fsPromises.readFile(fullPath)
|
|
1193
|
+
]);
|
|
1159
1194
|
return {
|
|
1160
1195
|
path: filePath,
|
|
1161
1196
|
size: stats.size,
|
|
1162
|
-
mtime: stats.mtimeMs
|
|
1197
|
+
mtime: stats.mtimeMs,
|
|
1198
|
+
hash: codex.calculateContentHash(content)
|
|
1163
1199
|
};
|
|
1164
1200
|
})
|
|
1165
1201
|
);
|