Skip to content

Commit 77a64ed

Browse files
committed
fix: AgentPrimitive TUI try/catch, standardize uses safeParse
1 parent 348efa9 commit 77a64ed

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

src/cli/primitives/AgentPrimitive.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -354,24 +354,29 @@ export class AgentPrimitive extends BasePrimitive<AddAgentOptions, RemovableReso
354354
};
355355
});
356356
} else {
357-
// TUI fallback — dynamic imports to avoid pulling ink (async) into registry
358-
requireTTY();
359-
const [{ render }, { default: React }, { AddFlow }] = await Promise.all([
360-
import('ink'),
361-
import('react'),
362-
import('../tui/screens/add/AddFlow'),
363-
]);
364-
const { clear, unmount } = render(
365-
React.createElement(AddFlow, {
366-
isInteractive: false,
367-
initialResource: 'agent',
368-
onExit: () => {
369-
clear();
370-
unmount();
371-
process.exit(0);
372-
},
373-
})
374-
);
357+
try {
358+
// TUI fallback — dynamic imports to avoid pulling ink (async) into registry
359+
requireTTY();
360+
const [{ render }, { default: React }, { AddFlow }] = await Promise.all([
361+
import('ink'),
362+
import('react'),
363+
import('../tui/screens/add/AddFlow'),
364+
]);
365+
const { clear, unmount } = render(
366+
React.createElement(AddFlow, {
367+
isInteractive: false,
368+
initialResource: 'agent',
369+
onExit: () => {
370+
clear();
371+
unmount();
372+
process.exit(0);
373+
},
374+
})
375+
);
376+
} catch (error) {
377+
console.error(getErrorMessage(error));
378+
process.exit(1);
379+
}
375380
}
376381
});
377382

src/cli/telemetry/schemas/common-shapes.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ export function safeSchema<T extends Record<string, SafeField>>(shape: T) {
1111
/** Lowercase a CLI value and parse it through a Zod enum, returning the narrowed type. */
1212
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1313
export function standardize<T extends z.ZodEnum<any>>(schema: T, value: string): z.infer<T> {
14-
return schema.parse(value.toLowerCase()) as z.infer<T>;
14+
const lower = value.toLowerCase();
15+
const result = schema.safeParse(lower);
16+
// If the value doesn't match the enum, return the lowercased value anyway —
17+
// recordCommandRun's try/catch will silently drop the invalid metric.
18+
return (result.success ? result.data : lower) as z.infer<T>;
1519
}
1620

1721
// Primitive types

0 commit comments

Comments
 (0)