Skip to content

feat(import): expose archive-backed import explain (#2178) - #2249

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/import-explain-closure-2178
Jun 20, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/import-explain-closure-2178

Conversation

@Sinity

@Sinity Sinity commented Jun 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Completes #2178 by making ImportExplain archive-backed and cross-surface: Polylogue.explain_import(...) can now explain already-observed raw evidence by raw_ref or source_path, MCP exposes the shared ImportExplainPayload, and the daemon exposes a shell-supported /api/import/explain route. The archive-backed path reads source.db raw/artifact evidence and index.db produced rows without re-reading raw payload bytes.

Problem

The first #2178 implementation was useful but incomplete: it explained local paths before import, while the issue also required a raw-ref/source-path read path for prior import evidence and explicit Python API/MCP/daemon treatment. That left ImportExplain narrowly true for CLI/API preflight but not broadly useful as an evidence-cockpit surface.

Solution

  • Added explain_import_archive(...) in polylogue/sources/import_explain.py to build ImportExplainPayload from existing source.db and index.db rows.
  • Extended Polylogue.explain_import(...) so callers can pass raw_ref or source_path for archive-backed explanations, while preserving the existing path preflight behavior.
  • Added MCP explain_import and classified it in the MCP envelope contract matrix as a typed report payload.
  • Added daemon route GET /api/import/explain with route-contract/OpenAPI metadata as shell_supported local import/source evidence inspection.
  • Redacts archive source paths by default (~/... for home paths, .../filename for other absolute paths) and omits raw bytes from every exposed payload.

Closure matrix for #2178:

  • Shared ImportExplainPayload: satisfied by the existing payloads and reused by CLI/API/MCP/daemon.
  • Representative provider/path explanation: satisfied by existing Codex path tests.
  • CLI JSON/NDJSON preflight: already landed and retained.
  • Raw-ref/source-path retrieval from archive evidence: satisfied by archive-backed source/index tests.
  • Python API/MCP/daemon surfaces: satisfied by Polylogue.explain_import, MCP explain_import, and /api/import/explain.
  • Generated schemas/docs: OpenAPI route contract regenerated; CLI output schema unchanged.
  • Failure/privacy coverage: existing malformed path/ZIP tests retained; archive-backed tests prove raw bytes are omitted and absolute paths are redacted.

Verification

  • devtools test tests/unit/api/test_facade_contracts.py::test_explain_import_reads_archived_raw_evidence tests/unit/api/test_facade_contracts.py::test_explain_import_redacts_non_home_absolute_archive_paths tests/unit/mcp/test_server_surfaces.py::TestArchiveGenericToolSurfaces::test_explain_import_reads_shared_facade_payload tests/unit/mcp/test_envelope_contracts.py::TestRegistryWideClassification::test_every_registered_tool_is_classified tests/unit/mcp/test_envelope_contracts.py::test_envelope_class_carries_required_fields tests/unit/daemon/test_web_reader.py::TestReaderSessionState::test_import_explain_route_reads_archived_raw_evidence -q — 16 passed.
  • devtools verify --quick — exit 0.
  • devtools verify — exit 0; 266 affected tests passed in 147.78s, peak pytest RSS 781.5 MiB.

Closes #2178

Summary by CodeRabbit

Release Notes

  • New Features
    • Added import explanation API endpoint and tool that displays detailed information about import sources, including metadata about artifacts, parsing status, validation results, and produced data rows.
    • Supports explaining both local and archived import evidence with optional path redaction for privacy.

Problem: #2178's landed baseline explained local import paths, but broad closure also required archived raw/source evidence retrieval plus explicit MCP and daemon/web treatment. That left the feature useful as a preflight, but not as an evidence-cockpit read surface.\n\nWhat changed: add archive-backed ImportExplain construction over source.db and index.db, extend the Python facade with raw_ref/source_path lookup, expose the shared payload through MCP and a shell-supported daemon route, classify the MCP tool contract, and regenerate OpenAPI route metadata. Archive-backed explanations omit raw bytes and redact absolute paths by default.\n\nVerification: devtools test focused ImportExplain/API/MCP/daemon nodes passed; devtools verify --quick passed; devtools verify passed with 266 affected tests.
@coderabbitai

coderabbitai Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds explain_import_archive to polylogue/sources/import_explain.py to query archived SQLite (source.db/index.db) evidence and construct ImportExplainPayload with path redaction. The API facade explain_import gains optional raw_ref/source_path/redact_paths parameters and routes to the new function. A new daemon HTTP endpoint GET /api/import/explain and MCP tool explain_import expose this capability, backed by route contract metadata and OpenAPI spec updates.

Changes

Archive-backed import explain feature

Layer / File(s) Summary
explain_import_archive core implementation
polylogue/sources/import_explain.py
Adds explain_import_archive with read-only SQLite helpers, raw/artifact row selection, per-entry ImportExplainEntryPayload construction (parse/validation/decode status, produced-row aggregation from sessions/messages/blocks/actions with index.db fallback), path redaction, raw ref normalization, and __all__ export update.
API facade expansion and daemon HTTP endpoint
polylogue/api/archive.py, polylogue/daemon/http.py, polylogue/daemon/route_contracts.py, docs/openapi/search.yaml
explain_import facade accepts optional raw_ref/source_path/redact_paths and branches to explain_import_archive; _handle_import_explain handler added with 400/503 validation, sync-bridge invocation, and exclude_none=True serialization; route registered in static GET table; route contract and OpenAPI entries added.
MCP explain_import tool
polylogue/mcp/server_tools.py
Registers explain_import MCP read tool with path/raw_ref/source_path/source_name/limit/redact_paths inputs, at-least-one-target validation, and facade delegation.
Tests across all surfaces
tests/unit/api/test_facade_contracts.py, tests/unit/daemon/test_web_reader.py, tests/unit/mcp/test_server_surfaces.py, tests/unit/mcp/test_envelope_contracts.py, tests/unit/daemon/test_route_contracts.py, tests/infra/mcp.py
Archive-seeding helpers and assertions for facade redaction, daemon HTTP smoke test for /api/import/explain, MCP surface invocation/payload shape test, envelope-contract matrix updated for ImportExplainPayload, route-contract metadata row, and infra mock aligned with new tool name.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Sinity/polylogue#2158: Shares the same table-driven daemon static GET route dispatch and test_route_contracts.py parameterization pattern that this PR extends with /api/import/explain.

Poem

🐇 Hopped into the archive depths below,
Where SQLite rows in source.db glow,
"raw_ref or source_path," the bunny declared,
"Absolute paths shall be redacted and spared!"
ImportExplainPayload returned with care,
MCP, daemon, façade — surfaces everywhere! 🗄️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: exposing an archive-backed import explain feature.
Description check ✅ Passed The description comprehensively covers all required sections: Summary, Problem, Solution, Verification, and includes context about Closure matrix and Risks in the Verification section.
Linked Issues check ✅ Passed The PR fulfills all key closure criteria from #2178: archive-backed explanations via raw_ref/source_path [polylogue/sources/import_explain.py], extended Python API [polylogue/api/archive.py], MCP surface [polylogue/mcp/server_tools.py], daemon route with metadata [polylogue/daemon/http.py, route_contracts.py], privacy coverage via path redaction and byte omission across all surfaces [multiple test files], and updated generated schemas/docs.
Out of Scope Changes check ✅ Passed All code changes are directly scoped to #2178 objectives: implementing archive-backed import explanations, extending surfaces (MCP/daemon/API), adding route contracts, and comprehensive test coverage without introducing tangential features.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/import-explain-closure-2178

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

github-actions Bot pushed a commit that referenced this pull request Jun 20, 2026
@Sinity
Sinity merged commit a818508 into master Jun 20, 2026
13 of 14 checks passed
@Sinity
Sinity deleted the feature/feat/import-explain-closure-2178 branch June 20, 2026 21:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b59701b8bb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/api/archive.py
)
if path is None:
raise ValueError("path is required unless raw_ref or source_path is provided")
return explain_import_path(Path(path), source_name=source_name, limit=limit)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor redaction for local import paths

When callers use the newly exposed MCP/daemon local-path mode with the default redact_paths=True (or omit no_redact on /api/import/explain), this branch ignores that setting and calls explain_import_path directly, which resolves and serializes absolute local paths into source_path and skipped rows. That violates the new route contract that paths are redacted unless explicitly requested and can leak server-local archive/source paths; either apply the same redaction to path-backed explanations or disallow path on the redacted surfaces.

Useful? React with 👍 / 👎.

@github-actions github-actions Bot mentioned this pull request Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(import): explain provider detection, parsing, and produced archive rows

1 participant