feat(genkit-tools/cli): Add docs discovery tools to the CLI#4453
feat(genkit-tools/cli): Add docs discovery tools to the CLI#4453ssbushi wants to merge 2 commits intosb/mcpDocsImprovementsfrom
Conversation
Summary of ChangesHello @ssbushi, 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 significantly enhances the Genkit CLI by providing direct, integrated access to its documentation. Users can now effortlessly list, read, and search through Genkit's documentation directly from their command line. This functionality is underpinned by a newly established, centralized utility layer for documentation handling, which also incorporates an efficient caching strategy to optimize the retrieval of documentation bundles. 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 new CLI commands (docs:list, docs:search, docs:read) for discovering and reading Genkit documentation. This is achieved by adding a new docs.ts command file and refactoring existing documentation-related logic from mcp/docs.ts into a new shared utility file utils/docs.ts. The refactoring is well-done and improves code reuse. My feedback includes suggestions to improve type safety in error handling and to enhance the readability of the search scoring logic by replacing magic numbers with named constants.
| } catch (e: any) { | ||
| logger.error(`Failed to load documentation: ${e.message}`); | ||
| } |
There was a problem hiding this comment.
For improved type safety, it's a best practice to catch errors as unknown and then check their type before accessing properties like message. This avoids potential runtime errors if a non-Error object is thrown.
| } catch (e: any) { | |
| logger.error(`Failed to load documentation: ${e.message}`); | |
| } | |
| } catch (e: unknown) { | |
| logger.error(`Failed to load documentation: ${e instanceof Error ? e.message : String(e)}`); | |
| } |
| } catch (e: any) { | ||
| logger.error(`Failed to load documentation: ${e.message}`); | ||
| } |
There was a problem hiding this comment.
For improved type safety, it's a best practice to catch errors as unknown and then check their type before accessing properties like message. This avoids potential runtime errors if a non-Error object is thrown.
| } catch (e: any) { | |
| logger.error(`Failed to load documentation: ${e.message}`); | |
| } | |
| } catch (e: unknown) { | |
| logger.error(`Failed to load documentation: ${e instanceof Error ? e.message : String(e)}`); | |
| } |
| } catch (e: any) { | ||
| logger.error(`Failed to load documentation: ${e.message}`); | ||
| } |
There was a problem hiding this comment.
For improved type safety, it's a best practice to catch errors as unknown and then check their type before accessing properties like message. This avoids potential runtime errors if a non-Error object is thrown.
| } catch (e: any) { | |
| logger.error(`Failed to load documentation: ${e.message}`); | |
| } | |
| } catch (e: unknown) { | |
| logger.error(`Failed to load documentation: ${e instanceof Error ? e.message : String(e)}`); | |
| } |
| terms.forEach((term) => { | ||
| if (title.includes(term)) score += 10; | ||
| if (desc.includes(term)) score += 5; | ||
| if (headers.includes(term)) score += 3; | ||
| if (file.includes(term)) score += 5; | ||
| }); |
There was a problem hiding this comment.
The scoring logic uses magic numbers (10, 5, 3, 5), which can make the code harder to understand and maintain. It's better to extract these values into named constants to improve readability and make it easier to adjust the scoring in the future.
const TITLE_SCORE = 10;
const DESC_SCORE = 5;
const HEADERS_SCORE = 3;
const FILE_PATH_SCORE = 5;
terms.forEach((term) => {
if (title.includes(term)) score += TITLE_SCORE;
if (desc.includes(term)) score += DESC_SCORE;
if (headers.includes(term)) score += HEADERS_SCORE;
if (file.includes(term)) score += FILE_PATH_SCORE;
});
Checklist (if applicable):