Skip to content

Commit c6cc326

Browse files
Route Node hooks.invoke through generated client-global handler
CLI 1.0.71 promoted hooks.invoke to a client-global RPC method with a generated HooksHandler interface. The handwritten SDK registered its own hooks.invoke handler on the connection, which the generated registerClientGlobalApiHandlers then shadowed with an unwired handler that threw "No hooks client-global handler registered" — so hooks never fired. Wire the existing handleHooksInvoke routing into the generated clientGlobalHandlers.hooks slot and drop the redundant handwritten connection.onRequest("hooks.invoke") registration. Behavior is unchanged; the dispatcher and its payload validation are reused as-is. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ae226b7f-caf9-46f3-b8c5-b9a21c5d7951
1 parent bc82988 commit c6cc326

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

nodejs/src/client.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,11 @@ export class CopilotClient {
830830

831831
private setupClientGlobalHandlers(): void {
832832
const handlers: import("./generated/rpc.js").ClientGlobalApiHandlers = {};
833+
// `hooks.invoke` is a client-global RPC method whose payload carries a
834+
// `sessionId`; route each invocation to the matching session's dispatcher.
835+
handlers.hooks = {
836+
invoke: async (params) => await this.handleHooksInvoke(params),
837+
};
833838
if (this.requestHandler) {
834839
handlers.llmInference = createCopilotRequestAdapter(this.requestHandler, () => {
835840
if (!this.connection) {
@@ -2796,15 +2801,6 @@ export class CopilotClient {
27962801
await this.handleAutoModeSwitchRequest(params)
27972802
);
27982803

2799-
this.connection.onRequest(
2800-
"hooks.invoke",
2801-
async (params: {
2802-
sessionId: string;
2803-
hookType: string;
2804-
input: unknown;
2805-
}): Promise<{ output?: unknown }> => await this.handleHooksInvoke(params)
2806-
);
2807-
28082804
this.connection.onRequest(
28092805
"systemMessage.transform",
28102806
async (params: {

nodejs/test/client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,7 +3133,7 @@ describe("CopilotClient", () => {
31333133

31343134
it("routes hooks.invoke JSON-RPC requests to the SessionHooks handler", async () => {
31353135
// Validates the full JSON-RPC entry point used by the CLI:
3136-
// CopilotClient.handleHooksInvoke({sessionId, hookType, input})
3136+
// clientGlobalHandlers.hooks.invoke({sessionId, hookType, input})
31373137
// → CopilotSession._handleHooksInvoke(hookType, input)
31383138
// → SessionHooks.onPostToolUseFailure(normalizedInput, {sessionId})
31393139
//
@@ -3164,7 +3164,7 @@ describe("CopilotClient", () => {
31643164
cwd: "/tmp",
31653165
};
31663166

3167-
const response = await (client as any).handleHooksInvoke({
3167+
const response = await (client as any).clientGlobalHandlers.hooks.invoke({
31683168
sessionId: session.sessionId,
31693169
hookType: "postToolUseFailure",
31703170
input: failureInput,

0 commit comments

Comments
 (0)