Files
kevinveenbirkenbachandClaude Opus 5.5 326f063bd3 fix(codescan): clear the mechanical CodeQL notes and lint them away (WIP)
Work-in-progress commit on the collective code-scanning sidetree, so main
can be merged in; the single quality-high gate runs on the integration
branch before the pull request.

Fixes the CodeQL notes py/import-and-import-from, py/unused-import,
py/unused-global-variable, py/empty-except, py/mixed-tuple-returns and
py/unused-local-variable across 194 files, and adds one lint per rule under
tests/lint/repository/python/ so none of them can come back:
test_import_and_import_from, test_unused_imports_hidden_from_ruff,
test_unused_global_variables, test_empty_except, test_mixed_tuple_returns,
test_unused_local_variables, plus test_modules_import.

Accepted security finding: MEDUSA-MP-SCAN-2056 (low) on
utils/i18n/client.py:21, an import line matched by a keyword heuristic;
operator-confirmed false positive.

🎯 Fix: 85 %
💥 Break: 8 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 78
🚦 Gate: ⛔ fix 85 % < 90, break 8 % > 5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 18:44:29 +00:00

130 lines
3.1 KiB
Python

"""Interactive REPL that forwards each input line to ``python -m cli`` on the host.
Ctrl+C only cancels the current input; the console exits on ``exit``/``quit`` or EOF (Ctrl+D).
Ctrl+Shift+C is intercepted by the terminal emulator (copy shortcut) and never reaches the app.
The prompt tracks a category stack: typing a bare category name cd's into it,
``..`` walks one level up, ``/`` returns to root, path tokens with ``/`` or
``..`` navigate, ``infinito [path]`` jumps absolute, ``ls`` lists the current
folder, everything else runs with the current path prepended.
"""
from __future__ import annotations
import contextlib
import importlib
import shlex
import sys
from .banner import print_banner as _print_banner
from .constants import (
AUTHOR,
AUTHOR_URL,
CLI_ROOT,
DOCS_URL,
EXIT_TOKENS,
HELP_ALIASES,
LICENSE_NAME,
LICENSE_URL,
LS_DESC_LIMIT,
LS_TOKEN,
PROMPT_PREFIX,
ROOT_NAV_TOKEN,
STRIPPABLE_PREFIXES,
WEB_URL,
)
from .ls import do_ls as _do_ls
from .navigation import (
is_category as _is_category,
)
from .navigation import (
is_navigation_token as _is_navigation_token,
)
from .navigation import (
normalize as _normalize,
)
from .navigation import (
prompt as _prompt,
)
from .navigation import (
resolve_argv as _resolve_argv,
)
from .navigation import (
resolve_cd as _resolve_cd,
)
from .runner import (
run_cli as _run_cli,
)
with contextlib.suppress(ImportError):
importlib.import_module("readline")
__all__ = [
"AUTHOR",
"AUTHOR_URL",
"CLI_ROOT",
"DOCS_URL",
"EXIT_TOKENS",
"HELP_ALIASES",
"LICENSE_NAME",
"LICENSE_URL",
"LS_DESC_LIMIT",
"LS_TOKEN",
"PROMPT_PREFIX",
"ROOT_NAV_TOKEN",
"STRIPPABLE_PREFIXES",
"WEB_URL",
"main",
]
def main() -> int:
_print_banner()
current: list[str] = []
while True:
try:
line = input(_prompt(current))
except KeyboardInterrupt:
print()
continue
except EOFError:
print()
return 0
stripped = line.strip()
if not stripped:
continue
if stripped in EXIT_TOKENS:
return 0
try:
argv = shlex.split(stripped)
except ValueError as exc:
print(f"console: parse error: {exc}", file=sys.stderr)
continue
head = argv[0]
if head == LS_TOKEN and len(argv) == 1:
_do_ls(current)
continue
if head == ROOT_NAV_TOKEN:
target = "/" + "/".join(argv[1:]) if len(argv) > 1 else "/"
resolved = _resolve_cd(current, target)
if resolved is not None:
current = resolved
continue
if len(argv) == 1 and _is_navigation_token(head):
resolved = _resolve_cd(current, head)
if resolved is not None:
current = resolved
continue
if len(argv) == 1 and _is_category([*current, head]):
current.append(head)
continue
_run_cli(_resolve_argv(current, _normalize(argv)), current=current)
if __name__ == "__main__":
raise SystemExit(main())