Remove allowDuringStreaming flag - commands always run immediately
Hook commands now always execute immediately, even during streaming. If a command needs to interact with the LLM, it uses pi.sendMessage() which handles queueing automatically. This simplifies the API and eliminates the issue of queued slash commands being sent to the LLM instead of executing.
This commit is contained in:
@@ -442,8 +442,7 @@ export interface HookCommandContext {
|
||||
export interface RegisteredCommand {
|
||||
name: string;
|
||||
description?: string;
|
||||
/** If true, command runs during streaming instead of being queued */
|
||||
allowDuringStreaming?: boolean;
|
||||
|
||||
handler: (ctx: HookCommandContext) => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -456,9 +455,9 @@ export interface HookAPI {
|
||||
on(event: "session", handler: HookHandler<SessionEvent, SessionEventResult | void>): void;
|
||||
// biome-ignore lint/suspicious/noConfusingVoidType: void allows handlers to not return anything
|
||||
on(event: "context", handler: HookHandler<ContextEvent, ContextEventResult | void>): void;
|
||||
// biome-ignore lint/suspicious/noConfusingVoidType: void allows handlers to not return anything
|
||||
on(
|
||||
event: "before_agent_start",
|
||||
// biome-ignore lint/suspicious/noConfusingVoidType: void allows handlers to not return anything
|
||||
handler: HookHandler<BeforeAgentStartEvent, BeforeAgentStartEventResult | void>,
|
||||
): void;
|
||||
on(event: "agent_start", handler: HookHandler<AgentStartEvent>): void;
|
||||
@@ -527,10 +526,7 @@ export interface HookAPI {
|
||||
* Register a custom slash command.
|
||||
* Handler receives HookCommandContext.
|
||||
*/
|
||||
registerCommand(
|
||||
name: string,
|
||||
options: { description?: string; allowDuringStreaming?: boolean; handler: RegisteredCommand["handler"] },
|
||||
): void;
|
||||
registerCommand(name: string, options: { description?: string; handler: RegisteredCommand["handler"] }): void;
|
||||
|
||||
/**
|
||||
* Execute a shell command and return stdout/stderr/code.
|
||||
|
||||
@@ -744,13 +744,13 @@ export class InteractiveMode {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this hook command can run during streaming (not queued)
|
||||
if (text.startsWith("/") && this.session.hookRunner && this.session.isStreaming) {
|
||||
// Hook commands always run immediately, even during streaming
|
||||
// (if they need to interact with LLM, they use pi.sendMessage which handles queueing)
|
||||
if (text.startsWith("/") && this.session.hookRunner) {
|
||||
const spaceIndex = text.indexOf(" ");
|
||||
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
||||
const command = this.session.hookRunner.getCommand(commandName);
|
||||
if (command?.allowDuringStreaming) {
|
||||
// Execute hook command right away
|
||||
if (command) {
|
||||
this.editor.addToHistory(text);
|
||||
this.editor.setText("");
|
||||
await this.session.prompt(text);
|
||||
@@ -758,7 +758,7 @@ export class InteractiveMode {
|
||||
}
|
||||
}
|
||||
|
||||
// Queue message if agent is streaming
|
||||
// Queue regular messages if agent is streaming
|
||||
if (this.session.isStreaming) {
|
||||
await this.session.queueMessage(text);
|
||||
this.updatePendingMessagesDisplay();
|
||||
|
||||
Reference in New Issue
Block a user