mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-07-09 17:08:29 +00:00
Load active-project AGENTS.md path-chain guidance into the protocol area without duplicating the project root instructions. Move the AGENTS.md protocol wording into a prompt template, reuse existing file/path helpers, and cover direct-path discovery plus prompt assembly with focused tests.
7 KiB
7 KiB
projects.py DOX
Purpose
- Own the
projects.pyhelper module. - This module owns project metadata, workspace creation, Git status, and project-scoped settings including per-project MCP server config.
- Keep this file-level DOX profile synchronized with
projects.pybecause this directory is intentionally flat.
Ownership
projects.pyowns the runtime implementation.projects.py.dox.mdowns durable notes about responsibilities, contracts, side effects, and verification for that implementation.- Classes:
FileStructureInjectionSettings(TypedDict)SubAgentSettings(TypedDict)BasicProjectData(TypedDict)GitStatusData(TypedDict)EditProjectData(BasicProjectData)- Top-level functions:
get_projects_parent_folder()get_project_folder(name: str)get_project_meta(name: str, *sub_dirs)validate_project_name(name: str | None) -> strdelete_project(name: str)create_project(name: str, data: BasicProjectData)clone_git_project(name: str, git_url: str, git_token: str, data: BasicProjectData): Clone a git repository as a new A0 project. Token is used only for cloning via http header.load_project_header(name: str)_default_file_structure_settings()_normalizeBasicData(data: BasicProjectData) -> BasicProjectData_normalizeEditData(data: EditProjectData) -> EditProjectData_edit_data_to_basic_data(data: EditProjectData)_basic_data_to_edit_data(data: BasicProjectData) -> EditProjectDataupdate_project(name: str, data: EditProjectData)load_basic_project_data(name: str) -> BasicProjectDataload_edit_project_data(name: str) -> EditProjectDatasave_project_header(name: str, data: BasicProjectData)load_project_extended_data(name: str) -> ProjectExtendedDatasave_project_extended_data(name: str, project_data: ProjectExtendedData)_project_extended_data_for_save(data: object) -> ProjectExtendedData_merge_project_extended_data(data: EditProjectData, extended_data: object) -> Noneload_project_mcp_servers(name: str) -> strsave_project_mcp_servers(name: str, mcp_servers: str)get_active_projects_list()_get_projects_list(parent_dir)activate_project(context_id: str, name: str, mark_dirty: bool=...)deactivate_project(context_id: str, mark_dirty: bool=...)reactivate_project_in_chats(name: str)deactivate_project_in_chats(name: str)build_system_prompt_vars(name: str)get_agents_md_chain(root: str, target: str) -> list[tuple[str, str]]build_agents_md_protocol(name: str, target: str | None=...) -> strget_additional_instructions_files(name: str)get_project_instruction_files(name: str, include_agents_md: bool=...) -> list[tuple[str, str]]get_project_agents_md_instruction_file(name: str) -> tuple[str, str] | None_format_project_instruction_files(instruction_files: list[tuple[str, str]]) -> str_normalize_include_agents_md(value: object) -> bool- Notable constants/configuration names:
PROJECTS_PARENT_DIR,PROJECT_META_DIR,PROJECT_INSTRUCTIONS_DIR,PROJECT_KNOWLEDGE_DIR,PROJECT_SKILLS_DIR,PROJECT_HEADER_FILE,PROJECT_MCP_SERVERS_FILE,PROJECT_AGENTS_MD_FILES,DEFAULT_MCP_SERVERS_CONFIG,CONTEXT_DATA_KEY_PROJECT.
Runtime Contracts
- Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.
- Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.
- Per-project MCP server configuration is persisted as
.a0proj/mcp_servers.json, exposed throughload_edit_project_data(...), and saved during project create/clone/update flows. - Additional project-edit payload sections are delegated through extensible
load_project_extended_data(...)andsave_project_extended_data(...); the project helper must stay storage-agnostic and plugin-specific config rules belong to the owning plugin. - Project extension data may add named top-level sections such as
llm, but it must not overwrite core project fields owned byEditProjectData. - Project extension save payloads exclude core project fields and transient inputs such as
git_token; plugins needing core metadata should load it by project name. - Project metadata setup creates and repairs
.a0proj/instructions,.a0proj/knowledge, and.a0proj/skillsso settings surfaces can open those folders consistently. - AGENTS.md discovery is a linear root-to-target chain walk with
AGENTS.override.mdprecedence; sibling directories are not scanned. - Active-project AGENTS.md protocol guidance excludes the exact project root AGENTS.md because
build_system_prompt_vars(...)already loads it into project instructions; prose for that protocol block lives inprompts/agent.protocol.projects.agents_md.md. - Project MCP config uses the same JSON string shape as global MCP settings: an object with
mcpServers. - Project MCP load/save paths validate project names as simple folder basenames before touching
.a0proj/mcp_servers.json. - Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion, plugin state, settings/state persistence, secret handling.
- Imported dependency areas include:
helpers,helpers.print_style,os,typing.
Key Concepts
- Important called helpers/classes observed in the source:
files.get_abs_path,files.delete_dir,deactivate_project_in_chats,files.create_dir_safe,create_project_meta_folders,_normalizeBasicData,save_project_header,save_project_mcp_servers,load_project_mcp_servers,save_project_extended_data,load_project_extended_data,_project_extended_data_for_save,_merge_project_extended_data,_PROJECT_CORE_EDIT_KEYS,_PROJECT_TRANSIENT_INPUT_KEYS,extension.extensible,files.basename,dirty_json.parse,FileStructureInjectionSettings,cast,_normalizeEditData,load_edit_project_data,_edit_data_to_basic_data,save_project_variables,save_project_secrets,save_project_subagents,reactivate_project_in_chats,load_basic_project_data. - Keep request/response, tool, or helper semantics documented here at the same time as source changes.
Work Guidance
- Preserve public helper APIs used by core code and plugins unless every caller is updated.
- Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded.
- Prefer adding cohesive helper functions here only when behavior is reused across modules.
Verification
- Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers.
- Related tests observed by source search:
tests/test_model_config_project_presets.pytests/test_office_document_store.pytests/test_plugin_activation_ui.pytests/test_projects.pytests/test_skills_runtime.pytests/test_task_scheduler_timezone.pytests/test_time_travel.pytests/test_tool_action_contracts.py
Child DOX Index
No child DOX files.