fix(coding-agent): validate extension command registration

Reject extension commands without a non-empty string name or a handler
at registration, instead of letting them crash the editor when typing /.

fixes #10054
This commit is contained in:
David Brailovsky 2026-09-30 15:01:08 +02:00
parent c34f2d6ad5
commit dc83372f8f
2 changed files with 9 additions and 0 deletions

View file

@ -19,6 +19,7 @@
- Fixed codemode `image()` accepting malformed base64 data or unsupported image types, which persisted an invalid image block that made every later provider request fail with HTTP 400 ([#10215](https://github.com/earendil-works/pi/issues/10215)).
- Fixed codemode failing to start its script worker from the standalone Windows executable ([#10204](https://github.com/earendil-works/pi/issues/10204)).
- Fixed prompt submission slowing down with session length, because resolving the session's model selection looked up the model catalog once per assistant message ([#10198](https://github.com/earendil-works/pi/issues/10198)).
- Fixed extension commands registered without a string name or handler crashing pi when typing `/`; the extension now fails to load with an error instead ([#10054](https://github.com/earendil-works/pi/issues/10054)).
## [0.99.1] - 2026-09-29

View file

@ -301,6 +301,14 @@ function createExtensionAPI(
registerCommand(name: string, options: Omit<RegisteredCommand, "name" | "sourceInfo">): void {
assertActive();
if (typeof name !== "string" || name.length === 0) {
throw new Error(
`Command registered by extension "${extension.path}" must have a non-empty string name. Use pi.registerCommand("name", { description, handler }).`,
);
}
if (typeof options?.handler !== "function") {
throw new Error(`Command "/${name}" registered by extension "${extension.path}" must define handler().`);
}
extension.commands.set(name, {
name,
sourceInfo: extension.sourceInfo,