refresh_command.py

clew/refresh_command.py

`clew refresh` — bring an index current after an edit: fast in place when it can, full when not.

refresh_main

int clew.refresh_command.refresh_main(list[str] argv)

Refresh an index, fast tier first.

clew/refresh_command.py:35

Show on the map →

Called by _build, _build, _ensure_index, main, wiki_main

Tested by

1 teststest_a_fast_refresh_serves_the_edited_files_includes_as_a_full_build_does

Calls _build_argparser, _run_pipeline, target_for, try_fast_refresh

Source · 32 lines
def refresh_main(argv: list[str]) -> int:
    """THE FALLBACK IS THE ORDINARY BUILD, through the same `_run_pipeline` a plain `clew` runs,
    so a refused fast tier produces exactly the index a full build would — and that build drops
    any pending `fast.*` record, because it writes a fresh database.

    @brief Entry point for `clew refresh`.
    @return 0.
    @version 1
    """
    from .cli import _build_argparser, _run_pipeline
    from .fasttier import try_fast_refresh

    parser = argparse.ArgumentParser(
        prog=f"clew {REFRESH_COMMAND}",
        description="Refresh an index after an edit: in place when possible, else a full build.",
    )
    parser.add_argument("--repo-root", help="working tree (default: the current directory)")
    parser.add_argument("--output", help="index path (default: where a plain build writes it)")
    args = parser.parse_args(argv)
    repo = Path(args.repo_root).expanduser().resolve() if args.repo_root else Path.cwd().resolve()
    if args.output:
        output = Path(args.output).expanduser().resolve()
    else:
        from .mcp_server.state import target_for

        output = Path(target_for(repo).db_path)
    if try_fast_refresh(output, repo, output.with_name(output.name + ".idxcache")) is None:
        logger.info("refresh: running a full build")
        _run_pipeline(
            _build_argparser().parse_args(["--output", str(output), "--repo-root", str(repo)])
        )
    return 0

1 more lines, not shown

Activity · 16 steps
lines 44–44from .cli import _build_argparser, _run_pipelinelines 45–45from .fasttier import try_fast_refreshlines 47–50parser = argparse.ArgumentParser( prog=f"clew {REFRESH_COMMAND}", description="Refresh an index after an edit: in place when possible, else a full build.", )lines 51–51parser.add_argument("--repo-root", help="working tree (default: the current directory)")lines 52–52parser.add_argument("--output", help="index path (default: where a plain build writes it)")lines 53–53args = parser.parse_args(argv)lines 54–54repo = Path(args.repo_root).expanduser().resolve() if args.repo_root else Path.cwd().resolve()lines 55–55◇ if args.outputlines 56–56output = Path(args.output).expanduser().resolve()lines 57–57elselines 58–58from .mcp_server.state import target_forlines 60–60output = Path(target_for(repo).db_path)lines 61–61◇ if try_fast_refresh(output, repo, output.with_name(output.name + ".idxcache")) is Nonelines 62–62logger.info("refresh: running a full build")lines 63–65_run_pipeline( _build_argparser().parse_args(["--output", str(output), "--repo-root", str(repo)]) )lines 66–66return 0

Requirements

REQ-DDB-INDEX-006