Conversation
Given that CLI is a blocking command line application When running pack test in CI Then add --auto-exit flag to terminate after execution This prevents the test from hanging indefinitely in CI.
Given that tsup bundles code to dist/cli but agents are in dist/agents When JudgeAgent initializes in production Then fallback to dist/agents/devhub/judge/ path if local file not found Fixes: ENOENT error when running from packaged distribution
Summary of ChangesHello @crazygo, 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 focuses on enhancing the overall reliability and stability of the system. It improves how a core agent initializes by making its prompt file location more robust across different environments and refines the test suite by ensuring CLI processes terminate cleanly, leading to more dependable automated tests. Highlights
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 improves the agent initialization logic to support different environments and makes a test script more robust. My review focuses on the new file path logic in JudgeAgent.ts. While the intent to support both development and production environments is good, the implementation has some fragility. I've added comments regarding the error handling and the hardcoded fallback path, which could be a source of future maintenance issues.
| try { | ||
| await fs.access(systemPromptPath); | ||
| } catch { | ||
| // Fallback: look in dist/agents/devhub/judge/ | ||
| const distRoot = path.resolve(agentDir, '../../'); | ||
| systemPromptPath = path.join(distRoot, 'agents/devhub/judge/judge.agent.md'); | ||
| } |
There was a problem hiding this comment.
The catch block is empty, which is generally discouraged as it can swallow important errors. For example, if fs.access fails due to a permissions issue on a parent directory, this code will silently proceed to the fallback path, masking the real problem.
Please add the error parameter to the catch block. Even if you don't log the error, it's better practice not to have a completely empty catch.
| try { | |
| await fs.access(systemPromptPath); | |
| } catch { | |
| // Fallback: look in dist/agents/devhub/judge/ | |
| const distRoot = path.resolve(agentDir, '../../'); | |
| systemPromptPath = path.join(distRoot, 'agents/devhub/judge/judge.agent.md'); | |
| } | |
| try { | |
| await fs.access(systemPromptPath); | |
| } catch (_error) { | |
| // Fallback: look in dist/agents/devhub/judge/ | |
| const distRoot = path.resolve(agentDir, '../../'); | |
| systemPromptPath = path.join(distRoot, 'agents/devhub/judge/judge.agent.md'); | |
| } |
| const distRoot = path.resolve(agentDir, '../../'); | ||
| systemPromptPath = path.join(distRoot, 'agents/devhub/judge/judge.agent.md'); |
There was a problem hiding this comment.
This fallback path construction is quite fragile. It relies on a hardcoded relative path ../../ and a long, specific path string 'agents/devhub/judge/judge.agent.md'. This makes the code brittle and hard to maintain if the project structure or build output changes.
While a larger refactor might be out of scope for this PR, consider defining these path segments as constants at the top of the file to improve readability and make them easier to update in one place.
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the robustness of agent initialization for handling different deployment environments and improves test reliability by ensuring the CLI exits automatically during test execution.
- Implements fallback logic in
JudgeAgentto locate prompt files in both development and production directory structures - Adds
--auto-exitflag to test script to ensure deterministic test completion
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| scripts/test-pack.js | Added --auto-exit flag to CLI command for reliable test execution |
| packages/agents/devhub/judge/JudgeAgent.ts | Introduced dual-path resolution for judge.agent.md file to support both development and bundled production environments |
Comments suppressed due to low confidence (1)
packages/agents/devhub/judge/JudgeAgent.ts:52
- The approach used here differs from the established pattern used by other agents in the codebase. The
SummarizerAgentandDevHubagents useloadAgentPipelineConfigfromagentLoader.ts, which already has robust logic to handle development vs production paths, including searching indist/agents/andpackages/agents/.
Consider using the same approach for consistency:
async initialize() {
const agentDir = path.dirname(fileURLToPath(import.meta.url));
const { systemPrompt } = await loadAgentPipelineConfig(agentDir, {
coordinatorFileName: 'judge.agent.md',
});
this.systemPrompt = systemPrompt;
addLog(`[JudgeAgent] Initialized with prompt length: ${this.systemPrompt.length}`);
}This would require importing loadAgentPipelineConfig from ../../runtime/agentLoader.js.
async initialize() {
// In production (dist/), agent files are in dist/agents/devhub/judge/
// In development, they're alongside this file
const agentDir = path.dirname(fileURLToPath(import.meta.url));
let systemPromptPath = path.join(agentDir, 'judge.agent.md');
// Check if running from dist/cli (bundled), need to go to dist/agents
try {
await fs.access(systemPromptPath);
} catch {
// Fallback: look in dist/agents/devhub/judge/
const distRoot = path.resolve(agentDir, '../../');
systemPromptPath = path.join(distRoot, 'agents/devhub/judge/judge.agent.md');
}
this.systemPrompt = await fs.readFile(systemPromptPath, 'utf-8');
addLog(`[JudgeAgent] Initialized with prompt length: ${this.systemPrompt.length}`);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } catch { | ||
| // Fallback: look in dist/agents/devhub/judge/ | ||
| const distRoot = path.resolve(agentDir, '../../'); | ||
| systemPromptPath = path.join(distRoot, 'agents/devhub/judge/judge.agent.md'); |
There was a problem hiding this comment.
The fallback logic has a potential issue. If the primary path fails, the code attempts to read from a fallback path without verifying its existence. If both paths fail, fs.readFile on line 49 will throw an unhandled error, causing initialization to fail without a clear error message.
Consider adding error handling or verification for the fallback path:
try {
await fs.access(systemPromptPath);
} catch {
// Fallback: look in dist/agents/devhub/judge/
const distRoot = path.resolve(agentDir, '../../');
systemPromptPath = path.join(distRoot, 'agents/devhub/judge/judge.agent.md');
try {
await fs.access(systemPromptPath);
} catch {
throw new Error(`Could not locate judge.agent.md in either ${path.join(agentDir, 'judge.agent.md')} or ${systemPromptPath}`);
}
}| systemPromptPath = path.join(distRoot, 'agents/devhub/judge/judge.agent.md'); | |
| systemPromptPath = path.join(distRoot, 'agents/devhub/judge/judge.agent.md'); | |
| try { | |
| await fs.access(systemPromptPath); | |
| } catch { | |
| throw new Error(`Could not locate judge.agent.md in either ${path.join(agentDir, 'judge.agent.md')} or ${systemPromptPath}`); | |
| } |
This pull request improves the robustness of agent initialization and the test script for running the package CLI. The most important changes are grouped below:
Agent Initialization Robustness:
JudgeAgentclass'sinitializemethod to handle both development and production environments when locating thejudge.agent.mdprompt file. It now attempts to read the file from the local directory and falls back to thedist/agents/devhub/judge/directory if not found, ensuring compatibility across build setups.Test Script Improvements:
scripts/test-pack.jsto include the--auto-exitflag when running the CLI, which likely ensures the process exits automatically after execution, making tests more reliable.