Agent Zero AI framework
Use 4-space indented tree in workdir EXTRAS
linklitib9ecb61a5c9a
diff --git a/extensions/python/message_loop_prompts_after/_75_include_workdir_extras.py b/extensions/python/message_loop_prompts_after/_75_include_workdir_extras.pyindex a6b5cf10b..f62aadf10 100644--- a/extensions/python/message_loop_prompts_after/_75_include_workdir_extras.py+++ b/extensions/python/message_loop_prompts_after/_75_include_workdir_extras.py@@ -36,7 +36,10 @@ class IncludeWorkdirExtras(Extension):if runtime.is_development():folder = files.normalize_a0_path(folder)- file_structure = projects.get_file_structure(project_name)+ file_structure = projects.get_file_structure(+ project_name,+ output_mode=file_tree.OUTPUT_MODE_INDENT,+ )else:set = settings.get_settings_for_prompt()enabled = bool(set["workdir_show"])@@ -63,7 +66,7 @@ class IncludeWorkdirExtras(Extension):max_folders=max_folders,max_lines=max_lines,ignore=gitignore_raw,- output_mode=file_tree.OUTPUT_MODE_STRING,+ output_mode=file_tree.OUTPUT_MODE_INDENT,))diff --git a/helpers/file_tree.py b/helpers/file_tree.pyindex dda866c0b..51a860cd4 100644--- a/helpers/file_tree.py+++ b/helpers/file_tree.py@@ -21,6 +21,7 @@ SORT_DESC = "desc"OUTPUT_MODE_STRING = "string"OUTPUT_MODE_FLAT = "flat"OUTPUT_MODE_NESTED = "nested"+OUTPUT_MODE_INDENT = "indent"def _from_timestamp(timestamp: float) -> datetime:@@ -37,7 +38,7 @@ def file_tree(max_files: int = 0,sort: tuple[Literal["name", "created", "modified"], Literal["asc", "desc"]] = ("modified", "desc"),ignore: str | None = None,- output_mode: Literal["string", "flat", "nested"] = OUTPUT_MODE_STRING,+ output_mode: Literal["string", "flat", "nested", "indent"] = OUTPUT_MODE_STRING,) -> str | list[dict]:"""Render a directory tree relative to the repository base path.@@ -101,7 +102,7 @@ def file_tree(raise ValueError(f"Unsupported sort key: {sort_key!r}")if sort_direction not in {SORT_ASC, SORT_DESC}:raise ValueError(f"Unsupported sort direction: {sort_direction!r}")- if output_mode not in {OUTPUT_MODE_STRING, OUTPUT_MODE_FLAT, OUTPUT_MODE_NESTED}:+ if output_mode not in {OUTPUT_MODE_STRING, OUTPUT_MODE_FLAT, OUTPUT_MODE_NESTED, OUTPUT_MODE_INDENT}:raise ValueError(f"Unsupported output mode: {output_mode!r}")if max_depth < 0:raise ValueError("max_depth must be >= 0")@@ -257,6 +258,14 @@ def file_tree(lines.append(node.text)return "\n".join(lines)+ if output_mode == OUTPUT_MODE_INDENT:+ display_name = output_root+ root_line = f"{display_name.rstrip(os.sep)}/"+ lines = [root_line]+ for node in iter_visible():+ lines.append(_format_indent_line(node))+ return "\n".join(lines)+if output_mode == OUTPUT_MODE_FLAT:return [make_root_item(None)] + _build_tree_items_flat(list(iter_visible()))@@ -635,6 +644,16 @@ def _format_line(node: _TreeEntry) -> str:return "".join(segments) + connector + label+def _format_indent_line(node: _TreeEntry) -> str:+ """Render one tree entry as a 4-space-indented line (compact token form)."""+ indent = " " * max(node.level - 1, 0)+ if node.item_type == "folder":+ return f"{indent}{node.name}/"+ if node.item_type == "comment":+ return f"{indent}# {node.name}"+ return f"{indent}{node.name}"++def _build_tree_items_flat(items: Sequence[_TreeEntry]) -> list[dict]:return [{diff --git a/helpers/file_tree.py.dox.md b/helpers/file_tree.py.dox.mdindex db3625d70..8a01988b7 100644--- a/helpers/file_tree.py.dox.md+++ b/helpers/file_tree.py.dox.md@@ -15,7 +15,7 @@- `as_dict(self) -> dict[str, Any]`- Top-level functions:- `_from_timestamp(timestamp: float) -> datetime`-- `file_tree(relative_path: str, max_depth: int=..., max_lines: int=..., folders_first: bool=..., max_folders: int=..., max_files: int=..., sort: tuple[Literal['name', 'created', 'modified'], Literal['asc', 'desc']]=..., ignore: str | None=..., output_mode: Literal['string', 'flat', 'nested']=...) -> str | list[dict]`: Render a directory tree relative to the repository base path.+- `file_tree(relative_path: str, max_depth: int=..., max_lines: int=..., folders_first: bool=..., max_folders: int=..., max_files: int=..., sort: tuple[Literal['name', 'created', 'modified'], Literal['asc', 'desc']]=..., ignore: str | None=..., output_mode: Literal['string', 'flat', 'nested', 'indent']=...) -> str | list[dict]`: Render a directory tree relative to the repository base path.- `_normalize_relative_path(path: str) -> str`- `_directory_has_visible_entries(directory: str, root_abs_path: str, ignore_spec: PathSpec, cache: dict[str, bool], max_depth_remaining: int) -> bool`- `_create_summary_comment(parent: _TreeEntry, noun: str, count: int) -> _TreeEntry`@@ -31,7 +31,7 @@- `_build_tree_items_flat(items: Sequence[_TreeEntry]) -> list[dict]`- `_to_nested_structure(items: Sequence[_TreeEntry]) -> list[dict]`- `_iter_depth_first(items: Sequence[_TreeEntry]) -> Iterable[_TreeEntry]`-- Notable constants/configuration names: `SORT_BY_NAME`, `SORT_BY_CREATED`, `SORT_BY_MODIFIED`, `SORT_ASC`, `SORT_DESC`, `OUTPUT_MODE_STRING`, `OUTPUT_MODE_FLAT`, `OUTPUT_MODE_NESTED`.+- Notable constants/configuration names: `SORT_BY_NAME`, `SORT_BY_CREATED`, `SORT_BY_MODIFIED`, `SORT_ASC`, `SORT_DESC`, `OUTPUT_MODE_STRING`, `OUTPUT_MODE_FLAT`, `OUTPUT_MODE_NESTED`, `OUTPUT_MODE_INDENT`.## Runtime Contractsdiff --git a/helpers/projects.py b/helpers/projects.pyindex 11f407952..9f6a7000b 100644--- a/helpers/projects.py+++ b/helpers/projects.py@@ -788,7 +788,11 @@ def get_knowledge_files_count(name: str):)return len(files.list_files_in_dir_recursively(knowledge_folder))-def get_file_structure(name: str, basic_data: BasicProjectData|None=None) -> str:+def get_file_structure(+ name: str,+ basic_data: BasicProjectData|None=None,+ output_mode: str = file_tree.OUTPUT_MODE_STRING,+) -> str:project_folder = get_project_folder(name)if basic_data is None:basic_data = load_basic_project_data(name)@@ -800,7 +804,7 @@ def get_file_structure(name: str, basic_data: BasicProjectData|None=None) -> strmax_folders=basic_data["file_structure"]["max_folders"],max_lines=basic_data["file_structure"]["max_lines"],ignore=basic_data["file_structure"]["gitignore"],- output_mode=file_tree.OUTPUT_MODE_STRING+ output_mode=output_mode))# empty?diff --git a/helpers/projects.py.dox.md b/helpers/projects.py.dox.mdindex 4de0b9338..62b519f60 100644--- a/helpers/projects.py.dox.md+++ b/helpers/projects.py.dox.md@@ -41,6 +41,7 @@- `load_project_mcp_servers(name: str) -> str`- `save_project_mcp_servers(name: str, mcp_servers: str)`- `get_active_projects_list()`+- `get_file_structure(name: str, basic_data: BasicProjectData|None=None, output_mode: str = file_tree.OUTPUT_MODE_STRING) -> str`- `_get_projects_list(parent_dir)`- `reconcile_agent_profile(context: AgentContext, project_name: str | None) -> bool`- `reconcile_agent_profiles(project_name: str | None, *, all_scopes: bool=...) -> None`@@ -65,6 +66,7 @@## Runtime Contracts- Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.+- `get_file_structure(...)` delegates rendering to `helpers.file_tree.file_tree`; the default `OUTPUT_MODE_STRING` keeps user-facing surfaces (project structure API) box-drawn, while the workdir EXTRAS extension passes `OUTPUT_MODE_INDENT` for the token-compact agent-facing tree.- 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 through `load_edit_project_data(...)`, and saved during project create/clone/update flows.- Additional project-edit payload sections are delegated through extensible `load_project_extended_data(...)` and `save_project_extended_data(...)`; the project helper must stay storage-agnostic and plugin-specific config rules belong to the owning plugin.diff --git a/webui/components/projects/project-file-structure-test.html b/webui/components/projects/project-file-structure-test.htmlindex b39b0eb8b..13b76564f 100644--- a/webui/components/projects/project-file-structure-test.html+++ b/webui/components/projects/project-file-structure-test.html@@ -13,6 +13,7 @@<div><h3>File structure test - <span x-text="$store.projects.selectedProject.name"></span></h3>+ <div class="field-description">The agent receives this map in a token-compact 4-space indented form to save context; this preview shows the human-readable box-drawing variant.</div><pre x-text="$store.projects.fileStructureTestOutput"></pre></div>diff --git a/webui/components/settings/agent/workdir-file-structure-test.html b/webui/components/settings/agent/workdir-file-structure-test.htmlindex b07f9220c..b284341ab 100644--- a/webui/components/settings/agent/workdir-file-structure-test.html+++ b/webui/components/settings/agent/workdir-file-structure-test.html@@ -12,6 +12,7 @@<template x-if="$store.settings && $store.settings.settings"><div><h3>Workdir structure test - <span x-text="$store.settings.settings.workdir_path"></span></h3>+ <div class="field-description">The agent receives this map in a token-compact 4-space indented form to save context; this preview shows the human-readable box-drawing variant.</div><pre x-text="$store.settings.workdirFileStructureTestOutput"></pre></div></template>