diff --git a/extensions/index.ts b/extensions/index.ts index c5ca5ca..27834bd 100644 --- a/extensions/index.ts +++ b/extensions/index.ts @@ -26,8 +26,6 @@ const execFileAsync = promisify(execFile); const AGY_CHAT_DIR = path.join(os.homedir(), ".agy-chat"); const STATE_FILE = path.join(AGY_CHAT_DIR, "conversation_id"); const CONV_DIR = path.join(os.homedir(), ".gemini", "antigravity-cli", "conversations"); -// Cartella scratch per i file esterni da analizzare (workaround accesso agy) -const AGY_SCRATCH = path.join(os.homedir(), ".agy-scratch"); const DEFAULT_TIMEOUT_MS = 180_000; // 3 min const IMAGE_TIMEOUT_MS = 300_000; // 5 min @@ -681,14 +679,14 @@ ${blocks.join("\n\n")}`; } // Workaround: se un file da analizzare è FUORI dalla cartella di lavoro corrente, -// lo copia in una cartella scratch accessibile e riscrive i riferimenti nel prompt. -// Previene errori di accesso/competenza quando agy legge file esterni al workspace. +// lo copia in /tmp (cartella nativamente accessibile da agy) con un nome univoco +// casuale e riscrive i riferimenti nel prompt. Previene errori di accesso/competenza +// quando agy legge file esterni al workspace, senza sovrascrivere file esistenti. function stageExternalFiles( prompt: string, filePaths: string[], ): { prompt: string; filePaths: string[]; dirs: string[] } { const cwdBase = path.resolve(process.cwd()) + path.sep; - const dirs = new Set(); const stagedPaths: string[] = []; let newPrompt = prompt; @@ -701,19 +699,20 @@ function stageExternalFiles( continue; } try { - fs.mkdirSync(AGY_SCRATCH, { recursive: true }); - const dest = path.join(AGY_SCRATCH, path.basename(abs)); + const ext = path.extname(abs); + const unique = `agy_stage_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}${ext}`; + const dest = path.join(os.tmpdir(), unique); fs.copyFileSync(abs, dest); // riscrivi i riferimenti nel prompt (path originale e assoluto) newPrompt = newPrompt.split(f).join(dest).split(abs).join(dest); stagedPaths.push(dest); - dirs.add(AGY_SCRATCH); } catch { // se la copia fallisce, lascia il path originale (potrebbe comunque funzionare) stagedPaths.push(f); } } - return { prompt: newPrompt, filePaths: stagedPaths, dirs: [...dirs] }; + // /tmp è accessibile nativamente da agy → nessun --add-dir necessario + return { prompt: newPrompt, filePaths: stagedPaths, dirs: [] }; } async function executeAgy(opts: AgyExecOptions) { @@ -722,11 +721,10 @@ async function executeAgy(opts: AgyExecOptions) { const finalPrompt = opts.contextBlock ? `${opts.contextBlock}\n\n${staged.prompt}` : staged.prompt; const args: string[] = ["-p", finalPrompt]; - // add-dir per i file + // add-dir per i file (i file esterni sono stagizzati in /tmp, accessibile nativamente) const dirs = new Set(); for (const d of opts.addDirs ?? []) if (d) dirs.add(d); for (const f of staged.filePaths) if (f) dirs.add(path.dirname(f)); - for (const d of staged.dirs) dirs.add(d); for (const d of dirs) args.push("--add-dir", d); // conversazione