fix: create /workspaces dir, clone repo before running agent
Made-with: Cursor
This commit is contained in:
68
dist/server.js
vendored
68
dist/server.js
vendored
@@ -1,10 +1,46 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = __importDefault(require("express"));
|
||||
const cors_1 = __importDefault(require("cors"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const child_process_1 = require("child_process");
|
||||
const job_store_1 = require("./job-store");
|
||||
const agent_runner_1 = require("./agent-runner");
|
||||
const agents_1 = require("./agents");
|
||||
@@ -15,10 +51,36 @@ const PORT = process.env.PORT || 3333;
|
||||
// ---------------------------------------------------------------------------
|
||||
// Build ToolContext from environment variables
|
||||
// ---------------------------------------------------------------------------
|
||||
function ensureWorkspace(repo) {
|
||||
const base = process.env.WORKSPACE_BASE || '/workspaces';
|
||||
if (!repo) {
|
||||
const dir = path.join(base, 'default');
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
return dir;
|
||||
}
|
||||
const dir = path.join(base, repo.replace('/', '_'));
|
||||
const gitea = {
|
||||
apiUrl: process.env.GITEA_API_URL || '',
|
||||
apiToken: process.env.GITEA_API_TOKEN || '',
|
||||
username: process.env.GITEA_USERNAME || ''
|
||||
};
|
||||
if (!fs.existsSync(path.join(dir, '.git'))) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
const authedUrl = `${gitea.apiUrl}/${repo}.git`
|
||||
.replace('https://', `https://${gitea.username}:${gitea.apiToken}@`);
|
||||
try {
|
||||
(0, child_process_1.execSync)(`git clone "${authedUrl}" "${dir}"`, { stdio: 'pipe' });
|
||||
}
|
||||
catch {
|
||||
// Repo may not exist yet — just init
|
||||
(0, child_process_1.execSync)(`git init`, { cwd: dir, stdio: 'pipe' });
|
||||
(0, child_process_1.execSync)(`git remote add origin "${authedUrl}"`, { cwd: dir, stdio: 'pipe' });
|
||||
}
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
function buildContext(repo) {
|
||||
const workspaceRoot = repo
|
||||
? `${process.env.WORKSPACE_BASE || '/workspaces'}/${repo.replace('/', '_')}`
|
||||
: (process.env.WORKSPACE_BASE || '/workspaces/default');
|
||||
const workspaceRoot = ensureWorkspace(repo);
|
||||
return {
|
||||
workspaceRoot,
|
||||
gitea: {
|
||||
|
||||
Reference in New Issue
Block a user