MCP HubMCP Hub
스킬 목록으로 돌아가기

lsp-safe-edit

blackwell-systems
업데이트됨 5 days ago
53
2
53
GitHub에서 보기
디자인design

정보

이 스킬은 코드 수정을 안전하게 적용합니다. 먼저 변경 사항을 미리보고 LSP 진단 결과를 비교한 후에만 디스크에 기록합니다. 새로운 오류가 발생하지 않는 경우에만 편집 내용을 확정하며, 문제가 발생하면 빠른 수정 사항을 제시합니다. 개발자는 내장된 검증 기능을 통해 위험 없는 리팩터링 및 다중 파일 수정 작업에 이 기능을 사용해야 합니다.

빠른 설치

Claude Code

추천
기본
npx skills add blackwell-systems/agent-lsp -a claude-code
플러그인 명령대체
/plugin add https://github.com/blackwell-systems/agent-lsp
Git 클론대체
git clone https://github.com/blackwell-systems/agent-lsp.git ~/.claude/skills/lsp-safe-edit

Claude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요

문서

Requires the agent-lsp MCP server.

lsp-safe-edit

Wrap any code edit with a before/after diagnostic comparison. Speculatively previews the change in-memory before touching disk, then diffs errors introduced vs. resolved after applying. If errors appear, surfaces code actions to fix them.

Prerequisites

LSP must be running for the target workspace. If not yet initialized, call mcp__lsp__start_lsp with the workspace root before proceeding.

Auto-init note: agent-lsp supports workspace auto-inference from file paths. Explicit start_lsp is only needed when switching workspace roots.

Input

  • target file(s): One or more files to be edited (absolute paths).
  • description of change: What you intend to edit and why.

Workflow

Step 1 — Open target file(s)

Call mcp__lsp__open_document for each file that will be edited:

mcp__lsp__open_document(file_path: "/abs/path/to/file.go", language_id: "go")

Step 2 — Capture baseline diagnostics (BEFORE)

Call mcp__lsp__get_diagnostics for each target file. Store as BEFORE. For multi-file edits, collect diagnostics for all files involved.

BEFORE = mcp__lsp__get_diagnostics(file_path: "/abs/path/to/file.go")

If the server returns an empty list immediately after open, wait briefly and retry — LSP analysis is async.

Step 3 — Speculative preview (preview_edit)

Before touching disk, call mcp__lsp__preview_edit to preview the error delta of the intended change:

mcp__lsp__preview_edit(
  file_path: "/abs/path/to/file.go",
  start_line: <N>,
  start_column: <col>,
  end_line: <N>,
  end_column: <col>,
  new_text: "<replacement text>"
)

Returns net_delta (new errors introduced minus errors resolved) without writing to disk.

Decision:

net_deltaAction
≤ 0Proceed — edit improves or does not worsen error state
> 0Pause. Report introduced errors to user and ask: "Proceed anyway? [y/n]"

If net_delta > 0 and user says "n", stop. Do not apply the edit.

Multi-file edits: preview_edit covers one file at a time. For edits spanning multiple files, run it for each file independently and sum the deltas. If any file shows net_delta > 0, pause before continuing.

When to skip Step 3: If the intended change is a new file (Write), there is no existing file to simulate against. Skip to Step 4.

Step 3b — Refactor preview with simulate_chain (renames and signature changes)

Use this step instead of or after Step 3 when the change is a rename, signature change, or any edit with dependent follow-on edits (e.g., updating all call sites after adding a parameter).

simulate_chain applies a sequence of speculative edits in-memory and reports whether the cumulative change is safe — without touching disk:

mcp__lsp__simulate_chain({
  "workspace_root": "/abs/path/to/workspace",
  "language": "go",
  "edits": [
    {
      "file_path": "/abs/path/to/file.go",
      "start_line": <N>, "start_column": <col>,
      "end_line": <N>,   "end_column": <col>,
      "new_text": "<replacement>"
    },
    // additional dependent edits (e.g. call site updates) ...
  ]
})

Returns:

  • cumulative_delta — net error change across all steps
  • safe_to_apply_through_step — how many steps are safe to apply in sequence

Decision:

cumulative_deltasafe_to_apply_through_stepAction
≤ 0= total stepsAll steps safe. Proceed to Step 4.
≤ 0< total stepsSafe up to that step. Review remaining steps.
> 0anyNet regression. Report to user before proceeding.

When to use Step 3b:

  • Renaming an exported symbol and updating its call sites
  • Adding/removing a parameter and updating all callers
  • Any multi-file refactor where edits are order-dependent

When to skip Step 3b:

  • Simple in-place edits with no dependent follow-on edits (Step 3 is sufficient)
  • New file creation (no existing text to simulate against)

Step 4 — Apply the edit to disk

Apply the change using the Edit or Write tool:

  • Use Edit for targeted replacements in an existing file.
  • Use Write only when creating a new file or doing a full rewrite.
Edit(file_path: "/abs/path/to/file.go", old_string: "...", new_string: "...")

For multi-file edits, apply each file's changes before collecting post-edit diagnostics (Step 5). If any individual edit fails, stop and report before applying remaining files.

Step 5 — Capture post-edit diagnostics (AFTER)

