Repository navigation
fix: /status 权限行改传活 Session(宿主 current(session) 契约自 0.1.2-alpha.2 起变更 → 整行静默消失) - #5
Merged
Conversation
Since dsh 0.1.2-alpha.2 the host folds `sessionProjections.stateOf(session, "permissions")`, so `current()` takes a Session — not an event array. This bridge still passed `sessionEvents(agent.session)`, which makes the host throw and `safeCurrent()` silently swallow it: the `/status` permission row never rendered, and `/perm` list lost its "current session" marker. - ops.ts: drop `SessionEventLike`; `current(session: unknown)` now documents the host contract and the exact failure symptom. - bridge.ts: `safeCurrent()` passes `agent.session` (the event-array hop is gone); exceptions still degrade to `undefined`. - status-colors.test.ts: the mock enforces the host contract (an event array throws) and records the argument; a regression case asserts the live Session is passed. Verified with the repo's own gates on Node 22: `npm run build` clean, `npm test` 421/421 passing.
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.
症状
/status的「• 权限:」行在受支持的宿主上永不出现,且无任何报错;/perm list的「◀ 当前会话」标记同样失效(两处都走同一个safeCurrent())。根因:宿主契约已换,本仓调用形状没跟上
packages/interaction/permission-presets/src/index.ts:308是current(session: Session): string;内部permissionState(session)(同文件:295-299)走ctx.sessionProjections.stateOf(session, "permissions"),必须传 Session,否则抛permission: permissions session projection is not registered。1a72ae202a(2026-08-19,refactor(session): migrate host state reads to projections)从「事件数组」改为「Session」,随 tagdsh-v0.1.2-alpha.2起生效(0.1.2-alpha.2/3/4/5、rc.1、0.1.3-alpha.1/2、0.1.5-alpha.1/2、0.1.5-rc.1 全含)。src/dsh/ops.ts:174仍声明current(events: readonly SessionEventLike[]),src/bridge/bridge.ts:3389-3396的safeCurrent()传的是sessionEvents(agent.session)。current(<数组>)→stateOf(<数组>, "permissions")→session-projection/src/index.ts:615-629的cellFor()读session.header/session.inheritedEventCount/session.snapshotEvents()→ TypeError → 被safeCurrent()的 try/catch 吞掉 → 返回undefined→ 渲染处...(permission ? ["• 权限: …"] : [])(bridge.ts:3494-3496)整行不输出。engines.dsh = ">=0.1.5-rc.1",即受支持的宿主 100% 命中该路径。改法(3 个文件)
src/dsh/ops.ts:删除SessionEventLike;签名改为current(session: unknown),注释写明宿主契约与失败症状。src/bridge/bridge.ts:safeCurrent()直接传agent.session(去掉事件数组那一跳);异常仍降级为undefined,使「会话没有权限投影」保持原静默行为。tests/status-colors.test.ts:mock 按宿主契约收紧(收到事件数组即抛错)并记录实参;新增回归用例断言current()收到的是活 Session。验证(本仓原生门禁,Node 22)
npm run build通过;npm test421/421 全绿(33 文件)。src/还原成改动前、仅保留新测试 →tests/status-colors.test.ts2 failed(新增用例 + 原「权限 danger-*」用例),证明该测试确实复现了症状而不是空跑。兼容性说明(请你定夺)
按现
engines(>=0.1.5-rc.1)直接切 Session 形状即可,无需回退。如果你仍想覆盖0.1.2-alpha.2之前的宿主,可改成try { current(session) } catch { current(events) }的双形状回退——我倾向不保留(单一契约更干净),这一条听你的。(本 PR 只动这一处形状,未夹带任何格式化或无关改动。)