feat(DIS-152): mapped project paths (host:virtual) for agents #66

Open
dev wants to merge 7 commits from refinement/mapped-project-paths into main
Showing only changes of commit 4b05ea885c - Show all commits

View file

@ -84,9 +84,9 @@ export function createClaudeMd(
const pathMappingsSection = const pathMappingsSection =
pathMappings && pathMappings.length > 0 pathMappings && pathMappings.length > 0
? `\n## Verfügbare Pfade\n\nDie folgenden Verzeichnisse sind dir zugänglich:\n${pathMappings ? `\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) => `- \`${m.virtual}\` → dein Projekt-Workspace`) .map((m) => `- Echter Pfad: \`${m.host}\` — in Antworten als: \`${m.virtual}\``)
.join("\n")}\n\n**Wichtig:** Nenne niemals absolute Host-Pfade in deinen Antworten.\nVerwende ausschließlich die oben gelisteten virtuellen Pfade.\n` .join("\n")}\n\n**Wichtig:** Nenne niemals den echten Host-Pfad in Discord-Antworten. Verwende ausschließlich den virtuellen Pfad.\n`
: ""; : "";
const content = `# ${displayName} const content = `# ${displayName}
@ -159,18 +159,33 @@ ${pathMappingsSection}`;
/** /**
* Creates the .claude/ directory structure for a workspace. * Creates the .claude/ directory structure for a workspace.
* This provides per-agent Claude Code configuration. * 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 claudeDir = path.join(workspacePath, ".claude");
const commandsDir = path.join(claudeDir, "commands"); const commandsDir = path.join(claudeDir, "commands");
// Create directory structure // Create directory structure
fs.mkdirSync(commandsDir, { recursive: true }); 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 = { const settings = {
permissions: { permissions: {
allow: ["Read", "Write(./**)", "Edit(./**)", "Bash(git diff *)"], allow,
ask: ["Bash(git push *)"], ask: ["Bash(git push *)"],
deny: [ deny: [
"Read(../**)", "Write(../**)", "Edit(../**)", "Read(../**)", "Write(../**)", "Edit(../**)",
@ -212,5 +227,5 @@ export function setupAgentWorkspace(
// Create all required files // Create all required files
createAgentYaml(workspacePath, name, role, channelId, model, pathMappings); createAgentYaml(workspacePath, name, role, channelId, model, pathMappings);
createClaudeMd(workspacePath, name, role, pathMappings); createClaudeMd(workspacePath, name, role, pathMappings);
createClaudeConfig(workspacePath); createClaudeConfig(workspacePath, pathMappings);
} }