staklink 0.3.16 → 0.3.18

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.
@@ -33610,11 +33610,15 @@ var Repo = class {
33610
33610
  }
33611
33611
  async branchExists(branch) {
33612
33612
  try {
33613
- const localCheck = await this.execCommand(`git show-ref --verify --quiet refs/heads/${branch}`).catch(() => null);
33613
+ const localCheck = await this.execCommand(
33614
+ `git show-ref --verify --quiet refs/heads/${branch}`
33615
+ ).catch(() => null);
33614
33616
  if (localCheck !== null) {
33615
33617
  return true;
33616
33618
  }
33617
- const remoteCheck = await this.execCommand(`git ls-remote --heads origin ${branch}`).catch(() => "");
33619
+ const remoteCheck = await this.execCommand(
33620
+ `git ls-remote --heads origin ${branch}`
33621
+ ).catch(() => "");
33618
33622
  return remoteCheck.trim().length > 0;
33619
33623
  } catch (e) {
33620
33624
  return false;
@@ -33635,6 +33639,9 @@ var Repo = class {
33635
33639
  }
33636
33640
  return branchName;
33637
33641
  }
33642
+ async checkout(branch) {
33643
+ return this.execCommand(`git checkout ${branch}`);
33644
+ }
33638
33645
  async checkoutNew(branch) {
33639
33646
  return this.execCommand(`git checkout -b ${branch}`);
33640
33647
  }
@@ -33928,7 +33935,7 @@ var SSEManager = class {
33928
33935
  var sseManager = new SSEManager();
33929
33936
 
33930
33937
  // src/proxy/version.ts
33931
- var VERSION = "0.3.16";
33938
+ var VERSION = "0.3.18";
33932
33939
 
33933
33940
  // node_modules/uuid/dist/esm/stringify.js
33934
33941
  var byteToHex = [];
@@ -33985,7 +33992,8 @@ var v4_default = v4;
33985
33992
  var REQS = {};
33986
33993
  var REQ_ORDER = [];
33987
33994
  var MAX_REQS = 100;
33988
- function startReq() {
33995
+ var BUSY_REQ_TYPES = /* @__PURE__ */ new Set();
33996
+ function startReq(req_type) {
33989
33997
  const key = v4_default();
33990
33998
  if (REQ_ORDER.length >= MAX_REQS) {
33991
33999
  const oldestKey = REQ_ORDER.shift();
@@ -33995,26 +34003,39 @@ function startReq() {
33995
34003
  }
33996
34004
  REQS[key] = {
33997
34005
  status: "pending",
33998
- result: void 0
34006
+ result: void 0,
34007
+ req_type
33999
34008
  };
34000
34009
  REQ_ORDER.push(key);
34010
+ if (req_type) {
34011
+ BUSY_REQ_TYPES.add(req_type);
34012
+ }
34001
34013
  return key;
34002
34014
  }
34003
34015
  function finishReq(id, result) {
34004
34016
  if (REQS[id]) {
34005
34017
  REQS[id].status = "completed";
34006
34018
  REQS[id].result = result;
34019
+ if (REQS[id].req_type) {
34020
+ BUSY_REQ_TYPES.delete(REQS[id].req_type);
34021
+ }
34007
34022
  }
34008
34023
  }
34009
34024
  function failReq(id, error82) {
34010
34025
  if (REQS[id]) {
34011
34026
  REQS[id].status = "failed";
34012
34027
  REQS[id].error = error82;
34028
+ if (REQS[id].req_type) {
34029
+ BUSY_REQ_TYPES.delete(REQS[id].req_type);
34030
+ }
34013
34031
  }
34014
34032
  }
34015
34033
  function checkReq(id) {
34016
34034
  return REQS[id];
34017
34035
  }
34036
+ function isReqTypeBusy(req_type) {
34037
+ return BUSY_REQ_TYPES.has(req_type);
34038
+ }
34018
34039
 
34019
34040
  // src/agent/utils.ts
34020
34041
  var proc5 = __toESM(require("child_process"), 1);
@@ -80333,29 +80354,48 @@ async function startProxyServer() {
80333
80354
  const repo = await NewRepo(r.url);
80334
80355
  const repoName = getRepoNameFromUrl(r.url);
80335
80356
  const stashCreated = await repo.stashDevcontainer();
80357
+ const requestedBranch = await repo.generateUniqueBranchName(r.branch_name);
80358
+ let currentBranch = (await repo.printCurrentBranch()).trim();
80359
+ console.log(`=> Current branch: ${currentBranch}`);
80360
+ console.log(`=> Requested branch: ${requestedBranch}`);
80361
+ if (currentBranch !== requestedBranch) {
80362
+ const branchExists = await repo.branchExists(requestedBranch);
80363
+ if (branchExists) {
80364
+ console.log(`=> Switching to existing branch: ${requestedBranch}`);
80365
+ await repo.checkout(requestedBranch);
80366
+ } else {
80367
+ console.log(`=> Creating new branch from current position: ${requestedBranch}`);
80368
+ await repo.checkoutNew(requestedBranch);
80369
+ }
80370
+ } else {
80371
+ console.log(`=> Already on correct branch: ${requestedBranch}`);
80372
+ }
80336
80373
  if (shouldCommit) {
80337
80374
  console.log(`=> COMMIT to ${r.url}`);
80338
80375
  console.log(`=> COMMIT in ${repo.printcwd()}`);
80339
- const isOnMain = await repo.isOnMainBranch();
80340
- const isOnBaseBranch = await repo.isOnBranch(r.base_branch);
80341
- if (isOnMain || isOnBaseBranch) {
80342
- const uniqueBranchName = await repo.generateUniqueBranchName(r.branch_name);
80343
- if (uniqueBranchName !== r.branch_name) {
80344
- console.log(`=> Branch ${r.branch_name} exists, using ${uniqueBranchName} instead`);
80345
- }
80346
- console.log(`=> CHECKOUT to new branch: ${uniqueBranchName}`);
80347
- await repo.checkoutNew(uniqueBranchName);
80376
+ const status = await repo.execCommand("git status --porcelain");
80377
+ if (status.trim()) {
80378
+ console.log(`=> Found uncommitted changes, committing...`);
80379
+ await repo.addAll();
80380
+ currentBranch = (await repo.printCurrentBranch()).trim();
80381
+ console.log(`=> COMMIT to ${r.url} on branch: ${currentBranch}`);
80382
+ await repo.commitWithCredentials(
80383
+ r.commit_name,
80384
+ code.git_credentials
80385
+ );
80386
+ console.log(`=> Commit successful`);
80387
+ } else {
80388
+ console.log(
80389
+ `=> No uncommitted changes, skipping commit (may have been committed by agent)`
80390
+ );
80348
80391
  }
80349
- await repo.addAll();
80350
- const currentBranch2 = (await repo.printCurrentBranch()).trim();
80351
- console.log(`=> COMMIT to ${r.url} on branch: ${currentBranch2}`);
80352
- await repo.commitWithCredentials(r.commit_name, code.git_credentials);
80353
80392
  }
80354
80393
  console.log(`=> PUSH to ${r.url}`);
80355
80394
  await repo.pushCurrentBranchWithCredentials(code.git_credentials);
80395
+ console.log(`=> Push successful`);
80356
80396
  const link = await repo.getLatestCommitLink();
80357
80397
  commits.push(link);
80358
- const currentBranch = (await repo.printCurrentBranch()).trim();
80398
+ currentBranch = (await repo.printCurrentBranch()).trim();
80359
80399
  branches[repoName] = currentBranch;
80360
80400
  console.log(`=> Branch for ${repoName}: ${currentBranch}`);
80361
80401
  if (stashCreated) {
@@ -80623,7 +80663,15 @@ ${diff.trim()}`);
80623
80663
  );
80624
80664
  app.put("/latest", async (req, res) => {
80625
80665
  console.log(`===> PUT /latest`);
80626
- const request_id = startReq();
80666
+ if (isReqTypeBusy("latest")) {
80667
+ console.log("=> /latest is already being processed, ignoring request");
80668
+ res.status(409).json({
80669
+ error: "Latest operation already in progress",
80670
+ status: "busy"
80671
+ });
80672
+ return;
80673
+ }
80674
+ const request_id = startReq("latest");
80627
80675
  try {
80628
80676
  const code = req.body;
80629
80677
  const workspaceRoot2 = await workspaceRoot();
@@ -10905,7 +10905,7 @@ var glob = Object.assign(glob_, {
10905
10905
  glob.glob = glob;
10906
10906
 
10907
10907
  // src/proxy/version.ts
10908
- var VERSION = "0.3.16";
10908
+ var VERSION = "0.3.18";
10909
10909
 
10910
10910
  // src/cli.ts
10911
10911
  var STAKLINK_PROXY = "staklink-proxy";
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "staklink",
3
3
  "displayName": "staklink",
4
4
  "description": "staklink process manager",
5
- "version": "0.3.16",
5
+ "version": "0.3.18",
6
6
  "type": "module",
7
7
  "publisher": "stakwork",
8
8
  "engines": {