@papercraneai/sandbox-agent 0.1.1 → 0.1.3
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/index.js +22 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -350,17 +350,31 @@ async function buildFileTree(dirPath) {
|
|
|
350
350
|
app.get("/health", (_req, res) => {
|
|
351
351
|
res.json({ status: "healthy", projectDir: PROJECT_DIR, version: pkg.version });
|
|
352
352
|
});
|
|
353
|
+
// Find the git repo root by traversing up from a starting directory
|
|
354
|
+
async function findGitRoot(startDir) {
|
|
355
|
+
let dir = resolve(startDir);
|
|
356
|
+
while (true) {
|
|
357
|
+
if (await directoryExists(join(dir, ".git"))) {
|
|
358
|
+
return dir;
|
|
359
|
+
}
|
|
360
|
+
const parent = dirname(dir);
|
|
361
|
+
if (parent === dir)
|
|
362
|
+
return null; // reached filesystem root
|
|
363
|
+
dir = parent;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
353
366
|
// Pull template updates (git pull + conditional npm install)
|
|
354
367
|
app.post("/pull-template", async (_req, res) => {
|
|
355
368
|
const workdir = getWorkingDirectory();
|
|
356
369
|
try {
|
|
357
|
-
//
|
|
358
|
-
|
|
359
|
-
|
|
370
|
+
// Find the git repo root (may be a parent of the working directory)
|
|
371
|
+
const gitRoot = await findGitRoot(workdir);
|
|
372
|
+
if (!gitRoot) {
|
|
373
|
+
res.status(400).json({ error: "Working directory is not inside a git repository" });
|
|
360
374
|
return;
|
|
361
375
|
}
|
|
362
|
-
// Run git pull
|
|
363
|
-
const pullOutput = runCommand("git pull",
|
|
376
|
+
// Run git pull from the repo root
|
|
377
|
+
const pullOutput = runCommand("git pull", gitRoot);
|
|
364
378
|
console.log(`git pull output: ${pullOutput}`);
|
|
365
379
|
// Check if already up to date
|
|
366
380
|
if (pullOutput.includes("Already up to date")) {
|
|
@@ -371,7 +385,7 @@ app.post("/pull-template", async (_req, res) => {
|
|
|
371
385
|
// git diff HEAD@{1} --name-only shows what changed in the last pull
|
|
372
386
|
let filesChanged = [];
|
|
373
387
|
try {
|
|
374
|
-
const diffOutput = runCommand("git diff HEAD@{1} --name-only",
|
|
388
|
+
const diffOutput = runCommand("git diff HEAD@{1} --name-only", gitRoot);
|
|
375
389
|
filesChanged = diffOutput.split("\n").filter(f => f.trim());
|
|
376
390
|
}
|
|
377
391
|
catch {
|
|
@@ -383,11 +397,11 @@ app.post("/pull-template", async (_req, res) => {
|
|
|
383
397
|
let npmInstalled = false;
|
|
384
398
|
if (packageJsonChanged) {
|
|
385
399
|
console.log("package.json changed, running npm install...");
|
|
386
|
-
await runNpmInstall(
|
|
400
|
+
await runNpmInstall(gitRoot);
|
|
387
401
|
npmInstalled = true;
|
|
388
402
|
}
|
|
389
403
|
// Ensure scaffold files still exist after pull
|
|
390
|
-
await ensureAppScaffold(
|
|
404
|
+
await ensureAppScaffold(gitRoot);
|
|
391
405
|
res.json({ updated: true, files_changed: filesChanged, npm_installed: npmInstalled });
|
|
392
406
|
}
|
|
393
407
|
catch (error) {
|