@probelabs/probe 0.6.0-rc239 → 0.6.0-rc240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ import {
6
6
  delegateTool,
7
7
  analyzeAllTool,
8
8
  createExecutePlanTool,
9
+ createCleanupExecutePlanTool,
9
10
  bashTool,
10
11
  editTool,
11
12
  createTool,
@@ -18,6 +19,7 @@ import {
18
19
  delegateSchema,
19
20
  analyzeAllSchema,
20
21
  executePlanSchema,
22
+ cleanupExecutePlanSchema,
21
23
  bashSchema,
22
24
  editSchema,
23
25
  createSchema,
@@ -27,6 +29,7 @@ import {
27
29
  delegateToolDefinition,
28
30
  analyzeAllToolDefinition,
29
31
  getExecutePlanToolDefinition,
32
+ getCleanupExecutePlanToolDefinition,
30
33
  bashToolDefinition,
31
34
  editToolDefinition,
32
35
  createToolDefinition,
@@ -63,6 +66,10 @@ export function createTools(configOptions) {
63
66
  }
64
67
  if (configOptions.enableExecutePlan && isToolAllowed('execute_plan')) {
65
68
  tools.executePlanTool = createExecutePlanTool(configOptions);
69
+ // cleanup_execute_plan is enabled together with execute_plan
70
+ if (isToolAllowed('cleanup_execute_plan')) {
71
+ tools.cleanupExecutePlanTool = createCleanupExecutePlanTool(configOptions);
72
+ }
66
73
  } else if (isToolAllowed('analyze_all')) {
67
74
  // analyze_all is fallback when execute_plan is not enabled
68
75
  tools.analyzeAllTool = analyzeAllTool(configOptions);
@@ -104,6 +111,7 @@ export {
104
111
  delegateSchema,
105
112
  analyzeAllSchema,
106
113
  executePlanSchema,
114
+ cleanupExecutePlanSchema,
107
115
  bashSchema,
108
116
  editSchema,
109
117
  createSchema,
@@ -114,6 +122,7 @@ export {
114
122
  delegateToolDefinition,
115
123
  analyzeAllToolDefinition,
116
124
  getExecutePlanToolDefinition,
125
+ getCleanupExecutePlanToolDefinition,
117
126
  bashToolDefinition,
118
127
  editToolDefinition,
119
128
  createToolDefinition,
package/src/index.js CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  delegateSchema,
28
28
  analyzeAllSchema,
29
29
  executePlanSchema,
30
+ cleanupExecutePlanSchema,
30
31
  attemptCompletionSchema,
31
32
  bashSchema,
32
33
  searchToolDefinition,
@@ -47,7 +48,7 @@ import {
47
48
  createToolDefinition
48
49
  } from './tools/edit.js';
49
50
  import { searchTool, queryTool, extractTool, delegateTool, analyzeAllTool } from './tools/vercel.js';
50
- import { createExecutePlanTool, getExecutePlanToolDefinition } from './tools/executePlan.js';
51
+ import { createExecutePlanTool, getExecutePlanToolDefinition, createCleanupExecutePlanTool, getCleanupExecutePlanToolDefinition } from './tools/executePlan.js';
51
52
  import { bashTool } from './tools/bash.js';
52
53
  import { editTool, createTool } from './tools/edit.js';
53
54
  import { ProbeAgent } from './agent/ProbeAgent.js';
@@ -93,6 +94,7 @@ export {
93
94
  delegateTool,
94
95
  analyzeAllTool,
95
96
  createExecutePlanTool,
97
+ createCleanupExecutePlanTool,
96
98
  bashTool,
97
99
  editTool,
98
100
  createTool,
@@ -106,6 +108,7 @@ export {
106
108
  delegateSchema,
107
109
  analyzeAllSchema,
108
110
  executePlanSchema,
111
+ cleanupExecutePlanSchema,
109
112
  attemptCompletionSchema,
110
113
  bashSchema,
111
114
  editSchema,
@@ -117,6 +120,7 @@ export {
117
120
  delegateToolDefinition,
118
121
  analyzeAllToolDefinition,
119
122
  getExecutePlanToolDefinition,
123
+ getCleanupExecutePlanToolDefinition,
120
124
  attemptCompletionToolDefinition,
121
125
  bashToolDefinition,
122
126
  editToolDefinition,
@@ -59,6 +59,11 @@ export const executePlanSchema = z.object({
59
59
  description: z.string().optional().describe('Human-readable description of what this plan does, for logging.')
60
60
  });
61
61
 
62
+ export const cleanupExecutePlanSchema = z.object({
63
+ clearOutputBuffer: z.boolean().optional().default(true).describe('Clear the output buffer from previous execute_plan calls'),
64
+ clearSessionStore: z.boolean().optional().default(false).describe('Clear the session store (persisted data across execute_plan calls)')
65
+ });
66
+
62
67
  // Schema for the attempt_completion tool - flexible validation for direct XML response
63
68
  export const attemptCompletionSchema = {
64
69
  // Custom validation that requires result parameter but allows direct XML response
@@ -431,6 +436,7 @@ export const DEFAULT_VALID_TOOLS = [
431
436
  'delegate',
432
437
  'analyze_all',
433
438
  'execute_plan',
439
+ 'cleanup_execute_plan',
434
440
  'listSkills',
435
441
  'useSkill',
436
442
  'listFiles',
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { tool } from 'ai';
9
- import { executePlanSchema, parseAndResolvePaths } from './common.js';
9
+ import { executePlanSchema, cleanupExecutePlanSchema, parseAndResolvePaths } from './common.js';
10
10
  import { createDSLRuntime } from '../agent/dsl/runtime.js';
11
11
  import { search } from '../search.js';
12
12
  import { query } from '../query.js';
@@ -347,7 +347,16 @@ RULES REMINDER:
347
347
  });
348
348
  }
349
349
 
350
- // All retries exhausted
350
+ // All retries exhausted — auto-cleanup output buffer to prevent stale data
351
+ if (outputBuffer && outputBuffer.items && outputBuffer.items.length > 0) {
352
+ const clearedChars = outputBuffer.items.reduce((sum, item) => sum + item.length, 0);
353
+ outputBuffer.items = [];
354
+ planSpan?.addEvent?.('dsl.auto_cleanup', {
355
+ 'cleanup.chars_cleared': clearedChars,
356
+ 'cleanup.reason': 'all_retries_exhausted',
357
+ });
358
+ }
359
+
351
360
  finalOutput = `Plan execution failed after ${maxRetries} retries.\n\nLast error: ${lastError}`;
352
361
  planSpan?.setAttributes?.({
353
362
  'dsl.result': 'all_retries_exhausted',
@@ -358,6 +367,11 @@ RULES REMINDER:
358
367
  planSpan?.end?.();
359
368
  return finalOutput;
360
369
  } catch (e) {
370
+ // Auto-cleanup output buffer on exception to prevent stale data
371
+ if (outputBuffer && outputBuffer.items && outputBuffer.items.length > 0) {
372
+ outputBuffer.items = [];
373
+ }
374
+
361
375
  planSpan?.setStatus?.('ERROR');
362
376
  planSpan?.addEvent?.('exception', {
363
377
  'exception.message': e.message,
@@ -808,3 +822,87 @@ output(table);
808
822
  return "Generated table with " + results.length + " items.";
809
823
  \`\`\``;
810
824
  }
825
+
826
+ /**
827
+ * Create the cleanup_execute_plan tool for the Vercel AI SDK.
828
+ *
829
+ * Cleans up output buffer and optionally session store from previous
830
+ * failed or interrupted execute_plan calls.
831
+ *
832
+ * @param {Object} options
833
+ * @param {Object} [options.outputBuffer] - Output buffer to clear
834
+ * @param {Object} [options.sessionStore] - Session store to clear
835
+ * @param {Object} [options.tracer] - OTEL tracer for tracing
836
+ * @returns {Object} Vercel AI SDK tool
837
+ */
838
+ export function createCleanupExecutePlanTool(options) {
839
+ const { outputBuffer, sessionStore, tracer } = options;
840
+
841
+ return tool({
842
+ description: 'Clean up output buffer and session store from previous execute_plan calls. ' +
843
+ 'Use this when a previous execute_plan failed and left stale data, or before starting a fresh analysis.',
844
+ parameters: cleanupExecutePlanSchema,
845
+ execute: async ({ clearOutputBuffer = true, clearSessionStore = false }) => {
846
+ const span = tracer?.createToolSpan?.('cleanup_execute_plan', {
847
+ 'cleanup.clear_output_buffer': clearOutputBuffer,
848
+ 'cleanup.clear_session_store': clearSessionStore,
849
+ }) || null;
850
+
851
+ const results = [];
852
+
853
+ try {
854
+ if (clearOutputBuffer && outputBuffer) {
855
+ const itemCount = outputBuffer.items?.length || 0;
856
+ const charCount = outputBuffer.items?.reduce((sum, item) => sum + item.length, 0) || 0;
857
+ outputBuffer.items = [];
858
+ results.push(`Output buffer cleared (${itemCount} items, ${charCount} chars)`);
859
+ }
860
+
861
+ if (clearSessionStore && sessionStore) {
862
+ const keyCount = Object.keys(sessionStore).length;
863
+ for (const key of Object.keys(sessionStore)) {
864
+ delete sessionStore[key];
865
+ }
866
+ results.push(`Session store cleared (${keyCount} keys)`);
867
+ }
868
+
869
+ const output = results.length > 0
870
+ ? `Cleanup complete:\n- ${results.join('\n- ')}`
871
+ : 'Nothing to clean up';
872
+
873
+ span?.setAttributes?.({
874
+ 'cleanup.result': output,
875
+ 'cleanup.success': true,
876
+ });
877
+ span?.setStatus?.('OK');
878
+ span?.end?.();
879
+
880
+ return output;
881
+ } catch (e) {
882
+ span?.setStatus?.('ERROR');
883
+ span?.addEvent?.('exception', { 'exception.message': e.message });
884
+ span?.end?.();
885
+ return `Cleanup failed: ${e.message}`;
886
+ }
887
+ },
888
+ });
889
+ }
890
+
891
+ /**
892
+ * XML tool definition for cleanup_execute_plan.
893
+ *
894
+ * @returns {string} Tool definition text
895
+ */
896
+ export function getCleanupExecutePlanToolDefinition() {
897
+ return `## cleanup_execute_plan
898
+ Description: Clean up output buffer and session store from previous execute_plan calls. Use when a previous execute_plan failed and left stale data, or before starting a fresh analysis.
899
+
900
+ Parameters:
901
+ - clearOutputBuffer: (optional, default: true) Clear the output buffer from previous execute_plan calls
902
+ - clearSessionStore: (optional, default: false) Clear the session store (persisted data across execute_plan calls)
903
+
904
+ Example:
905
+ <cleanup_execute_plan>
906
+ <clearOutputBuffer>true</clearOutputBuffer>
907
+ </cleanup_execute_plan>`;
908
+ }
@@ -11,8 +11,8 @@ export { editTool, createTool } from './edit.js';
11
11
  // Export LangChain tools
12
12
  export { createSearchTool, createQueryTool, createExtractTool } from './langchain.js';
13
13
 
14
- // Export execute_plan tool
15
- export { createExecutePlanTool, getExecutePlanToolDefinition } from './executePlan.js';
14
+ // Export execute_plan and cleanup_execute_plan tools
15
+ export { createExecutePlanTool, getExecutePlanToolDefinition, createCleanupExecutePlanTool, getCleanupExecutePlanToolDefinition } from './executePlan.js';
16
16
 
17
17
  // Export common schemas and utilities
18
18
  export {
@@ -22,6 +22,7 @@ export {
22
22
  delegateSchema,
23
23
  bashSchema,
24
24
  executePlanSchema,
25
+ cleanupExecutePlanSchema,
25
26
  delegateDescription,
26
27
  delegateToolDefinition,
27
28
  bashDescription,