Skip to content
Merged
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
250 changes: 0 additions & 250 deletions apps/desktop/src/main/lib/agent-setup.ts

This file was deleted.

71 changes: 71 additions & 0 deletions apps/desktop/src/main/lib/agent-setup/agent-wrappers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import fs from "node:fs";
import path from "node:path";
import { BIN_DIR, HOOKS_DIR } from "./paths";
import { findRealBinary } from "./utils";

/**
* Creates the Claude Code settings JSON file with notification hooks
*/
function createClaudeSettings(): string {
const settingsPath = path.join(HOOKS_DIR, "claude-settings.json");
const notifyPath = path.join(HOOKS_DIR, "notify.sh");

const settings = {
hooks: {
Stop: [{ hooks: [{ type: "command", command: notifyPath }] }],
PermissionRequest: [
{ matcher: "*", hooks: [{ type: "command", command: notifyPath }] },
],
},
};

fs.writeFileSync(settingsPath, JSON.stringify(settings), { mode: 0o644 });
return settingsPath;
}

/**
* Creates wrapper script for Claude Code
*/
export function createClaudeWrapper(): void {
const wrapperPath = path.join(BIN_DIR, "claude");
const realClaude = findRealBinary("claude");

if (!realClaude) {
console.log("[agent-setup] Claude not found, skipping wrapper");
return;
}

const settingsPath = createClaudeSettings();

const script = `#!/bin/bash
# Superset wrapper for Claude Code
# Injects notification hook settings

exec "${realClaude}" --settings "${settingsPath}" "$@"
`;
fs.writeFileSync(wrapperPath, script, { mode: 0o755 });
console.log(`[agent-setup] Created Claude wrapper -> ${realClaude}`);
}

/**
* Creates wrapper script for Codex
*/
export function createCodexWrapper(): void {
const wrapperPath = path.join(BIN_DIR, "codex");
const realCodex = findRealBinary("codex");

if (!realCodex) {
console.log("[agent-setup] Codex not found, skipping wrapper");
return;
}

const notifyPath = path.join(HOOKS_DIR, "notify.sh");
const script = `#!/bin/bash
# Superset wrapper for Codex
# Injects notification hook settings

exec "${realCodex}" -c 'notify=["bash","${notifyPath}"]' "$@"
`;
fs.writeFileSync(wrapperPath, script, { mode: 0o755 });
console.log(`[agent-setup] Created Codex wrapper -> ${realCodex}`);
}
45 changes: 45 additions & 0 deletions apps/desktop/src/main/lib/agent-setup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import fs from "node:fs";
import { createClaudeWrapper, createCodexWrapper } from "./agent-wrappers";
import { createNotifyScript } from "./notify-hook";
import { BASH_DIR, BIN_DIR, HOOKS_DIR, ZSH_DIR } from "./paths";
import {
createBashWrapper,
createZshWrapper,
getShellArgs,
getShellEnv,
} from "./shell-wrappers";

/**
* Sets up the ~/.superset directory structure and agent wrappers
* Called on app startup
*/
export function setupAgentHooks(): void {
console.log("[agent-setup] Initializing agent hooks...");

// Create directories
fs.mkdirSync(BIN_DIR, { recursive: true });
fs.mkdirSync(HOOKS_DIR, { recursive: true });
fs.mkdirSync(ZSH_DIR, { recursive: true });
fs.mkdirSync(BASH_DIR, { recursive: true });

// Create scripts
createNotifyScript();
createClaudeWrapper();
createCodexWrapper();

// Create shell initialization wrappers
createZshWrapper();
createBashWrapper();

console.log("[agent-setup] Agent hooks initialized");
}

/**
* Returns the bin directory path
*/
export function getSupersetBinDir(): string {
return BIN_DIR;
}

// Re-export shell utilities for terminal usage
export { getShellArgs, getShellEnv };
Loading