Add scratchpad feature with read, write, and edit operations#27
Add scratchpad feature with read, write, and edit operations#27marcelsamyn merged 1 commit intomainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request delivers a foundational scratchpad feature, providing users with a private, persistent space to store and manipulate text. It establishes the necessary database infrastructure, implements robust backend logic for reading, writing, and safely editing content, and exposes these capabilities through new API endpoints. Crucially, it integrates this new functionality into the AI assistant's toolset, enhancing its ability to manage user-specific information. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new scratchpad feature, enabling users to store, read, write, and edit persistent text content. The changes include a new scratchpads table in the database schema, core library functions (readScratchpad, writeScratchpad, editScratchpad), corresponding API routes, and integration with the MCP server. Zod schemas are used for robust request and response validation, and the TypeID system has been extended for scratchpad IDs. The implementation includes safeguards for the edit operation to prevent ambiguous replacements. However, critical security vulnerabilities, primarily related to Insecure Direct Object Reference (IDOR), were identified. The API endpoints and MCP tools accept a userId directly from the request without proper authorization checks, which could allow any user to access or modify the scratchpad of any other user. It is crucial to implement robust authentication and authorization checks to ensure users can only interact with their own data.
| const params = scratchpadReadRequestSchema.parse(await readBody(event)); | ||
| return scratchpadResponseSchema.parse(await readScratchpad(params)); |
There was a problem hiding this comment.
| const params = scratchpadWriteRequestSchema.parse(await readBody(event)); | ||
| return scratchpadResponseSchema.parse(await writeScratchpad(params)); |
There was a problem hiding this comment.
| const params = scratchpadEditRequestSchema.parse(await readBody(event)); | ||
| return scratchpadEditResponseSchema.parse(await editScratchpad(params)); |
There was a problem hiding this comment.
src/lib/mcp/mcp-server.ts
Outdated
| server.tool( | ||
| "read scratchpad", | ||
| scratchpadReadRequestSchema, | ||
| async ({ userId }) => { | ||
| const result = await readScratchpad({ userId }); | ||
| return { | ||
| content: [ | ||
| { type: "text", text: result.content || "(empty scratchpad)" }, | ||
| ], | ||
| }; | ||
| }, | ||
| ); | ||
|
|
||
| // Write scratchpad (overwrite or append) | ||
| server.tool( | ||
| "write scratchpad", | ||
| scratchpadWriteRequestSchema, | ||
| async (params) => { | ||
| const result = await writeScratchpad(params); | ||
| return { | ||
| content: [ | ||
| { type: "text", text: `Scratchpad updated.\n\n${result.content}` }, | ||
| ], | ||
| }; | ||
| }, | ||
| ); | ||
|
|
||
| // Edit scratchpad (replace text with safeguards) | ||
| server.tool( | ||
| "edit scratchpad", | ||
| scratchpadEditRequestSchema, | ||
| async (params) => { | ||
| const result = await editScratchpad(params); | ||
| if (!result.applied) { | ||
| return { | ||
| content: [{ type: "text", text: `Edit failed: ${result.message}` }], | ||
| isError: true, | ||
| }; | ||
| } | ||
| return { | ||
| content: [ | ||
| { type: "text", text: `Edit applied.\n\n${result.content}` }, | ||
| ], | ||
| }; | ||
| }, | ||
| ); |
There was a problem hiding this comment.
The MCP tools for reading, writing, and editing scratchpads accept a userId as a parameter and pass it directly to the underlying library functions without any authorization checks. If these tools are exposed to untrusted users (e.g., through an AI assistant), they could be used to access or modify other users' scratchpads.
.gitignore
Outdated
|
|
||
| postgres_data/ | ||
| minio-data/ No newline at end of file | ||
| minio-data/package-lock.json |
There was a problem hiding this comment.
The .gitignore entry was changed from minio-data/ to minio-data/package-lock.json. The original entry ignored the entire minio-data directory and its contents. The new entry only ignores package-lock.json within that directory. This means other files in minio-data/ will now be tracked by Git. Please confirm if this change in scope is intentional. If the entire minio-data directory should still be ignored, the entry should remain minio-data/.
minio-data/
| }); | ||
|
|
||
| if (!existing) { | ||
| return { content: "", updatedAt: new Date() }; |
There was a problem hiding this comment.
When a scratchpad does not exist, the readScratchpad function returns a synthetic updatedAt timestamp (new Date()). This can be semantically misleading as a non-existent entity doesn't truly have an updatedAt timestamp from the database. Consider making updatedAt optional in ScratchpadResponse and its Zod schema (scratchpadResponseSchema) to accurately reflect when a scratchpad has not yet been persisted.
8fb9a8e to
7c8bbe1
Compare
Add a scratchpad/notepad that LLM assistants can read, write, and edit directly, giving them explicit control over what they remember alongside the automatic background ingestion pipeline. - New `scratchpads` table (one per user, dedicated table following userProfiles pattern) - Scratchpad service with read, write (overwrite/append), and edit (targeted text replacement with safeguards) - Edit safeguards: existence check, uniqueness check (text must appear exactly once), exact string matching (no regex), returns current content on failure for retry - MCP tools: "read scratchpad", "write scratchpad", "edit scratchpad" - HTTP routes: POST /scratchpad/read, /scratchpad/write, /scratchpad/edit - Drizzle migration for the new table - Add package-lock.json to .gitignore https://claude.ai/code/session_01BNiwDytpczv5sEB3dsxPgQ
7c8bbe1 to
8fd6268
Compare
Summary
This PR introduces a new scratchpad feature that allows users to store and manage persistent text content. The scratchpad supports read, write (with overwrite/append modes), and edit operations with built-in safeguards.
Key Changes
scratchpadstable with user-specific storage (one scratchpad per user via unique constraint onuser_id)src/lib/scratchpad.tswith three main operations:readScratchpad: Retrieves existing scratchpad content or returns empty statewriteScratchpad: Overwrites or appends content to scratchpadeditScratchpad: Safely replaces text with validation to prevent ambiguous replacements/scratchpad/:read.post.ts: Fetch scratchpad contentwrite.post.ts: Create or update scratchpadedit.post.ts: Modify specific text within scratchpadscratchpadto the TypeID system for consistent ID generationImplementation Details
updatedAttimestamp for audit purposeshttps://claude.ai/code/session_01BNiwDytpczv5sEB3dsxPgQ