Problem
nao sync currently cleans stale databases, paths (schema/table dirs), and repos — but only at the directory level (cleanup_stale_paths in cli/nao_core/commands/sync/cleanup.py uses shutil.rmtree on whole folders).
If a user changes nao_config.yaml to remove a template (e.g. drops preview), the now-stale preview.md is left behind, because the table folder itself still exists. Cleanup only kicks in when an entire schema/table becomes stale.
This is especially relevant to #1043, which renames templates (how_to_use.md → query_history.md, and removes description.md). On every existing user's next sync, those old files will linger as orphans alongside the new ones — confusing, and they'll be picked up as context by the agent.
Note: per-file cleanup already exists for the Notion provider (cleanup_stale_pages → unlink), just never generalized to database table folders.
Expected behavior
Suggested approach
Delete only files whose name is a known template output (current and legacy: columns.md, query_history.md, preview.md, profiling.md, ai_summary.md, plus legacy how_to_use.md, description.md) that is not in the table's currently-expected set. This removes de-selected/renamed templates, leaves annotations.md and custom files untouched, keeps skipped-but-configured files, and needs no dependency on markers (#1042). Implement in cleanup.py, called from the same post-sync spot as cleanup_stale_paths.
Related
Problem
nao synccurrently cleans stale databases, paths (schema/table dirs), and repos — but only at the directory level (cleanup_stale_pathsincli/nao_core/commands/sync/cleanup.pyusesshutil.rmtreeon whole folders).If a user changes
nao_config.yamlto remove a template (e.g. dropspreview), the now-stalepreview.mdis left behind, because the table folder itself still exists. Cleanup only kicks in when an entire schema/table becomes stale.This is especially relevant to #1043, which renames templates (
how_to_use.md→query_history.md, and removesdescription.md). On every existing user's next sync, those old files will linger as orphans alongside the new ones — confusing, and they'll be picked up as context by the agent.Note: per-file cleanup already exists for the Notion provider (
cleanup_stale_pages→unlink), just never generalized to database table folders.Expected behavior
how_to_use.mdanddescription.mdare removed on sync.annotations.md(manual notes) or any non-template / user-authored file.profiling.mdunder aonce/intervalrefresh policy).--selectguard (skip cleanup during partial syncs).Suggested approach
Delete only files whose name is a known template output (current and legacy:
columns.md,query_history.md,preview.md,profiling.md,ai_summary.md, plus legacyhow_to_use.md,description.md) that is not in the table's currently-expected set. This removes de-selected/renamed templates, leavesannotations.mdand custom files untouched, keeps skipped-but-configured files, and needs no dependency on markers (#1042). Implement incleanup.py, called from the same post-sync spot ascleanup_stale_paths.Related