Skip to content

Fix/release#54

Merged
crazygo merged 2 commits intoreleasefrom
fix/release
Nov 14, 2025
Merged

Fix/release#54
crazygo merged 2 commits intoreleasefrom
fix/release

Conversation

@crazygo
Copy link
Owner

@crazygo crazygo commented Nov 14, 2025

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:

  • Updated the JudgeAgent class's initialize method to handle both development and production environments when locating the judge.agent.md prompt file. It now attempts to read the file from the local directory and falls back to the dist/agents/devhub/judge/ directory if not found, ensuring compatibility across build setups.

Test Script Improvements:

  • Modified the test script command in scripts/test-pack.js to include the --auto-exit flag when running the CLI, which likely ensures the process exits automatically after execution, making tests more reliable.

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
Copilot AI review requested due to automatic review settings November 14, 2025 09:04
@crazygo crazygo merged commit 55c65a1 into release Nov 14, 2025
6 checks passed
@gemini-code-assist-2025-10-22

Summary of Changes

Hello @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

  • Agent Initialization Robustness: The JudgeAgent's initialize method has been updated to handle both development and production environments when locating its prompt file (judge.agent.md). It now attempts to read the file from the local directory and falls back to the dist/agents/devhub/judge/ directory if not found, ensuring compatibility across various build setups.
  • Test Script Improvements: The test script in scripts/test-pack.js has been modified to include the --auto-exit flag when running the CLI. This change ensures that the CLI process exits automatically after execution, which enhances the reliability and stability of the test suite.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist-2025-10-22 gemini-code-assist-2025-10-22 bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +41 to +47
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');
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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');
}

Comment on lines +45 to +46
const distRoot = path.resolve(agentDir, '../../');
systemPromptPath = path.join(distRoot, 'agents/devhub/judge/judge.agent.md');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 JudgeAgent to locate prompt files in both development and production directory structures
  • Adds --auto-exit flag 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 SummarizerAgent and DevHub agents use loadAgentPipelineConfig from agentLoader.ts, which already has robust logic to handle development vs production paths, including searching in dist/agents/ and packages/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');
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}`);
    }
}
Suggested change
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}`);
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant