staklink 0.4.4 → 0.4.6

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.
@@ -60411,6 +60411,23 @@ var Repo = class {
60411
60411
  log("nowBranch:", nowBranch);
60412
60412
  return nowBranch.includes(`* ${base_branch}`);
60413
60413
  }
60414
+ async getDefaultBranch() {
60415
+ try {
60416
+ const result = await this.execCommand(
60417
+ `git remote show origin | sed -n '/HEAD branch/s/.*: //p'`
60418
+ );
60419
+ return result.trim();
60420
+ } catch {
60421
+ try {
60422
+ await this.execCommand(
60423
+ "git show-ref --verify --quiet refs/heads/main"
60424
+ );
60425
+ return "main";
60426
+ } catch {
60427
+ return "master";
60428
+ }
60429
+ }
60430
+ }
60414
60431
  async checkoutMainBranchOrBaseBranch(base_branch) {
60415
60432
  if (base_branch) {
60416
60433
  return this.execCommand(`git checkout -f ${base_branch}`);
@@ -60777,7 +60794,7 @@ var SSEManager = class {
60777
60794
  var sseManager = new SSEManager();
60778
60795
 
60779
60796
  // src/proxy/version.ts
60780
- var VERSION = "0.4.4";
60797
+ var VERSION = "0.4.6";
60781
60798
 
60782
60799
  // node_modules/uuid/dist/esm/stringify.js
60783
60800
  var byteToHex = [];
@@ -60950,7 +60967,12 @@ var fs8 = __toESM(require("fs"), 1);
60950
60967
  var path7 = __toESM(require("path"), 1);
60951
60968
  var os = __toESM(require("os"), 1);
60952
60969
 
60953
- // src/agent/system_suffix.ts
60970
+ // src/agent/system_prompt.ts
60971
+ var SYSTEM_CORE = `You are a software systems expert. You are working on a cloud dev server (code-server) that is running a software project. The user's application is being run with pm2. You can use the pm2 cli to inspect the running processes. There may also be supporting services running as docker containers. Because you are running on a cloud server, certain operation may not be possible, such as launching a desktop application, or opening a browser window. The user can see the running application from the pm2 service called "frontend" in an iframe on their end.
60972
+
60973
+ Do not commit or push code to github. That is handled by a workflow after you are done working.
60974
+
60975
+ `;
60954
60976
  var SYSTEM_SUFFIX = `
60955
60977
  You can ignore the .pod-config directory if you see it, its just config stuff
60956
60978
 
@@ -137820,7 +137842,8 @@ async function runAgent({
137820
137842
  const env2 = goose_env(apiKey, model);
137821
137843
  console.log("RUN goose with env", env2);
137822
137844
  const cleanPrompt = sanitizeShellArg(prompt);
137823
- let system = system_prompt ? sanitizeShellArg(system_prompt) + "\n\n" : "";
137845
+ let system = SYSTEM_CORE;
137846
+ system += system_prompt ? sanitizeShellArg(system_prompt) + "\n\n" : "";
137824
137847
  system += SYSTEM_SUFFIX;
137825
137848
  system = sanitizeShellArg(system);
137826
137849
  console.log("Using Goose CLI", cleanPrompt, system);
@@ -139430,7 +139453,8 @@ async function runAgent3({
139430
139453
  session,
139431
139454
  summarize
139432
139455
  }) {
139433
- let system = system_prompt ? system_prompt + "\n\n" : "";
139456
+ let system = SYSTEM_CORE;
139457
+ system += system_prompt ? system_prompt + "\n\n" : "";
139434
139458
  system += SYSTEM_SUFFIX;
139435
139459
  console.log("Codex agent using API key:", apiKey ? `${apiKey.substring(0, 8)}...` : "MISSING");
139436
139460
  if (apiKey) {
@@ -139463,7 +139487,7 @@ __export(repair_exports, {
139463
139487
  makeRepairPrompt: () => makeRepairPrompt,
139464
139488
  parseXML: () => parseXML
139465
139489
  });
139466
- var SYSTEM2 = `You are a software systems expert. Your job is to help set up the development environment for a software project. Fix the user's pm2 config and/or docker-compose files, and use the pm2 and docker cli to get the project running. YOUR GOAL IS TO THE GET THE frontend APP IN THE PM2 CONFIG FILE TO RUN CORRECTLY! Other apps and docker containers are only supporting services. You can restart the pm2 environment with "npx -y staklink reload" after making changes to the pm2 config or docker-compose files.
139490
+ var SYSTEM2 = SYSTEM_CORE + `Your job is to help set up the development environment for a software project. Fix the user's pm2 config and/or docker-compose files, and use the pm2 and docker cli to get the project running. YOUR GOAL IS TO THE GET THE frontend APP IN THE PM2 CONFIG FILE TO RUN CORRECTLY! Other apps and docker containers are only supporting services. You can restart the pm2 environment with "npx -y staklink reload" after making changes to the pm2 config or docker-compose files.
139467
139491
 
139468
139492
  When you have gotten the frontend running, or gotten as far as you can, respond to the user by saying either "<status>COMPLETE</status>" or "<status>FAILED</status>". If COMPLETE, then tell the user the fixed config files (put the exact raw content of the files in the XML tags, no extra text like triple backticks or language label). FOR YOUR FINAL TEXT RESPONSE, USE THE THE FOLLOWING XML FORMAT:
139469
139493
 
@@ -141103,41 +141127,137 @@ Stderr: ${error88.stderr}`
141103
141127
  };
141104
141128
 
141105
141129
  // src/proxy/git_actions.ts
141130
+ var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
141131
+ ".png",
141132
+ ".jpg",
141133
+ ".jpeg",
141134
+ ".gif",
141135
+ ".bmp",
141136
+ ".webp",
141137
+ ".ico",
141138
+ ".svg",
141139
+ ".tiff",
141140
+ ".tif",
141141
+ ".avif"
141142
+ ]);
141143
+ var MIME_TYPES = {
141144
+ ".png": "image/png",
141145
+ ".jpg": "image/jpeg",
141146
+ ".jpeg": "image/jpeg",
141147
+ ".gif": "image/gif",
141148
+ ".bmp": "image/bmp",
141149
+ ".webp": "image/webp",
141150
+ ".ico": "image/x-icon",
141151
+ ".svg": "image/svg+xml",
141152
+ ".tiff": "image/tiff",
141153
+ ".tif": "image/tiff",
141154
+ ".avif": "image/avif"
141155
+ };
141156
+ function isImageFile(filePath) {
141157
+ return IMAGE_EXTENSIONS.has(import_path4.default.extname(filePath).toLowerCase());
141158
+ }
141159
+ async function binaryDiffContent(repo, filePath, action) {
141160
+ const isBinary = await isGitBinaryFile(repo, filePath);
141161
+ if (!isBinary) {
141162
+ return null;
141163
+ }
141164
+ if (action === "delete") {
141165
+ if (isImageFile(filePath)) {
141166
+ return `Binary image file deleted: ${filePath}`;
141167
+ }
141168
+ return `Binary file deleted: ${filePath}`;
141169
+ }
141170
+ if (isImageFile(filePath)) {
141171
+ try {
141172
+ const absPath = import_path4.default.join(repo.printcwd(), filePath);
141173
+ const buffer = import_fs4.default.readFileSync(absPath);
141174
+ const ext2 = import_path4.default.extname(filePath).toLowerCase();
141175
+ const mime = MIME_TYPES[ext2] || "application/octet-stream";
141176
+ const b64 = buffer.toString("base64");
141177
+ return `--- ${action === "create" ? "/dev/null" : `a/${filePath}`}
141178
+ +++ b/${filePath}
141179
+ Binary image file (${mime}, ${formatBytes(buffer.length)})
141180
+ data:${mime};base64,${b64}`;
141181
+ } catch {
141182
+ return `Binary image file changed: ${filePath} (could not read file)`;
141183
+ }
141184
+ }
141185
+ return `Binary file changed: ${filePath}`;
141186
+ }
141187
+ async function isGitBinaryFile(repo, filePath) {
141188
+ try {
141189
+ const numstat = await repo.execCommand(
141190
+ `git diff --numstat HEAD -- "${filePath}"`
141191
+ );
141192
+ if (numstat.trim().startsWith("- -")) {
141193
+ return true;
141194
+ }
141195
+ } catch {
141196
+ }
141197
+ try {
141198
+ const absPath = import_path4.default.join(repo.printcwd(), filePath);
141199
+ const buf = Buffer.alloc(8192);
141200
+ const fd = import_fs4.default.openSync(absPath, "r");
141201
+ const bytesRead = import_fs4.default.readSync(fd, buf, 0, 8192, 0);
141202
+ import_fs4.default.closeSync(fd);
141203
+ for (let i = 0; i < bytesRead; i++) {
141204
+ if (buf[i] === 0) {
141205
+ return true;
141206
+ }
141207
+ }
141208
+ } catch {
141209
+ }
141210
+ return false;
141211
+ }
141212
+ function formatBytes(bytes) {
141213
+ if (bytes < 1024) {
141214
+ return `${bytes} B`;
141215
+ }
141216
+ if (bytes < 1024 * 1024) {
141217
+ return `${(bytes / 1024).toFixed(1)} KB`;
141218
+ }
141219
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
141220
+ }
141106
141221
  async function handleBranchDiff(req, res) {
141107
141222
  try {
141108
141223
  const results = [];
141109
141224
  const repos = await getReposMaybe();
141110
- const baseBranch = req.query.base || "main";
141111
141225
  for (const r of repos) {
141112
141226
  const repo = await NewRepo(r);
141113
141227
  const repoName = getRepoNameFromUrl(r);
141114
141228
  const currentBranch = (await repo.printCurrentBranch()).trim();
141115
- if (currentBranch === baseBranch) {
141116
- continue;
141117
- }
141118
- let mergeBase;
141119
- try {
141120
- mergeBase = (await repo.execCommand(`git merge-base ${baseBranch} HEAD`)).trim();
141121
- } catch {
141229
+ const baseBranch = req.query.base || await repo.getDefaultBranch();
141230
+ const onBaseBranch = currentBranch === baseBranch;
141231
+ let diffBase;
141232
+ if (onBaseBranch) {
141233
+ diffBase = "HEAD";
141234
+ } else {
141122
141235
  try {
141123
- mergeBase = (await repo.execCommand(`git merge-base origin/${baseBranch} HEAD`)).trim();
141236
+ diffBase = (await repo.execCommand(`git merge-base ${baseBranch} HEAD`)).trim();
141124
141237
  } catch {
141125
- warn(
141126
- `Could not find merge base for ${repoName}, skipping...`
141127
- );
141128
- continue;
141238
+ try {
141239
+ diffBase = (await repo.execCommand(
141240
+ `git merge-base origin/${baseBranch} HEAD`
141241
+ )).trim();
141242
+ } catch {
141243
+ warn(
141244
+ `Could not find merge base for ${repoName}, skipping...`
141245
+ );
141246
+ continue;
141247
+ }
141129
141248
  }
141130
141249
  }
141131
141250
  let diffOutput = "";
141132
141251
  try {
141133
141252
  diffOutput = await repo.execCommand(
141134
- `git diff --name-status ${mergeBase}`
141253
+ `git diff --name-status ${diffBase}`
141135
141254
  );
141136
141255
  } catch (error88) {
141137
141256
  warn(`Error getting branch diff for repo ${repoName}:`, error88);
141138
141257
  continue;
141139
141258
  }
141140
141259
  const lines = diffOutput.trim().split("\n").filter((line) => line);
141260
+ const trackedFiles = /* @__PURE__ */ new Set();
141141
141261
  for (const line of lines) {
141142
141262
  const parts = line.split(" ");
141143
141263
  if (parts.length < 2) {
@@ -141145,6 +141265,7 @@ async function handleBranchDiff(req, res) {
141145
141265
  }
141146
141266
  const status = parts[0];
141147
141267
  const filePath = parts[1];
141268
+ trackedFiles.add(filePath);
141148
141269
  let action;
141149
141270
  if (status.startsWith("A")) {
141150
141271
  action = "create";
@@ -141154,12 +141275,17 @@ async function handleBranchDiff(req, res) {
141154
141275
  action = "modify";
141155
141276
  }
141156
141277
  let content = "";
141157
- try {
141158
- content = await repo.execCommand(
141159
- `git diff ${mergeBase} -- "${filePath}"`
141160
- );
141161
- } catch (error88) {
141162
- warn(`Error getting branch diff for ${filePath}:`, error88);
141278
+ const binaryContent = await binaryDiffContent(repo, filePath, action);
141279
+ if (binaryContent !== null) {
141280
+ content = binaryContent;
141281
+ } else {
141282
+ try {
141283
+ content = await repo.execCommand(
141284
+ `git diff ${diffBase} -- "${filePath}"`
141285
+ );
141286
+ } catch (error88) {
141287
+ warn(`Error getting branch diff for ${filePath}:`, error88);
141288
+ }
141163
141289
  }
141164
141290
  results.push({
141165
141291
  file: `${repoName}/${filePath}`,
@@ -141169,6 +141295,47 @@ async function handleBranchDiff(req, res) {
141169
141295
  errors: []
141170
141296
  });
141171
141297
  }
141298
+ let untrackedOutput = "";
141299
+ try {
141300
+ untrackedOutput = await repo.execCommand(
141301
+ "git ls-files --others --exclude-standard"
141302
+ );
141303
+ } catch (error88) {
141304
+ warn(
141305
+ `Error getting untracked files for repo ${repoName}:`,
141306
+ error88
141307
+ );
141308
+ }
141309
+ const untrackedLines = untrackedOutput.trim().split("\n").filter((line) => line && !trackedFiles.has(line));
141310
+ for (const filePath of untrackedLines) {
141311
+ let content = "";
141312
+ const binaryContent = await binaryDiffContent(
141313
+ repo,
141314
+ filePath,
141315
+ "create"
141316
+ );
141317
+ if (binaryContent !== null) {
141318
+ content = binaryContent;
141319
+ } else {
141320
+ try {
141321
+ const fileContent = await repo.execCommand(`cat "${filePath}"`);
141322
+ const fileLines = fileContent.split("\n");
141323
+ content = `--- /dev/null
141324
+ +++ b/${filePath}
141325
+ @@ -0,0 +1,${fileLines.length} @@
141326
+ ${fileLines.map((line) => "+" + line).join("\n")}`;
141327
+ } catch (error88) {
141328
+ warn(`Error reading untracked file ${filePath}:`, error88);
141329
+ }
141330
+ }
141331
+ results.push({
141332
+ file: `${repoName}/${filePath}`,
141333
+ action: "create",
141334
+ content,
141335
+ repoName,
141336
+ errors: []
141337
+ });
141338
+ }
141172
141339
  }
141173
141340
  res.status(200).json(results);
141174
141341
  } catch (error88) {
@@ -141210,15 +141377,24 @@ async function handleDiff(_req, res) {
141210
141377
  action = "modify";
141211
141378
  }
141212
141379
  let content = "";
141213
- try {
141214
- if (action === "delete") {
141215
- content = await repo.execCommand(`git diff HEAD -- "${filePath}"`);
141216
- } else {
141217
- log("Getting diff for", filePath);
141218
- content = await repo.execCommand(`git diff HEAD -- "${filePath}"`);
141380
+ const binaryContent = await binaryDiffContent(repo, filePath, action);
141381
+ if (binaryContent !== null) {
141382
+ content = binaryContent;
141383
+ } else {
141384
+ try {
141385
+ if (action === "delete") {
141386
+ content = await repo.execCommand(
141387
+ `git diff HEAD -- "${filePath}"`
141388
+ );
141389
+ } else {
141390
+ log("Getting diff for", filePath);
141391
+ content = await repo.execCommand(
141392
+ `git diff HEAD -- "${filePath}"`
141393
+ );
141394
+ }
141395
+ } catch (error88) {
141396
+ warn(`Error getting diff for ${filePath}:`, error88);
141219
141397
  }
141220
- } catch (error88) {
141221
- warn(`Error getting diff for ${filePath}:`, error88);
141222
141398
  }
141223
141399
  results.push({
141224
141400
  file: `${repoName}/${filePath}`,
@@ -141231,15 +141407,24 @@ async function handleDiff(_req, res) {
141231
141407
  const untrackedLines = untrackedOutput.trim().split("\n").filter((line) => line);
141232
141408
  for (const filePath of untrackedLines) {
141233
141409
  let content = "";
141234
- try {
141235
- const fileContent = await repo.execCommand(`cat "${filePath}"`);
141236
- const lines2 = fileContent.split("\n");
141237
- content = `--- /dev/null
141410
+ const binaryContent = await binaryDiffContent(
141411
+ repo,
141412
+ filePath,
141413
+ "create"
141414
+ );
141415
+ if (binaryContent !== null) {
141416
+ content = binaryContent;
141417
+ } else {
141418
+ try {
141419
+ const fileContent = await repo.execCommand(`cat "${filePath}"`);
141420
+ const lines2 = fileContent.split("\n");
141421
+ content = `--- /dev/null
141238
141422
  +++ b/${filePath}
141239
141423
  @@ -0,0 +1,${lines2.length} @@
141240
141424
  ${lines2.map((line) => "+" + line).join("\n")}`;
141241
- } catch (error88) {
141242
- warn(`Error reading untracked file ${filePath}:`, error88);
141425
+ } catch (error88) {
141426
+ warn(`Error reading untracked file ${filePath}:`, error88);
141427
+ }
141243
141428
  }
141244
141429
  results.push({
141245
141430
  file: `${repoName}/${filePath}`,
@@ -10967,7 +10967,7 @@ var glob = Object.assign(glob_, {
10967
10967
  glob.glob = glob;
10968
10968
 
10969
10969
  // src/proxy/version.ts
10970
- var VERSION = "0.4.4";
10970
+ var VERSION = "0.4.6";
10971
10971
 
10972
10972
  // src/deps.ts
10973
10973
  var import_child_process = require("child_process");
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.4.4",
5
+ "version": "0.4.6",
6
6
  "type": "module",
7
7
  "publisher": "stakwork",
8
8
  "engines": {