feat: centralize runtime directories behind GHBOT_RUNTIME_DIR (D-13)
This commit is contained in:
1 parent
941e1d2681
commit
d9666c94a7
7 files changed
+64
-6
No files matched your search
+2
-1
@@ -7,6 +7,7 @@ import process from "node:process";
|
||||
import { config } from "../config.js";
|
||||
import { logger } from "../logger.js";
|
||||
import { startOneRunApiProxy } from "./apiProxy.js";
|
||||
import { tempRootDirectory } from "../runtimePaths.js";
|
||||
|
||||
const GOOSE_RUN_TIMEOUT_MS = 10 * 60 * 1000;
|
||||
const GOOSE_DOCKER_IMAGE = "node:24-bookworm";
|
||||
@@ -56,7 +57,7 @@ export async function runGoosePrompt(
|
||||
throw new Error("GOOSE_API_KEY is required when running a goose prompt.");
|
||||
}
|
||||
|
||||
const tempRoot = path.join(process.cwd(), ".ghbot-tmp");
|
||||
const tempRoot = tempRootDirectory();
|
||||
await fs.mkdir(tempRoot, { recursive: true });
|
||||
const tempDir = await fs.mkdtemp(path.join(tempRoot, "goose-"));
|
||||
const workingDirectory = options.workingDirectory
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
} from "../repository/knowledge.js";
|
||||
import { hasProtectedSegment, isProtectedBasename } from "../security/sanitization.js";
|
||||
import { listPullRequestFiles } from "../github/pulls.js";
|
||||
import { tempRootDirectory } from "../runtimePaths.js";
|
||||
|
||||
const CHAT_MARKER_PREFIX = "<!-- ghbot-chat:v1";
|
||||
const MAX_REPLY_CHARS = 60_000;
|
||||
@@ -310,7 +311,7 @@ function isNotFoundError(error: unknown): boolean {
|
||||
|
||||
export async function createRepositorySnapshot(sourceWorktree: string): Promise<string> {
|
||||
const sourceRoot = await fs.realpath(sourceWorktree);
|
||||
const tempRoot = path.join(process.cwd(), ".ghbot-tmp");
|
||||
const tempRoot = tempRootDirectory();
|
||||
await fs.mkdir(tempRoot, { recursive: true });
|
||||
const snapshot = await fs.mkdtemp(path.join(tempRoot, "pr-chat-"));
|
||||
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { z } from "zod";
|
||||
import { logger } from "../logger.js";
|
||||
import { cacheRootDirectory } from "../runtimePaths.js";
|
||||
import type { ReviewDecision } from "../types.js";
|
||||
|
||||
const findingSchema = z.object({
|
||||
@@ -114,7 +115,7 @@ export async function deleteLocalReviewCache(pullNumber: number): Promise<void>
|
||||
}
|
||||
|
||||
function cachePath(pullNumber: number): string {
|
||||
return path.join(process.cwd(), ".ghbot-cache", `pr-${pullNumber}.json`);
|
||||
return path.join(cacheRootDirectory(), `pr-${pullNumber}.json`);
|
||||
}
|
||||
|
||||
function isFileNotFound(error: unknown): boolean {
|
||||
|
||||
@@ -9,6 +9,7 @@ import { createRepositorySnapshot } from "../chat/processor.js";
|
||||
import { config } from "../config.js";
|
||||
import { logger } from "../logger.js";
|
||||
import { hasProtectedSegment, isProtectedBasename } from "../security/sanitization.js";
|
||||
import { tempRootDirectory } from "../runtimePaths.js";
|
||||
import {
|
||||
loadRepositoryKnowledge,
|
||||
REPOSITORY_KNOWLEDGE_SCRATCH_PATH,
|
||||
@@ -99,7 +100,7 @@ export async function resolvePullRequestConflicts(
|
||||
}
|
||||
|
||||
const worktree = await fs.realpath(params.worktree);
|
||||
const tempRoot = path.join(process.cwd(), ".ghbot-tmp");
|
||||
const tempRoot = tempRootDirectory();
|
||||
await fs.mkdir(tempRoot, { recursive: true });
|
||||
const askPassDirectory = await fs.mkdtemp(path.join(tempRoot, "git-auth-"));
|
||||
const askPassPath = path.join(askPassDirectory, "askpass.sh");
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import path from "node:path";
|
||||
import process from "node:process";
|
||||
|
||||
/**
|
||||
* Runtime scratch/cache directories live under one configurable root so
|
||||
* deployments with read-only or restricted working directories (D-13) can move
|
||||
* them without code changes. Defaults to the process working directory.
|
||||
*/
|
||||
export function runtimeDirectory(): string {
|
||||
const configured = process.env.GHBOT_RUNTIME_DIR?.trim();
|
||||
return configured ? configured : process.cwd();
|
||||
}
|
||||
|
||||
export function tempRootDirectory(): string {
|
||||
return path.join(runtimeDirectory(), ".ghbot-tmp");
|
||||
}
|
||||
|
||||
export function cacheRootDirectory(): string {
|
||||
return path.join(runtimeDirectory(), ".ghbot-cache");
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
validateRepositoryKnowledge
|
||||
} from "../repository/knowledge.js";
|
||||
import { parseReviewCacheContent } from "../review/cache.js";
|
||||
import { runtimeDirectory as resolveRuntimeDirectory } from "../runtimePaths.js";
|
||||
import { downloadR2Object, isR2Configured, uploadR2Object } from "./r2.js";
|
||||
|
||||
const MAX_REVIEW_CACHE_BYTES = 256 * 1024;
|
||||
@@ -62,7 +63,7 @@ export async function restorePersistentCache(params: {
|
||||
if (!params.storage && !isR2Configured()) {
|
||||
return;
|
||||
}
|
||||
const runtimeDirectory = params.runtimeDirectory ?? process.cwd();
|
||||
const runtimeDirectory = params.runtimeDirectory ?? resolveRuntimeDirectory();
|
||||
const storage = params.storage ?? r2Store;
|
||||
|
||||
await restoreObject({
|
||||
@@ -95,7 +96,7 @@ export async function savePersistentCache(params: {
|
||||
if (!params.storage && !isR2Configured()) {
|
||||
return;
|
||||
}
|
||||
const runtimeDirectory = params.runtimeDirectory ?? process.cwd();
|
||||
const runtimeDirectory = params.runtimeDirectory ?? resolveRuntimeDirectory();
|
||||
const storage = params.storage ?? r2Store;
|
||||
|
||||
if (params.saveRepositoryKnowledge) {
|
||||
|
||||
Reference in new issue
Block a user