feat(cli): add profile switching, bulk-import with column mapping, and fix shell completions

IM
3mo ago
+4017-1968

Description

This PR introduces three major, high-impact improvements to the Moss CLI to enhance developer experience, streamline multi-project workflows, and fix a critical bug in the shell completions command.


1. πŸ› Fix Shell Completions Fall-through Bug

While running the CLI tests, I discovered that the command was failing with:
Shell completion is unavailable in this Typer installation.

Upon inspection of packages/moss-cli/src/moss_cli/commands/completions.py, I identified a fall-through bug in the exception handling block:

    except Exception:  # pragma: no cover
        try:
            from typer._completion_shared import get_completion_script  # type: ignore
        except Exception:  # pragma: no cover - depends on Typer installation
            output.print_error(
                "Shell completion is unavailable in this Typer installation.",
                json_mode,
            )
            raise typer.Exit(1)
        output.print_error(
            "Shell completion is unavailable in this Typer installation.",
            json_mode,
        )
        raise typer.Exit(1)

Even when the inner import from typer._completion_shared succeeded, the code fell through to print the error and exit non-zero.

  • Fix: Removed the duplicate error print/raise block at the end of the outer except block so that successful imports correctly proceed to script generation.
  • Result: All shell completion tests are now 100% green!

2. πŸ“ Profile Switching Commands (Closes #176, Closes #126)

Added subcommands to make switching between named credential profiles seamless and explicit without manually editing configuration files or relying on environment variables:

  • moss profile use <profile-name> (or moss profile set-default <profile-name>): Sets the active/default profile in the config.
  • moss profile current: Displays the currently selected profile (taking into account CLI flags and env vars).

3. πŸ“₯ Bulk-Import with Column Mapping (Closes #379)

Added a powerful bulk-loading command to import documents from arbitrary CSV, JSON, or JSONL files without writing code:

  • moss doc import <index_name> -f <file_path>
  • Supports column mapping via --id-column / -i and --text-column / -t to map arbitrary column/key names to document ID and text.
  • Automatically maps all other columns/keys to the document's metadata dictionary (satisfying the Dict[str, str] constraint of DocumentInfo by converting values to strings and serializing complex objects/lists to JSON strings).
  • Supports explicit metadata filtering selection via --metadata-columns / -m and toggling with --include-all-metadata / --no-include-all-metadata.

4. πŸ§ͺ Comprehensive Test Coverage

Added robust unit and integration tests in tests/test_profiles.py covering:

  • set_active_profile success and failure paths.
  • moss profile use, set-default, and current CLI commands.
  • CSV, JSON, and JSONL document parsers with arbitrary column mapping.
  • End-to-end integration test of moss doc import with mocked API client responses.

All 42 CLI tests are now fully passing!