@@ -525,18 +525,12 @@ def on_new_files(paths):
525525 watch_directory (raw_dir , on_new_files )
526526
527527
528- @cli .command ()
529- @click .option ("--fix" , is_flag = True , default = False , help = "Automatically fix lint issues (not yet implemented)." )
530- @click .pass_context
531- def lint (ctx , fix ):
532- """Lint the knowledge base for structural and semantic inconsistencies."""
533- if fix :
534- click .echo ("Warning: --fix is not yet implemented. Running lint in report-only mode." )
535- kb_dir = _find_kb_dir (ctx .obj .get ("kb_dir_override" ))
536- if kb_dir is None :
537- click .echo ("No knowledge base found. Run `openkb init` first." )
538- return
528+ async def run_lint (kb_dir : Path ) -> Path :
529+ """Run structural + knowledge lint, write report, return report path.
539530
531+ Async because knowledge lint uses an LLM agent. Usable from CLI
532+ (via ``asyncio.run``) and directly from the chat REPL.
533+ """
540534 from openkb .lint import run_structural_lint
541535 from openkb .agent .linter import run_knowledge_lint
542536
@@ -545,15 +539,13 @@ def lint(ctx, fix):
545539 _setup_llm_key (kb_dir )
546540 model : str = config .get ("model" , DEFAULT_CONFIG ["model" ])
547541
548- # Structural lint
549542 click .echo ("Running structural lint..." )
550543 structural_report = run_structural_lint (kb_dir )
551544 click .echo (structural_report )
552545
553- # Knowledge lint (semantic)
554546 click .echo ("Running knowledge lint..." )
555547 try :
556- knowledge_report = asyncio . run ( run_knowledge_lint (kb_dir , model ) )
548+ knowledge_report = await run_knowledge_lint (kb_dir , model )
557549 except Exception as exc :
558550 knowledge_report = f"Knowledge lint failed: { exc } "
559551 click .echo (knowledge_report )
@@ -568,17 +560,25 @@ def lint(ctx, fix):
568560 report_path .write_text (report_content , encoding = "utf-8" )
569561 append_log (kb_dir / "wiki" , "lint" , f"report → { report_path .name } " )
570562 click .echo (f"\n Report written to { report_path } " )
563+ return report_path
571564
572565
573- @cli .command (name = "list" )
566+ @cli .command ()
567+ @click .option ("--fix" , is_flag = True , default = False , help = "Automatically fix lint issues (not yet implemented)." )
574568@click .pass_context
575- def list_cmd (ctx ):
576- """List all documents in the knowledge base."""
569+ def lint (ctx , fix ):
570+ """Lint the knowledge base for structural and semantic inconsistencies."""
571+ if fix :
572+ click .echo ("Warning: --fix is not yet implemented. Running lint in report-only mode." )
577573 kb_dir = _find_kb_dir (ctx .obj .get ("kb_dir_override" ))
578574 if kb_dir is None :
579575 click .echo ("No knowledge base found. Run `openkb init` first." )
580576 return
577+ asyncio .run (run_lint (kb_dir ))
578+
581579
580+ def print_list (kb_dir : Path ) -> None :
581+ """Print all documents in the knowledge base. Usable from CLI and chat REPL."""
582582 openkb_dir = kb_dir / ".openkb"
583583 hashes_file = openkb_dir / "hashes.json"
584584 if not hashes_file .exists ():
@@ -631,15 +631,19 @@ def list_cmd(ctx):
631631 click .echo (f" - { r } " )
632632
633633
634- @cli .command ()
634+ @cli .command (name = "list" )
635635@click .pass_context
636- def status (ctx ):
637- """Show the current status of the knowledge base."""
636+ def list_cmd (ctx ):
637+ """List all documents in the knowledge base."""
638638 kb_dir = _find_kb_dir (ctx .obj .get ("kb_dir_override" ))
639639 if kb_dir is None :
640640 click .echo ("No knowledge base found. Run `openkb init` first." )
641641 return
642+ print_list (kb_dir )
642643
644+
645+ def print_status (kb_dir : Path ) -> None :
646+ """Print knowledge base status. Usable from CLI and chat REPL."""
643647 wiki_dir = kb_dir / "wiki"
644648 subdirs = ["sources" , "summaries" , "concepts" , "reports" ]
645649
@@ -687,3 +691,14 @@ def status(ctx):
687691 import datetime
688692 mtime = datetime .datetime .fromtimestamp (newest_report .stat ().st_mtime )
689693 click .echo (f" Last lint: { mtime .strftime ('%Y-%m-%d %H:%M:%S' )} " )
694+
695+
696+ @cli .command ()
697+ @click .pass_context
698+ def status (ctx ):
699+ """Show the current status of the knowledge base."""
700+ kb_dir = _find_kb_dir (ctx .obj .get ("kb_dir_override" ))
701+ if kb_dir is None :
702+ click .echo ("No knowledge base found. Run `openkb init` first." )
703+ return
704+ print_status (kb_dir )
0 commit comments