@saeed42/worktree-worker 1.4.0 → 1.4.1

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.
Files changed (2) hide show
  1. package/dist/main.js +42 -0
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -466,6 +466,48 @@ var GitService = class {
466
466
  const result = await this.exec(["remote", "get-url", remote], cwd);
467
467
  return result.code === 0 ? result.stdout.trim() : null;
468
468
  }
469
+ /**
470
+ * Configure git credential helper with token (temporary, for operations like worktree add)
471
+ * SECURITY: Token is stored in /tmp and should be cleared after operation
472
+ */
473
+ async configureCredentials(githubToken) {
474
+ const log = logger.child({ service: "git", operation: "configureCredentials" });
475
+ log.debug("Configuring git credentials");
476
+ await this.exec(["config", "--global", "credential.helper", "store --file=/tmp/.git-credentials"]);
477
+ await this.exec(["config", "--global", "core.askPass", ""]);
478
+ const { writeFile: writeFile2 } = await import("fs/promises");
479
+ const credLine = `https://x-access-token:${githubToken}@github.com
480
+ `;
481
+ await writeFile2("/tmp/.git-credentials", credLine, { mode: 384 });
482
+ log.debug("Git credentials configured");
483
+ }
484
+ /**
485
+ * Clear git credentials (call after operations complete)
486
+ */
487
+ async clearCredentials() {
488
+ const log = logger.child({ service: "git", operation: "clearCredentials" });
489
+ log.debug("Clearing git credentials");
490
+ const { unlink: unlink2 } = await import("fs/promises");
491
+ try {
492
+ await unlink2("/tmp/.git-credentials");
493
+ } catch {
494
+ }
495
+ await this.exec(["config", "--global", "--unset", "credential.helper"]).catch(() => {
496
+ });
497
+ log.debug("Git credentials cleared");
498
+ }
499
+ /**
500
+ * Run an operation with temporary credentials
501
+ * SECURITY: Credentials are cleared after operation completes (success or failure)
502
+ */
503
+ async withCredentials(githubToken, operation) {
504
+ await this.configureCredentials(githubToken);
505
+ try {
506
+ return await operation();
507
+ } finally {
508
+ await this.clearCredentials();
509
+ }
510
+ }
469
511
  };
470
512
  var gitService = new GitService();
471
513
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saeed42/worktree-worker",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Git worktree management service for AI agent trials",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",