Skip to content

Default GitHub mode on #221

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Mar 12, 2025
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
2 changes: 1 addition & 1 deletion packages/agent/src/core/toolAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const toolContext: ToolContext = {
userSession: false,
pageFilter: 'simple',
tokenTracker: new TokenTracker(),
githubMode: false,
githubMode: true,
};

// Mock tool for testing
Expand Down
17 changes: 12 additions & 5 deletions packages/agent/src/tools/interaction/agentMessage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';

import { backgroundToolRegistry, BackgroundToolStatus } from '../../core/backgroundTools.js';
import {
backgroundToolRegistry,
BackgroundToolStatus,
} from '../../core/backgroundTools.js';
import { Tool } from '../../core/types.js';

import { agentStates } from './agentStart.js';
Expand Down Expand Up @@ -76,11 +79,15 @@ export const agentMessageTool: Tool<Parameters, ReturnType> = {
if (terminate) {
agentState.aborted = true;
agentState.completed = true;

// Update background tool registry with terminated status
backgroundToolRegistry.updateToolStatus(instanceId, BackgroundToolStatus.TERMINATED, {
terminatedByUser: true
});
backgroundToolRegistry.updateToolStatus(
instanceId,
BackgroundToolStatus.TERMINATED,
{
terminatedByUser: true,
},
);

return {
output: agentState.output || 'Sub-agent terminated before completion',
Expand Down
37 changes: 25 additions & 12 deletions packages/agent/src/tools/interaction/agentStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { v4 as uuidv4 } from 'uuid';
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';

import { backgroundToolRegistry, BackgroundToolStatus, BackgroundToolType } from '../../core/backgroundTools.js';
import {
backgroundToolRegistry,
BackgroundToolStatus,
} from '../../core/backgroundTools.js';
import {
getDefaultSystemPrompt,
getModel,
Expand Down Expand Up @@ -92,7 +95,7 @@ export const agentStartTool: Tool<Parameters, ReturnType> = {
returnsJsonSchema: zodToJsonSchema(returnSchema),
execute: async (params, context) => {
const { logger, agentId } = context;

// Validate parameters
const {
description,
Expand All @@ -102,10 +105,10 @@ export const agentStartTool: Tool<Parameters, ReturnType> = {
relevantFilesDirectories,
enableUserPrompt = false,
} = parameterSchema.parse(params);

// Create an instance ID
const instanceId = uuidv4();

// Register this agent with the background tool registry
backgroundToolRegistry.registerAgent(agentId || 'unknown', goal);
logger.verbose(`Registered agent with ID: ${instanceId}`);
Expand Down Expand Up @@ -154,23 +157,33 @@ export const agentStartTool: Tool<Parameters, ReturnType> = {
state.completed = true;
state.result = result;
state.output = result.result;

// Update background tool registry with completed status
backgroundToolRegistry.updateToolStatus(instanceId, BackgroundToolStatus.COMPLETED, {
result: result.result.substring(0, 100) + (result.result.length > 100 ? '...' : '')
});
backgroundToolRegistry.updateToolStatus(
instanceId,
BackgroundToolStatus.COMPLETED,
{
result:
result.result.substring(0, 100) +
(result.result.length > 100 ? '...' : ''),
},
);
}
} catch (error) {
// Update agent state with the error
const state = agentStates.get(instanceId);
if (state && !state.aborted) {
state.completed = true;
state.error = error instanceof Error ? error.message : String(error);

// Update background tool registry with error status
backgroundToolRegistry.updateToolStatus(instanceId, BackgroundToolStatus.ERROR, {
error: error instanceof Error ? error.message : String(error)
});
backgroundToolRegistry.updateToolStatus(
instanceId,
BackgroundToolStatus.ERROR,
{
error: error instanceof Error ? error.message : String(error),
},
);
}
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/tools/interaction/agentTools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const mockContext: ToolContext = {
headless: true,
userSession: false,
pageFilter: 'none',
githubMode: false,
githubMode: true,
};

describe('Agent Tools', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/tools/interaction/subAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const mockContext: ToolContext = {
headless: true,
userSession: false,
pageFilter: 'none',
githubMode: false,
githubMode: true,
};

describe('subAgentTool', () => {
Expand Down
42 changes: 29 additions & 13 deletions packages/agent/src/tools/interaction/subAgent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';

import { backgroundToolRegistry, BackgroundToolStatus, BackgroundToolType } from '../../core/backgroundTools.js';
import {
backgroundToolRegistry,
BackgroundToolStatus,
} from '../../core/backgroundTools.js';
import {
getDefaultSystemPrompt,
getModel,
Expand Down Expand Up @@ -70,7 +73,7 @@ export const subAgentTool: Tool<Parameters, ReturnType> = {
returnsJsonSchema: zodToJsonSchema(returnSchema),
execute: async (params, context) => {
const { logger, agentId } = context;

// Validate parameters
const {
description,
Expand All @@ -79,9 +82,12 @@ export const subAgentTool: Tool<Parameters, ReturnType> = {
workingDirectory,
relevantFilesDirectories,
} = parameterSchema.parse(params);

// Register this sub-agent with the background tool registry
const subAgentId = backgroundToolRegistry.registerAgent(agentId || 'unknown', goal);
const subAgentId = backgroundToolRegistry.registerAgent(
agentId || 'unknown',
goal,
);
logger.verbose(`Registered sub-agent with ID: ${subAgentId}`);

// Construct a well-structured prompt
Expand Down Expand Up @@ -109,19 +115,29 @@ export const subAgentTool: Tool<Parameters, ReturnType> = {
...context,
workingDirectory: workingDirectory ?? context.workingDirectory,
});

// Update background tool registry with completed status
backgroundToolRegistry.updateToolStatus(subAgentId, BackgroundToolStatus.COMPLETED, {
result: result.result.substring(0, 100) + (result.result.length > 100 ? '...' : '')
});

backgroundToolRegistry.updateToolStatus(
subAgentId,
BackgroundToolStatus.COMPLETED,
{
result:
result.result.substring(0, 100) +
(result.result.length > 100 ? '...' : ''),
},
);

return { response: result.result };
} catch (error) {
// Update background tool registry with error status
backgroundToolRegistry.updateToolStatus(subAgentId, BackgroundToolStatus.ERROR, {
error: error instanceof Error ? error.message : String(error)
});

backgroundToolRegistry.updateToolStatus(
subAgentId,
BackgroundToolStatus.ERROR,
{
error: error instanceof Error ? error.message : String(error),
},
);

throw error;
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/tools/interaction/userPrompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const mockContext: ToolContext = {
headless: true,
userSession: false,
pageFilter: 'none',
githubMode: false,
githubMode: true,
};

describe('userPromptTool', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/tools/io/textEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const toolContext: ToolContext = {
userSession: false,
pageFilter: 'simple',
tokenTracker: new TokenTracker(),
githubMode: false,
githubMode: true,
};

describe('textEditor', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/tools/system/respawn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const toolContext: ToolContext = {
userSession: false,
pageFilter: 'simple',
tokenTracker: new TokenTracker(),
githubMode: false,
githubMode: true,
};
describe('respawnTool', () => {
it('should have correct name and description', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/tools/system/shellExecute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const toolContext: ToolContext = {
userSession: false,
pageFilter: 'simple',
tokenTracker: new TokenTracker(),
githubMode: false,
githubMode: true,
};

describe('shellExecute', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/tools/system/shellMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const toolContext: ToolContext = {
userSession: false,
pageFilter: 'simple',
tokenTracker: new TokenTracker(),
githubMode: false,
githubMode: true,
};

// Helper function to get instanceId from shellStart result
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/tools/system/shellStart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const toolContext: ToolContext = {
userSession: false,
pageFilter: 'simple',
tokenTracker: new TokenTracker(),
githubMode: false,
githubMode: true,
};
describe('shellStartTool', () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/tools/system/sleep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const toolContext: ToolContext = {
userSession: false,
pageFilter: 'simple',
tokenTracker: new TokenTracker(),
githubMode: false,
githubMode: true,
};

describe('sleep tool', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/settings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const projectConfigFile = (): string => getProjectConfigFile();
// Default configuration
const defaultConfig = {
// Add default configuration values here
githubMode: false,
githubMode: true,
headless: true,
userSession: false,
pageFilter: 'none' as 'simple' | 'none' | 'readability',
Expand Down
24 changes: 12 additions & 12 deletions packages/cli/tests/commands/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ describe('Config Command', () => {
warn: vi.fn(),
};
vi.mocked(Logger).mockImplementation(() => mockLogger as unknown as Logger);
vi.mocked(getConfig).mockReturnValue({ githubMode: false });
vi.mocked(getConfig).mockReturnValue({ githubMode: true });
vi.mocked(getDefaultConfig).mockReturnValue({
githubMode: false,
githubMode: true,
customPrompt: '',
});
vi.mocked(updateConfig).mockImplementation((config) => ({
githubMode: false,
githubMode: true,
...config,
}));
vi.mocked(getConfigAtLevel).mockReturnValue({});
vi.mocked(clearConfigKey).mockImplementation(() => ({ githubMode: false }));
vi.mocked(clearConfigKey).mockImplementation(() => ({ githubMode: false }));
vi.mocked(clearConfigKey).mockImplementation(() => ({ githubMode: true }));
vi.mocked(clearConfigKey).mockImplementation(() => ({ githubMode: true }));
});

afterEach(() => {
Expand All @@ -107,13 +107,13 @@ describe('Config Command', () => {
it('should filter out invalid config keys in list command', async () => {
// Mock getConfig to return config with invalid keys
vi.mocked(getConfig).mockReturnValue({
githubMode: false,
githubMode: true,
invalidKey: 'some value',
} as any);

// Mock getDefaultConfig to return only valid keys
vi.mocked(getDefaultConfig).mockReturnValue({
githubMode: false,
githubMode: true,
});

await command.handler!({
Expand Down Expand Up @@ -249,13 +249,13 @@ describe('Config Command', () => {
it('should clear a configuration value', async () => {
// Mock getConfig to include the key we want to clear
vi.mocked(getConfig).mockReturnValue({
githubMode: false,
githubMode: true,
customPrompt: 'custom value',
});

// Mock getDefaultConfig to include the key we want to clear
vi.mocked(getDefaultConfig).mockReturnValue({
githubMode: false,
githubMode: true,
customPrompt: '',
});

Expand Down Expand Up @@ -333,7 +333,7 @@ describe('Config Command', () => {

it('should handle non-existent key for clear command', async () => {
vi.mocked(getConfig).mockReturnValue({
githubMode: false,
githubMode: true,
});

await command.handler!({
Expand Down Expand Up @@ -370,13 +370,13 @@ describe('Config Command', () => {
it('should list all configuration values with default indicators', async () => {
// Mock getConfig to return a mix of default and custom values
vi.mocked(getConfig).mockReturnValue({
githubMode: false, // default value
githubMode: true, // default value
customPrompt: 'custom value', // custom value
});

// Mock getDefaultConfig to return the default values
vi.mocked(getDefaultConfig).mockReturnValue({
githubMode: false,
githubMode: true,
customPrompt: '',
});

Expand Down
8 changes: 4 additions & 4 deletions packages/cli/tests/settings/config-defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Config Defaults for CLI Options', () => {
it('should use config values for headless, userSession, and pageFilter when not provided in args', async () => {
// Setup mock config with default values
vi.mocked(getConfig).mockReturnValue({
githubMode: false,
githubMode: true,
headless: true,
userSession: false,
pageFilter: 'none',
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('Config Defaults for CLI Options', () => {
it('should use command line args for headless, userSession, and pageFilter when provided', async () => {
// Setup mock config with default values
vi.mocked(getConfig).mockReturnValue({
githubMode: false,
githubMode: true,
headless: true, // Default is true
userSession: false, // Default is false
pageFilter: 'none', // Default is none
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('Config Defaults for CLI Options', () => {
it('should test the actual toolAgent call with config defaults', async () => {
// Setup mock config with default values
vi.mocked(getConfig).mockReturnValue({
githubMode: false,
githubMode: true,
headless: true,
userSession: false,
pageFilter: 'none',
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('Config Defaults for CLI Options', () => {
it('should test the actual toolAgent call with command line args', async () => {
// Setup mock config with default values
vi.mocked(getConfig).mockReturnValue({
githubMode: false,
githubMode: true,
headless: true, // Default is true
userSession: false, // Default is false
pageFilter: 'none', // Default is none
Expand Down
Loading
Loading