Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Updated code to resolve failing cli testcases #4100

Merged
merged 3 commits into from
Mar 31, 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
7 changes: 4 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
"format": "prettier --write ./src",
"format:check": "prettier --check ./src",
"clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json tsconfig.tsbuildinfo",
"test:setup-commands": "vitest test/setup-commands.test.js",
"test:agent-commands": "vitest test/agent-commands.test.js",
"test:agent-customisations": "vitest test/agent-customisation.test.js"
"test:setup-commands": "vitest run test/setup-commands.test.js",
"test:agent-commands": "vitest run test/agent-commands.test.js",
"test:agent-customisations": "vitest run test/agent-customisation.test.js",
"test:cli": "bun run test:setup-commands && bun run test:agent-commands && bun run test:agent-customisations"
},
"devDependencies": {
"@babel/core": "^7.22.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { Command } from 'commander';

export const AGENT_RUNTIME_URL =
process.env.AGENT_RUNTIME_URL?.replace(/\/$/, '') ||
`http://localhost:${process.env.SERVER_PORT ?? 3000}`;
export const AGENTS_BASE_URL = `${AGENT_RUNTIME_URL}/api/agents`;
`http://localhost:${process.env.SERVER_PORT || '3000'}`;
const AGENTS_BASE_URL = `${AGENT_RUNTIME_URL}/api/agents`;

// Define basic agent interface for type safety
/**
Expand Down
23 changes: 23 additions & 0 deletions packages/cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ export const start = new Command()
.option('-c, --configure', 'Reconfigure services and AI models (skips using saved configuration)')
.option('--character <character>', 'Path or URL to character file to use instead of default')
.option('--build', 'Build the project before starting')
.option('--characters <paths>', 'multiple character configuration files separated by commas')
.action(async (options) => {
displayBanner();

Expand All @@ -602,12 +603,34 @@ export const start = new Command()
const characterData = await loadCharacterTryPath(characterPath);
options.characters.push(characterData);
}
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding this!

// Single character
logger.info(`Loading character from ${characterPath}`);
const characterData = await loadCharacterTryPath(characterPath);
options.characters.push(characterData);
}
await startAgents(options);
} catch (error) {
logger.error(`Failed to load character: ${error}`);
process.exit(1);
}
} else if (options.characters) {
// Handle --characters option
options.characters = [];
try {
const characterPaths = options.characters.split(',').map((path) => path.trim());
for (const charPath of characterPaths) {
if (charPath) {
logger.info(`Loading character from ${charPath}`);
const characterData = await loadCharacterTryPath(charPath);
options.characters.push(characterData);
}
}
await startAgents(options);
} catch (error) {
logger.error(`Failed to load multiple characters: ${error}`);
process.exit(1);
}
} else {
await startAgents(options);
}
Expand Down
24 changes: 23 additions & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ async function main() {

const program = new Command().name('elizaos').version(version);

// Create a stop command for testing purposes
const stopCommand = new Command('stop')
.description('Stop all running ElizaOS agents')
.action(async () => {
logger.info('Stopping all ElizaOS agents...');
// Use pkill to terminate all ElizaOS processes
try {
await import('child_process').then(({ exec }) => {
exec('pkill -f "node.*elizaos" || true', (error) => {
if (error) {
logger.error(`Error stopping processes: ${error.message}`);
} else {
logger.success('Server shutdown complete');
}
});
});
} catch (error) {
logger.error(`Failed to stop processes: ${error.message}`);
}
});

program
.addCommand(create)
.addCommand(project)
Expand All @@ -63,7 +84,8 @@ async function main() {
.addCommand(test)
.addCommand(env)
.addCommand(dev)
.addCommand(publish);
.addCommand(publish)
.addCommand(stopCommand);

// if no args are passed, display the banner
if (process.argv.length === 2) {
Expand Down
Loading
Loading