Skip to content

Commit be36291

Browse files
author
Andy Klier
committed
fixing state
1 parent 927faa4 commit be36291

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/filesystem/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,13 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
589589

590590

591591
server.setRequestHandler(CallToolRequestSchema, async (request) => {
592+
// Generate a unique prompt ID for this request that remains stable across multiple calls
593+
// We'll use a combination of the current hour and minute to make it stable for a short period
594+
const now = new Date();
595+
const promptId = `prompt-${now.getFullYear()}${now.getMonth()}${now.getDate()}-${now.getHours()}${now.getMinutes()}`;
596+
592597
try {
593598
const { name, arguments: args } = request.params;
594-
595-
// Generate a unique prompt ID for this request
596-
const promptId = 'prompt-' + Date.now() + '-' + Math.floor(Math.random() * 10000);
597599

598600
// Get the response from the appropriate tool handler
599601
let response;
@@ -839,13 +841,13 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
839841
throw new Error(`Unknown tool: ${name}`);
840842
}
841843

842-
// Reset validation state after successful response
843-
await resetValidationState();
844+
// Reset validation state after successful response, but preserve state within the same prompt
845+
await resetValidationState(promptId);
844846

845847
return response;
846848
} catch (error) {
847-
// Reset validation state even on error
848-
await resetValidationState();
849+
// Reset validation state even on error, but preserve state within the same prompt
850+
await resetValidationState(promptId);
849851

850852
const errorMessage = error instanceof Error ? error.message : String(error);
851853
return {

src/filesystem/state-utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ export async function saveState(state: PromptState): Promise<void> {
2525
await fs.writeFile(STATE_FILE_PATH, JSON.stringify(state, null, 2), 'utf-8');
2626
}
2727

28-
// Reset the validation state
29-
export async function resetValidationState(): Promise<void> {
28+
// Reset the validation state, but only if it's a new prompt
29+
export async function resetValidationState(currentPromptId?: string): Promise<void> {
3030
const state = await getState();
31-
if (state.checkedThisPrompt) {
31+
// Only reset if no promptId is provided or if it's different from the current one
32+
if (!currentPromptId || state.promptId !== currentPromptId) {
3233
state.checkedThisPrompt = false;
3334
state.promptId = null;
3435
await saveState(state);
3536
// State reset for next prompt
3637
}
38+
// Skip reset if we're in the same prompt to allow multiple operations
3739
}
3840

3941
// Check if we've already validated in this prompt

0 commit comments

Comments
 (0)