Appendix

June 29, 2026 · View on GitHub

Compact lookup tables for agents: every ctx_refactor action, its HTTP endpoint, key parameters, backing — plus the user-facing IDE surfaces (Gain Tool Window, editor-focus reporter, status-bar widget, Tools-menu actions). Full description (curl, responses, guards, architecture, E2E): Journey 19 — JetBrains Plugin.

Language: English; tool/endpoint/parameter names and error codes stay verbatim. Serena delineation: an independent reimplementation (not a derivation, lean-ctx license) — it replaces Serena + the official JetBrains MCP as the code-intelligence interface.

Coordinates & invocation

  • Invocation: ctx_refactor action=<action> … (MCP) or POST 127.0.0.1:<port><endpoint> with header X-LeanCtx-Token: <token>, body = JSON.
  • ctx_refactor layer: line 1-indexed, column 0-indexed. Wire layer: line/character 0-based; line in type_hierarchy / symbols_overview / inspections responses is 1-based.
  • Business-level negative case: HTTP 200 + {"error":{"code","message"}}.

Functions

ActionHTTP endpointPurposeKey parametersBacking
referencesPOST /referencessemantic usagespath, line, column, scopeB (+A fallback)
definitionPOST /definitionjump to definitionpath, line, columnB (+A fallback)
implementationsPOST /implementationsimplementations/overridespath, line, column, scopeB (+A fallback)
declarationPOST /declarationdeclarationpath, line, columnB-only
type_hierarchyPOST /type_hierarchysuper-/subtype treepath, line, column, directionB-only
symbols_overviewPOST /symbols_overviewtop-level symbols of the filepathB (+headless tree-sitter)
inspectionsPOST /inspections, POST /list_inspectionsrun/list inspectionspath, mode=run|listB-only
replace_symbol_bodyPOST /replaceSymbolBodyreplace symbol bodyname_path/path+line, new_body, expected_hashB (+headless)
insert_before_symbolPOST /insertBeforeSymbolinsert sibling beforename_path, text, expected_hashB (+headless)
insert_after_symbolPOST /insertAfterSymbolinsert sibling aftername_path, text, expected_hashB (+headless)
renamePOST /renamePreview/renameApplyrename symbol + all usagesnew_name, force, search_commentsB-only (BACKEND_REQUIRED)
reformatPOST /reformatreformat file in-placepathB-only
movePOST /movePreview/moveApplymove symbol + referencestarget, forceB-only (BACKEND_REQUIRED)
safe_deletePOST /safeDeletePreview/safeDeleteApplydelete when no blockersforceB-only (BACKEND_REQUIRED)
inlinePOST /inlinePreview/inlineApplyinline symbol at call sitesforceB-only (BACKEND_REQUIRED)

Backing: B = JetBrains IDE (plugin via HTTP); A = rust-analyzer (headless); headless = tree-sitter / local_range_write without an IDE. The refactoring engine (rename/move/safe_delete/inline) is two-phase (*Preview*Apply, plan_hash-protected) and has no headless path.

find_symbol (Serena) → ctx_search action="symbol" / ctx_outline, not ctx_refactor.

IDE UI surfaces (non-HTTP)

These are user-facing IDE touchpoints, not part of the ctx_refactor HTTP surface. See the Gain Tool Window (§4), Editor-Focus Reporter (§5) and IDE UI Integration (§6) sections of Journey 19 for full detail.

SurfaceIdentifier / registry keyWhat it doesBacking
Gain Tool WindowGAIN_TOOL_WINDOW_ID ("LeanCtxGain")dockable bottom tool window rendering the Gain report; visibility-gated 30 s polling (GainPollController)lean-ctx gain --json subprocess (off EDT, 10 s timeout)
Editor-focus reporterleanctx.editor.signal.enabled (default true)reports the focused editor file path (path only, in-project) to lift #500 ranking; 2 s debounce, opt-out via registry keylean-ctx editor-signal --file <absPath> (fire-and-forget)
Status-bar widgetid="com.leanctx.statusBar", order="after encodingWidget"shows ⚡ <N> saved (30 s refresh); click activates the Gain Tool WindowStatsReader reads ~/.lean-ctx/stats.json
Tools menu (lean-ctx)action group LeanCtx.Menu (ToolsMenu, anchor last)four actions: Setup / Doctor / Gain Report / Dashboardper-action (see below)

Tools-menu actions

ActionIDRunsOutput
SetupLeanCtx.Setuplean-ctx setupMessages popup (ANSI-stripped)
DoctorLeanCtx.Doctorlean-ctx doctorMessages popup (ANSI-stripped)
Gain ReportLeanCtx.Gainactivates the Gain Tool Window (GAIN_TOOL_WINDOW_ID)tool window (no binary spawn)
DashboardLeanCtx.Dashboardlean-ctx dashboardfire-and-forget (CLI opens its own dashboard)

Setup/Doctor extend LeanCtxCommandAction(vararg args): run BinaryResolver.runCommand, pipe captured stdout (or stderr when blank) through stripAnsi (util/AnsiText.kt, regex \[[0-9;?]*[ -/]*[@-~], fix b933e510), then show a Messages.showInfoMessage popup titled lean-ctx. GainAction and DashboardAction extend AnAction directly.

Guards (short form)

  • BLAKE3 conflict guard (expected_hash edits / plan_hash refactoring) — Rust-central; the plugin does not hash. Mismatch → CONFLICT.
  • PathJail — every mutation and every reported path is checked against project_root.
  • Smart mode — dumb mode → INDEXING (no partial result).
  • AuthX-LeanCtx-Token per project; missing → 401. 127.0.0.1 only.
  • Gain subprocess isolation — the Gain Tool Window shells out to lean-ctx gain --json (off the EDT, 10 s timeout); GainScore stays the single source of truth in Rust, Kotlin only renders. Failures map to typed panel states (BinaryNotFound / Failed(reason)), never an exception.
  • Editor-focus privacy — path only, never file content; only real, local files inside the current project are reported (no scratch/library/directory buffers). Missing/old binary or IO error is swallowed silently.
  • Output hygiene — all CLI output shown in the IDE (Gain panel, Setup/Doctor popups) is ANSI-stripped via stripAnsi before display.

Error codes

CodeTriggerFix
UNAUTHORIZED (401)token missing/wrongsend a valid X-LeanCtx-Token
NOT_FOUND (404)unknown routecheck the endpoint path
FILE_NOT_FOUNDfile not readableverify the path with ctx_tree
POSITION_OUT_OF_RANGEline/column past EOFre-resolve the range
CONFLICThash mismatch or conflicts ∧ !forcere-read fresh; use force if appropriate
AMBIGUOUS_SYMBOLname_path > 1 matchqualify (Class/method)
NO_SYMBOLname_path 0 matchescorrect the name/path
INDEXINGIDE in dumb modewait, retry
UNSUPPORTED_LANGUAGEno LSP/PSI processorlanguage not supported
BACKEND_REQUIREDrefactoring without an IDEopen the IDE with the project
INTERNALother errorcheck the message

The Gain Tool Window and editor-focus reporter are subprocess/CLI consumers, not HTTP endpoints — they do not surface the codes above. Gain failures map to the BinaryNotFound / Failed(reason) panel states (see §4.1); a lost editor-focus signal is silent and harmless.

See also