Repository navigation
Conversation
rtk records usage in its HOME ledger, which a workspace-write sandbox cannot write, so rtk gain stayed empty. The executors now inject RTK_DB_PATH pointing at the session workspace by default (<workspace>/.rtk/history.db) unless rtkTracking is false, and rtkDbPath accepts an absolute or workspace-relative override. The new bash-rtk-command bundle row registers /rtk, which prints the current workspace ledger from rtk gain.
Add a web-only bash-rtk-stats row exposing the read-only GET /rtk/stats endpoint (rtk gain JSON summary with a 10s cache, and &detail=1 for the text report) and a browser half declared through dsh.client that registers an rtk savings pill in conversation.composer.dock. The pill polls the route, opens the ledger detail in a native dialog (close button, backdrop click and Escape all dismiss it), and hides itself when there is no ledger data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
装了这个插件之后,命令输出确实被 rtk 压缩了,但
rtk gain一直是空的,一条记录都没有。问题出在账本的位置:rtk 把 history.db 放在
~/.local/share/rtk/,而 DSH 的 workspace-write 沙箱只允许写会话工作区、/tmp和平台临时目录。Linux 上就是用 bwrap 把根目录挂成只读,再把工作区单独 bind 成可写,HOME 落在只读那边。rtk 每次往 HOME 记账都会失败,而且它不吭声,所以压缩照常、账本永远空着。界面上也没有地方能直接看到省了多少 token。这个 PR 把账本放进会话工作区,再补上两个查看入口:聊天里的
/rtk命令,和输入框下方的一颗统计徽章。Reproduction
cordis.patch.yml改成bash-sandbox: disabled: true、bash-rtk: disabled: false。git status,输出会变成 rtk 的紧凑格式。rtk gain。~/.local/share/rtk/history.db看看有没有新记录。Expected Behavior
rtk gain能看到当前工作区跑了多少条命令、省了多少 token。界面上最好也能直接看到,不用来回敲命令。Actual Behavior
在 DSH 里跑
rtk gain直接报错:也见过
Read-only file system (os error 30)。在普通终端里打开数据库没问题,但里面只有终端跑过的命令;DSH 里被插件包装执行的命令一条都没记上。Environment
Additional Context
DSH 沙箱的可写根写死成
[workspaceRoot, /tmp, os.tmpdir()],sandbox-policy也只有mode/workspaceRoot两个配置,没有地方能额外加一个可写目录,所以我选择把账本挪进工作区。具体改了这些:
RTK_DB_PATH=<workspace>/.rtk/history.db。新增两个配置:rtkTracking默认开,关掉就不注入;rtkDbPath可以指定绝对路径或相对工作区的路径。外部环境里已经设了RTK_DB_PATH的话以它为准;read-only 和 danger-full-access 两种模式保持原样。/rtk命令(bash-rtk-command行),在聊天里直接打印当前工作区的账本。bash-rtk-stats行,提供只读的GET /rtk/stats:默认返回rtk gain --format json的摘要,缓存 10 秒,加&detail=1返回文本报告。前端半侧(client/index.js,通过dsh.client声明)在conversation.composer.dock上注册一颗rtk统计徽章,tooltip 里是节省的数字,点开能看账本明细,没有数据就不显示。弹窗可以用右上角 ×、点背景或 Esc 关闭。验证过的:
tsc(src 和 tests)、43 个 vitest 用例、tsdown构建、node --check client/index.js、dsh --profile web --help冷启动都通过;本机起 web 后用curl 'http://127.0.0.1:3080/rtk/stats?sessionId=<id>'能拿到{"ok":true,"summary":{...}}。注意前端 bundle 是 host 启动时快照的,改完
client/index.js需要重启dsh web并刷新页面才会生效。几个已知限制:账本按工作区各存一份,不会跨工作区汇总;
/rtk和/rtk/stats目前只认RTK_DB_PATH和默认路径,还没读执行器配置里的rtkDbPath。同类插件的做法可以对照
@viogus/dsh-rtk(给 macOS Seatbelt 打补丁,放开 rtk 状态目录)和@wingsbutterfly/dsh-rtk(给改写后的命令注入RTK_DB_PATH)。