@fractary/codex-cli 0.10.27 → 0.10.29

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.js CHANGED
@@ -118,10 +118,13 @@ async function isValidGitRepo(repoPath) {
118
118
  return false;
119
119
  }
120
120
  }
121
- function getCodexRepoUrl(config) {
121
+ function getCodexRepoUrl(config, token) {
122
122
  const codexRepo = config.codex_repo || "codex";
123
123
  validateGitHubName(config.organization, "organization");
124
124
  validateGitHubName(codexRepo, "repository");
125
+ if (token) {
126
+ return `https://x-access-token:${encodeURIComponent(token)}@github.com/${config.organization}/${codexRepo}.git`;
127
+ }
125
128
  return `https://github.com/${config.organization}/${codexRepo}.git`;
126
129
  }
127
130
  async function execGit(repoPath, args) {
@@ -185,6 +188,10 @@ async function ensureCodexCloned(config, options) {
185
188
  const branch = options?.branch || "main";
186
189
  if (await isValidGitRepo(tempPath) && !options?.force) {
187
190
  try {
191
+ if (options?.token) {
192
+ const repoUrl2 = getCodexRepoUrl(config, options.token);
193
+ await execGit(tempPath, ["remote", "set-url", "origin", repoUrl2]);
194
+ }
188
195
  await gitFetch(tempPath, branch);
189
196
  await gitCheckout(tempPath, branch);
190
197
  await gitPull(tempPath);
@@ -195,7 +202,7 @@ async function ensureCodexCloned(config, options) {
195
202
  await fs2.rm(tempPath, { recursive: true, force: true });
196
203
  }
197
204
  }
198
- const repoUrl = getCodexRepoUrl(config);
205
+ const repoUrl = getCodexRepoUrl(config, options?.token);
199
206
  try {
200
207
  await fs2.rm(tempPath, { recursive: true, force: true });
201
208
  } catch (error) {
@@ -945,6 +952,23 @@ function syncCommand() {
945
952
  const cmd = new Command("sync");
946
953
  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) => {
947
954
  try {
955
+ const envFilePath = path4.join(process.cwd(), ".fractary", "env", ".env");
956
+ try {
957
+ const { readFile } = await import('fs/promises');
958
+ const envContent = await readFile(envFilePath, "utf-8");
959
+ for (const line of envContent.split("\n")) {
960
+ const trimmed = line.trim();
961
+ if (!trimmed || trimmed.startsWith("#")) continue;
962
+ const eqIdx = trimmed.indexOf("=");
963
+ if (eqIdx === -1) continue;
964
+ const key = trimmed.slice(0, eqIdx).trim();
965
+ const val = trimmed.slice(eqIdx + 1).trim().replace(/^["']|["']$/g, "");
966
+ if (key && !process.env[key]) {
967
+ process.env[key] = val;
968
+ }
969
+ }
970
+ } catch {
971
+ }
948
972
  const configPath = path4.join(process.cwd(), ".fractary", "config.yaml");
949
973
  let config;
950
974
  try {
@@ -976,6 +1000,7 @@ function syncCommand() {
976
1000
  }
977
1001
  const direction = options.direction;
978
1002
  const targetBranch = getEnvironmentBranch(config, options.env);
1003
+ const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN || void 0;
979
1004
  const localStorage = createLocalStorage({
980
1005
  baseDir: process.cwd()
981
1006
  });
@@ -1050,7 +1075,8 @@ function syncCommand() {
1050
1075
  console.log(chalk10.blue("\u2139 Cloning/updating codex repository..."));
1051
1076
  }
1052
1077
  codexRepoPath = await ensureCodexCloned2(config, {
1053
- branch: targetBranch
1078
+ branch: targetBranch,
1079
+ token
1054
1080
  });
1055
1081
  if (!options.json) {
1056
1082
  console.log(chalk10.dim(` Codex cloned to: ${codexRepoPath}`));
@@ -1106,7 +1132,8 @@ function syncCommand() {
1106
1132
  console.log(chalk10.blue("\u2139 Cloning/updating codex repository..."));
1107
1133
  }
1108
1134
  codexRepoPath = await ensureCodexCloned2(config, {
1109
- branch: targetBranch
1135
+ branch: targetBranch,
1136
+ token
1110
1137
  });
1111
1138
  if (!options.json) {
1112
1139
  console.log(chalk10.dim(` Codex cloned to: ${codexRepoPath}`));