Skip to content

code-intelligence: 研究按需加载的 Pi-native LSP 能力,而不是常驻第二套 IDE Runtime #163

Open

Description

@tt-a1i

结论

OMP 的 LSP 是相对 OpenPI 最明确的功能优势之一:它把 diagnostics、definition、references、symbols、rename、code actions 等高保真代码事实直接暴露给模型,能减少纯文本搜索与猜测式修改的往返。

OpenPI 值得做一个按需加载、Pi-native、零常驻税的 LSP 研究,但不应复制 OMP 的完整 IDE Runtime,也不应默认安装或常驻启动语言服务器。

这是 #45 的具体拆分,不重复讨论 Harness 总体重量。

对比证据

固定审查点:

OMP 的 LSP 工具覆盖 diagnostics、definition、references、hover、symbols、rename、rename_file、code actions、type definition、implementation、status、reload、capabilities 与 raw request,并把读写审批分开。OMP LSP contract

它按 cwd 缓存配置与 client,可自动探测 server,并在共享 mux 失败时回退私有进程;请求有 abort/timeout,WorkspaceEdit 可 preview 或 apply。OMP LSP lifecycle

OpenPI 当前的 package-owned tool surface 只有 search、delegate、workflow、background、session 等按需组,没有代码语义工具;普通 parent Session 的 OpenPI 默认工具面仍为空。OpenPI tool surface

OpenPI 可保留的优势:

  • Pi 继续拥有 Session、普通工具、provider/model 与 Trust;
  • capability gateway 保持普通 turn 零 resident schema;
  • 不为 LSP 引入第二 provider stack、全局 daemon 或 IDE 状态库。

需要回答的问题

  1. LSP 应归 OpenPI 可选 capability、独立 Pi package,还是优先推动到 Pi core?
  2. 只有明确需要 diagnostics/navigation/refactor 时才加载,能否保持普通 turn 的 prompt/cache 完全不变?
  3. 语言服务器由哪个 Session/cwd 拥有?Session switch、Trust 变化、取消与 shutdown 如何清理?
  4. navigation/diagnostics 是 read,rename/code action 是 write;raw request 是否首版禁止?
  5. 首版是否只复用已安装 server,不自动下载,缺失时给出可操作证据?
  6. diagnostics 如何绑定 file fingerprint / mutation epoch,避免 late result 污染?
  7. read-only child-safe 与 mutation action 如何独立分类?

建议验证

在 TypeScript、Rust、Python 上做 paired benchmark:

  • 找 definition/references 后修改;
  • 修复类型或编译诊断;
  • 跨文件 rename;
  • 排除“文本同名、语义不同”的误命中。

比较文本搜索基线与同模型临时 LSP probe,记录首次/后续延迟、tool calls、tokens、正确引用率、误改率、server 失败退化、取消及进程清理。

只有稳定增益后才做最小原型:按需 capability、只接现有 server,首版只开放 diagnostics/definition/references/symbols,mutation action 后置。

验收标准

  • 固定模型、任务、源码的 paired evidence
  • 普通 turn active tools、system prompt 与 cache shape 不变
  • server 缺失、crash、timeout、abort 都 fail closed
  • Session/cwd 切换与 shutdown 不残留进程
  • read/write action 有独立权限与 child 分类
  • late diagnostics 不跨 mutation epoch
  • 明确最终归属

明确不做

  • 不从完整 LSP mux/daemon 起步;
  • 不自动安装语言服务器;
  • 不让 LSP 常驻普通 turn;
  • 不替换 Pi 普通 read/edit/write;
  • 不把 raw JSON-RPC request 作为首版默认能力。

