Watch the raw/ directory for new documents and process them automatically.
(ctx)
| 1830 | @cli.command() |
| 1831 | @click.pass_context |
| 1832 | def watch(ctx): |
| 1833 | """Watch the raw/ directory for new documents and process them automatically.""" |
| 1834 | kb_dir = _find_kb_dir(ctx.obj.get("kb_dir_override")) |
| 1835 | if kb_dir is None: |
| 1836 | click.echo("No knowledge base found. Run `openkb init` first.") |
| 1837 | return |
| 1838 | |
| 1839 | from openkb.watcher import watch_directory |
| 1840 | |
| 1841 | raw_dir = kb_dir / "raw" |
| 1842 | raw_dir.mkdir(exist_ok=True) |
| 1843 | |
| 1844 | def on_new_files(paths): |
| 1845 | for p in paths: |
| 1846 | fp = Path(p) |
| 1847 | if fp.suffix.lower() not in SUPPORTED_EXTENSIONS: |
| 1848 | click.echo( |
| 1849 | f"Skipping unsupported file type: {fp.suffix}. " |
| 1850 | f"Supported: {', '.join(sorted(SUPPORTED_EXTENSIONS))}" |
| 1851 | ) |
| 1852 | continue |
| 1853 | add_single_file(fp, kb_dir) |
| 1854 | |
| 1855 | click.echo(f"Watching {raw_dir} for new documents. Press Ctrl+C to stop.") |
| 1856 | watch_directory(raw_dir, on_new_files) |
| 1857 | |
| 1858 | |
| 1859 | async def run_lint(kb_dir: Path) -> Path | None: |
nothing calls this directly
no test coverage detected