Weavatrix Refactor Js

io.github.sergii-ziborov由 GitHub 账号 sergii-ziborov 发布v0.1.6更新于 Oct 24, 2026

Transactional refactoring MCP with 11 evidence-backed tools, hash-bound previews, and rollback.

已验证STDIO仅桌面文件与存储开发者工具

概览

AI 生成的概览

本地 MCP 服务器,为编码助手提供有证据支撑、事务化的 JavaScript/TypeScript 重构,含哈希绑定的预览、原子写入与回滚。

可以做什么
  • 预览、确认并应用跨语言符号重命名,覆盖 JS/TS、SQL、Python、Rust、Go、Java、C# 与 Solidity,并支持多个符号合并为一次事务
  • 为签名修改、符号体编辑、批量替换和导入清理生成可证明的编辑计划,再原子化应用
  • 审查结构性变更:文件与符号移动的架构和循环依赖投影,以及删除就绪度检查
  • 回滚最近一次应用,并通过内置的只读代码智能工具(依赖图、影响面、审计、架构、端点)查看结果
适用场景
当助手需要在代码库中做真实的多文件源码修改,且希望每处改动都被证明、预览并可回滚,而不是盲目写入时使用。适合重视陈旧文件检测、来源证据与回滚的重构场景。
运行要求
通过 npx(Node.js)在本地运行,需传入仓库路径参数;仅桌面端,stdio 传输。写入源码还需设置 WEAVATRIX_ALLOW_SOURCE_EDITS=1 并提供有效的单次确认令牌。可选 WEAVATRIX_PRECISION(lsp 或 off)与 WEAVATRIX_REFACTOR_HOME 用于回滚快照存储。未声明认证。
安装前请注意
该服务器会写入和删除源码文件:设置 WEAVATRIX_ALLOW_SOURCE_EDITS=1 即授权应用与回滚,请仅在确有需要的会话中开启。若应用后文件发生变动,回滚会被拒绝;恢复不完整时会留下可重试的包。非 JS/TS 后端始终报告 PARTIAL 完整性,测试与人工审查仍是发布依据。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Weavatrix Refactor Js,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

Weavatrix Refactor JS

[CI] [npm] [MIT]

Part of the Weavatrix ecosystem. This repository preserves the explicit JavaScript refactoring line.

This is the JavaScript refactoring engine of Weavatrix, continued as weavatrix-refactor-js. The weavatrix-refactor package ships the native Rust MCP host built on weavatrix-rust and the weavatrix-edit / weavatrix-refactor-plan / weavatrix-worktree crates. This package continues that version line: [email protected] was the last JavaScript release under the old name, and [email protected] picks up from it. Install weavatrix-refactor-js, or pin [email protected], to stay on the JavaScript implementation.

Evidence-backed, transactional refactoring for coding agents.

weavatrix-refactor-js is the write-capable member of the JavaScript family. It combines the complete read-only weavatrix-js code-intelligence MCP with 11 refactoring tools that can prove a change, preview it against the current working tree, apply it atomically, refresh the graph, and roll it back.

Engine boundary: this package hosts the weavatrix-js engine. It does not use the native weavatrix-rust engine, and installing both packages does not silently upgrade this one's analysis layer. Its state lives in ~/.weavatrix-refactor-js, kept separate from the Rust host's so the two never share a lock, a token store, or a rollback journal.

It is substantially more than a rename wrapper:

  • semantic JS/TS rename through the bundled language server;
  • SQL table and field rename with schema-aware evidence;
  • strict graph-plus-lexical rename for Python, Rust, Go, Java, C#, and Solidity;
  • several related JS/TS renames merged into one atomic transaction;
  • signature, symbol-body, import, bulk-replace, move, and delete-safety workflows;
  • byte-exact file hashes, before text, provenance, uncertainty, and graph revision in every applyable plan;
  • stale-tree detection, repository locking, rollback bundles, and automatic rollback after a mid-write failure;
  • architecture and cycle projection before structural moves;
  • post-change blast-radius and verification tools inherited from the core.

Why this is a separate package

The MIT weavatrix-js core is physically read-only: its published artifact has no repository source-write path. This package is the explicit write boundary. Installing it and selecting its refactor profile makes the edit capability visible; without this package, the server cannot modify source.

The split is a safety property, not packaging cosmetics:

