Skip to content

nao sync: clean up stale template files (per-file cleanup) #1193

Description

@ad4mou

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.mdquery_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_pagesunlink), just never generalized to database table folders.

Expected behavior

  • After syncing a table, remove template-managed files in its folder that are no longer configured.
  • Cover the Refactor templates naming #1043 rename: legacy how_to_use.md and description.md are removed on sync.
  • Never delete annotations.md (manual notes) or any non-template / user-authored file.
  • Never delete files for templates still configured but skipped this run (e.g. profiling.md under a once/interval refresh policy).
  • Respect the existing --select guard (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 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions