Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Il tracciamento dei todo fornisce un modo strutturato per gestire le attività e mostrare i progressi agli utenti. Il Claude Agent SDK include funzionalità todo integrate che aiutano a organizzare flussi di lavoro complessi e mantenere gli utenti informati sulla progressione delle attività.
I todo seguono un ciclo di vita prevedibile:
pending quando le attività vengono identificatein_progress quando inizia il lavoroL'SDK crea automaticamente todo per:
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Ottimizza le prestazioni della mia app React e traccia i progressi con i todo",
options: { maxTurns: 15 }
})) {
// Gli aggiornamenti dei todo si riflettono nel flusso dei messaggi
if (message.type === "tool_use" && message.name === "TodoWrite") {
const todos = message.input.todos;
console.log("Aggiornamento Stato Todo:");
todos.forEach((todo, index) => {
const status = todo.status === "completed" ? "✅" :
todo.status === "in_progress" ? "🔧" : "❌";
console.log(`${index + 1}. ${status} ${todo.content}`);
});
}
}import { query } from "@anthropic-ai/claude-agent-sdk";
class TodoTracker {
private todos: any[] = [];
displayProgress() {
if (this.todos.length === 0) return;
const completed = this.todos.filter(t => t.status === "completed").length;
const inProgress = this.todos.filter(t => t.status === "in_progress").length;
const total = this.todos.length;
console.log(`\nProgressi: ${completed}/${total} completati`);
console.log(`Attualmente lavorando su: ${inProgress} attività\n`);
this.todos.forEach((todo, index) => {
const icon = todo.status === "completed" ? "✅" :
todo.status === "in_progress" ? "🔧" : "❌";
const text = todo.status === "in_progress" ? todo.activeForm : todo.content;
console.log(`${index + 1}. ${icon} ${text}`);
});
}
async trackQuery(prompt: string) {
for await (const message of query({
prompt,
options: { maxTurns: 20 }
})) {
if (message.type === "tool_use" && message.name === "TodoWrite") {
this.todos = message.input.todos;
this.displayProgress();
}
}
}
}
// Utilizzo
const tracker = new TodoTracker();
await tracker.trackQuery("Costruisci un sistema di autenticazione completo con i todo");