feat(cli): default 'add' to raw/ with summary + cleanup, auto_delete_added_files config - #232
Conversation
eecc0bc to
680c04b
Compare
|
Rewrote this branch's history to remove unrelated commits. The branch had accidentally picked up commits from the (now-withdrawn, see Rebuilt cleanly from current |
0885647 to
153149c
Compare
…ption - New 'openkb add-all' command processes all files in raw/ directory - New config parameter 'auto_delete_added_files' (default: false) - When enabled, both 'add' and 'add-all' automatically delete successfully ingested files - Updated help texts to document the new cleanup behavior - Config applies to all ingest methods: direct files, directories, and URLs
Duplicates (skipped files) should also be auto-deleted when auto_delete_added_files is enabled, so raw/ stays clean. Only 'failed' status files are preserved to allow retries. Updated docstrings and helper function logic accordingly.
When auto_delete_added_files is enabled, the add-all command now recursively cleans up empty subdirectories in raw/ after file deletion. Directories are deleted from deepest to shallowest to ensure proper cleanup. Added summary output showing count of cleaned directories.
153149c to
a57bcd9
Compare
Note
This PR was created in collaboration between a human and AI: implementation, tests, and
PR text were created by an AI assistant under the guidance and review of the human author.
Problem
The
openkb addcommand supports adding directories recursively, but users who frequentlydownload documents to
raw/had to manually invokeopenkb add raw/and then manuallydelete processed files. There was no batch-processing shortcut for the
raw/stagingdirectory, no summary of the outcome, and no configuration option to auto-delete successfully
ingested files and duplicates.
An earlier version of this PR addressed this by adding a separate
openkb add-allcommand.On further review this duplicated almost the entire
adddirectory-processing code path(same file walk, same filtering, same per-file ingestion call). This PR now consolidates that
functionality directly into
addinstead of introducing a second, largely redundant command.Solution / Changes
openkb add(no changes for existing usage):add <path>behaves exactly as before for files, directories, and URLs.addwith no PATH argument (and no--from-pageindex-cloud) now defaults to theKB's
raw/directory, walks it recursively, and ingests all supported file types(PDF, Markdown, DOCX, PPTX, XLSX, XLS, HTML, TXT, CSV).
raw/or an explicit path),addnow prints anaggregated summary at the end:
Added: X, Skipped: Y, Failed: Z, Deleted: W.auto_delete_added_filesis enabled, now-empty subdirectories are cleaned up after adirectory run (in addition to per-file deletion, which already existed).
New configuration parameter:
auto_delete_added_files(boolean, default:false)addautomatically deletes files after processingraw/), and URLsImplementation:
_delete_if_auto_cleanup_enabled()helper function to handle cleanup logic_cleanup_empty_directories()for post-run empty-subdirectory cleanupadd-allcommand entirely (unreleased, no deprecation/alias needed)in favor of
addwith no PATH argumentadd's docstring to document the default-raw/, summary, and cleanup behaviorIssues