diff --git a/src/agent/identity.ts b/src/agent/identity.ts index 1980c8d..3394348 100644 --- a/src/agent/identity.ts +++ b/src/agent/identity.ts @@ -84,9 +84,9 @@ export function createClaudeMd( const pathMappingsSection = pathMappings && pathMappings.length > 0 - ? `\n## Verfügbare Pfade\n\nDie folgenden Verzeichnisse sind dir zugänglich:\n${pathMappings - .map((m) => `- \`${m.virtual}\` → dein Projekt-Workspace`) - .join("\n")}\n\n**Wichtig:** Nenne niemals absolute Host-Pfade in deinen Antworten.\nVerwende ausschließlich die oben gelisteten virtuellen Pfade.\n` + ? `\n## Verfügbare Pfade\n\nDie folgenden Verzeichnisse sind dir zugänglich. Nutze den echten Pfad zum Lesen/Schreiben, nenne aber in Antworten **immer** den virtuellen Pfad:\n\n${pathMappings + .map((m) => `- Echter Pfad: \`${m.host}\` — in Antworten als: \`${m.virtual}\``) + .join("\n")}\n\n**Wichtig:** Nenne niemals den echten Host-Pfad in Discord-Antworten. Verwende ausschließlich den virtuellen Pfad.\n` : ""; const content = `# ${displayName} @@ -159,18 +159,33 @@ ${pathMappingsSection}`; /** * Creates the .claude/ directory structure for a workspace. * This provides per-agent Claude Code configuration. + * pathMappings host paths are added to the allow list so the agent + * can actually read/write the mapped project directories. */ -export function createClaudeConfig(workspacePath: string): void { +export function createClaudeConfig( + workspacePath: string, + pathMappings?: Array<{ host: string; virtual: string }> +): void { const claudeDir = path.join(workspacePath, ".claude"); const commandsDir = path.join(claudeDir, "commands"); // Create directory structure fs.mkdirSync(commandsDir, { recursive: true }); - // Create settings.json with agent-specific settings + // Base allow list — always includes workspace-local operations + const allow: string[] = ["Read", "Write(./**)", "Edit(./**)", "Bash(git diff *)"]; + + // Add explicit read/write/edit permissions for each mapped host path + for (const mapping of pathMappings ?? []) { + const normalized = mapping.host.replace(/\\/g, "/"); + allow.push(`Read(${normalized}/**)`); + allow.push(`Write(${normalized}/**)`); + allow.push(`Edit(${normalized}/**)`); + } + const settings = { permissions: { - allow: ["Read", "Write(./**)", "Edit(./**)", "Bash(git diff *)"], + allow, ask: ["Bash(git push *)"], deny: [ "Read(../**)", "Write(../**)", "Edit(../**)", @@ -212,5 +227,5 @@ export function setupAgentWorkspace( // Create all required files createAgentYaml(workspacePath, name, role, channelId, model, pathMappings); createClaudeMd(workspacePath, name, role, pathMappings); - createClaudeConfig(workspacePath); + createClaudeConfig(workspacePath, pathMappings); }