feat: add PostgreSQL database analysis tool and agent#204
Merged
Conversation
- Change tool_choice from Required to Auto to let model decide when to use tools - Add loop detection for confirm_extraction calls - Stop extraction after 3+ confirm_extraction calls to prevent infinite loops - This resolves issue where GLM-4.6 repeatedly calls confirm_extraction tool
- Convenience script to run PdfToTextAgent with Zai GLM-4.6 - Uses config from ~/Library/Application Support/nocodo/api.toml - Supports custom prompt and allowed working directories
- Format long lines across agent modules for better readability - Add smart payload redaction in Gemini client to log tool definitions and system prompts only once, reducing log verbosity - Configure HTTP client with no_proxy option Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implement read-only PostgreSQL database query execution capabilities, mirroring the existing SQLite reader tool and agent. This provides AI-powered database analysis for PostgreSQL with comprehensive security and credential isolation. Key Features: - Read-only SQL query execution with multi-layer security validation - Connection pooling with sqlx for efficient PostgreSQL access - Credential isolation (agent manages connections, LLM never sees credentials) - Schema auto-discovery using INFORMATION_SCHEMA - Reflection mode for inspecting database structure without writing SQL - Query validation using AST parsing with PostgreSQL dialect - Transaction-level safety with READ ONLY mode - Statement timeout and result set limits Implementation: Tool Layer (nocodo-tools): - Add PostgresReaderRequest/Response types with Query and Reflect modes - Implement PostgresExecutor with connection pooling and query validation - Create formatter for LLM-friendly output - Build reflection queries using INFORMATION_SCHEMA (schemas, tables, columns, indexes, views, foreign keys, constraints, stats) - Multi-layer security: AST validation, keyword blocking, read-only transactions, statement timeouts Agent Layer (nocodo-agents): - Implement PostgresReaderAgent with schema discovery at initialization - Generate dynamic system prompt with discovered table list - Inject connection string into tool calls (hidden from LLM) - Add LLM schema definition for postgres_reader tool - Create standalone runner binary for testing Security Measures: - Only SELECT queries allowed (INSERT/UPDATE/DELETE/DROP blocked) - Connection string never exposed to LLM - BEGIN READ ONLY transaction wrapper - Statement timeout (5 seconds) - Result set limits (max 1000 rows) - AST-based query validation with dangerous keyword scanning Dependencies: - Add sqlx with postgres feature and tokio runtime - Add url crate for connection string parsing - Add testcontainers for integration testing - Feature-gated behind 'postgres' flag Testing: - Unit tests for query validation and connection string parsing - PostgreSQL-specific reflection query tests - Runner binary for manual testing (postgres-reader-runner) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
📊 Code Complexity Analysis
💡 Suggestion: This is a large PR with 6412 added lines. Consider:
Automated analysis by GitHub Actions |
🤖 Automated Code Review SummaryThis automated review was generated to help ensure code quality and security standards. Rust Code Analysis
Security Analysis
Recommendations
This review was automatically generated. Please address any issues before merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Testing