massgen 0.0.3__py3-none-any.whl → 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of massgen might be problematic. Click here for more details.
- massgen/__init__.py +142 -8
- massgen/adapters/__init__.py +29 -0
- massgen/adapters/ag2_adapter.py +483 -0
- massgen/adapters/base.py +183 -0
- massgen/adapters/tests/__init__.py +0 -0
- massgen/adapters/tests/test_ag2_adapter.py +439 -0
- massgen/adapters/tests/test_agent_adapter.py +128 -0
- massgen/adapters/utils/__init__.py +2 -0
- massgen/adapters/utils/ag2_utils.py +236 -0
- massgen/adapters/utils/tests/__init__.py +0 -0
- massgen/adapters/utils/tests/test_ag2_utils.py +138 -0
- massgen/agent_config.py +329 -55
- massgen/api_params_handler/__init__.py +10 -0
- massgen/api_params_handler/_api_params_handler_base.py +99 -0
- massgen/api_params_handler/_chat_completions_api_params_handler.py +176 -0
- massgen/api_params_handler/_claude_api_params_handler.py +113 -0
- massgen/api_params_handler/_response_api_params_handler.py +130 -0
- massgen/backend/__init__.py +39 -4
- massgen/backend/azure_openai.py +385 -0
- massgen/backend/base.py +341 -69
- massgen/backend/base_with_mcp.py +1102 -0
- massgen/backend/capabilities.py +386 -0
- massgen/backend/chat_completions.py +577 -130
- massgen/backend/claude.py +1033 -537
- massgen/backend/claude_code.py +1203 -0
- massgen/backend/cli_base.py +209 -0
- massgen/backend/docs/BACKEND_ARCHITECTURE.md +126 -0
- massgen/backend/{CLAUDE_API_RESEARCH.md → docs/CLAUDE_API_RESEARCH.md} +18 -18
- massgen/backend/{GEMINI_API_DOCUMENTATION.md → docs/GEMINI_API_DOCUMENTATION.md} +9 -9
- massgen/backend/docs/Gemini MCP Integration Analysis.md +1050 -0
- massgen/backend/docs/MCP_IMPLEMENTATION_CLAUDE_BACKEND.md +177 -0
- massgen/backend/docs/MCP_INTEGRATION_RESPONSE_BACKEND.md +352 -0
- massgen/backend/docs/OPENAI_GPT5_MODELS.md +211 -0
- massgen/backend/{OPENAI_RESPONSES_API_FORMAT.md → docs/OPENAI_RESPONSE_API_TOOL_CALLS.md} +3 -3
- massgen/backend/docs/OPENAI_response_streaming.md +20654 -0
- massgen/backend/docs/inference_backend.md +257 -0
- massgen/backend/docs/permissions_and_context_files.md +1085 -0
- massgen/backend/external.py +126 -0
- massgen/backend/gemini.py +1850 -241
- massgen/backend/grok.py +40 -156
- massgen/backend/inference.py +156 -0
- massgen/backend/lmstudio.py +171 -0
- massgen/backend/response.py +1095 -322
- massgen/chat_agent.py +131 -113
- massgen/cli.py +1560 -275
- massgen/config_builder.py +2396 -0
- massgen/configs/BACKEND_CONFIGURATION.md +458 -0
- massgen/configs/README.md +559 -216
- massgen/configs/ag2/ag2_case_study.yaml +27 -0
- massgen/configs/ag2/ag2_coder.yaml +34 -0
- massgen/configs/ag2/ag2_coder_case_study.yaml +36 -0
- massgen/configs/ag2/ag2_gemini.yaml +27 -0
- massgen/configs/ag2/ag2_groupchat.yaml +108 -0
- massgen/configs/ag2/ag2_groupchat_gpt.yaml +118 -0
- massgen/configs/ag2/ag2_single_agent.yaml +21 -0
- massgen/configs/basic/multi/fast_timeout_example.yaml +37 -0
- massgen/configs/basic/multi/gemini_4o_claude.yaml +31 -0
- massgen/configs/basic/multi/gemini_gpt5nano_claude.yaml +36 -0
- massgen/configs/{gemini_4o_claude.yaml → basic/multi/geminicode_4o_claude.yaml} +3 -3
- massgen/configs/basic/multi/geminicode_gpt5nano_claude.yaml +36 -0
- massgen/configs/basic/multi/glm_gemini_claude.yaml +25 -0
- massgen/configs/basic/multi/gpt4o_audio_generation.yaml +30 -0
- massgen/configs/basic/multi/gpt4o_image_generation.yaml +31 -0
- massgen/configs/basic/multi/gpt5nano_glm_qwen.yaml +26 -0
- massgen/configs/basic/multi/gpt5nano_image_understanding.yaml +26 -0
- massgen/configs/{three_agents_default.yaml → basic/multi/three_agents_default.yaml} +8 -4
- massgen/configs/basic/multi/three_agents_opensource.yaml +27 -0
- massgen/configs/basic/multi/three_agents_vllm.yaml +20 -0
- massgen/configs/basic/multi/two_agents_gemini.yaml +19 -0
- massgen/configs/{two_agents.yaml → basic/multi/two_agents_gpt5.yaml} +14 -6
- massgen/configs/basic/multi/two_agents_opensource_lmstudio.yaml +31 -0
- massgen/configs/basic/multi/two_qwen_vllm_sglang.yaml +28 -0
- massgen/configs/{single_agent.yaml → basic/single/single_agent.yaml} +1 -1
- massgen/configs/{single_flash2.5.yaml → basic/single/single_flash2.5.yaml} +1 -2
- massgen/configs/basic/single/single_gemini2.5pro.yaml +16 -0
- massgen/configs/basic/single/single_gpt4o_audio_generation.yaml +22 -0
- massgen/configs/basic/single/single_gpt4o_image_generation.yaml +22 -0
- massgen/configs/basic/single/single_gpt4o_video_generation.yaml +24 -0
- massgen/configs/basic/single/single_gpt5nano.yaml +20 -0
- massgen/configs/basic/single/single_gpt5nano_file_search.yaml +18 -0
- massgen/configs/basic/single/single_gpt5nano_image_understanding.yaml +17 -0
- massgen/configs/basic/single/single_gptoss120b.yaml +15 -0
- massgen/configs/basic/single/single_openrouter_audio_understanding.yaml +15 -0
- massgen/configs/basic/single/single_qwen_video_understanding.yaml +15 -0
- massgen/configs/debug/code_execution/command_filtering_blacklist.yaml +29 -0
- massgen/configs/debug/code_execution/command_filtering_whitelist.yaml +28 -0
- massgen/configs/debug/code_execution/docker_verification.yaml +29 -0
- massgen/configs/debug/skip_coordination_test.yaml +27 -0
- massgen/configs/debug/test_sdk_migration.yaml +17 -0
- massgen/configs/docs/DISCORD_MCP_SETUP.md +208 -0
- massgen/configs/docs/TWITTER_MCP_ENESCINAR_SETUP.md +82 -0
- massgen/configs/providers/azure/azure_openai_multi.yaml +21 -0
- massgen/configs/providers/azure/azure_openai_single.yaml +19 -0
- massgen/configs/providers/claude/claude.yaml +14 -0
- massgen/configs/providers/gemini/gemini_gpt5nano.yaml +28 -0
- massgen/configs/providers/local/lmstudio.yaml +11 -0
- massgen/configs/providers/openai/gpt5.yaml +46 -0
- massgen/configs/providers/openai/gpt5_nano.yaml +46 -0
- massgen/configs/providers/others/grok_single_agent.yaml +19 -0
- massgen/configs/providers/others/zai_coding_team.yaml +108 -0
- massgen/configs/providers/others/zai_glm45.yaml +12 -0
- massgen/configs/{creative_team.yaml → teams/creative/creative_team.yaml} +16 -6
- massgen/configs/{travel_planning.yaml → teams/creative/travel_planning.yaml} +16 -6
- massgen/configs/{news_analysis.yaml → teams/research/news_analysis.yaml} +16 -6
- massgen/configs/{research_team.yaml → teams/research/research_team.yaml} +15 -7
- massgen/configs/{technical_analysis.yaml → teams/research/technical_analysis.yaml} +16 -6
- massgen/configs/tools/code-execution/basic_command_execution.yaml +25 -0
- massgen/configs/tools/code-execution/code_execution_use_case_simple.yaml +41 -0
- massgen/configs/tools/code-execution/docker_claude_code.yaml +32 -0
- massgen/configs/tools/code-execution/docker_multi_agent.yaml +32 -0
- massgen/configs/tools/code-execution/docker_simple.yaml +29 -0
- massgen/configs/tools/code-execution/docker_with_resource_limits.yaml +32 -0
- massgen/configs/tools/code-execution/multi_agent_playwright_automation.yaml +57 -0
- massgen/configs/tools/filesystem/cc_gpt5_gemini_filesystem.yaml +34 -0
- massgen/configs/tools/filesystem/claude_code_context_sharing.yaml +68 -0
- massgen/configs/tools/filesystem/claude_code_flash2.5.yaml +43 -0
- massgen/configs/tools/filesystem/claude_code_flash2.5_gptoss.yaml +49 -0
- massgen/configs/tools/filesystem/claude_code_gpt5nano.yaml +31 -0
- massgen/configs/tools/filesystem/claude_code_single.yaml +40 -0
- massgen/configs/tools/filesystem/fs_permissions_test.yaml +87 -0
- massgen/configs/tools/filesystem/gemini_gemini_workspace_cleanup.yaml +54 -0
- massgen/configs/tools/filesystem/gemini_gpt5_filesystem_casestudy.yaml +30 -0
- massgen/configs/tools/filesystem/gemini_gpt5nano_file_context_path.yaml +43 -0
- massgen/configs/tools/filesystem/gemini_gpt5nano_protected_paths.yaml +45 -0
- massgen/configs/tools/filesystem/gpt5mini_cc_fs_context_path.yaml +31 -0
- massgen/configs/tools/filesystem/grok4_gpt5_gemini_filesystem.yaml +32 -0
- massgen/configs/tools/filesystem/multiturn/grok4_gpt5_claude_code_filesystem_multiturn.yaml +58 -0
- massgen/configs/tools/filesystem/multiturn/grok4_gpt5_gemini_filesystem_multiturn.yaml +58 -0
- massgen/configs/tools/filesystem/multiturn/two_claude_code_filesystem_multiturn.yaml +47 -0
- massgen/configs/tools/filesystem/multiturn/two_gemini_flash_filesystem_multiturn.yaml +48 -0
- massgen/configs/tools/mcp/claude_code_discord_mcp_example.yaml +27 -0
- massgen/configs/tools/mcp/claude_code_simple_mcp.yaml +35 -0
- massgen/configs/tools/mcp/claude_code_twitter_mcp_example.yaml +32 -0
- massgen/configs/tools/mcp/claude_mcp_example.yaml +24 -0
- massgen/configs/tools/mcp/claude_mcp_test.yaml +27 -0
- massgen/configs/tools/mcp/five_agents_travel_mcp_test.yaml +157 -0
- massgen/configs/tools/mcp/five_agents_weather_mcp_test.yaml +103 -0
- massgen/configs/tools/mcp/gemini_mcp_example.yaml +24 -0
- massgen/configs/tools/mcp/gemini_mcp_filesystem_test.yaml +23 -0
- massgen/configs/tools/mcp/gemini_mcp_filesystem_test_sharing.yaml +23 -0
- massgen/configs/tools/mcp/gemini_mcp_filesystem_test_single_agent.yaml +17 -0
- massgen/configs/tools/mcp/gemini_mcp_filesystem_test_with_claude_code.yaml +24 -0
- massgen/configs/tools/mcp/gemini_mcp_test.yaml +27 -0
- massgen/configs/tools/mcp/gemini_notion_mcp.yaml +52 -0
- massgen/configs/tools/mcp/gpt5_nano_mcp_example.yaml +24 -0
- massgen/configs/tools/mcp/gpt5_nano_mcp_test.yaml +27 -0
- massgen/configs/tools/mcp/gpt5mini_claude_code_discord_mcp_example.yaml +38 -0
- massgen/configs/tools/mcp/gpt_oss_mcp_example.yaml +25 -0
- massgen/configs/tools/mcp/gpt_oss_mcp_test.yaml +28 -0
- massgen/configs/tools/mcp/grok3_mini_mcp_example.yaml +24 -0
- massgen/configs/tools/mcp/grok3_mini_mcp_test.yaml +27 -0
- massgen/configs/tools/mcp/multimcp_gemini.yaml +111 -0
- massgen/configs/tools/mcp/qwen_api_mcp_example.yaml +25 -0
- massgen/configs/tools/mcp/qwen_api_mcp_test.yaml +28 -0
- massgen/configs/tools/mcp/qwen_local_mcp_example.yaml +24 -0
- massgen/configs/tools/mcp/qwen_local_mcp_test.yaml +27 -0
- massgen/configs/tools/planning/five_agents_discord_mcp_planning_mode.yaml +140 -0
- massgen/configs/tools/planning/five_agents_filesystem_mcp_planning_mode.yaml +151 -0
- massgen/configs/tools/planning/five_agents_notion_mcp_planning_mode.yaml +151 -0
- massgen/configs/tools/planning/five_agents_twitter_mcp_planning_mode.yaml +155 -0
- massgen/configs/tools/planning/gpt5_mini_case_study_mcp_planning_mode.yaml +73 -0
- massgen/configs/tools/web-search/claude_streamable_http_test.yaml +43 -0
- massgen/configs/tools/web-search/gemini_streamable_http_test.yaml +43 -0
- massgen/configs/tools/web-search/gpt5_mini_streamable_http_test.yaml +43 -0
- massgen/configs/tools/web-search/gpt_oss_streamable_http_test.yaml +44 -0
- massgen/configs/tools/web-search/grok3_mini_streamable_http_test.yaml +43 -0
- massgen/configs/tools/web-search/qwen_api_streamable_http_test.yaml +44 -0
- massgen/configs/tools/web-search/qwen_local_streamable_http_test.yaml +43 -0
- massgen/coordination_tracker.py +708 -0
- massgen/docker/README.md +462 -0
- massgen/filesystem_manager/__init__.py +21 -0
- massgen/filesystem_manager/_base.py +9 -0
- massgen/filesystem_manager/_code_execution_server.py +545 -0
- massgen/filesystem_manager/_docker_manager.py +477 -0
- massgen/filesystem_manager/_file_operation_tracker.py +248 -0
- massgen/filesystem_manager/_filesystem_manager.py +813 -0
- massgen/filesystem_manager/_path_permission_manager.py +1261 -0
- massgen/filesystem_manager/_workspace_tools_server.py +1815 -0
- massgen/formatter/__init__.py +10 -0
- massgen/formatter/_chat_completions_formatter.py +284 -0
- massgen/formatter/_claude_formatter.py +235 -0
- massgen/formatter/_formatter_base.py +156 -0
- massgen/formatter/_response_formatter.py +263 -0
- massgen/frontend/__init__.py +1 -2
- massgen/frontend/coordination_ui.py +471 -286
- massgen/frontend/displays/base_display.py +56 -11
- massgen/frontend/displays/create_coordination_table.py +1956 -0
- massgen/frontend/displays/rich_terminal_display.py +1259 -619
- massgen/frontend/displays/simple_display.py +9 -4
- massgen/frontend/displays/terminal_display.py +27 -68
- massgen/logger_config.py +681 -0
- massgen/mcp_tools/README.md +232 -0
- massgen/mcp_tools/__init__.py +105 -0
- massgen/mcp_tools/backend_utils.py +1035 -0
- massgen/mcp_tools/circuit_breaker.py +195 -0
- massgen/mcp_tools/client.py +894 -0
- massgen/mcp_tools/config_validator.py +138 -0
- massgen/mcp_tools/docs/circuit_breaker.md +646 -0
- massgen/mcp_tools/docs/client.md +950 -0
- massgen/mcp_tools/docs/config_validator.md +478 -0
- massgen/mcp_tools/docs/exceptions.md +1165 -0
- massgen/mcp_tools/docs/security.md +854 -0
- massgen/mcp_tools/exceptions.py +338 -0
- massgen/mcp_tools/hooks.py +212 -0
- massgen/mcp_tools/security.py +780 -0
- massgen/message_templates.py +342 -64
- massgen/orchestrator.py +1515 -241
- massgen/stream_chunk/__init__.py +35 -0
- massgen/stream_chunk/base.py +92 -0
- massgen/stream_chunk/multimodal.py +237 -0
- massgen/stream_chunk/text.py +162 -0
- massgen/tests/mcp_test_server.py +150 -0
- massgen/tests/multi_turn_conversation_design.md +0 -8
- massgen/tests/test_azure_openai_backend.py +156 -0
- massgen/tests/test_backend_capabilities.py +262 -0
- massgen/tests/test_backend_event_loop_all.py +179 -0
- massgen/tests/test_chat_completions_refactor.py +142 -0
- massgen/tests/test_claude_backend.py +15 -28
- massgen/tests/test_claude_code.py +268 -0
- massgen/tests/test_claude_code_context_sharing.py +233 -0
- massgen/tests/test_claude_code_orchestrator.py +175 -0
- massgen/tests/test_cli_backends.py +180 -0
- massgen/tests/test_code_execution.py +679 -0
- massgen/tests/test_external_agent_backend.py +134 -0
- massgen/tests/test_final_presentation_fallback.py +237 -0
- massgen/tests/test_gemini_planning_mode.py +351 -0
- massgen/tests/test_grok_backend.py +7 -10
- massgen/tests/test_http_mcp_server.py +42 -0
- massgen/tests/test_integration_simple.py +198 -0
- massgen/tests/test_mcp_blocking.py +125 -0
- massgen/tests/test_message_context_building.py +29 -47
- massgen/tests/test_orchestrator_final_presentation.py +48 -0
- massgen/tests/test_path_permission_manager.py +2087 -0
- massgen/tests/test_rich_terminal_display.py +14 -13
- massgen/tests/test_timeout.py +133 -0
- massgen/tests/test_v3_3agents.py +11 -12
- massgen/tests/test_v3_simple.py +8 -13
- massgen/tests/test_v3_three_agents.py +11 -18
- massgen/tests/test_v3_two_agents.py +8 -13
- massgen/token_manager/__init__.py +7 -0
- massgen/token_manager/token_manager.py +400 -0
- massgen/utils.py +52 -16
- massgen/v1/agent.py +45 -91
- massgen/v1/agents.py +18 -53
- massgen/v1/backends/gemini.py +50 -153
- massgen/v1/backends/grok.py +21 -54
- massgen/v1/backends/oai.py +39 -111
- massgen/v1/cli.py +36 -93
- massgen/v1/config.py +8 -12
- massgen/v1/logging.py +43 -127
- massgen/v1/main.py +18 -32
- massgen/v1/orchestrator.py +68 -209
- massgen/v1/streaming_display.py +62 -163
- massgen/v1/tools.py +8 -12
- massgen/v1/types.py +9 -23
- massgen/v1/utils.py +5 -23
- massgen-0.1.0.dist-info/METADATA +1245 -0
- massgen-0.1.0.dist-info/RECORD +273 -0
- massgen-0.1.0.dist-info/entry_points.txt +2 -0
- massgen/frontend/logging/__init__.py +0 -9
- massgen/frontend/logging/realtime_logger.py +0 -197
- massgen-0.0.3.dist-info/METADATA +0 -568
- massgen-0.0.3.dist-info/RECORD +0 -76
- massgen-0.0.3.dist-info/entry_points.txt +0 -2
- /massgen/backend/{Function calling openai responses.md → docs/Function calling openai responses.md} +0 -0
- {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/WHEEL +0 -0
- {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/licenses/LICENSE +0 -0
- {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,1085 @@
|
|
|
1
|
+
# MassGen Permissions System and Context Files
|
|
2
|
+
|
|
3
|
+
This document explains MassGen's filesystem permissions system, context file management, and how to implement support in new backends.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
MassGen implements a sophisticated permissions system that allows agents to access user-specified files and directories with granular permission control. The system distinguishes between different types of paths and applies appropriate permissions based on the agent's role in the workflow.
|
|
8
|
+
|
|
9
|
+
## Architecture
|
|
10
|
+
|
|
11
|
+
### Core Components
|
|
12
|
+
|
|
13
|
+
1. **PathPermissionManager**: Central permission validation engine
|
|
14
|
+
2. **FilesystemManager**: High-level filesystem operations and workspace management
|
|
15
|
+
3. **Backend Integration**: Permission enforcement through hooks or MCP servers
|
|
16
|
+
4. **Context Paths**: User-specified files/directories with explicit permissions
|
|
17
|
+
|
|
18
|
+
### Permission Enforcement Strategies
|
|
19
|
+
|
|
20
|
+
MassGen uses different permission enforcement strategies based on backend capabilities:
|
|
21
|
+
|
|
22
|
+
- **Function-based backends** (OpenAI, Claude Code): Use `FunctionHookManager` with pre-call hooks
|
|
23
|
+
- **Session-based backends** (Gemini): Use `PermissionClientSession` to wrap MCP sessions
|
|
24
|
+
- **MCP backends** (Claude): Use MCP server hooks for permission validation
|
|
25
|
+
|
|
26
|
+
## Path Types and Permissions
|
|
27
|
+
|
|
28
|
+
### 1. Workspace Paths (`cwd`)
|
|
29
|
+
- **Purpose**: Primary working directory for agent operations
|
|
30
|
+
- **Permission**: Always `WRITE` - agents can create, modify, and delete files
|
|
31
|
+
- **Scope**: Agent-specific, isolated from other agents
|
|
32
|
+
- **Example**: `agent_workspace/`, `claude_code_workspace/`
|
|
33
|
+
|
|
34
|
+
### 2. Temporary Workspace Paths
|
|
35
|
+
- **Purpose**: Shared workspace for context sharing between agents
|
|
36
|
+
- **Permission**: Always `READ` - agents can read but not modify
|
|
37
|
+
- **Scope**: Contains snapshots from other agents for context
|
|
38
|
+
- **Example**: `temp_workspaces/agent1/`, `temp_workspaces/agent2/`
|
|
39
|
+
|
|
40
|
+
### 3. Context Paths (User-specified)
|
|
41
|
+
- **Purpose**: User-defined files/directories for agent access, e.g., for working in an existing repository
|
|
42
|
+
- **Permission**: Configurable `READ` or `WRITE` per path
|
|
43
|
+
- **Behavior**:
|
|
44
|
+
- **Coordination agents**: Always `READ` regardless of YAML configuration
|
|
45
|
+
- **Final agent**: Respects YAML configuration (`READ` or `WRITE`)
|
|
46
|
+
- For now, we assume only one context path can have `WRITE` access to avoid complexity -- this represents the case of a single project directory being modified as is default in other CLI tools. We allow multiple write paths, but have no guarantee of performance.
|
|
47
|
+
- The default behavior will be for the final agent to copy files from its workspace to the context path write directory at the end of the run, mimicking what would happen if we edited the files directly.
|
|
48
|
+
- **Example**: Project source files, documentation, configuration files
|
|
49
|
+
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
### YAML Configuration Example
|
|
53
|
+
|
|
54
|
+
```yaml
|
|
55
|
+
agents:
|
|
56
|
+
- id: "context_agent"
|
|
57
|
+
backend:
|
|
58
|
+
type: "claude_code"
|
|
59
|
+
model: "claude-sonnet-4-20250514"
|
|
60
|
+
cwd: "workspace1" # Agent-specific workspace
|
|
61
|
+
|
|
62
|
+
- id: "final_agent"
|
|
63
|
+
backend:
|
|
64
|
+
type: "openai"
|
|
65
|
+
model: "gpt-5"
|
|
66
|
+
cwd: "workspace2" # Agent-specific workspace
|
|
67
|
+
|
|
68
|
+
orchestrator:
|
|
69
|
+
snapshot_storage: "snapshots"
|
|
70
|
+
agent_temporary_workspace: "temp_workspaces"
|
|
71
|
+
# Context paths applied to all agents with permission control
|
|
72
|
+
context_paths:
|
|
73
|
+
- path: "/home/user/project/src"
|
|
74
|
+
permission: "write" # Final agent can modify, context agents read-only
|
|
75
|
+
- path: "/home/user/project/docs"
|
|
76
|
+
permission: "read" # All agents get read-only access
|
|
77
|
+
- path: "/home/user/shared_data"
|
|
78
|
+
permission: "write" # Final agent can modify, context agents read-only
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Configuration Parameters
|
|
82
|
+
|
|
83
|
+
**Agent Level:**
|
|
84
|
+
- `cwd`: Agent's primary workspace directory (agent-specific isolation)
|
|
85
|
+
- Automatically relocated to `.massgen/workspaces/` for clean project organization
|
|
86
|
+
|
|
87
|
+
**Orchestrator Level:**
|
|
88
|
+
- `context_paths`: List of user-specified paths with permissions applied to all agents
|
|
89
|
+
- `path`: Absolute path to **file or directory** (both are supported)
|
|
90
|
+
- `permission`: "read" or "write" - determines final agent access (context agents always read-only)
|
|
91
|
+
- `protected_paths`: Optional list of paths within a context path that are immune from modification/deletion
|
|
92
|
+
- **Default permission**: "write" when added interactively
|
|
93
|
+
- **File context paths**: When a file is specified, only that file is accessible (sibling files are blocked)
|
|
94
|
+
- `snapshot_storage`: Directory for storing agent workspace snapshots
|
|
95
|
+
- Automatically relocated to `.massgen/snapshots/`
|
|
96
|
+
- `agent_temporary_workspace`: Parent directory for temporary workspaces
|
|
97
|
+
- Automatically relocated to `.massgen/temp_workspaces/`
|
|
98
|
+
|
|
99
|
+
**Permission Behavior:**
|
|
100
|
+
- **Context agents**: Always get READ access to context paths regardless of permission setting
|
|
101
|
+
- **Final agent**: Gets the configured permission (READ or WRITE) for context paths
|
|
102
|
+
- **Workspace (`cwd`)**: Always WRITE access for the owning agent
|
|
103
|
+
|
|
104
|
+
### Interactive Context Path Management
|
|
105
|
+
|
|
106
|
+
When running MassGen in **interactive mode** with filesystem support enabled (at least one agent has `cwd` configured), you'll be prompted to add the current directory as a context path:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
📂 Context Paths:
|
|
110
|
+
No context paths configured
|
|
111
|
+
|
|
112
|
+
❓ Add current directory as context path?
|
|
113
|
+
/home/user/project
|
|
114
|
+
[Y]es (default) / [P]rotected / [N]o / [C]ustom path:
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Features:**
|
|
118
|
+
- **Default behavior**: Pressing Enter adds current directory with **write** permission
|
|
119
|
+
- **Protected paths**: Enter 'p' to add current directory with protected paths (files/dirs immune from modification)
|
|
120
|
+
- **Custom paths**: Enter 'c' to specify a different file or directory (supports both absolute and relative paths)
|
|
121
|
+
- **Auto-detection**: Only shows when filesystem is enabled (agents have `cwd` configured)
|
|
122
|
+
- **Smart defaults**: Default permission is "write" for both current directory and custom paths
|
|
123
|
+
- **File support**: Can add individual files as context paths - only that file is accessible, siblings are blocked
|
|
124
|
+
|
|
125
|
+
**Example interaction:**
|
|
126
|
+
```bash
|
|
127
|
+
cd /home/user/my-project
|
|
128
|
+
massgen --config config.yaml
|
|
129
|
+
|
|
130
|
+
# Prompt appears:
|
|
131
|
+
❓ Add current directory as context path?
|
|
132
|
+
/home/user/my-project
|
|
133
|
+
[Y]es (default) / [N]o / [C]ustom path: [Enter]
|
|
134
|
+
|
|
135
|
+
✓ Added /home/user/my-project (write)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
This eliminates the need to manually edit YAML config files for context paths.
|
|
139
|
+
|
|
140
|
+
### Using MassGen in Any Directory
|
|
141
|
+
|
|
142
|
+
MassGen is designed to work seamlessly from any directory without manual configuration changes. Here's how to use it effectively:
|
|
143
|
+
|
|
144
|
+
#### Quick Start: Directory-Based Workflow
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Navigate to your project
|
|
148
|
+
cd /home/user/my-project
|
|
149
|
+
|
|
150
|
+
# Run MassGen in interactive mode
|
|
151
|
+
uv tool run massgen --config tools/filesystem/gemini_gpt5_filesystem_multiturn.yaml
|
|
152
|
+
|
|
153
|
+
# You'll be prompted to add the current directory as a context path
|
|
154
|
+
❓ Add current directory as context path?
|
|
155
|
+
/home/user/my-project
|
|
156
|
+
[Y]es (default) / [N]o / [C]ustom path: [Enter]
|
|
157
|
+
|
|
158
|
+
✓ Added /home/user/my-project (write)
|
|
159
|
+
|
|
160
|
+
# Now agents can access and modify files in your project!
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### Single-Command Usage
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# Run a single task in any directory
|
|
167
|
+
cd /path/to/project
|
|
168
|
+
uv tool run massgen --config tools/filesystem/gemini_gpt5_filesystem_multiturn.yaml "Add error handling to the authentication module"
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### How It Works
|
|
172
|
+
|
|
173
|
+
1. **Config Resolution**: MassGen automatically finds config files:
|
|
174
|
+
- First checks the exact path you provide
|
|
175
|
+
- Falls back to searching in the package's `configs/` directory
|
|
176
|
+
- Works from any directory on your system
|
|
177
|
+
|
|
178
|
+
2. **Environment Variables**: `.env` files are loaded from multiple locations (priority order):
|
|
179
|
+
- MassGen package `.env` (development fallback)
|
|
180
|
+
- User home `~/.massgen/.env` (global user config)
|
|
181
|
+
- Current directory `.env` (highest priority)
|
|
182
|
+
|
|
183
|
+
3. **Path Management**: All paths are automatically organized under `.massgen/`:
|
|
184
|
+
- `cwd` paths → `.massgen/workspaces/`
|
|
185
|
+
- `snapshot_storage` → `.massgen/snapshots/`
|
|
186
|
+
- `agent_temporary_workspace` → `.massgen/temp_workspaces/`
|
|
187
|
+
|
|
188
|
+
4. **Context Paths**: In interactive mode with filesystem enabled, you're prompted to add the current directory
|
|
189
|
+
|
|
190
|
+
#### Installation for Global Access
|
|
191
|
+
|
|
192
|
+
Install MassGen using `uv tool` for isolated, global access:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Clone the repository
|
|
196
|
+
git clone https://github.com/Leezekun/MassGen.git
|
|
197
|
+
cd MassGen
|
|
198
|
+
|
|
199
|
+
# Install MassGen as a global tool in editable mode
|
|
200
|
+
uv tool install -e .
|
|
201
|
+
|
|
202
|
+
# Now run from any directory
|
|
203
|
+
cd ~/projects/website
|
|
204
|
+
uv tool run massgen --config tools/filesystem/gemini_gpt5_filesystem_multiturn.yaml
|
|
205
|
+
|
|
206
|
+
cd ~/documents/research
|
|
207
|
+
uv tool run massgen --config tools/filesystem/gemini_gpt5_filesystem_multiturn.yaml
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Benefits of `uv tool` installation:**
|
|
211
|
+
- ✅ Isolated Python environment (no conflicts with system Python)
|
|
212
|
+
- ✅ Available globally from any directory
|
|
213
|
+
- ✅ Editable mode (`-e .`) allows live development
|
|
214
|
+
- ✅ Easy updates with `git pull` (editable mode)
|
|
215
|
+
- ✅ Clean uninstall with `uv tool uninstall massgen`
|
|
216
|
+
|
|
217
|
+
#### Working Across Multiple Projects
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# Project 1: Web development
|
|
221
|
+
cd ~/projects/website
|
|
222
|
+
uv tool run massgen --config tools/filesystem/gemini_gpt5_filesystem_multiturn.yaml
|
|
223
|
+
# Adds ~/projects/website as context path
|
|
224
|
+
|
|
225
|
+
# Project 2: Data analysis
|
|
226
|
+
cd ~/data/analytics
|
|
227
|
+
uv tool run massgen --config tools/filesystem/gemini_gpt5_filesystem_multiturn.yaml
|
|
228
|
+
# Adds ~/data/analytics as context path
|
|
229
|
+
|
|
230
|
+
# Project 3: Documentation
|
|
231
|
+
cd ~/docs/user-manual
|
|
232
|
+
uv tool run massgen --config tools/filesystem/gemini_gpt5_filesystem_multiturn.yaml
|
|
233
|
+
# Adds ~/docs/user-manual as context path
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Each project gets its own `.massgen/` directory with isolated workspaces, sessions, and snapshots.
|
|
237
|
+
|
|
238
|
+
#### Best Practices
|
|
239
|
+
|
|
240
|
+
1. **Store configs centrally**: Keep your config files in `~/.massgen/configs/` or `~/massgen-configs/`
|
|
241
|
+
2. **Use relative paths**: Config files use relative paths that get auto-relocated to `.massgen/`
|
|
242
|
+
3. **Add to gitignore**: Add `.massgen/` to `.gitignore` in each project
|
|
243
|
+
4. **Share configs**: Reuse the same config across different projects - context paths are added interactively
|
|
244
|
+
|
|
245
|
+
**Example config for multi-directory use:**
|
|
246
|
+
```yaml
|
|
247
|
+
agents:
|
|
248
|
+
- id: "agent1"
|
|
249
|
+
backend:
|
|
250
|
+
type: "openai"
|
|
251
|
+
model: "gpt-4"
|
|
252
|
+
cwd: "workspace1" # Auto-relocated to .massgen/workspaces/workspace1/
|
|
253
|
+
|
|
254
|
+
orchestrator:
|
|
255
|
+
snapshot_storage: "snapshots" # Auto-relocated to .massgen/snapshots/
|
|
256
|
+
agent_temporary_workspace: "temp_workspaces" # Auto-relocated to .massgen/temp_workspaces/
|
|
257
|
+
# No context_paths needed - added interactively when you run massgen
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
This config works in **any directory** - just `cd` to your project and run `massgen`!
|
|
261
|
+
|
|
262
|
+
### .massgen Directory Structure
|
|
263
|
+
|
|
264
|
+
MassGen automatically organizes all state files under a `.massgen/` directory for clean project organization:
|
|
265
|
+
|
|
266
|
+
```
|
|
267
|
+
your-project/
|
|
268
|
+
├── .massgen/ # All MassGen state
|
|
269
|
+
│ ├── sessions/ # Multi-turn conversation history
|
|
270
|
+
│ ├── workspaces/ # Agent working directories
|
|
271
|
+
│ │ ├── workspace1/
|
|
272
|
+
│ │ └── workspace2/
|
|
273
|
+
│ ├── snapshots/ # Workspace snapshots
|
|
274
|
+
│ └── temp_workspaces/ # Previous turn results
|
|
275
|
+
├── massgen/ # Your project files
|
|
276
|
+
├── .env # Protected from agent writes
|
|
277
|
+
└── .git/ # Protected from agent writes
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Benefits:**
|
|
281
|
+
- ✅ **Clean Projects**: All MassGen files contained in one directory
|
|
282
|
+
- ✅ **Easy Gitignore**: Just add `.massgen/` to `.gitignore`
|
|
283
|
+
- ✅ **Portable**: Move or delete `.massgen/` without affecting your project
|
|
284
|
+
- ✅ **Protected Workspaces**: Even if `.massgen` is in excluded patterns, workspace paths inside can be fully writable
|
|
285
|
+
|
|
286
|
+
**Path relocation** happens automatically:
|
|
287
|
+
- Relative paths in config are relocated under `.massgen/`
|
|
288
|
+
- Absolute paths and paths already under `.massgen/` are left unchanged
|
|
289
|
+
- Applies to: `cwd`, `snapshot_storage`, `agent_temporary_workspace`
|
|
290
|
+
|
|
291
|
+
**File Delivery Challenge:**
|
|
292
|
+
When `.massgen/` is inside a context path with write permission (e.g., user adds `/home/user/project/` as writable context), agents might mistakenly think that creating files in their workspace (`.massgen/workspaces/`) satisfies the delivery requirement. This is incorrect - the workspace is just a staging area.
|
|
293
|
+
|
|
294
|
+
**Solution:**
|
|
295
|
+
The system prompt explicitly warns agents: **"Files inside `.massgen/` do NOT count as delivered."** The final agent must explicitly copy or write files from the workspace to the actual target context path using full absolute paths. This ensures deliverables end up in the user's project directory, not buried in `.massgen/`.
|
|
296
|
+
|
|
297
|
+
### Real-World Example
|
|
298
|
+
|
|
299
|
+
Based on the filesystem permissions test configuration (`fs_permissions_test.yaml`):
|
|
300
|
+
|
|
301
|
+
```yaml
|
|
302
|
+
agents:
|
|
303
|
+
- id: "gpt5nano_1"
|
|
304
|
+
backend:
|
|
305
|
+
type: "openai"
|
|
306
|
+
model: "gpt-5"
|
|
307
|
+
cwd: "workspace1" # Isolated workspace for this agent
|
|
308
|
+
|
|
309
|
+
- id: "gpt5nano_2"
|
|
310
|
+
backend:
|
|
311
|
+
type: "openai"
|
|
312
|
+
model: "gpt-5"
|
|
313
|
+
cwd: "workspace2" # Separate isolated workspace
|
|
314
|
+
|
|
315
|
+
orchestrator:
|
|
316
|
+
snapshot_storage: "snapshots"
|
|
317
|
+
agent_temporary_workspace: "temp_workspaces"
|
|
318
|
+
context_paths:
|
|
319
|
+
- path: "/home/nick/GitHubProjects/MassGen/v0.0.21-example"
|
|
320
|
+
permission: "write" # Final agent can modify this project directory
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
**What happens:**
|
|
324
|
+
1. **Both agents** can read files from `/home/nick/GitHubProjects/MassGen/v0.0.21-example`
|
|
325
|
+
2. **Context agent** (`gpt5nano_1`) gets READ-only access during coordination
|
|
326
|
+
3. **Final agent** (`gpt5nano_2`) gets WRITE access and can modify project files
|
|
327
|
+
4. **Each agent** has full WRITE access to their own workspace (`workspace1`, `workspace2`)
|
|
328
|
+
5. **Temporary workspaces** allow agents to share context from previous coordination rounds
|
|
329
|
+
|
|
330
|
+
## Snapshot Management and Agent Coordination
|
|
331
|
+
|
|
332
|
+
### Overview
|
|
333
|
+
|
|
334
|
+
During multi-agent coordination, MassGen uses a snapshot-based system to enable context sharing between agents. This ensures that all agents can see each other's work (complete or partial) and collaborate effectively.
|
|
335
|
+
|
|
336
|
+
### When Snapshots Are Saved
|
|
337
|
+
|
|
338
|
+
Snapshots are workspace copies saved at specific coordination points:
|
|
339
|
+
|
|
340
|
+
**1. Completed Answers:**
|
|
341
|
+
- Agent provides a complete answer via `new_answer` tool
|
|
342
|
+
- Workspace snapshot saved to `snapshot_storage/{agent_id}/`
|
|
343
|
+
- Snapshot overwrites previous one (keeps only most recent)
|
|
344
|
+
- Also saved to log directories with timestamp for debugging
|
|
345
|
+
|
|
346
|
+
**2. Completed Votes:**
|
|
347
|
+
- Agent votes for another agent's answer via `vote` tool
|
|
348
|
+
- Workspace snapshot saved (captures any work done before voting)
|
|
349
|
+
|
|
350
|
+
**3. Partial Work on Restart (NEW):**
|
|
351
|
+
- Agent is interrupted mid-answer due to another agent providing a new answer
|
|
352
|
+
- All other agents get `restart_pending = True` flag
|
|
353
|
+
- **Before restarting, agent's partial workspace is saved as a snapshot**
|
|
354
|
+
- This ensures other agents can see the partial work in their temp workspaces
|
|
355
|
+
- Critical for preserving incremental progress during coordination
|
|
356
|
+
|
|
357
|
+
### Workspace Lifecycle
|
|
358
|
+
|
|
359
|
+
| Location | When Cleared | Purpose |
|
|
360
|
+
|----------|-------------|---------|
|
|
361
|
+
| **Agent workspace** (`workspace1/`) | After saving snapshot (except final) | Clean slate for next execution |
|
|
362
|
+
| **Temp workspace** (`temp_workspaces/{agent_id}/`) | Before each agent execution | Fresh copy of all other agents' latest work |
|
|
363
|
+
| **Temp workspace parent** | At orchestration startup | Remove stale data from previous runs |
|
|
364
|
+
| **Snapshot storage** (`snapshots/{agent_id}/`) | When new snapshot saved | Overwritten with latest (only most recent kept) |
|
|
365
|
+
|
|
366
|
+
### Context Sharing Flow
|
|
367
|
+
|
|
368
|
+
**1. Snapshot Storage** (`snapshot_storage/{agent_id}/`):
|
|
369
|
+
- Source of truth for each agent's latest work
|
|
370
|
+
- Only most recent snapshot kept (overwritten on each save)
|
|
371
|
+
- Contains complete OR partial work, whichever is most recent
|
|
372
|
+
|
|
373
|
+
**2. Temporary Workspaces** (`temp_workspaces/{agent_id}/`):
|
|
374
|
+
- Populated before each agent execution via `_copy_all_snapshots_to_temp_workspace()`
|
|
375
|
+
- Contains all OTHER agents' latest snapshots
|
|
376
|
+
- Uses anonymous IDs (agent1, agent2, etc.) for privacy
|
|
377
|
+
- Read-only access for agents
|
|
378
|
+
|
|
379
|
+
**3. Agent Workspace** (`workspace1/`, `workspace2/`):
|
|
380
|
+
- Agent's personal working directory
|
|
381
|
+
- Full write access
|
|
382
|
+
- Cleared after saving snapshot (to prepare for restart)
|
|
383
|
+
|
|
384
|
+
### Restart and Partial Work Preservation
|
|
385
|
+
|
|
386
|
+
When an agent is restarted due to new answers from other agents:
|
|
387
|
+
|
|
388
|
+
```python
|
|
389
|
+
# orchestrator.py: Agent restart sequence
|
|
390
|
+
1. Detect restart_pending flag is True
|
|
391
|
+
2. Call _save_partial_work_on_restart(agent_id)
|
|
392
|
+
- Saves current workspace state to snapshots/
|
|
393
|
+
- Logs workspace contents for debugging
|
|
394
|
+
- Preserves any files created during partial execution
|
|
395
|
+
3. Clear workspace (prepare for fresh start)
|
|
396
|
+
4. Agent restarts with access to:
|
|
397
|
+
- All other agents' snapshots in temp_workspaces/
|
|
398
|
+
- Including the partial work from interrupted agents
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
**Example Coordination Flow:**
|
|
402
|
+
|
|
403
|
+
```
|
|
404
|
+
Round 1:
|
|
405
|
+
- Agent A starts → writes files to workspace1/
|
|
406
|
+
- Agent B starts → writes files to workspace2/
|
|
407
|
+
- Agent A completes answer → snapshot saved to snapshots/agentA/
|
|
408
|
+
- Agent B gets restart_pending=True (new answer detected)
|
|
409
|
+
- Agent B's partial work saved → snapshot saved to snapshots/agentB/
|
|
410
|
+
- Agent B's workspace cleared
|
|
411
|
+
|
|
412
|
+
Round 2:
|
|
413
|
+
- Agent A restarts
|
|
414
|
+
- temp_workspaces/agentA/ now contains agentB's partial work
|
|
415
|
+
- Can see what Agent B was working on
|
|
416
|
+
- Agent B restarts
|
|
417
|
+
- temp_workspaces/agentB/ contains agentA's complete answer
|
|
418
|
+
- Can build upon Agent A's completed work
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
**Key Design Decision:** Partial work is ALWAYS saved before restart. This ensures:
|
|
422
|
+
- No work is lost during agent restarts
|
|
423
|
+
- All agents can see each other's progress (complete or partial)
|
|
424
|
+
- Better collaboration through incremental visibility
|
|
425
|
+
- Debugging is easier with complete workspace history
|
|
426
|
+
|
|
427
|
+
### Implementation Details
|
|
428
|
+
|
|
429
|
+
**Snapshot Save Method** (`filesystem_manager.py:save_snapshot()`):
|
|
430
|
+
1. Copies workspace contents to `snapshot_storage/{agent_id}/` (overwrites existing)
|
|
431
|
+
2. Also saves to log directories: `log_session/agent_id/timestamp/workspace/`
|
|
432
|
+
3. Does NOT clear workspace (clearing happens separately)
|
|
433
|
+
|
|
434
|
+
**Partial Work Save** (`orchestrator.py:_save_partial_work_on_restart()`):
|
|
435
|
+
```python
|
|
436
|
+
async def _save_partial_work_on_restart(self, agent_id: str) -> None:
|
|
437
|
+
"""Save partial work before restarting due to new answers from others."""
|
|
438
|
+
await self._save_agent_snapshot(
|
|
439
|
+
agent_id,
|
|
440
|
+
answer_content=None, # No complete answer yet
|
|
441
|
+
context_data=self.get_last_context(agent_id),
|
|
442
|
+
is_final=False,
|
|
443
|
+
)
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
**Temp Workspace Population** (`orchestrator.py:_copy_all_snapshots_to_temp_workspace()`):
|
|
447
|
+
1. Collects all snapshots from `snapshot_storage/{agent_id}/` directories
|
|
448
|
+
2. Clears existing temp workspace for target agent
|
|
449
|
+
3. Copies all other agents' snapshots using anonymous IDs
|
|
450
|
+
4. Agent can now read other agents' work through temp workspace
|
|
451
|
+
|
|
452
|
+
## Permission Validation Flow
|
|
453
|
+
|
|
454
|
+
### 1. Path Resolution
|
|
455
|
+
```python
|
|
456
|
+
# PathPermissionManager resolves and validates paths
|
|
457
|
+
resolved_path = path.resolve()
|
|
458
|
+
permission = self.get_permission(resolved_path)
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
### 2. Permission Check
|
|
462
|
+
```python
|
|
463
|
+
async def pre_tool_use_hook(self, tool_name: str, tool_args: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
|
|
464
|
+
"""Validate tool calls based on permissions."""
|
|
465
|
+
if self._is_write_tool(tool_name):
|
|
466
|
+
return self._validate_write_tool(tool_name, tool_args)
|
|
467
|
+
return (True, None) # Allow read operations and non-file tools
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### 3. Backend-Specific Enforcement
|
|
471
|
+
|
|
472
|
+
#### Function-based Backends (OpenAI responses, Chat Completions, Claude)
|
|
473
|
+
```python
|
|
474
|
+
# Base class sets up per-agent function hooks
|
|
475
|
+
self.function_hook_manager = FunctionHookManager()
|
|
476
|
+
permission_hook = PathPermissionManagerHook(
|
|
477
|
+
self.filesystem_manager.path_permission_manager
|
|
478
|
+
)
|
|
479
|
+
self.function_hook_manager.register_global_hook(HookType.PRE_CALL, permission_hook)
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
#### Session-based Backends (Gemini)
|
|
483
|
+
```python
|
|
484
|
+
# Convert sessions to permission-aware sessions
|
|
485
|
+
from ..mcp_tools.hooks import convert_sessions_to_permission_sessions
|
|
486
|
+
mcp_sessions = convert_sessions_to_permission_sessions(
|
|
487
|
+
mcp_sessions,
|
|
488
|
+
self.filesystem_manager.path_permission_manager
|
|
489
|
+
)
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
**Fallback Behavior**: If MCP SDK is not available, Gemini gracefully falls back to workflow tools only (no filesystem access). This eliminates the need for permission validation since no file operations are possible.
|
|
493
|
+
|
|
494
|
+
#### Special Backends (Claude Code)
|
|
495
|
+
```python
|
|
496
|
+
# Claude Code uses native filesystem tools with hook integration
|
|
497
|
+
# Hooks are passed directly to ClaudeCodeOptions
|
|
498
|
+
hooks_config = self.filesystem_manager.get_claude_code_hooks_config()
|
|
499
|
+
|
|
500
|
+
options = {
|
|
501
|
+
"cwd": workspace_path,
|
|
502
|
+
"permission_mode": "acceptEdits",
|
|
503
|
+
"allowed_tools": allowed_tools,
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
# Add hooks if available
|
|
507
|
+
if hooks_config:
|
|
508
|
+
options["hooks"] = hooks_config
|
|
509
|
+
|
|
510
|
+
return ClaudeCodeOptions(**options)
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
## Implementing Backend Support
|
|
514
|
+
|
|
515
|
+
### Step 1: Extend LLMBackend
|
|
516
|
+
|
|
517
|
+
```python
|
|
518
|
+
from .base import LLMBackend, FilesystemSupport
|
|
519
|
+
|
|
520
|
+
class NewBackend(LLMBackend):
|
|
521
|
+
def __init__(self, api_key: Optional[str] = None, **kwargs):
|
|
522
|
+
super().__init__(api_key, **kwargs)
|
|
523
|
+
# Backend initialization
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
### Step 2: Declare Filesystem Support
|
|
527
|
+
|
|
528
|
+
```python
|
|
529
|
+
def get_filesystem_support(self) -> FilesystemSupport:
|
|
530
|
+
"""Declare what type of filesystem support this backend provides."""
|
|
531
|
+
# Choose based on your backend's capabilities:
|
|
532
|
+
return FilesystemSupport.NONE # No filesystem support
|
|
533
|
+
return FilesystemSupport.NATIVE # Built-in filesystem tools (like Claude Code)
|
|
534
|
+
return FilesystemSupport.MCP # Filesystem through MCP servers
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### Step 3: Configure Parameter Exclusions
|
|
538
|
+
|
|
539
|
+
```python
|
|
540
|
+
# Use base class exclusions to avoid API parameter conflicts
|
|
541
|
+
excluded_params = self.get_base_excluded_config_params().union({
|
|
542
|
+
"backend_specific_param1",
|
|
543
|
+
"backend_specific_param2",
|
|
544
|
+
})
|
|
545
|
+
|
|
546
|
+
# Filter parameters before API calls
|
|
547
|
+
api_params = {k: v for k, v in all_params.items()
|
|
548
|
+
if k not in excluded_params and v is not None}
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
### Step 4: Implement Permission Hooks (if needed)
|
|
552
|
+
|
|
553
|
+
#### For Function-based Backends
|
|
554
|
+
```python
|
|
555
|
+
# Use default base class behavior - no override needed
|
|
556
|
+
# Base class automatically sets up FunctionHookManager with permission hooks
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
#### For Session-based Backends
|
|
560
|
+
```python
|
|
561
|
+
def _setup_permission_hooks(self):
|
|
562
|
+
"""Session-based backends use MCP session wrapping for permissions."""
|
|
563
|
+
# Override to prevent function hook creation - permissions handled at session level
|
|
564
|
+
logger.debug("[Backend] Using session-based permissions, skipping function hook setup")
|
|
565
|
+
|
|
566
|
+
# In your session creation code:
|
|
567
|
+
if self.filesystem_manager:
|
|
568
|
+
from ..mcp_tools.hooks import convert_sessions_to_permission_sessions
|
|
569
|
+
sessions = convert_sessions_to_permission_sessions(
|
|
570
|
+
sessions,
|
|
571
|
+
self.filesystem_manager.path_permission_manager
|
|
572
|
+
)
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
**Why Override is Necessary**: Without the override, backends would create unused `FunctionHookManager` instances while using session-based permissions, leading to resource waste and debugging confusion. When MCP SDK is unavailable, session-based backends fall back to workflow tools only (no filesystem access), making permission validation unnecessary.
|
|
576
|
+
|
|
577
|
+
#### For Special Backends (Claude Code)
|
|
578
|
+
```python
|
|
579
|
+
def _setup_permission_hooks(self):
|
|
580
|
+
"""Claude Code uses native filesystem tools with built-in hook support."""
|
|
581
|
+
# Claude Code hooks are passed via ClaudeCodeOptions, not function hooks
|
|
582
|
+
# No function hook manager needed - permissions handled at tool level
|
|
583
|
+
pass
|
|
584
|
+
|
|
585
|
+
# In your client setup:
|
|
586
|
+
hooks_config = {}
|
|
587
|
+
if self.filesystem_manager:
|
|
588
|
+
hooks_config = self.filesystem_manager.get_claude_code_hooks_config()
|
|
589
|
+
|
|
590
|
+
options = ClaudeCodeOptions(
|
|
591
|
+
cwd=workspace_path,
|
|
592
|
+
hooks=hooks_config, # Native Claude Code hook integration
|
|
593
|
+
# ... other options
|
|
594
|
+
)
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
## Security Considerations
|
|
599
|
+
|
|
600
|
+
### Path Validation
|
|
601
|
+
- All paths are resolved to absolute paths to prevent directory traversal
|
|
602
|
+
- Workspace boundaries are enforced to prevent cross-agent access
|
|
603
|
+
- Dangerous commands are blocked regardless of permissions
|
|
604
|
+
- **Default System File Exclusions**: Certain paths are automatically protected from write access regardless of context path permissions
|
|
605
|
+
|
|
606
|
+
### Default Excluded Patterns
|
|
607
|
+
|
|
608
|
+
The following paths are **always excluded from write access** as system-level defaults to prevent accidental modification of critical files:
|
|
609
|
+
|
|
610
|
+
```python
|
|
611
|
+
DEFAULT_EXCLUDED_PATTERNS = [
|
|
612
|
+
".massgen", # MassGen state directory
|
|
613
|
+
".env", # Environment variables
|
|
614
|
+
".git", # Git repository data
|
|
615
|
+
"node_modules", # Node.js dependencies
|
|
616
|
+
"__pycache__", # Python bytecode cache
|
|
617
|
+
".venv", # Python virtual environment
|
|
618
|
+
"venv", # Python virtual environment (alternate name)
|
|
619
|
+
".pytest_cache", # Pytest cache
|
|
620
|
+
".mypy_cache", # Mypy type checker cache
|
|
621
|
+
".ruff_cache", # Ruff linter cache
|
|
622
|
+
".DS_Store", # macOS metadata
|
|
623
|
+
"massgen_logs", # MassGen log files
|
|
624
|
+
]
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
**Behavior:**
|
|
628
|
+
- These patterns are checked against all path components
|
|
629
|
+
- If any part of a path matches an excluded pattern, it becomes read-only
|
|
630
|
+
- **Exception**: Workspace paths (agent's `cwd`) override exclusions - agents can write within their own workspace even if it's under `.massgen/workspaces/`
|
|
631
|
+
- Context paths with write permission will still have these specific files/directories protected
|
|
632
|
+
|
|
633
|
+
**Example:**
|
|
634
|
+
```yaml
|
|
635
|
+
orchestrator:
|
|
636
|
+
context_paths:
|
|
637
|
+
- path: "/home/user/project"
|
|
638
|
+
permission: "write"
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
Even with write permission, the agent **cannot** modify:
|
|
642
|
+
- `/home/user/project/.env`
|
|
643
|
+
- `/home/user/project/.git/`
|
|
644
|
+
- `/home/user/project/node_modules/`
|
|
645
|
+
|
|
646
|
+
But the agent **can** write to their workspace:
|
|
647
|
+
- `/home/user/project/.massgen/workspaces/workspace1/` (full write access)
|
|
648
|
+
|
|
649
|
+
### Path Priority Resolution
|
|
650
|
+
|
|
651
|
+
When multiple managed paths could match a given file path, MassGen uses **depth-first priority**:
|
|
652
|
+
|
|
653
|
+
1. **More specific (deeper) paths take precedence** over parent paths
|
|
654
|
+
2. Paths are sorted by depth (number of path components) in descending order
|
|
655
|
+
3. The first matching path determines the permission
|
|
656
|
+
|
|
657
|
+
**Example:**
|
|
658
|
+
|
|
659
|
+
```yaml
|
|
660
|
+
orchestrator:
|
|
661
|
+
context_paths:
|
|
662
|
+
- path: "/home/user/project" # Depth: 4 parts
|
|
663
|
+
permission: "read"
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
Agent configuration:
|
|
667
|
+
```yaml
|
|
668
|
+
agents:
|
|
669
|
+
- id: "agent1"
|
|
670
|
+
backend:
|
|
671
|
+
cwd: "/home/user/project/.massgen/workspaces/workspace1" # Depth: 7 parts
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
When checking `/home/user/project/.massgen/workspaces/workspace1/index.html`:
|
|
675
|
+
1. First checks workspace path (depth 7) → **WRITE** ✅ (workspace always writable)
|
|
676
|
+
2. Never reaches context path (depth 4) → read permission not applied
|
|
677
|
+
|
|
678
|
+
This ensures workspace paths always take precedence over their parent context paths.
|
|
679
|
+
|
|
680
|
+
### Permission Isolation
|
|
681
|
+
- Each agent gets its own `FunctionHookManager` instance
|
|
682
|
+
- No global state sharing between agents
|
|
683
|
+
- Context paths are validated on every access
|
|
684
|
+
|
|
685
|
+
### Dangerous Operation Prevention
|
|
686
|
+
```python
|
|
687
|
+
def _validate_command_tool(self, tool_name: str, tool_args: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
|
|
688
|
+
"""Block dangerous system commands."""
|
|
689
|
+
dangerous_patterns = [
|
|
690
|
+
"rm ", "rm -", "rmdir", "del ",
|
|
691
|
+
"sudo ", "su ", "chmod ", "chown ",
|
|
692
|
+
"format ", "fdisk", "mkfs",
|
|
693
|
+
]
|
|
694
|
+
# Block dangerous operations regardless of permissions
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
## Troubleshooting
|
|
698
|
+
|
|
699
|
+
### Common Issues
|
|
700
|
+
|
|
701
|
+
#### "0 pre-tool hooks" in logs
|
|
702
|
+
**Cause**: Backend not passing permission hooks to tool execution
|
|
703
|
+
**Solution**: Ensure hooks are passed to MCP client or function execution
|
|
704
|
+
|
|
705
|
+
#### "Unexpected keyword argument" errors
|
|
706
|
+
**Cause**: Backend passing MassGen-specific parameters to API
|
|
707
|
+
**Solution**: Use `get_base_excluded_config_params()` for parameter filtering
|
|
708
|
+
|
|
709
|
+
#### Permission denied for workspace files
|
|
710
|
+
**Cause**: Incorrect path resolution or workspace setup
|
|
711
|
+
**Solution**: Verify workspace paths are properly added to `PathPermissionManager`
|
|
712
|
+
|
|
713
|
+
### Debugging
|
|
714
|
+
|
|
715
|
+
Enable detailed logging to trace permission validation:
|
|
716
|
+
|
|
717
|
+
```python
|
|
718
|
+
logger.debug(f"[PathPermissionManager] Validating {tool_name} for path: {path}")
|
|
719
|
+
logger.debug(f"[PathPermissionManager] Found permission: {permission}")
|
|
720
|
+
logger.debug(f"[PathPermissionManager] Managed paths: {self.managed_paths}")
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
## Migration Guide
|
|
724
|
+
|
|
725
|
+
### Upgrading Existing Backends
|
|
726
|
+
|
|
727
|
+
1. **Update parameter exclusions**:
|
|
728
|
+
```python
|
|
729
|
+
# Old approach
|
|
730
|
+
excluded_params = {"cwd", "agent_id", "type"}
|
|
731
|
+
|
|
732
|
+
# New approach
|
|
733
|
+
excluded_params = self.get_base_excluded_config_params().union({
|
|
734
|
+
"backend_specific_param"
|
|
735
|
+
})
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
2. **Override permission hooks if needed**:
|
|
739
|
+
```python
|
|
740
|
+
def _setup_permission_hooks(self):
|
|
741
|
+
"""Override for backends that don't use function hooks."""
|
|
742
|
+
if self.get_filesystem_support() == FilesystemSupport.MCP:
|
|
743
|
+
pass # Use MCP-level hooks instead
|
|
744
|
+
else:
|
|
745
|
+
super()._setup_permission_hooks() # Use default function hooks
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
3. **Add filesystem support declaration**:
|
|
749
|
+
```python
|
|
750
|
+
def get_filesystem_support(self) -> FilesystemSupport:
|
|
751
|
+
return FilesystemSupport.MCP # or NATIVE/NONE based on capabilities
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
## Examples
|
|
755
|
+
|
|
756
|
+
This section provides complete examples demonstrating MassGen's filesystem capabilities across different scenarios.
|
|
757
|
+
|
|
758
|
+
### Single-Turn Web Development
|
|
759
|
+
|
|
760
|
+
**Scenario**: Create a coding puzzle game with Vite
|
|
761
|
+
**Config**: `massgen/configs/tools/filesystem/gemini_gpt5_filesystem_casestudy.yaml`
|
|
762
|
+
|
|
763
|
+
```bash
|
|
764
|
+
# Navigate to your project directory
|
|
765
|
+
cd ~/projects/coding-puzzles
|
|
766
|
+
|
|
767
|
+
# Run MassGen with filesystem support
|
|
768
|
+
uv tool run massgen --config tools/filesystem/gemini_gpt5_filesystem_casestudy.yaml \
|
|
769
|
+
"Build a game where users see a diverse set of up-to-date small, static coding puzzles related to common coding bugs. Then, award them points if they can clearly spot the error in the code. Use Vite with a package.json with minimal dependencies."
|
|
770
|
+
|
|
771
|
+
# Prompted to add current directory as context path
|
|
772
|
+
❓ Add current directory as context path?
|
|
773
|
+
/Users/user/projects/coding-puzzles
|
|
774
|
+
[Y]es (default) / [N]o / [C]ustom path: [Enter]
|
|
775
|
+
|
|
776
|
+
✓ Added /Users/user/projects/coding-puzzles (write)
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
**Config file:**
|
|
780
|
+
```yaml
|
|
781
|
+
agents:
|
|
782
|
+
- id: "gemini"
|
|
783
|
+
backend:
|
|
784
|
+
type: "gemini"
|
|
785
|
+
model: "gemini-2.5-flash"
|
|
786
|
+
cwd: "workspace1" # Auto-relocated to .massgen/workspaces/workspace1/
|
|
787
|
+
|
|
788
|
+
- id: "gemini2"
|
|
789
|
+
backend:
|
|
790
|
+
type: "gemini"
|
|
791
|
+
model: "gemini-2.5-flash"
|
|
792
|
+
cwd: "workspace2" # Auto-relocated to .massgen/workspaces/workspace2/
|
|
793
|
+
|
|
794
|
+
orchestrator:
|
|
795
|
+
snapshot_storage: "snapshots" # Auto-relocated to .massgen/snapshots/
|
|
796
|
+
agent_temporary_workspace: "temp_workspaces" # Auto-relocated to .massgen/temp_workspaces/
|
|
797
|
+
# context_paths added interactively
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
**Result**: Game files delivered to `/Users/user/projects/coding-puzzles/` with MassGen state in `.massgen/`
|
|
801
|
+
|
|
802
|
+
### Multi-Turn Interactive Development
|
|
803
|
+
|
|
804
|
+
**Scenario**: Iterative development across multiple conversation turns
|
|
805
|
+
**Config**: `massgen/configs/tools/filesystem/multiturn/two_gemini_flash_filesystem_multiturn.yaml`
|
|
806
|
+
|
|
807
|
+
```bash
|
|
808
|
+
# Start interactive session
|
|
809
|
+
cd ~/projects/web-app
|
|
810
|
+
uv tool run massgen --config tools/filesystem/multiturn/two_gemini_flash_filesystem_multiturn.yaml
|
|
811
|
+
|
|
812
|
+
# Turn 1: Create basic structure
|
|
813
|
+
User: "Create a React app with authentication"
|
|
814
|
+
Assistant: [Creates basic React app with login/logout]
|
|
815
|
+
Files delivered to: ~/projects/web-app/
|
|
816
|
+
|
|
817
|
+
# Turn 2: Add features building on Turn 1
|
|
818
|
+
User: "Add user profile management"
|
|
819
|
+
Assistant: [Builds upon existing React app, adds profile features]
|
|
820
|
+
Files delivered to: ~/projects/web-app/ (updated)
|
|
821
|
+
|
|
822
|
+
# Turn 3: Further refinements
|
|
823
|
+
User: "Add password reset functionality"
|
|
824
|
+
Assistant: [References previous turns, adds password reset to existing app]
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
**Config file:**
|
|
828
|
+
```yaml
|
|
829
|
+
agents:
|
|
830
|
+
- id: "gemini"
|
|
831
|
+
backend:
|
|
832
|
+
type: "gemini"
|
|
833
|
+
model: "gemini-2.5-flash"
|
|
834
|
+
cwd: "workspace1"
|
|
835
|
+
|
|
836
|
+
- id: "gemini2"
|
|
837
|
+
backend:
|
|
838
|
+
type: "gemini"
|
|
839
|
+
model: "gemini-2.5-flash"
|
|
840
|
+
cwd: "workspace2"
|
|
841
|
+
|
|
842
|
+
orchestrator:
|
|
843
|
+
snapshot_storage: "snapshots"
|
|
844
|
+
agent_temporary_workspace: "temp_workspaces"
|
|
845
|
+
session_storage: "sessions" # Enables multi-turn persistence
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
**File Structure After 3 Turns:**
|
|
849
|
+
```
|
|
850
|
+
~/projects/web-app/
|
|
851
|
+
├── .massgen/
|
|
852
|
+
│ ├── sessions/session_20250928_143022/
|
|
853
|
+
│ │ ├── SESSION_SUMMARY.txt
|
|
854
|
+
│ │ ├── turn_1/
|
|
855
|
+
│ │ │ ├── workspace/ # Turn 1 final output
|
|
856
|
+
│ │ │ ├── answer.txt
|
|
857
|
+
│ │ │ └── metadata.json
|
|
858
|
+
│ │ ├── turn_2/
|
|
859
|
+
│ │ │ └── ... # Turn 2 results
|
|
860
|
+
│ │ └── turn_3/
|
|
861
|
+
│ │ └── ... # Turn 3 results
|
|
862
|
+
│ ├── workspaces/
|
|
863
|
+
│ │ ├── workspace1/ # Agent workspaces
|
|
864
|
+
│ │ └── workspace2/
|
|
865
|
+
│ └── logs/log_20250928_143022/
|
|
866
|
+
│ ├── turn_1/massgen_debug.log
|
|
867
|
+
│ ├── turn_2/massgen_debug.log
|
|
868
|
+
│ └── turn_3/massgen_debug.log
|
|
869
|
+
├── src/ # Your actual React app
|
|
870
|
+
├── package.json # Project files delivered by agents
|
|
871
|
+
└── README.md
|
|
872
|
+
```
|
|
873
|
+
|
|
874
|
+
#### Alternative Multi-Turn Config with Mixed Backends
|
|
875
|
+
|
|
876
|
+
**Config**: `massgen/configs/tools/filesystem/multiturn/grok4_gpt5_claude_code_filesystem_multiturn.yaml`
|
|
877
|
+
|
|
878
|
+
```bash
|
|
879
|
+
# Multi-backend approach: Grok + GPT-5 for diverse perspectives
|
|
880
|
+
cd ~/projects/complex-app
|
|
881
|
+
uv tool run massgen --config tools/filesystem/multiturn/grok4_gpt5_claude_code_filesystem_multiturn.yaml
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
**Config highlights:**
|
|
885
|
+
```yaml
|
|
886
|
+
agents:
|
|
887
|
+
- id: "agent_a"
|
|
888
|
+
backend:
|
|
889
|
+
type: "grok"
|
|
890
|
+
model: "grok-4-fast-reasoning"
|
|
891
|
+
cwd: "workspace1"
|
|
892
|
+
|
|
893
|
+
- id: "agent_b"
|
|
894
|
+
backend:
|
|
895
|
+
type: "openai"
|
|
896
|
+
model: "gpt-5-mini"
|
|
897
|
+
reasoning:
|
|
898
|
+
effort: "medium"
|
|
899
|
+
cwd: "workspace2"
|
|
900
|
+
|
|
901
|
+
orchestrator:
|
|
902
|
+
session_storage: "sessions" # Multi-turn persistence
|
|
903
|
+
```
|
|
904
|
+
|
|
905
|
+
This config provides diverse agent perspectives while maintaining the same multi-turn workflow.
|
|
906
|
+
|
|
907
|
+
### Working with Existing Codebases
|
|
908
|
+
|
|
909
|
+
**Scenario**: Debug and fix issues in an existing project
|
|
910
|
+
|
|
911
|
+
```bash
|
|
912
|
+
# Navigate to existing project with issues
|
|
913
|
+
cd ~/projects/existing-app
|
|
914
|
+
|
|
915
|
+
# Run MassGen to analyze and fix
|
|
916
|
+
uv tool run massgen --config tools/filesystem/gemini_gpt5_filesystem_casestudy.yaml \
|
|
917
|
+
"The authentication is broken - users can't log in. Find and fix the issue."
|
|
918
|
+
|
|
919
|
+
# Add current directory for analysis and fixes
|
|
920
|
+
❓ Add current directory as context path?
|
|
921
|
+
/Users/user/projects/existing-app
|
|
922
|
+
[Y]es (default) / [N]o / [C]ustom path: [Enter]
|
|
923
|
+
|
|
924
|
+
✓ Added /Users/user/projects/existing-app (write)
|
|
925
|
+
```
|
|
926
|
+
|
|
927
|
+
**Agent Process:**
|
|
928
|
+
1. **Read existing code** from context path: `/Users/user/projects/existing-app/`
|
|
929
|
+
2. **Analyze** authentication flow in current codebase
|
|
930
|
+
3. **Work in workspace**: `.massgen/workspaces/workspace1/`
|
|
931
|
+
4. **Deliver fixes** to context path: `/Users/user/projects/existing-app/`
|
|
932
|
+
|
|
933
|
+
**Key Benefit**: Agents understand existing code structure and fix issues in place
|
|
934
|
+
|
|
935
|
+
### Permission Scenarios
|
|
936
|
+
|
|
937
|
+
#### Read-Only Analysis
|
|
938
|
+
```yaml
|
|
939
|
+
orchestrator:
|
|
940
|
+
context_paths:
|
|
941
|
+
- path: "/path/to/legacy-system"
|
|
942
|
+
permission: "read" # Analysis only, no modifications
|
|
943
|
+
```
|
|
944
|
+
|
|
945
|
+
#### Multiple Context Paths
|
|
946
|
+
```yaml
|
|
947
|
+
orchestrator:
|
|
948
|
+
context_paths:
|
|
949
|
+
- path: "/path/to/shared-library"
|
|
950
|
+
permission: "read" # Reference existing code
|
|
951
|
+
- path: "/path/to/my-project"
|
|
952
|
+
permission: "write" # Deliver new code here
|
|
953
|
+
```
|
|
954
|
+
|
|
955
|
+
#### File Context Paths (Individual Files)
|
|
956
|
+
```yaml
|
|
957
|
+
orchestrator:
|
|
958
|
+
context_paths:
|
|
959
|
+
- path: "/path/to/config.yaml"
|
|
960
|
+
permission: "read" # Only this file is accessible
|
|
961
|
+
- path: "/path/to/logo.png"
|
|
962
|
+
permission: "read" # Share specific assets without exposing directory
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
**How it works:**
|
|
966
|
+
- Agent can read `/path/to/config.yaml` ✅
|
|
967
|
+
- Agent **cannot** read `/path/to/other_file.txt` ❌ (sibling files blocked)
|
|
968
|
+
- Agent **cannot** list `/path/to/` directory ❌
|
|
969
|
+
- Only the explicitly specified file is accessible
|
|
970
|
+
|
|
971
|
+
**Use cases:**
|
|
972
|
+
- Share specific configuration files without exposing secrets
|
|
973
|
+
- Provide reference images/assets without directory access
|
|
974
|
+
- Grant access to individual data files for analysis
|
|
975
|
+
|
|
976
|
+
**Interactive example:**
|
|
977
|
+
```bash
|
|
978
|
+
❓ Add current directory as context path?
|
|
979
|
+
/home/user/project
|
|
980
|
+
[Y]es (default) / [P]rotected / [N]o / [C]ustom path: c
|
|
981
|
+
Enter path (absolute or relative, file or directory): ./config.yaml
|
|
982
|
+
Permission [read/write] (default: write): read
|
|
983
|
+
✓ Added /home/user/project/config.yaml (read)
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
#### System File Protection
|
|
987
|
+
Even with write permission, these paths are automatically protected:
|
|
988
|
+
- `/path/to/my-project/.env` → Always read-only
|
|
989
|
+
- `/path/to/my-project/.git/` → Always read-only
|
|
990
|
+
- `/path/to/my-project/node_modules/` → Always read-only
|
|
991
|
+
- `/path/to/my-project/.massgen/` → Always read-only (except agent workspaces)
|
|
992
|
+
|
|
993
|
+
### Directory-Based Workflow Patterns
|
|
994
|
+
|
|
995
|
+
#### Pattern 1: New Project Creation
|
|
996
|
+
```bash
|
|
997
|
+
mkdir ~/projects/new-app
|
|
998
|
+
cd ~/projects/new-app
|
|
999
|
+
uv tool run massgen --config <config> "Create a new Express.js API"
|
|
1000
|
+
# Result: New project files in ~/projects/new-app/
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
#### Pattern 2: Existing Project Enhancement
|
|
1004
|
+
```bash
|
|
1005
|
+
cd ~/projects/existing-app # Contains package.json, src/, etc.
|
|
1006
|
+
uv tool run massgen --config <config> "Add GraphQL support"
|
|
1007
|
+
# Result: GraphQL files added to existing structure
|
|
1008
|
+
```
|
|
1009
|
+
|
|
1010
|
+
#### Pattern 3: Cross-Project Development
|
|
1011
|
+
```bash
|
|
1012
|
+
cd ~/projects/mobile-app
|
|
1013
|
+
# Custom path to shared component library
|
|
1014
|
+
uv tool run massgen --config <config>
|
|
1015
|
+
# Custom path: ~/shared/ui-components (read-only reference)
|
|
1016
|
+
# Target: ~/projects/mobile-app (write access)
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
### Error Scenarios and Solutions
|
|
1020
|
+
|
|
1021
|
+
#### Missing Context Path
|
|
1022
|
+
```bash
|
|
1023
|
+
# Error: Context path doesn't exist
|
|
1024
|
+
Error: Context paths not found:
|
|
1025
|
+
- /path/that/does/not/exist
|
|
1026
|
+
|
|
1027
|
+
# Solution: Create directory first or use correct path
|
|
1028
|
+
mkdir /path/that/does/not/exist
|
|
1029
|
+
```
|
|
1030
|
+
|
|
1031
|
+
#### Sibling File Access Blocked (File Context Paths)
|
|
1032
|
+
```bash
|
|
1033
|
+
# Scenario: Added /project/config.yaml as file context path
|
|
1034
|
+
# Agent tries to access sibling file
|
|
1035
|
+
Tool: read_file
|
|
1036
|
+
Path: /project/secrets.yaml
|
|
1037
|
+
Result: ❌ Access denied: '/project/secrets.yaml' is not an explicitly allowed file in this directory
|
|
1038
|
+
|
|
1039
|
+
# Solution: This is working as intended!
|
|
1040
|
+
# Only the explicitly added file is accessible
|
|
1041
|
+
# To allow access to other files, add them as separate context paths:
|
|
1042
|
+
context_paths:
|
|
1043
|
+
- path: "/project/config.yaml"
|
|
1044
|
+
permission: "read"
|
|
1045
|
+
- path: "/project/secrets.yaml" # Add explicitly if needed
|
|
1046
|
+
permission: "read"
|
|
1047
|
+
|
|
1048
|
+
# Or add the entire directory instead:
|
|
1049
|
+
context_paths:
|
|
1050
|
+
- path: "/project"
|
|
1051
|
+
permission: "read"
|
|
1052
|
+
```
|
|
1053
|
+
|
|
1054
|
+
#### Delivery Confusion
|
|
1055
|
+
```bash
|
|
1056
|
+
# Problem: Files created in workspace but not delivered
|
|
1057
|
+
Files created:
|
|
1058
|
+
- .massgen/workspaces/workspace1/app.js # ❌ Not delivered
|
|
1059
|
+
|
|
1060
|
+
# Solution: Agent must copy to context path
|
|
1061
|
+
Files delivered:
|
|
1062
|
+
- /path/to/project/app.js # ✅ Delivered to target
|
|
1063
|
+
```
|
|
1064
|
+
|
|
1065
|
+
## Related Documentation
|
|
1066
|
+
|
|
1067
|
+
- **Multi-Turn Design**: `docs/dev_notes/multi_turn_filesystem_design.md` - Detailed architecture for session persistence and turn-based workflows
|
|
1068
|
+
- **MCP Integration**: `docs/dev_notes/gemini_filesystem_mcp_design.md` - How filesystem access works through Model Context Protocol
|
|
1069
|
+
- **Context Sharing**: `docs/dev_notes/v0.0.14-context.md` - Original context sharing design
|
|
1070
|
+
- **User Context Paths**: `docs/case_studies/user-context-path-support-with-copy-mcp.md` - Case study on adding user-specified paths
|
|
1071
|
+
- **Claude Code Workspace**: `docs/case_studies/claude-code-workspace-management.md` - Native filesystem integration patterns
|
|
1072
|
+
|
|
1073
|
+
## Conclusion
|
|
1074
|
+
|
|
1075
|
+
MassGen's permissions system provides secure, granular access control for multi-agent workflows while maintaining simplicity for backend implementers. The system automatically handles the complexity of permission validation while allowing backends to focus on their core functionality.
|
|
1076
|
+
|
|
1077
|
+
**Key Features:**
|
|
1078
|
+
- ✅ **File and directory context paths**: Share individual files or entire directories
|
|
1079
|
+
- ✅ **Sibling file isolation**: File context paths prevent access to other files in the same directory
|
|
1080
|
+
- ✅ **Protected paths**: Mark specific files/directories as immune from modification
|
|
1081
|
+
- ✅ **Interactive configuration**: Add context paths without editing YAML files
|
|
1082
|
+
- ✅ **Automatic path validation**: Prevents common misconfigurations
|
|
1083
|
+
- ✅ **MCP integration**: Works seamlessly with MCP filesystem servers
|
|
1084
|
+
|
|
1085
|
+
For new backends, simply extend `LLMBackend`, declare your filesystem support level, and the base class handles the rest. The system scales from simple file access to complex multi-project workflows with cross-drive support and granular file-level permissions.
|