Call mcp__lsp__get_diagnostics again for each edited file. Store as AFTER.

AFTER = mcp__lsp__get_diagnostics(file_path: "/abs/path/to/file.go")

For multi-file edits, collect diagnostics for all files and merge the results.

Step 6 — Compute the diagnostic diff

Compare BEFORE and AFTER:

  • Introduced = diagnostics in AFTER not in BEFORE (new problems).
  • Resolved = diagnostics in BEFORE not in AFTER (fixed problems).

Match by (file, line, message) tuple to handle line-number shifts. Treat error and warning severity separately.

Step 7 — Surface code actions if errors were introduced

If any new error-severity diagnostics appear, call mcp__lsp__suggest_fixes at each error location to surface quick fixes:

mcp__lsp__suggest_fixes(
  file_path: "<file>",
  start_line: <error line>,
  start_column: 1,
  end_line: <error line>,
  end_column: 999
)

Report available code actions to the user:

Errors introduced (2):
  file.go:34 — undefined: MyType
    → Code action: Import "mypackage" (quickfix)
  file.go:51 — cannot use int as string
    → No code actions available

Apply code actions? [y/n/select]

If the user accepts, apply the code action's WorkspaceEdit via mcp__lsp__apply_edit, then re-collect diagnostics and re-diff.

Step 8 — Format (optional)

If the diagnostic diff is clean (net change ≤ 0), offer to format the edited file via the language server:

mcp__lsp__format_document({ "file_path": "/abs/path/to/file" })

Returns TextEdit[]. If non-empty, apply immediately:

mcp__lsp__apply_edit({ "workspace_edit": <TextEdit[]> })

Skip if the user did not ask for formatting, or if there are unresolved errors (fix errors before formatting).

Step 9 — Report using DiagnosticDiffFormat

Output the final summary:

## Edit Summary

Files changed: N
Errors introduced: A  →  Errors resolved: B  (net: A-B)
Warnings introduced: C  →  Warnings resolved: D

### Introduced errors
- file.go:34 — undefined: MyType

### Resolved errors
- file.go:12 — unused variable: x

Decision Guide

Net changeAction
0Safe. No new errors.
NegativeNet improvement — errors resolved. Safe.
Positive (after code actions)Do NOT commit. Offer to revert.

When net change > 0 after code actions:

  1. Show the full list of remaining introduced errors.
  2. Offer to revert using the original old_string in a follow-up Edit call.
  3. Wait for user decision before proceeding.

Do not commit or stage files when net change > 0.


Multi-file workflow

For edits spanning multiple files (e.g., changing a function signature and all its call sites):

  1. Open all files in Step 1.
  2. Collect BEFORE diagnostics for all files.
  3. Simulate each file independently in Step 3 — sum net_delta values.
  4. Apply edits file by file in Step 4 — stop on first failure.
  5. Collect AFTER diagnostics for all files and merge.
  6. Check code actions on any file showing new errors.

Report the combined diagnostic diff across all files in the final summary.

GitHub 저장소

blackwell-systems/agent-lsp
경로: skills/lsp-safe-edit
0
agentskillsai-agentsai-toolingclaudeclaude-codecode-intelligence

연관 스킬

executing-plans

디자인

executing-plans 스킬은 검토 체크포인트가 포함된 통제된 배치로 실행할 완전한 구현 계획이 있을 때 사용합니다. 이 스킬은 계획을 불러와 비판적으로 검토한 후, 소규모 배치(기본값 3개 작업)로 작업을 실행하면서 각 배치 사이에 진행 상황을 아키텍트 검토를 위해 보고합니다. 이를 통해 내재된 품질 관리 체크포인트를 갖춘 체계적인 구현이 보장됩니다.

스킬 보기

requesting-code-review

디자인

이 스킬은 코드 변경 사항을 요구 사항에 따라 분석하기 위해 코드 리뷰어 하위 에이전트를 호출합니다. 작업 완료 후, 주요 기능 구현 후, 또는 메인 브랜치에 병합하기 전에 사용해야 합니다. 이 리뷰는 현재 구현체와 원래 계획을 비교하여 문제를 조기에 발견하는 데 도움이 됩니다.

스킬 보기

connect-mcp-server

디자인

이 스킬은 개발자들이 HTTP, stdio 또는 SSE 전송 방식을 통해 MCP 서버를 Claude Code에 연결하는 포괄적인 가이드를 제공합니다. GitHub, Notion 및 사용자 정의 API와 같은 외부 서비스를 통합하기 위한 설치, 구성, 인증 및 보안을 다룹니다. MCP 통합 설정, 외부 도구 구성 또는 Claude의 모델 컨텍스트 프로토콜 작업 시 활용하세요.

스킬 보기

web-cli-teleport

디자인

이 스킬은 작업 분석을 기반으로 개발자가 Claude Code 웹 인터페이스와 CLI 인터페이스 중 선택할 수 있도록 돕고, 두 환경 간 원활한 세션 텔레포트를 가능하게 합니다. 웹, CLI 또는 모바일 환경 전환 시 세션 상태와 컨텍스트를 관리하여 워크플로를 최적화합니다. 다양한 단계에서 서로 다른 도구가 필요한 복잡한 프로젝트에 사용하세요.

스킬 보기