@luban-code/luban-code 1.147.4 → 1.152.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,12 +15,14 @@
15
15
  ## Highlights
16
16
 
17
17
  - **Plan first, execute after you approve** — Plan mode is read-only by construction (write tools are not registered, commands are checked). The plan is saved as a Markdown file you can edit; executing it re-reads that file. You can also pick a Cursor plan (`~/.cursor/plans/*.plan.md`) from the command palette and execute it with Luban.
18
- - **Review in the editor, not in chat** — every write opens a real diff: accept or reject hunk by hunk from CodeLens or the diff title bar.
18
+ - **Review in the editor, not in chat** — pending writes show as a summary card; open the real diff from “View diff” (or turn on `luban.review.autoOpenDiff`) and accept or reject hunk by hunk from CodeLens or the diff title bar.
19
19
  - **Context without ceremony** — `@file`, `@folder/`, `#selection`, or right-click a file or folder in the Explorer → **Add File / Folder to Luban Chat** (drops the token into the current chat) or **Add File / Folder to Luban New Chat** (opens a fresh session first, then inserts the token and focuses the input); select code in the editor and it shows **Add to Chat / Add to New Chat** right above the selection (CodeLens), or right-click **Add Selection to Luban Chat** (or `Cmd/Ctrl+Alt+A`) to drop a `#selection path:start-end` token that carries its own position, so several selections can stack, or **Add Selection to Luban New Chat** to open a fresh session first, then insert the token and focus the input; plus automatic context from the editor around your cursor; a local BM25 index backs `search_code`, with `glob` for filenames and `grep` for regex.
20
+ - **Live context, not just files** — `@problems` inlines the current language-server errors/warnings (paths relative to the workspace), `@git` inlines the branch and uncommitted changes (`@git staged` for the index), and `@terminal` inlines the last few integrated-terminal commands and their output. All three appear in the `@` popup, expand at most once per message, and say plainly “nothing here” instead of inventing content.
20
21
  - **Real edits, reversible** — `write_file` / `replace_in_file` / `apply_patch` (multi-file add/update/delete), plus `delete_file` / `move_file`; every change lands in REVIEW with per-hunk accept/undo, and `read_lints` lets the agent see type/syntax errors right after writing.
21
22
  - **Any OpenAI-compatible provider** — DeepSeek, Ollama, llama.cpp, vLLM and friends via `~/.luban/providers.json`. API keys go to SecretStorage, never to disk.
22
23
  - **Sessions that survive a reload** — history on disk, several concurrent tabs, a message queue while a turn is running, opt-in multi-turn memory. Sent prompts can be edited in place (`✎`): pressing Send truncates everything after it and reruns the turn with the edited text. The history popup has a search box: titles filter as you type, 2+ characters also scan message text, tool results and file references.
23
24
  - **Built for cheap multi-turn** — message layout is aligned to token prefix caching (typically 95%+ cache hits after the second turn); each turn shows input / output / cache / context usage, and a local ledger feeds a token dashboard.