text
weavatrix-js core       weavatrix-refactor-js                 repositoryread-only evidence  ->  plan + preview + confirmation  ->  atomic writegraph / LSP / audit     hashes / provenance / rollback     refreshed graph

Architecture

The implementation is a ports-and-adapters system with one-way boundaries:

text
edit-plan model  <-  filesystem / lock / token adapters       ^                         ^       |                         |plan engines     ->  preview / apply / rollback workflows  ->  MCP adapter
  • Model validates the frozen weavatrix.edit-plan.v1 envelope and applies byte-exact edits as pure string transformations.
  • Platform adapters own real-path containment, atomic replacement, repository locks, single-use tokens, and durable rollback bundles.
  • Plan engines compute rename, signature, symbol, import, move, delete, and bulk-replace evidence without owning the write workflow.
  • Application workflows bind a preview to the current repository, issue and consume confirmation tokens, apply under a lock, and restore on failure.
  • MCP adapter composes the 11 refactor tools with the read-only weavatrix-js catalog and exposes one stdio server.

The checked-in strict architecture contract enforces zero runtime cycles, files no longer than 300 lines, and functions no longer than 100 lines. It has no exceptions or ratchet baseline.

What makes the refactor workflow different

An ordinary editor rename answers: "Which text edits should I make now?" Weavatrix Refactor also answers:

QuestionEvidence returned
Is this the exact symbol?Stable graph symbol id plus parser/LSP selection range
Which references are proven?Per-edit provenance: EXACT_LSP, RESOLVED, EXTRACTED, or LEXICAL_EXACT
What was not proven?Explicit uncertainReferences, notModified, warnings, and PARTIAL completeness
Which files were even looked at?The rename session seeds every graph-declared reference plus every indexed file whose text contains the identifier; anything it could not open is named and forces PARTIAL
Did the tree change after preview?File sha256 plus exact before text rechecked under the write lock
Can several renames partially succeed?No. Related renames are conflict-checked and applied as one transaction
What happens after a disk/write failure?Already-written files are restored; a durable rollback bundle remains
Will a move worsen architecture?Projected runtime cycles, boundary violations, improvements, and blast radius
Did the refactor preserve behavior-shaped structure?Refreshed graph plus verified_change caller/import/reference conservation

The system fails closed when proof is insufficient. It never upgrades an INFERRED edge into an applyable edit and never hides an ambiguous reference.

The complete rename workflow

rename_symbol and rename_related_symbols are complete operations, not PLANNED-only helpers. Each method owns both phases.

1. Preview

Call the rename method normally:

json
{  "symbol": "src/users.ts#getUser@12",  "new_name": "getCustomer"}

The method computes the rename, validates every plan file against the working tree, and returns PREVIEW_OK with a short-lived confirmToken. Preview never writes source and does not require the environment write gate.

2. Apply through the same method

Repeat the same operation inputs and add the confirmation:

json
{  "symbol": "src/users.ts#getUser@12",  "new_name": "getCustomer",  "mode": "apply",  "confirm_token": "<token from preview>"}

The tool recomputes the deterministic plan, verifies that the token belongs to that plan and repository, takes the repository lock, rechecks hashes and before text, writes a rollback bundle, and applies every edit bottom-up.

The same contract applies to a coordinated set:

json
{  "renames": [    {"symbol": "src/api.ts#getUser@8", "new_name": "getCustomer"},    {"symbol": "src/api.ts#getOrder@20", "new_name": "getPurchase"}  ]}

rename_related_symbols detects overlapping edits, chains, swaps, shadowing risk, and per-sub-rename failure before it issues a token. Apply is one atomic multi-file operation.

Refactoring tools

Complete write workflows

ToolWhat it actually does
rename_symbolCross-language preview/confirm/apply rename. Dispatches to exact JS/TS LSP, SQL schema, or strict graph+lexical backends; returns honest backend completeness and every uncovered reference.
rename_related_symbolsCoordinates up to 50 JS/TS symbol renames in one shared language-server session and one atomic edit plan. Detects conflicts, chains, swaps, snapshot drift, and any failed sub-rename before writing.
apply_edit_planGeneric two-phase executor for weavatrix.edit-plan.v1 envelopes from the other tools or weavatrix-online. Preview issues a plan-bound token; apply writes atomically with rollback.
rollback_last_applyRestores the latest pre-apply bundle. Refuses if post-apply files drifted; retries converge after an incomplete restore.

