AUDIT / src /lib /agentLoop /toolDefs /toolDefsCode.ts
Arypulka98's picture
feat(audit): deploy full backend cluster node (part 3)
95eb75a verified
Raw
History Blame Contribute Delete
6.91 kB
// ─── Code execution tools — run_code, execute_shell, pip_install, run_python, math_eval, run_tests, lint_code, diff_text ───────────────────────────────────────────────────────────
// P3-4 split da toolDefinitions.ts — DO NOT edit toolDefinitions.ts directly
// Tools (8): run_code, execute_shell, pip_install, run_python, math_eval, run_tests, lint_code, diff_text
import type { ChatCompletionTool } from "openai/resources/chat/completions";
export const CODE_TOOLS: (ChatCompletionTool | undefined)[] = [
{
type: "function",
function: {
name: "run_code",
description: "Esegui codice JavaScript in un sandbox sicuro nel browser. Accede a fetch(), vfs, memory, uuid(), csvParse(), download(), generatePDF(). Usa per calcoli, elaborazione dati, generazione file.",
parameters: { type: "object", properties: { code: { type: "string", description: "Codice JavaScript async da eseguire." } }, required: ["code"] }
}
},
{
type: "function",
function: {
name: "execute_shell",
description: "Esegui un comando shell Linux sul backend server (Python 3.11, git, curl, ls, grep disponibili). Ogni esecuzione è in una directory temporanea isolata. Usa per: calcoli Python, git operations, download file, elaborazione dati lato server.",
parameters: { type: "object", properties: { command: { type: "string", description: "Comando shell da eseguire (es. 'python3 -c \"import math; print(math.pi)\"')" }, timeout: { type: "number", description: "Timeout in secondi (default 15, max 60)" } }, required: ["command"] }
}
},
{
type: "function",
function: {
name: "pip_install",
description: "Installa pacchetti Python sul backend server con pip. Usa prima di execute_shell quando serve una libreria non standard (es. numpy, pandas, requests, matplotlib).",
parameters: { type: "object", properties: { packages: { type: "array", items: { type: "string" }, description: "Lista pacchetti da installare (es. ['numpy', 'pandas'])" } }, required: ["packages"] }
}
},
{
type: "function",
function: {
name: "run_python",
description: "Esegui Python nel browser con Pyodide (offline, zero backend). numpy/pandas/scipy/matplotlib inclusi. micropip installa altri pacchetti automaticamente dagli import. Preferisci a execute_shell per calcoli, data analysis, scripting.",
parameters: {
type: "object",
properties: {
code: { type: "string", description: "Codice Python da eseguire" },
packages: { type: "array", items: { type: "string" }, description: "Pacchetti extra via micropip (opzionale)" }
},
required: ["code"]
}
}
},
{
type: "function",
function: {
name: "math_eval",
description: "Calcola espressioni matematiche in modo sicuro. Supporta: +,-,*,/,^,%, sin,cos,tan,sqrt,log,pow,PI,E,abs,ceil,floor,round,min,max. Usa per calcoli precisi invece di fare a mente.",
parameters: { type: "object", properties: { expr: { type: "string", description: "Espressione matematica (es. 'sqrt(144) + pow(2,10)', 'sin(PI/4) * 100')" } }, required: ["expr"] }
}
},
{
type: "function",
function: {
name: "run_tests",
description: "Esegui test JavaScript con un framework built-in (describe/it/expect). Usa per verificare funzioni, algoritmi, API. Supporta: toBe, toEqual, toBeTruthy, toBeFalsy, toContain, toBeGreaterThan, toBeLessThan, toBeNull, toThrow.",
parameters: {
type: "object",
properties: {
code: { type: "string", description: "Codice JavaScript con test. describe/it/expect/test disponibili. Puoi importare funzioni dal codice applicativo." },
description: { type: "string", description: "Breve descrizione di cosa si sta testando" }
},
required: ["code"]
}
}
},
{
type: "function",
function: {
name: "lint_code",
description: "Analisi statica del codice JavaScript/TypeScript. Rileva: var (→ let/const), == (→ ===), console.log, any TypeScript, TODO/FIXME, linee troppo lunghe, bracket non chiusi, pattern pericolosi. Restituisce lista di warning/errori con numero di riga.",
parameters: {
type: "object",
properties: {
code: { type: "string", description: "Codice sorgente da analizzare" },
language: { type: "string", enum: ["javascript","typescript","jsx","tsx"], description: "Linguaggio (default: typescript)" },
strict: { type: "boolean", description: "Modalità strict: include anche warning minori (default: false)" }
},
required: ["code"]
}
}
},
{
type: "function",
function: {
name: "diff_text",
description: "Mostra le differenze tra due testi/codici (diff unificato). Usa per confrontare versioni di file, vedere cosa è cambiato tra vecchio e nuovo codice.",
parameters: {
type: "object",
properties: {
original: { type: "string", description: "Testo originale (vecchia versione)" },
modified: { type: "string", description: "Testo modificato (nuova versione)" },
label_a: { type: "string", description: "Label per l'originale (default: 'original')" },
label_b: { type: "string", description: "Label per la versione modificata (default: 'modified')" }
},
required: ["original", "modified"]
}
}
},
// ── P37-PA: python_analyze — analisi statica Python (2026-06-21) ────────────
{
type: 'function',
function: {
name: 'python_analyze',
description: 'Analisi statica di codice Python lato backend: sintassi (ast.parse), complessità ciclomatica per funzione, lista import, suggerimenti di qualità. Opzionale: esegue in sandbox isolata con run_code=true. Usa per: trovare errori sintassi, misurare qualità codice, preparare review, debug prima di execute_shell.',
parameters: {
type: 'object',
properties: {
content: { type: 'string', description: 'Codice Python da analizzare (max 50000 caratteri).' },
filepath: { type: 'string', description: 'Nome file (es. main.py) — opzionale, per logging.' },
goal: { type: 'string', description: 'Obiettivo analisi (es. "trova bug", "misura qualità") — opzionale.' },
run_code: { type: 'boolean', description: 'Se true: esegue il codice in sandbox isolata dopo analisi (max 200 righe). Default: false.' }
},
required: ['content']
}
}
},
];