Skip to content

Commit bc6513a

Browse files
committed
fix: validate agents exist before dev/deploy commands
Fixes #150 and #151 where CLI crashes or fails late when no agents are defined in the project. Now shows helpful error messages instead. - DevScreen: Add noAgentsError state and render error screen with guidance to run 'agentcore add agent' - preflight: Validate agents array in validateProject() before proceeding with deployment
1 parent 102c99c commit bc6513a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/cli/operations/deploy/preflight.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ export async function validateProject(): Promise<PreflightContext> {
7070
const projectSpec = await configIO.readProjectSpec();
7171
const awsTargets = await configIO.readAWSDeploymentTargets();
7272

73+
// Validate that at least one agent is defined
74+
if (!projectSpec.agents || projectSpec.agents.length === 0) {
75+
throw new Error(
76+
'No agents defined in project. Add at least one agent with "agentcore add agent" before deploying.'
77+
);
78+
}
79+
7380
// Validate runtime names don't exceed AWS limits
7481
validateRuntimeNames(projectSpec);
7582

src/cli/tui/screens/dev/DevScreen.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export function DevScreen(props: DevScreenProps) {
111111
const [selectedAgentIndex, setSelectedAgentIndex] = useState(0);
112112
const [selectedAgentName, setSelectedAgentName] = useState<string | undefined>(props.agentName);
113113
const [agentsLoaded, setAgentsLoaded] = useState(false);
114+
const [noAgentsError, setNoAgentsError] = useState(false);
114115

115116
const workingDir = props.workingDir ?? process.cwd();
116117

@@ -136,8 +137,8 @@ export function DevScreen(props: DevScreenProps) {
136137
setSelectedAgentName(agents[0].name);
137138
setMode('input');
138139
} else if (agents.length === 0) {
139-
// No supported agents, will show error via useDevServer
140-
setMode('input');
140+
// No supported agents, show error screen
141+
setNoAgentsError(true);
141142
}
142143

143144
setAgentsLoaded(true);
@@ -323,10 +324,25 @@ export function DevScreen(props: DevScreenProps) {
323324
);
324325

325326
// Return null while loading
326-
if (!agentsLoaded || (mode !== 'select-agent' && (!configLoaded || !config))) {
327+
if (!agentsLoaded || (mode !== 'select-agent' && !noAgentsError && (!configLoaded || !config))) {
327328
return null;
328329
}
329330

331+
// Show error screen if no agents are defined
332+
if (noAgentsError) {
333+
return (
334+
<Screen title="Dev Server" onExit={props.onBack} helpText="Esc quit">
335+
<Box flexDirection="column">
336+
<Text color="red">No agents defined in project.</Text>
337+
<Text>Dev mode requires at least one Python agent with an entrypoint.</Text>
338+
<Text>
339+
Run <Text color="blue">agentcore add agent</Text> to create one.
340+
</Text>
341+
</Box>
342+
</Screen>
343+
);
344+
}
345+
330346
const statusColor = { starting: 'yellow', running: 'green', error: 'red', stopped: 'gray' }[status];
331347

332348
// Visible lines for display

0 commit comments

Comments
 (0)