fix(DIS-152): grant agent actual fs access to mapped host paths
Some checks failed
CI / build-and-test (ubuntu-latest) (pull_request) Has been cancelled
CI / build-and-test (windows-latest) (pull_request) Has been cancelled
CI / lint (pull_request) Has been cancelled

- createClaudeConfig() adds Read/Write/Edit(<hostPath>/**) to allow list
  for each path_mapping so Claude Code can actually access the directory
- createClaudeMd() shows agent both real path (to use) and virtual path
  (to mention in responses) — previously only showed virtual path

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Nick Tabeling 2026-04-13 10:51:19 +02:00
parent cd56793959
commit 4b05ea885c

View file

@ -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);
}