25
+ - **Sub-agents with hard boundaries** — `explore` does read-only research in its own context; `delegate` is a writable worker with a *required* `paths` whitelist, and two workers in one batch cannot claim the same path. "Delegated" never means "done": a read-only reviewer is dispatched whenever a worker actually wrote a file. See [Delegation](#delegation-sub-agents-with-hard-boundaries) below.
24
26
  - **Extensible** — local stdio MCP servers, `SKILL.md` skills and in-process plugins join the same tool loop; Plan mode only sees tools declared read-only.
25
27
  - **Plugins without a protocol** — drop a `plugin.json` + `index.js` into `~/.luban/plugins` or `<workspace>/.luban/plugins` and its tools show up as `pl__<plugin>__<tool>` (off by default via `luban.plugins.enabled`; they run in-process, so the first load and any content change ask for confirmation).
26
28
  - **Cloud backup over WebDAV** — its own **☁ Backup** tab in the settings panel (next to General / Settings / Usage) takes a server URL, username and app password (the password lives in SecretStorage, never on disk) and uploads sessions, image attachments, plans, provider config and `mcp.json` to your own WebDAV server. You can inspect the remote manifest and restore by sha1 diff; files about to be overwritten are snapshotted into `~/.luban/backups/` first, and `providers.json` is merged rather than replaced (API keys never come back from the remote side).
@@ -30,6 +32,30 @@
30
32
  - **A Markdown preview you can live with** — the built-in VSCodium preview is awkward, so Luban ships its own: **Luban: Markdown preview** (or the M↓ markdown icon in the editor title bar — icons only there, the title bar has no room for words) opens a side-by-side panel with syntax-highlighted code blocks, local images resolved relative to the file, and one-way scroll sync from the editor. Math (`$…$`, `$$…$$`, `\(…\)`, `\[…\]`) is typeset with a locally vendored KaTeX — no CDN, no network — and the CLI terminal degrades the same formulas to readable plain text. It reuses the same renderer as the chat panel and the same highlighter as the CLI terminal — one set of rules, three surfaces.
31
33
  - **Status-bar light** — one line in the status bar: `(o.o) run_command npm test`. The little carpenter's ASCII face plus what the agent is doing right now (thinking / writing / running a tool / waiting / done / error) — the same face you see in the terminal. Hover for the full picture of this turn, click to open the panel, and it falls asleep (`-_-`) when idle for a while. Turn it off with `luban.statusBar.enabled`.
32
34
 
35
+ ## Delegation: sub-agents with hard boundaries
36
+
37
+ Two kinds of sub-agent, and the only difference that matters is whether they can write.
38
+
39
+ - **`explore`** — read-only research in its own context. It searches, reads files and resolves call chains, then returns a conclusion. It cannot edit, cannot ask questions, and it ends when the work is done. Use it when you do not yet know where the change belongs.
40
+ - **`delegate`** — a writable worker for a non-overlapping set of files, able to run in parallel with other delegates. `paths` (the write whitelist) is required.
41
+
42
+ What makes this more than "spawn another loop":
43
+
44
+ | Constraint | Where it lives |
45
+ |---|---|
46
+ | A delegate can only write inside its own `paths` | Code. Every write tool checks the target before touching disk; matching is on separator boundaries, so `a/srcx/` never passes for a whitelist of `a/src`. |
47
+ | Two delegates in one batch cannot claim overlapping paths | Code. Path leases are taken at dispatch time — and checked *before* the per-turn budget is spent, so a rejected dispatch does not burn quota. |
48
+ | A sub-agent's conclusion cannot flood the parent's context | Code. Conclusions are capped at 6000 characters (`SUBAGENT_RESULT_MAX`) and a longer one is suffixed with an explicit note stating how many characters were dropped, instead of being silently cut. |
49
+ | "Delegated" never means "done" | `luban.agent.reviewAfterDelegate` (on by default) dispatches a read-only reviewer whenever the worker actually wrote a file. It is not a prompt instruction: turn the setting off and the request is simply not sent. |
50
+
51
+ Per turn the main loop may dispatch at most **4** sub-agents (`explore` + `delegate` share one budget; the reviewer comes out of the same budget), with **2** running in parallel by default (`luban.agent.subagentParallel`) and **24** rounds each (`luban.agent.subagentRounds`). `luban.agent.delegateModels` pins a different model per delegation when a task is cheap enough for a smaller one.
52
+
53
+ **Roles live on disk.** `.luban/agents/*.md` declares `name` / `description` / `model` / `tools` / `rounds` in frontmatter, and the body is the prompt. Roles are read-only by construction: `tools` must be a subset of the read-only tool set, and naming `write_file` there makes the role **fail to load** rather than silently granting it. A malformed file is skipped with one audit line and never takes the other roles down with it.
54
+
55
+ **Parallel writes need separate trees.** `luban.agent.worktreeDeliver` (off by default) gives each task its own git worktree and delivers a **branch** — no merge, no push, undo is deleting the branch. Lease exclusivity relaxes from "same workspace" to "same tree", so two workers touching the same-named file in different trees no longer block each other. If the repo is dirty, no tree is created and the task falls back to editing in place instead of being blocked.
56
+
57
+ **What a sub-agent is not.** There is no agent-to-agent chat. The coordinator keeps the shared hubs — `package.json`, lockfiles, public entry points and types — out of delegated `paths` and finishes those itself. Sub-agents exist to isolate context, not to negotiate.
58
+
33
59
  ## CLI
34
60
 
35
61
  This package also ships the `luban` command — a headless entry point that reuses the extension's agent tool loop (same `~/.luban/providers.json` config).
@@ -46,6 +72,8 @@ After a CLI-only install, run `luban config` (`luban init` is an alias) to write
46
72
 
47
73
  In agent mode, every write shows a unified diff and asks before touching disk (`--yes` skips the prompt). The old `--apply` flag is a deprecated alias kept for old scripts — `--agent` alone already enables writes, and `--apply` on its own no longer switches modes. `--yolo` is an alias for `--agent --yes` (enables writes **and** skips every confirm), for third-party hosts like Orca / Crush that pre-fill a permission-bypass flag; it is ignored when you explicitly ask for `--plan` / `--explore`. In interactive mode, `Enter` sends, `Ctrl-J` / `Alt+Enter` inserts a newline, `/` completes commands, `@` completes workspace paths, and `Esc` cancels the running turn. Run `luban --help` for all flags (`--model`, `--root`, `--json`, `--max-rounds`, …).
48
74
 
75
+ **Built-in browser and desktop control.** Both are off by default — in VS Code they are settings, and the CLI has no settings UI. Enable them per run with `--browser` / `--computer`, in the environment with `LUBAN_BROWSER=1` / `LUBAN_COMPUTER=1`, or persistently in `~/.luban/cli-settings.json` (same keys as VS Code, e.g. `{"browser.enabled": true}`; `--no-browser` wins over both). With `--browser` the model gets `open` / `snapshot` / `click` / `type` / `scroll` on a real Chromium — which is the difference between "the page says log in" and actually logging in, paginating and adding to cart: `web_fetch` only ever sees the unauthenticated HTML. Desktop control additionally needs a graphical session (`DISPLAY` or `WAYLAND_DISPLAY` plus `xdotool`); without one the tool is not listed at all instead of failing on first call. `HTTP(S)_PROXY` is honoured by the CLI's own fetches (`NODE_USE_ENV_PROXY`) and forwarded to Chromium as `--proxy-server`, with loopback added to `NO_PROXY`.
76
+
49
77
  Upgrade the CLI itself (reads npm `dist-tags`, then runs `npm i -g`):
50
78
 
51
79
  ```bash
package/README.zh.md CHANGED
@@ -19,7 +19,7 @@ VSCodium / VS Code 里的**侧边栏 AI 编码助手**:说人话 → 它改文
19
19
 
20
20
  **四个不一样的地方**
21
21
 
22
- - **审阅在编辑器里**:每写一个文件自动开出原生 diff,标题栏与两侧 CodeLens 逐块保留 / 撤销,聊天区只留一行摘要
22
+ - **审阅在编辑器里**:写入进侧栏摘要卡片,点「查看 diff」开原生 diff(`luban.review.autoOpenDiff` 默关,避免抢走聊天焦点);标题栏与两侧 CodeLens 逐块保留 / 撤销
23
23
  - **只读是真的只读**:Plan 模式下写文件的工具根本没注册,命令还要过一道只读校验,产出的计划落成 Markdown 文件,你改完再执行就按改后的走
24
24
  - **为省 token 而设计**:消息排布对齐前缀缓存(第 2 轮起通常 95%+ 命中),每轮显示输入 / 输出 / 缓存 / 上下文占用,另有本地账本与用量看板
25
25
  - **不挑模型**:任何 OpenAI 兼容端点(DeepSeek / Ollama / llama.cpp / vLLM…),API key 存 SecretStorage 不落盘
@@ -37,6 +37,7 @@ VSCodium / VS Code 里的**侧边栏 AI 编码助手**:说人话 → 它改文
37
37
  - 历史查询:会话弹层顶部有搜索框 —— 标题即时过滤,输入 2 个字以上连正文一起查(回答、工具结果、`@` 引用路径都能搜到),命中词高亮、命中行带一段摘要
38
38
  - 改历史:已发出的提问点气泡上的 `✎` 就能就地改,点「发送」自动截掉这条之后的记录并用改后的内容重新开跑一轮
39
39
  - 代码引用:`@` 选文件、`@` 选文件夹、`#` 引用编辑器选区;在编辑器里选中代码后,选区首行上方会直接浮出「加入聊天 / 加入新聊天」两枚 CodeLens(点一下即引用),也可右键「Add Selection to Luban Chat」(或 `Cmd/Ctrl+Alt+A`)插入带位置与行号的 `#selection 路径:起始-结束`,多次选区、跨文件都能叠加,发送时各自展开成一份引用,「Add Selection to Luban **New** Chat」则先开一个全新会话再插入并聚焦输入框,方便直接发第一条消息;资源管理器里右键文件 / 文件夹 →「Add File / Folder to Luban Chat」把 `@路径` / `@目录/` 插进当前会话,「Add File / Folder to Luban **New** Chat」则先开一个全新会话再插入并聚焦输入框,方便直接发第一条消息
40
+ - 现场引用:`@problems` 带上当前语言服务器诊断(error / warning,路径转成工作区相对),`@git` 带上当前分支与未提交改动(`@git staged` 换成暂存区口径),`@terminal` 带上最近几条集成终端命令与输出 —— 不用手动复制粘贴;三类都在 `@` 浮层里可选,同一条消息里只展开一次,取不到数据时明确说「没有」而不是编一段
40
41
  - 自动上下文:不写 `@` 也会把**本会话用过的文件**(`@` 引用过 / 带选区带过)的代码附在消息末尾(有选区给选区,否则光标附近约 200 行);别的会话正在看的文件不会被带进来,新会话首轮要带文件请用 `@` 或选中一段
41
42
  - 代码检索:`search_code` 本地词法索引 + BM25,返回「路径:行号: 命中行」,大仓库不用再 `list_files` 全量扫
42
43
  - Tab 补全:DeepSeek FIM 续写光标处代码,`Tab` 接受(默认关闭,命令面板一键开)
@@ -48,6 +49,7 @@ VSCodium / VS Code 里的**侧边栏 AI 编码助手**:说人话 → 它改文
48
49
  - 外部工具:本地 stdio MCP server 的工具并入同一个工具循环(`mcp__<server>__<tool>`),Plan 模式只放行声明只读的工具;设置面板里**独立一个「🔌 MCP」分区**,直接看每个 server 的状态 / 工具清单,点开关就能启停(先选写全局还是项目 `mcp.json`),不用手改 JSON
49
50
  - 本地插件:`~/.luban/plugins` 与 `<工作区>/.luban/plugins` 里放一个 `plugin.json` + `index.js`,它的工具就以 `pl__<plugin>__<tool>` 进同一个工具循环 —— 不用起进程、不用写协议(默认关闭,设置 `luban.plugins.enabled=true`;插件跑在扩展进程内,首次加载与内容变更都会先确认)
50
51
  - 技能:扫描 `~/.luban/skills`、`~/.claude/skills`、`~/.cursor/skills`、`~/.agents/skills` 与项目同名目录,把 `SKILL.md` 的 name/description 注入系统提示,模型需要时用 `read_skill` 读全文
52
+ - 有硬边界的子代理:`explore` 在自己上下文里只读调研,`delegate` 是可写 worker —— `paths`(写入白名单)必填,同批两个委托不能抢同一路径;「派完」也不等于「完成」,worker 真写了文件会自动派一个只读审查员。见下方[委派:有硬边界的子代理](#委派有硬边界的子代理)
51
53
  - 审阅改动:写完自动在编辑器开出 diff(标题栏「全部保留 / 全部撤销」+ 两侧 hunk 逐块 CodeLens)+ 行内 diff 高亮 + 侧边栏摘要卡片
52
54
  - 云端备份(WebDAV):设置面板里**独立一个「☁ 云端备份」分区**(与常规 / 设置 / 用量并列),填服务器地址 / 用户名 / 应用专用密码(密码进 SecretStorage),一键把会话、图片附件、计划、provider 配置与 `mcp.json` 传到自己的 WebDAV,也能查看远端清单并按 sha1 差异恢复回来(覆盖前先快照到 `~/.luban/backups/`,`providers.json` 只合并不覆盖、key 不回落)
53
55
 
@@ -55,6 +57,30 @@ VSCodium / VS Code 里的**侧边栏 AI 编码助手**:说人话 → 它改文
55
57
 
56
58
  **和原生 chat 的关系**:没有关系。它不注册 chatAgent、不占用原生聊天窗口、不需要 `@luban`,VS Code 怎么改 chat 层都影响不到它。
57
59
 
60
+ ## 委派:有硬边界的子代理
61
+
62
+ 子代理只有两种,唯一的区别是**能不能写**。
63
+
64
+ - **`explore`** — 在自己上下文里做只读调研:搜索、读文件、确认调用链,只把结论交回来。不能改文件、不能提问,用完即结束。适合「还不知道改动该落在哪」的时候。
65
+ - **`delegate`** — 可写 worker,负责一组互不重叠的文件,可与其它 delegate 并行。`paths`(写入白名单)必填。
66
+
67
+ 它不只是「再开一个循环」,差别在这四条:
68
+
69
+ | 约束 | 落在哪里 |
70
+ |---|---|
71
+ | delegate 只能写自己 `paths` 里的路径 | 代码层:每个写工具落盘前校验目标路径;按分隔符边界匹配,白名单给 `a/src` 时 `a/srcx/` 不会被误放行 |
72
+ | 同批两个 delegate 的路径不得相交 | 代码层:派发时先取路径租约,**先于**额度扣减 —— 被拒的委托不会白烧配额 |
73
+ | 子代理的结论不能撑爆父轮上下文 | 结论上限 6000 字符(`SUBAGENT_RESULT_MAX`),超长按上限截断并显式标注「已截断 N 字符」,不静默丢弃 |
74
+ | 「派完」不等于「完成」 | `luban.agent.reviewAfterDelegate`(默认开)在 worker **真的写了文件**后派只读审查员;这不是提示词要求 —— 关掉这个设置,那次请求根本不会发出 |
75
+
76
+ 主循环每轮最多派 **4** 个子代理(`explore` 与 `delegate` 共用一份额度,审查员也从同一份额度里扣),默认 **2** 个并行(`luban.agent.subagentParallel`),每个 **24** 回合(`luban.agent.subagentRounds`)。`luban.agent.delegateModels` 可以按任务换更小的模型。
77
+
78
+ **角色是磁盘上的东西。** `.luban/agents/*.md` 的 frontmatter 声明 `name` / `description` / `model` / `tools` / `rounds`,正文即提示词。角色**在构造上就是只读的**:`tools` 只能是只读工具集的子集,写了 `write_file` 会让该角色**加载失败**,而不是悄悄把写权限给它。解析失败只跳过那一个文件并记一条审计,不会连累其它角色。
79
+
80
+ **并行写需要各写各的树。** `luban.agent.worktreeDeliver`(默认关)给每个任务一棵独立 git worktree,交付物是**分支**:不 merge、不推远端,撤销 = 删掉分支。租约互斥的粒度从「同工作区」放宽到「同树」,两个 worker 在不同树里改同名文件不再互相挡路。仓库不干净时不建树,回落到就地改,而不是把任务卡住。
81
+
82
+ **子代理不是什么。** 没有 agent 之间自由对话。协调者把共享枢纽 —— `package.json`、锁文件、公共入口与类型 —— 排在委托 `paths` 之外,自己收尾。子代理的作用是隔离上下文,不是协商。
83
+
58
84
  ## CLI
59
85
 
60
86
  本包同时提供 `luban` 命令 —— 无头任务入口,复用扩展的 agent 工具循环(共用 `~/.luban/providers.json` 配置)。
@@ -71,6 +97,8 @@ luban # 交互多轮(需要 TTY
71
97
 
72
98
  agent 模式下每次落盘前会显示 unified diff 并逐次确认(`--yes` 可跳过确认)。旧的 `--apply` 已废弃,只是为兼容旧脚本保留的别名:`--agent` 本身就放开写,单独用 `--apply` 不再切模式(仍是只读)。`--yolo` 是 `--agent --yes` 的别名(放开写**且**不再逐次确认),供 Orca / Crush 这类会预填权限绕过 flag 的第三方宿主使用;若同时显式给了 `--plan` / `--explore`,它会被忽略(取保守一方)。交互模式里 `Enter` 发送、`Ctrl-J` / `Alt+Enter` 换行,输入 `/` 补全命令、`@` 补全文件,跑动中按 `Esc` 取消本轮。全量参数见 `luban --help`(`--model` / `--root` / `--json` / `--max-rounds` 等)。
73
99
 
100
+ **内建浏览器与桌面操作。** 两者默认关闭 —— VS Code 里是设置项,而 CLI 没有设置面板。临时打开用 `--browser` / `--computer`,写进环境用 `LUBAN_BROWSER=1` / `LUBAN_COMPUTER=1`,想长期生效就写 `~/.luban/cli-settings.json`(键名与 VS Code 一致,例如 `{"browser.enabled": true}`;`--no-browser` 优先级最高,可覆盖前两者)。开了 `--browser`,模型才拿到 `open` / `snapshot` / `click` / `type` / `scroll` 这套真浏览器动作 —— 这正是「页面要我登录」和「能登录、翻页、加购物车」的区别:`web_fetch` 永远只拿得到未登录的 HTML。桌面操作还要求有图形会话(`DISPLAY` 或 `WAYLAND_DISPLAY` + `xdotool`),没有时工具直接不进清单,而不是等模型调了才报错。CLI 自己的 fetch 会走 `HTTP(S)_PROXY`(`NODE_USE_ENV_PROXY`),浏览器侧同一地址转成 `--proxy-server`,本机地址自动进 `NO_PROXY`。
101
+
74
102
  CLI 自己也能升级(查 npm `dist-tags` → `npm i -g`):
75
103
 
76
104
  ```bash