Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/agents/devhub/judge/JudgeAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,20 @@ export class JudgeAgent extends PromptAgent implements RunnableAgent {
private systemPrompt?: string;

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));
const systemPromptPath = path.join(agentDir, 'judge.agent.md');
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');
Comment on lines +45 to +46

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

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


this.systemPrompt = await fs.readFile(systemPromptPath, 'utf-8');

addLog(`[JudgeAgent] Initialized with prompt length: ${this.systemPrompt.length}`);
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ run(`npm install --ignore-scripts`, {
});

// Run the extracted package binary (what users will actually run)
run(`node dist/cli/main.js --workspace /tmp --start -p 'list files'`, {
run(`node dist/cli/main.js --workspace /tmp --start -p 'list files' --auto-exit`, {
cwd: `${testDir}/package`,
env: cleanEnv,
});
Expand Down
Loading