mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 17:00:45 +00:00
Add immediate flag to hook commands for non-queued execution
Commands with immediate: true run right away even during streaming. Used for UI-only commands like /snake that don't interact with LLM.
This commit is contained in:
parent
165fb58b39
commit
818196d2c3
3 changed files with 21 additions and 1 deletions
|
|
@ -233,6 +233,7 @@ class SnakeComponent {
|
||||||
export default function (pi: HookAPI) {
|
export default function (pi: HookAPI) {
|
||||||
pi.registerCommand("snake", {
|
pi.registerCommand("snake", {
|
||||||
description: "Play Snake!",
|
description: "Play Snake!",
|
||||||
|
immediate: true, // Run immediately, even during streaming
|
||||||
handler: async (ctx) => {
|
handler: async (ctx) => {
|
||||||
if (!ctx.hasUI) {
|
if (!ctx.hasUI) {
|
||||||
ctx.ui.notify("Snake requires interactive mode", "error");
|
ctx.ui.notify("Snake requires interactive mode", "error");
|
||||||
|
|
|
||||||
|
|
@ -405,6 +405,8 @@ export interface HookCommandContext {
|
||||||
export interface RegisteredCommand {
|
export interface RegisteredCommand {
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
/** If true, command runs immediately even during streaming (doesn't get queued) */
|
||||||
|
immediate?: boolean;
|
||||||
handler: (ctx: HookCommandContext) => Promise<void>;
|
handler: (ctx: HookCommandContext) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -478,7 +480,10 @@ export interface HookAPI {
|
||||||
* Register a custom slash command.
|
* Register a custom slash command.
|
||||||
* Handler receives HookCommandContext.
|
* Handler receives HookCommandContext.
|
||||||
*/
|
*/
|
||||||
registerCommand(name: string, options: { description?: string; handler: RegisteredCommand["handler"] }): void;
|
registerCommand(
|
||||||
|
name: string,
|
||||||
|
options: { description?: string; immediate?: boolean; handler: RegisteredCommand["handler"] },
|
||||||
|
): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a shell command and return stdout/stderr/code.
|
* Execute a shell command and return stdout/stderr/code.
|
||||||
|
|
|
||||||
|
|
@ -752,6 +752,20 @@ export class InteractiveMode {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if this is an immediate hook command (runs even during streaming)
|
||||||
|
if (text.startsWith("/") && this.session.hookRunner && this.session.isStreaming) {
|
||||||
|
const spaceIndex = text.indexOf(" ");
|
||||||
|
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
||||||
|
const command = this.session.hookRunner.getCommand(commandName);
|
||||||
|
if (command?.immediate) {
|
||||||
|
// Execute immediate hook command right away
|
||||||
|
this.editor.addToHistory(text);
|
||||||
|
this.editor.setText("");
|
||||||
|
await this.session.prompt(text);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Queue message if agent is streaming
|
// Queue message if agent is streaming
|
||||||
if (this.session.isStreaming) {
|
if (this.session.isStreaming) {
|
||||||
await this.session.queueMessage(text);
|
await this.session.queueMessage(text);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue