Spaces:
Sleeping
Sleeping
File size: 9,519 Bytes
95eb75a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | // ─── Virtual File System tools — write/read/iterate/patch/list/delete/move/copy/info/diff/append/batch/extract/write_files ───────────────────────────────────────────────────────────
// P3-4 split da toolDefinitions.ts — DO NOT edit toolDefinitions.ts directly
// Tools (14): write_file, read_file, iterate_file, apply_patch, list_files, delete_file, move_file, copy_file, file_info, file_diff, append_to_file, batch_file_op, extract_zip, write_files
import type { ChatCompletionTool } from "openai/resources/chat/completions";
export const VFS_TOOLS: (ChatCompletionTool | undefined)[] = [
{
type: "function",
function: {
name: "write_file",
description: "Scrivi un file nel filesystem virtuale persistente. File scaricabili dall'utente.",
parameters: { type: "object", properties: { path: { type: "string", description: "Percorso (es. /output/data.csv)" }, content: { type: "string", description: "Contenuto del file" }, mime_type: { type: "string", description: "MIME type opzionale" } }, required: ["path","content"] }
}
},
{
type: "function",
function: {
name: "read_file",
description: "Leggi un file dal filesystem virtuale. Per file grandi usa offset+limit per paginare (ogni chunk è max 8000 chars).",
parameters: { type: "object", properties: { path: { type: "string", description: "Percorso file" }, offset: { type: "number", description: "Char offset da cui iniziare la lettura (default: 0). Usa per paginare file grandi." }, limit: { type: "number", description: "Numero massimo di caratteri da leggere (default: 8000). Usa con offset per paginare." } }, required: ["path"] }
}
},
{
type: "function",
function: {
name: "iterate_file",
description: "Leggi un file che hai già creato, ricevi il contenuto corrente e le istruzioni di modifica, poi riscrivi la versione aggiornata con write_file. Usa dopo create_webpage o write_file per migliorare o correggere il codice in modo incrementale.",
parameters: {
type: "object",
properties: {
path: { type: "string", description: "Percorso del file nel VFS (es. /pages/app.html)" },
instruction: { type: "string", description: "Cosa modificare (es. 'aggiungi dark mode', 'correggi il calcolo alla riga 42')" }
},
required: ["path", "instruction"]
}
}
},
{
type: "function",
function: {
name: "apply_patch",
description: "Applica una patch diff a un file esistente nel VFS. Usa diff-match-patch per modificare solo le righe necessarie invece di riscrivere il file intero. Preferisci questo tool rispetto a write_file quando devi cambiare porzioni specifiche di un file già esistente.",
parameters: {
type: "object",
properties: {
path: { type: "string", description: "Path del file target nel VFS" },
patch: { type: "string", description: "Patch in formato unified diff (@@...@@) oppure stringa di testo da cercare+rimpiazzare nel formato: SEARCH:\n<testo da trovare>\nREPLACE:\n<testo sostituto>" },
mode: { type: "string", enum: ["diff", "search_replace"], description: "Modalità: 'diff' per unified diff, 'search_replace' per ricerca/sostituzione semplice (default: search_replace)" },
},
required: ["path", "patch"],
},
},
},
{
type: "function",
function: {
name: "list_files",
description: "Elenca i file nel filesystem virtuale (VFS). Usa path per filtrare per directory (es. '/test' mostra solo /test/*). Senza path elenca tutti i file.",
parameters: { type: "object", properties: { path: { type: "string", description: "Directory da esplorare (es. '/test', '/src', '/regression'). Opzionale — senza parametro elenca tutti i file." } } }
}
},
{
type: "function",
function: {
name: "delete_file",
description: "Cancella un file dal filesystem virtuale.",
parameters: { type: "object", properties: { path: { type: "string", description: "Percorso del file da cancellare" } }, required: ["path"] }
}
},
{
type: "function",
function: {
name: "move_file",
description: "Sposta o rinomina un file nel filesystem virtuale. Legge il file sorgente, lo scrive nella destinazione e cancella il sorgente. Usa per rinominare o riorganizzare file nel VFS.",
parameters: { type: "object", properties: { from: { type: "string", description: "Percorso sorgente (es. /draft/output.txt)" }, to: { type: "string", description: "Percorso destinazione (es. /final/result.txt)" } }, required: ["from","to"] }
}
},
{
type: "function",
function: {
name: "copy_file",
description: "Copia un file nel VFS da un percorso a un altro (non distruttivo — mantiene l'originale). Usa per duplicare file prima di modificarli.",
parameters: { type: "object", properties: { from: { type: "string", description: "Percorso sorgente" }, to: { type: "string", description: "Percorso destinazione" } }, required: ["from","to"] }
}
},
{
type: "function",
function: {
name: "file_info",
description: "Mostra metadati di un file nel VFS: dimensione, righe, parole, MIME type, encoding, numero di backup disponibili.",
parameters: { type: "object", properties: { path: { type: "string", description: "Percorso del file" } }, required: ["path"] }
}
},
{
type: "function",
function: {
name: "file_diff",
description: "Confronta due file nel VFS e mostra un diff unificato riga per riga. Usa per vedere le differenze tra versioni di un file.",
parameters: { type: "object", properties: { path_a: { type: "string", description: "Primo file (originale)" }, path_b: { type: "string", description: "Secondo file (modificato)" } }, required: ["path_a","path_b"] }
}
},
{
type: "function",
function: {
name: "append_to_file",
description: "Aggiunge contenuto in coda a un file esistente nel VFS (non sovrascrive). Se il file non esiste, lo crea.",
parameters: { type: "object", properties: { path: { type: "string", description: "Percorso file" }, content: { type: "string", description: "Contenuto da aggiungere" }, separator: { type: "string", description: "Separatore tra vecchio e nuovo contenuto (default: newline)" } }, required: ["path","content"] }
}
},
{
type: "function",
function: {
name: "batch_file_op",
description: "Operazioni bulk su file nel VFS con pattern regex: copia, rinomina, cancella, elenca file corrispondenti. Usa dry_run:true per vedere cosa farebbe prima di eseguire.",
parameters: { type: "object", properties: { operation: { type: "string", enum: ["copy","delete","rename","list_matches"], description: "Operazione da eseguire" }, pattern: { type: "string", description: "Pattern regex sui path dei file (es. '\\.test\\.ts$', '^/drafts/')" }, replacement: { type: "string", description: "Stringa di rimpiazzo (per copy/rename, accetta $1 dai gruppi regex)" }, paths: { type: "array", items: { type: "string" }, description: "Lista opzionale di path su cui limitare l'operazione" }, dry_run: { type: "boolean", description: "Se true mostra cosa farebbe senza applicare (default: false)" } }, required: ["operation","pattern"] }
}
},
{
type: "function",
function: {
name: "extract_zip",
description: "Estrae il contenuto di un archivio ZIP dal VFS nelle singole directory/file. Usa dopo create_zip o clone_url_to_vfs su archivi .zip.",
parameters: { type: "object", properties: { path: { type: "string", description: "Percorso del file .zip nel VFS" }, dest_dir: { type: "string", description: "Directory di destinazione (default: stessa directory del zip senza estensione)" } }, required: ["path"] }
}
},
{
type: "function",
function: {
name: "write_files",
description:
"Scrive più file nel VFS in modo ATOMICO (o tutti o nessuno). " +
"Usa invece di N chiamate write_file sequenziali quando devi fare un refactoring " +
"su più file: se un file fallisce, NESSUN file viene scritto (rollback automatico). " +
"Max 50 file per chiamata. Supporta op=write (crea/sovrascrivi) e op=delete.",
parameters: {
type: "object",
properties: {
patches: {
type: "array",
description: "Lista di operazioni file da applicare atomicamente.",
items: {
type: "object",
properties: {
op: { type: "string", enum: ["write", "delete"], description: "Operazione: write=crea/sovrascrivi, delete=elimina" },
path: { type: "string", description: "Path del file nel VFS (es. src/App.tsx)" },
content: { type: "string", description: "Contenuto del file (richiesto per op=write)" },
type: { type: "string", description: "MIME type (default: text/plain)" },
},
required: ["op", "path"],
},
},
},
required: ["patches"],
},
},
},
];
|