Proven plan producers

ToolWhat it actually does
change_signatureAdds or removes a JS/TS function or method parameter. Performs byte-exact declaration and call-argument surgery; spread calls and value-requiring additions remain explicit uncertainty.
edit_symbolUses the indexed parser range for replace_symbol_body, insert_before_symbol, or insert_after_symbol. JS/TS output is parse-gated; line endings and UTF-16 coordinates are preserved.
bulk_replaceTwo-stage, occurrence-selective replacement over indexed files. First returns stable occurrence ids; the second call accepts chosen ids or an exact expected count and emits a hash-bound plan. Literal mode is the default; regex replacements use real capture expansion.
organize_importsRemoves only provably unused named JS/TS imports. Default and namespace imports stay uncertain; side-effect imports are untouched; sorting is deliberately left to the formatter.

These plans are applied with apply_edit_plan, using the same preview, token, atomic-write, and rollback protocol as rename.

Structural review and safety tools

ToolWhat it actually does
move_fileBuilds a JS/TS relocate review: rewrites importer specifiers and the moved file's own relative imports, then projects architecture effects. File renaming itself remains an explicit editor/agent action, so this is intentionally not an apply envelope.
move_symbolProjects a declaration move without inventing byte edits. Reports introduced/removed runtime cycles, target-file dependencies, architecture violations or improvements, and blast radius.
delete_readinessReturns safe: true, false, or UNPROVEN with known references, dynamic/reflection risks, confidence, and the declaration span. Exported symbols are capped at UNPROVEN; deletion is never automated.

Language and proof matrix

SurfaceBackendApplyable provenanceCompleteness contract
JavaScript / TypeScript renameBundled TypeScript language serverEXACT_LSPCOMPLETE only when every file that could mention the symbol was opened in the rename session and proven; any candidate left out forces PARTIAL
SQL table renameSchema-aware SQL scanner across SQL and host filesEXTRACTED / LEXICAL_EXACTReports every skipped or ambiguous reference
SQL field renameDefinition-safe SQL backendProven definition edits onlyUsages remain UNPROVEN rather than guessed
Python / Rust / Go / Java / C# / Solidity renameIndexed graph references plus exact lexical location on the recorded lineEXTRACTED / LEXICAL_EXACTAlways PARTIAL; ambiguous lines are never edited
JS/TS signature and importsParser plus graph call/reference evidenceEXTRACTED / RESOLVEDExplicitly partial where graph reach cannot prove absence
Symbol-anchored editIndexed parser ranges for every indexed languageEXTRACTEDJS/TS parse gate; other languages retain the parser-range evidence boundary

Edit-plan proof envelope

Every applyable plan uses weavatrix.edit-plan.v1. Its load-bearing fields are:

  • operation and graph revision;
  • repository-relative target paths only;
  • sha256 of every target file;
  • exact 1-based line and UTF-16 character ranges;
  • exact before and after text;
  • per-edit provenance;
  • uncertainReferences, notModified, warnings, and completeness.

The applier additionally protects against:

  • absolute paths, traversal, .git casing/trailing-dot tricks, NTFS streams, and escaping symlinks/junctions;
  • non-UTF-8 or oversized files;
  • overlapping edits, stale ranges, lone surrogates, and edits that split surrogate pairs;
  • two writers interleaving in the same repository;
  • token reuse, expiry, repository mismatch, or plan mismatch;
  • partial writes and incomplete rollback.

createdAt is provenance metadata and is the only field excluded from the confirmation fingerprint. This allows a rename method to recompute the same plan on its apply call; every executable field remains token-bound.

Result states agents can act on

StateMeaning
PREVIEW_OKEvery hash and before text matches; a single-use token was issued.
PREVIEW_BLOCKEDThe generated plan does not match the current tree; nothing can be applied.
WRITE_GATE_CLOSEDThe server was not deliberately started with source edits enabled.
APPLIEDEvery planned edit was written and the rollback bundle is available.
STALEThe working tree changed between preview and the locked apply check; nothing was written.
TOKEN_UNKNOWN / TOKEN_EXPIRED / TOKEN_*_MISMATCHConfirmation is absent, consumed, expired, or belongs to another plan/repository.
REPO_BUSYAnother apply or rollback currently owns the repository lock.
ROLLED_BACKA failed apply or explicit rollback restored the original files.
ROLLBACK_INCOMPLETERestoration was blocked for named files; the durable bundle remains retryable.
INVALID_PLANSchema, path, range, encoding, overlap, or provenance validation failed before writing.
INVALID_ARGSA required argument was missing or the wrong type; the offending names are listed. Nothing was planned.

