Skip to content

Commit cd39e99

Browse files
authored
Add shell alias for plugin tool hooks
- register shell as a compatibility alias for bash in plugin tool hooks\n- keep existing bash behavior unchanged\n- add unit coverage asserting shell tool registration
1 parent aa97a1a commit cd39e99

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/plugin.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,24 +1328,34 @@ function buildToolHookEntries(registry: CoreRegistry): Record<string, any> {
13281328
const entries: Record<string, any> = {};
13291329
const tools = registry.list();
13301330

1331-
for (const t of tools) {
1332-
const handler = registry.getHandler(t.name);
1333-
if (!handler) continue;
1334-
1335-
const zodArgs = jsonSchemaToZod(t.parameters);
1336-
1337-
entries[t.name] = tool({
1338-
description: t.description,
1331+
const addEntry = (name: string, description: string, zodArgs: any, handler: (args: any) => Promise<any>) => {
1332+
entries[name] = tool({
1333+
description,
13391334
args: zodArgs,
13401335
async execute(args: any, context: any) {
13411336
try {
13421337
return await handler(args);
13431338
} catch (error: any) {
1344-
log.warn("Tool hook execution failed", { tool: t.name, error: String(error?.message || error) });
1339+
log.warn("Tool hook execution failed", { tool: name, error: String(error?.message || error) });
13451340
throw error;
13461341
}
13471342
},
13481343
});
1344+
};
1345+
1346+
for (const t of tools) {
1347+
const handler = registry.getHandler(t.name);
1348+
if (!handler) continue;
1349+
1350+
const zodArgs = jsonSchemaToZod(t.parameters);
1351+
addEntry(t.name, t.description, zodArgs, handler);
1352+
1353+
// Some agent variants call `shell` instead of `bash`.
1354+
// Register a compatibility alias so subagent flows do not fail with
1355+
// unavailable tool errors.
1356+
if (t.name === "bash" && !entries.shell) {
1357+
addEntry("shell", t.description, zodArgs, handler);
1358+
}
13491359
}
13501360

13511361
return entries;

tests/unit/plugin-tools-hook.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe("Plugin tool hook", () => {
2828
// Verify default tools are registered
2929
const toolNames = Object.keys(hooks.tool || {});
3030
expect(toolNames).toContain("bash");
31+
expect(toolNames).toContain("shell");
3132
expect(toolNames).toContain("read");
3233
expect(toolNames).toContain("write");
3334
expect(toolNames).toContain("edit");

0 commit comments

Comments
 (0)