Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/agent-setup/src/agent-wrappers-grok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from "node:path";
import {
buildWrapperScript,
createWrapper,
getManagedNotifyHookCommand,
MANAGED_NOTIFY_RELATIVE_PATH,
removeOwnedFileIfMarked,
writeFileIfChanged,
Expand Down Expand Up @@ -48,7 +47,13 @@ export const GROK_BLOCKING_NOTIFICATION_TYPES = [
"elicitation_dialog",
] as const;

const GROK_MANAGED_HOOK_COMMAND = getManagedNotifyHookCommand("grok");
// Grok will not run a hook whose text names an unset env var (`$X`, `${X:-}`),
// so the home dir comes in through printenv as `$1` (#8375).
export function getGrokManagedNotifyHookCommand(): string {
return `sh -c '[ -n "$1" ] && [ -x "$1/${MANAGED_NOTIFY_RELATIVE_PATH}" ] && SUPERSET_HOOK_HARNESS=grok "$1/${MANAGED_NOTIFY_RELATIVE_PATH}" || true' sh "$(printenv SUPERSET_HOME_DIR)"`;
}

const GROK_MANAGED_HOOK_COMMAND = getGrokManagedNotifyHookCommand();

// Vendor hook configs Superset also manages. Grok replays them in compat mode;
// their events carry Claude's or Cursor's harness id, so the notify script
Expand Down
32 changes: 32 additions & 0 deletions packages/agent-setup/src/agent-wrappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2498,6 +2498,7 @@ import {
GROK_COMPAT_MARKER_START,
getGrokConfigTomlContent,
getGrokHooksJsonContent,
getGrokManagedNotifyHookCommand,
getGrokWrapperScript,
} from "./agent-wrappers-grok";

Expand Down Expand Up @@ -2539,6 +2540,37 @@ describe("grok hooks json", () => {
);
});

it("names no env var and notifies only when SUPERSET_HOME_DIR is set", () => {
const command = getGrokManagedNotifyHookCommand();
expect(command).not.toMatch(/\$\{?[A-Za-z_]/);

const home = path.join(TEST_ROOT, "grok-notify");
try {
const log = path.join(home, "log");
const notifyPath = path.join(home, "hooks", "notify.sh");
mkdirSync(path.dirname(notifyPath), { recursive: true });
writeFileSync(
notifyPath,
`#!/bin/sh\necho "$SUPERSET_HOOK_HARNESS" >> "${log}"\n`,
);
chmodSync(notifyPath, 0o755);
const { SUPERSET_HOME_DIR: _unset, ...env } = process.env;

const outside = spawnSync("sh", ["-c", command], { env });
expect(outside.status).toBe(0);
expect(outside.stderr.toString()).toBe("");
expect(existsSync(log)).toBe(false);

const inside = spawnSync("sh", ["-c", command], {
env: { ...env, SUPERSET_HOME_DIR: home },
});
expect(inside.status).toBe(0);
expect(readFileSync(log, "utf-8").trim()).toBe("grok");
} finally {
rmSync(home, { recursive: true, force: true });
}
});

it("keeps the notify template's subtype filter in sync with the matcher", () => {
const template = readFileSync(
path.join(import.meta.dir, "..", "templates", "notify-hook.template.sh"),
Expand Down
Loading