Activity

  1. added
    enhancement
    on Aug 25, 2026
  2. 627150795 commented on Aug 28, 2026

    @627150795
    Contributor

    I am taking a focused first pass on this issue: document a Pi-native, on-demand LSP capability contract with explicit loading, read/write boundaries, session ownership, and fail-closed behavior. This pass will be docs/design-only and will not add an LSP runtime or dependency.

  3. 627150795 commented on Aug 29, 2026

    @627150795
    Contributor

    I opened #259 (#259) for the focused first pass I claimed here. Scope: docs/design contract for explicit on-demand LSP loading, Session/workspace ownership, read/write boundaries, cancellation, cleanup, bounded output, trust, and fail-closed behavior. Validation passed: git diff --check, bun run lint, and bun run typecheck. This is intentionally docs-only and does not claim an LSP runtime is implemented or close this Issue automatically.

  4. tt-a1i commented on Sep 8, 2026

    @tt-a1i
    CollaboratorAuthor

    补充 2026-09-08 社区源码调研:这个 Issue 现在可以用更小的 Pi 原生包作为对照。OpenPI 本次基线为 ed9dbc1。以下只完成固定源码检查,没有安装插件、启动语言服务器或测量模型收益。

    优先考察 @narumitw/pi-lsp 0.49.7 的单请求生命周期。 在 09d0f4d,每个 ctx.sessionManager 有独立 scope 和 generation;Session 切换、关闭时先取消旧操作,再等待它们结束。LspSessionScope 在通知取消前发布关闭状态,并拒绝取消后返回的结果。runner 为请求创建 client,在 finally 中 shutdown,清理失败会向调用方报错;client 等待进程退出,必要时从 SIGTERM 升级到 SIGKILL。

    它只有 diagnostics/fix 两个工具,fix 默认 write=false,不自动安装服务器。这使“现成服务器、只开放 diagnostics”的实验更具体。不过,两工具仍在加载时注册;每次冷启动可能昂贵;该包不提供 definition/references,不能作为完整导航方案。

    共享池的对照可选 code-yeongyu/pi-lsp-client。 1c981df 的 manager 区分 refCount 与初始化等待者,提供空闲回收和状态快照。但 factory 注册六工具及自动 post-edit diagnostics,并从 Session shutdown 释放默认全局 manager;OpenPI 同进程多 Session 的归属关系仍需验证。

    建议先比较两种生命周期的冷/热延迟、诊断有效性、取消后的迟到结果和进程清理,再评估工具调用及 token 收益;不要先建设共享 daemon。路径、Trust、服务器自身行为及 child 分类仍是独立验收项,上述源码机制不能代替兼容性证明。

    研究记录:Pi 社区能力研究与候选清单(2026-09-08)。源码证据、运行验证与采用决策分别记录。

  5. tt-a1i commented on Sep 8, 2026

    @tt-a1i
    CollaboratorAuthor

    2026-09-08 插件目录补一条对照,不改 #163 的方向。

    pi-lens(npm 4.1.4,2026-09-07,https://github.com/apmantza/pi-lens)链比 @narumitw/pi-lsp(npm 0.49.7)完整(symbol / module report),但默认打开 autofix / format / tests。本轮未安装、未运行任一包。

    试点若做:mutation-off;不要把 Lens 默认值当 OpenPI 默认。更小的只读对照继续看已有评论里的 pi-lsp。不新开 Issue。

    目录记录:docs/research/PI_COMMUNITY_PLUGIN_SURVEY_2026-09-08.md。

  6. tt-a1i commented on Sep 8, 2026

    @tt-a1i
    CollaboratorAuthor

    2026-09-08 目录第二轮:AST rewrite 不并进本 Issue。

    code-yeongyu/pi-ast-grep(git-only 4a7d1be)是结构搜索/替换,不是按需 LSP。若讨论,走 #510。本 Issue 继续 mutation-off 的只读 LSP 试点对照(pi-lsp / pi-lens)。

    本轮未安装、未运行。

  7. tt-a1i commented on Sep 9, 2026

    @tt-a1i
    CollaboratorAuthor

    2026-09-09 源码实验(只读 clone,未 pi install、未启动语言服务器、未跑模型)。记录:docs/research/EXPERIMENT_CODE_INTEL_2026-09-09.md。不改本 Issue 方向。

    冻结身份: OpenPI a9b40f0。官方 Pi v0.85.1 / clone 6160683——ToolName 闭集无 LSP。pi-lens npm 4.1.5 9981f9a(09-08 目录是 4.1.4)。@narumitw/pi-lsp 0.49.7。pi-lsp-client 仍是 git 1c981df。pi-ast-grep 仍是 git 4a7d1be。

    构造上的 mutation-off(不是 prompt):

    • Lens 的 format / autofix / tests 是 tool_result/agent_end 钩子,默认开。--no-autoformat --no-autofix 是 one-way CLI,高于项目配置;但 .pi-lens.json 能把全局关掉的 format/autofix 再打开。--no-tests 才是 global-only。--no-lens 可被 /lens-toggle 恢复。工具照样注册。
    • lsp_fix.write 默认 false、ast_grep_replace 默认 dry-run、Lens rename 默认 preview,都还在 schema 里。模型传 true 就会写。
    • 唯一构造:不要加载写路径。不要注册 lsp_fix / lsp_rename / ast_grep_replace。不要 hook 自动写盘。不要 pi install 整包。

    常驻税: OpenPI 默认仍是零 OpenPI 工具。Lens 加载后至少 8 个 always-active(docs/agent-tools.md 仍写 6;源码另有 project_report / effective_config / loader)+ 默认 context injection。pi-lsp 2 个工具(含 fix)。pi-lsp-client 6 个工具 + 进程级 singleton 池 + 每个 edit 追加 diagnostics 文本 + /lsp install。原样 pi install 会绕过 OpenPI capability 门,也会进 child(本包只过滤 pi-intercom)。

    试点(最多 1–3 个 OpenPI 自有工具): lsp_diagnostics,必要时再加 lsp_goto_definition / lsp_find_references。生命周期对照 pi-lsp 的单请求 spawn/shutdown,不对照 Lens,不先建共享 daemon。AST 仍走 #510;fuzzy/semantic 仍走 #503;symbol_search/module_report 不是 LSP。

    成功/失败证据见该研究记录:正确文件:行、误改率、残留进程、迟到诊断、普通 turn 工具面仍为空、child 看不到未分类名。无 paired evidence 不开实现。

  8. tt-a1i commented on Sep 9, 2026

    @tt-a1i
    CollaboratorAuthor

    2026-09-09 dual-SHA absence check (source read only; no pi install, no language server, no model, no paid cell). Record: docs/research/EXPERIMENT_LSP_163_ABSENCE_2026-09-09.md. Does not change this Issue’s direction. No new Issue.

    Pinned revisions

    • this checkout a9b40f0044ee59c360a6077c1c0bdbdbd30da10b (package 0.4.0)
    • origin/main 0d17f4577fe31315fe6c95370d251bdb4e2413cf (package 0.8.1)
    • published tag v0.8.1 → a3edee28fec813582db6b3b1341754cef4597f81

    On all three, git grep -i -E 'lsp_diagnostics|lsp_goto|registerTool.*lsp' is empty (including docs/). OPENPI_CAPABILITY_GROUPS is still search | delegate | workflow | background | session — no codeIntel / lsp. CHILD_SAFE_PACKAGE_TOOL_NAMES is still fd / rg / git_show / git_diff / git_log (child-session.ts 25–31 on a9b40f0; 35–41 on 0d17f45). No extensions/lsp directory. Closed unmerged #259’s contract file is not in either tree. The Issue’s own baseline 2a69d3f is also empty for lsp_diagnostics.

    So #163 is still an OPEN pilot ticket, not a live tool on this checkout or on origin / published 0.8.1.

    Q2 cannot be scored on these SHAs. Arm A (preloaded fd/rg) can still collect locate / mis-edit baselines. B_lsp = A + OpenPI-owned lsp_diagnostics does not exist here. Starting A vs B_lsp now is infra_failed / campaign-blocked, not “LSP had no gain” and not “the model chose not to call it.” bash tsc is a different treatment. Do not pi install Lens / @narumitw/pi-lsp / pi-lsp-client to invent a tool: that bypasses the capability gate, brings mutation / resident schema / child leakage, and is not this package’s lsp_diagnostics. Formal candidate repos must strip docs/research/ or the notes leak the empty-grep gold.

    Pilot shape if it lands later: OpenPI-owned, capability-gated, mutation-off, at most 1–3 read-only tools (lsp_diagnostics first). Classify at the child boundary the same revision it registers. Do not vendor Lens. Do not build a language-server OS (mux, auto-install, /lsp-setup).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions