@@ -39,7 +39,9 @@ async function executePruneOperation(
3939
4040 if ( ! ids || ids . length === 0 ) {
4141 logger . debug ( `${ toolName } tool called but ids is empty or undefined` )
42- return `No IDs provided. Check the <prunable-tools> list for available IDs to ${ toolName . toLowerCase ( ) } .`
42+ throw new Error (
43+ `No IDs provided. Check the <prunable-tools> list for available IDs to ${ toolName . toLowerCase ( ) } .` ,
44+ )
4345 }
4446
4547 const numericToolIds : number [ ] = ids
@@ -48,7 +50,7 @@ async function executePruneOperation(
4850
4951 if ( numericToolIds . length === 0 ) {
5052 logger . debug ( `No numeric tool IDs provided for ${ toolName } : ` + JSON . stringify ( ids ) )
51- return "No numeric IDs provided. Format: ids: [id1, id2, ...]"
53+ throw new Error ( "No numeric IDs provided. Format: ids: [id1, id2, ...]" )
5254 }
5355
5456 // Fetch messages to calculate tokens and find current agent
@@ -65,7 +67,9 @@ async function executePruneOperation(
6567 // Validate that all numeric IDs are within bounds
6668 if ( numericToolIds . some ( ( id ) => id < 0 || id >= toolIdList . length ) ) {
6769 logger . debug ( "Invalid tool IDs provided: " + numericToolIds . join ( ", " ) )
68- return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list."
70+ throw new Error (
71+ "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list." ,
72+ )
6973 }
7074
7175 // Validate that all IDs exist in cache and aren't protected
@@ -78,7 +82,9 @@ async function executePruneOperation(
7882 "Rejecting prune request - ID not in cache (turn-protected or hallucinated)" ,
7983 { index, id } ,
8084 )
81- return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list."
85+ throw new Error (
86+ "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list." ,
87+ )
8288 }
8389 const allProtectedTools = config . tools . settings . protectedTools
8490 if ( allProtectedTools . includes ( metadata . tool ) ) {
@@ -87,7 +93,9 @@ async function executePruneOperation(
8793 id,
8894 tool : metadata . tool ,
8995 } )
90- return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list."
96+ throw new Error (
97+ "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list." ,
98+ )
9199 }
92100
93101 const filePath = getFilePathFromParameters ( metadata . parameters )
@@ -98,7 +106,9 @@ async function executePruneOperation(
98106 tool : metadata . tool ,
99107 filePath,
100108 } )
101- return "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list."
109+ throw new Error (
110+ "Invalid IDs provided. Only use numeric IDs from the <prunable-tools> list." ,
111+ )
102112 }
103113 }
104114
@@ -158,7 +168,9 @@ export function createDiscardTool(ctx: PruneToolContext): ReturnType<typeof tool
158168 const validReasons = [ "completion" , "noise" ] as const
159169 if ( typeof reason !== "string" || ! validReasons . includes ( reason as any ) ) {
160170 ctx . logger . debug ( "Invalid discard reason provided: " + reason )
161- return "No valid reason found. Use 'completion' or 'noise' as the first element."
171+ throw new Error (
172+ "No valid reason found. Use 'completion' or 'noise' as the first element." ,
173+ )
162174 }
163175
164176 const numericIds = args . ids . slice ( 1 )
@@ -186,7 +198,9 @@ export function createExtractTool(ctx: PruneToolContext): ReturnType<typeof tool
186198 ctx . logger . debug (
187199 "Extract tool called without distillation: " + JSON . stringify ( args ) ,
188200 )
189- return "Missing distillation. You must provide a distillation string for each ID."
201+ throw new Error (
202+ "Missing distillation. You must provide a distillation string for each ID." ,
203+ )
190204 }
191205
192206 // Log the distillation for debugging/analysis
0 commit comments