diff --git a/sdks/node/src/plugins/grok.ts b/sdks/node/src/plugins/grok.ts index 28e39a1..ac143e6 100644 --- a/sdks/node/src/plugins/grok.ts +++ b/sdks/node/src/plugins/grok.ts @@ -241,14 +241,19 @@ function removeManaged( result.push(group); continue; } + let groupChanged = false; const handlers = group.hooks.filter((handler) => { const managedId = managedAgentId(handler, scriptName); const remove = managedId !== undefined && (agentId === undefined || sameAgentId(managedId, agentId)); - if (remove) changed = true; + if (remove) { + changed = true; + groupChanged = true; + } return !remove; }); - if (handlers.length > 0) result.push(handlers.length === group.hooks.length ? group : { ...group, hooks: handlers }); + if (!groupChanged) result.push(group); + else if (handlers.length > 0) result.push({ ...group, hooks: handlers }); } return { groups: result, changed }; } diff --git a/sdks/node/test/grok-plugin.test.mjs b/sdks/node/test/grok-plugin.test.mjs index 3171ccd..159f91e 100644 --- a/sdks/node/test/grok-plugin.test.mjs +++ b/sdks/node/test/grok-plugin.test.mjs @@ -351,17 +351,17 @@ test('Grok install replaces stale Elydora handlers for every agent', async () => } }); -test('Grok uninstall preserves an untouched empty native event', async () => { +test('Grok uninstall preserves an untouched empty native group', async () => { const fixture = await createFixture({ config: { owner: 'user' } }); try { assert.equal(fixture.installResult.code, 0, fixture.installResult.stderr); const config = JSON.parse(await readFile(fixture.configPath, 'utf-8')); - config.hooks.PreToolUse = []; + config.hooks.PreToolUse.unshift({ hooks: [], label: 'keep empty group' }); await writeFile(fixture.configPath, JSON.stringify(config, null, 2)); const result = await runPlugin(fixture, 'uninstall', 'agent-1'); assert.equal(result.code, 0, result.stderr); const remaining = JSON.parse(await readFile(fixture.configPath, 'utf-8')); - assert.deepEqual(remaining.hooks.PreToolUse, []); + assert.deepEqual(remaining.hooks.PreToolUse, [{ hooks: [], label: 'keep empty group' }]); assert.equal(remaining.hooks.PostToolUse, undefined); } finally { await fixture.close();