Skip to content

API Reference parrot_tools.lsp.toolkit

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.lsp.toolkit

View source

Hash-verified navigation and checkpoint-diagnostic tools (FEAT-580, M3).

:class:LSPToolkit is the agent-facing surface of the LSP research pilot. It exposes exactly four public tools: the navigation methods lsp_definition/lsp_references, and the checkpoint-diagnostics methods lsp_diagnostics/lsp_diagnostic_delta with their bounded, in-memory :class:~parrot_tools.lsp.models.DiagnosticSnapshot baseline store (eight-entry LRU, 30-minute TTL).

Construction never spawns a process, opens a file, or probes an executable — :meth:LSPToolkit.__init__ only validates the trusted :class:~parrot_tools.lsp.models.LSPConfig. Every semantic call:

  1. Special-cases the environment_id="operator-unconfigured" sentinel before touching anything else.
  2. Validates the request shape via :class:~parrot_tools.lsp.models.SourcePosition.
  3. Captures a bounded "before" workspace snapshot (:func:parrot_tools.lsp.snapshot.capture_workspace), verifies the caller's expected_sha256 against the exact on-disk content, and restarts the owned :class:~parrot_tools.lsp.session.PyrightSession whenever the workspace/config digest has changed since it was last started.
  4. Issues the allowlisted request, normalizes Location/LocationLink results into bounded, confined :class:~parrot_tools.lsp.models.LSPLocation entries (dropping anything outside repo_root or not Python source/stub, with an explicit omission count).
  5. Captures an "after" snapshot; a changed digest discards the response as workspace_changed rather than serving stale cross-file evidence.

The checkpoint-diagnostics methods share the same session/lifecycle paths (operation lock, session acquisition/restart, before/after snapshot verification) instead of owning a second session. lsp_diagnostics retains a complete raw diagnostic set as a new baseline only when the underlying :class:~parrot_tools.lsp.session.PyrightSession.diagnostics publication was complete; lsp_diagnostic_delta compares two complete sets by (path, source, code, severity, full_message) multiset keys — excluding ranges, so a pure line shift never looks like a fix plus a new error — and always retains the current complete set as a fresh baseline. A baseline is rejected explicitly (never silently treated as clean) when it is missing, expired, scope-mismatched, or was captured under a different environment/config/server identity; a source-only restart (unchanged identity) is not incompatible.

Every :class:~parrot_tools.lsp.models.LSPFailure raised by the snapshot/session layers is converted into a typed :class:~parrot_tools.lsp.models.LSPResult here — nothing escapes a public method as a raw exception except asyncio.CancelledError, which is always propagated after the per-instance operation lock has been released (via the enclosing async with/finally blocks).

Class LSPToolkit

Optional Python semantic evidence for saved worktree files.

Owns exactly one lazy :class:~parrot_tools.lsp.session.PyrightSession, bound permanently to one canonical repo_root. auto_open=False: each public method validates input first, then acquires the session itself so server errors return in the typed :class:LSPResult envelope instead of escaping the framework's _ensure_open() pre-method hook.

Parameter Type Default Description
config LSPConfig | dict[str, Any] A trusted, already-validated :class:LSPConfig, or a plain mapping of the same fields (constructed here — this still performs pure, in-memory validation only).
**kwargs Any {} Forwarded to :class:AbstractToolkit.

Method LSPToolkit.lsp_definition

Resolve a verified expression; return bounded locations or an explicit failure.

lsp_definition(path: str, line: int, column: int, expected_sha256: str) -> LSPResult

Parameter Type Default Description
path str
line int
column int
expected_sha256 str

Returns: LSPResult

Method LSPToolkit.lsp_references

Find static references; limit is 1-200 and truncation is explicit.

lsp_references(path: str, line: int, column: int, expected_sha256: str, include_declaration: bool = False, limit: int = 50) -> LSPResult

Parameter Type Default Description
path str
line int
column int
expected_sha256 str
include_declaration bool False
limit int 50

Returns: LSPResult

Method LSPToolkit.lsp_diagnostics

Analyze 1-20 saved Python files and retain a complete baseline when possible.

lsp_diagnostics(paths: list[str]) -> LSPResult

Parameter Type Default Description
paths list[str]

Returns: LSPResult

Method LSPToolkit.lsp_diagnostic_delta

Compare the same file set after saved edits; unknown coverage never means clean.

lsp_diagnostic_delta(baseline_id: str, paths: list[str]) -> LSPResult

Parameter Type Default Description
baseline_id str
paths list[str]

Returns: LSPResult

Method LSPToolkit.cleanup

Await :meth:_close; idempotent, safe to call repeatedly.

The local MCP factory (FEAT-580 M4) only calls _close() when _opened was set by _ensure_open() — which never happens for this toolkit since auto_open=False. cleanup() is the lifecycle hook that unconditionally runs on shutdown, so it is the one that must actually release the owned Pyright process.

cleanup() -> None

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally