@fractary/codex-cli 0.10.27 → 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 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
  });
@@ -1082,7 +1107,8 @@ function syncCommand() {
1082
1107
  console.log(chalk10__default.default.blue("\u2139 Cloning/updating codex repository..."));
1083
1108
  }
1084
1109
  codexRepoPath = await ensureCodexCloned2(config, {
1085
- branch: targetBranch
1110
+ branch: targetBranch,
1111
+ token
1086
1112
  });
1087
1113
  if (!options.json) {
1088
1114
  console.log(chalk10__default.default.dim(` Codex cloned to: ${codexRepoPath}`));
@@ -1138,7 +1164,8 @@ function syncCommand() {
1138
1164
  console.log(chalk10__default.default.blue("\u2139 Cloning/updating codex repository..."));
1139
1165
  }
1140
1166
  codexRepoPath = await ensureCodexCloned2(config, {
1141
- branch: targetBranch
1167
+ branch: targetBranch,
1168
+ token
1142
1169
  });
1143
1170
  if (!options.json) {
1144
1171
  console.log(chalk10__default.default.dim(` Codex cloned to: ${codexRepoPath}`));