Planner-specific states such as NOT_FOUND, NO_CHANGE, CONFLICT, BLOCKED, UNPROVEN, and NOT_SUPPORTED remain visible instead of being collapsed into a generic failure.

The three write gates

Repository source changes require all three:

  1. weavatrix-refactor-js is installed and the refactor profile selects edit;
  2. the server starts with WEAVATRIX_ALLOW_SOURCE_EDITS=1;
  3. the apply call presents a valid, unexpired, single-use token bound to the exact plan and repository.

Preview and every read-only analysis remain available while the environment gate is closed.

End-to-end change proof

The package includes all 34 read-only core tools in the same MCP server. A strong refactor session can therefore stay in one evidence chain:

  1. inspect_symbol, context_bundle, or get_dependents identifies the exact target;
  2. rename_symbol, change_signature, move_symbol, or another refactor tool previews the change;
  3. the write workflow applies atomically;
  4. the next graph call auto-refreshes changed files and reverse importers;
  5. verified_change compares callers, imports, and references against the merge base;
  6. change_impact, verify_architecture, coverage_map, run_audit, and find_duplicates inspect the consequences.

Useful inherited surfaces include:

  • architecture maps and navigation: module_map, query_graph, shortest_path, context_bundle;
  • impact and proof: change_impact, get_dependents, prepare_change, verified_change;
  • health: run_audit, find_dead_code, find_duplicates, coverage_map, hot_path_review;
  • contracts: list_endpoints, trace_endpoint, trace_api_contract;
  • target architecture: get_architecture_contract, verify_architecture, explain_architecture_violation;
  • repository control: open_repo, rebuild_graph, graph_diff, list_known_repos.

See the weavatrix-js README for the complete JavaScript host catalog.

Run it

Start the merged read-only-plus-refactor MCP server for one repository:

bash
npx -y weavatrix-refactor-js <repoRoot>

For an MCP client, the minimal configuration is:

json
{  "mcpServers": {    "weavatrix": {      "command": "npx",      "args": ["-y", "weavatrix-refactor-js", "/absolute/path/to/repository"]    }  }}

On Windows, use npx.cmd when the client does not resolve command shims. With no environment override, every analysis and preview tool works but source writes fail closed. Add "env": {"WEAVATRIX_ALLOW_SOURCE_EDITS": "1"} only for a session in which apply and rollback are deliberately authorized.

Applications that already host weavatrix-js can compose the same extension:

js
import {startMcpServer} from 'weavatrix-js/mcp-runtime'import {refactorExtension} from 'weavatrix-refactor-js/extension'
await startMcpServer({  defaultCapabilities: 'refactor',  loadExtensions: async () => [refactorExtension()],})

The exported extension registers tools and the refactor capability profile; it does not silently open the write gate.

Scope and honest limits

  • Related multi-symbol rename is currently JS/TS-only.
  • move_file cannot rename the file through apply_edit_plan; it is a review plan because file relocation has different filesystem semantics.
  • move_symbol is a topology/architecture dry-run, not byte-edit synthesis.
  • Graph+lexical language backends cannot prove reference completeness and stay PARTIAL even when every known reference was located.
  • delete_readiness never auto-deletes, and public/exported APIs cannot receive an automatic clean verdict.
  • Tests, typechecking, runtime checks, and human review remain the release authority. Weavatrix supplies bounded evidence; it does not fabricate proof.

Package boundary

PackageLicenseResponsibility
weavatrix-jsMITRead-only JavaScript graph, analysis, evidence, architecture, and verification
weavatrix-refactor-jsMITProven refactor plans, transactional writes, and rollback
weavatrix-onlineMITExplicit public network connector and remote plan/evidence workflows

The refactor package extends the legacy JavaScript core only through weavatrix-js/extension-api and weavatrix-js/analysis-kit; it does not copy or relicense that core. The canonical weavatrix package is the native Rust engine and is not this JavaScript extension host.

License

MIT.

来源:README.md,提交 01eb296

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.6最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分