Compare commits
No commits in common. "f87055b75b76180824e52a8c8c7946c12d3066fb" and "5c80061f08cec764131300008d4d5396612936a3" have entirely different histories.
f87055b75b
...
5c80061f08
|
|
@ -1,10 +1,5 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 1.0.2 — 2026-11-14
|
|
||||||
|
|
||||||
- 修复 host 插件在干净 profile 里激活失败(`1 entry did not activate`):`apply()` 先读 `ctx.permissionPresets` 再判断,而 Cordis 对未在 `inject` 声明的服务读取会直接抛 `cannot get property "permissionPresets" without inject`,于是 `else` 里的 `ctx.inject` 兜底永远走不到。现在统一用 `ctx.inject(['permissionPresets', 'agents'], …)` 挂载自动审查监听,服务缺失时插件照常激活,服务就绪后再挂载;reveal / metrics 路由不受影响。
|
|
||||||
- 新增 `tests/host-activation.test.ts`:用真实 Cordis `Context` 在只提供 `webServer` 的干净环境加载 host 入口,断言 fiber 为 `ACTIVE`,并验证服务就绪后空白会话仍会被切到 `auto`。
|
|
||||||
|
|
||||||
## 1.0.1 — 2026-11-13
|
## 1.0.1 — 2026-11-13
|
||||||
|
|
||||||
- 恢复并完善「默认打开模式为自动审查(`auto`)」功能:
|
- 恢复并完善「默认打开模式为自动审查(`auto`)」功能:
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,8 @@ function apply(ctx, options) {
|
||||||
const flags = options?.flags ?? loadFlags();
|
const flags = options?.flags ?? loadFlags();
|
||||||
log.info("[dsh-better-chat] loaded", { readerEnabled: flags.readerEnabled });
|
log.info("[dsh-better-chat] loaded", { readerEnabled: flags.readerEnabled });
|
||||||
const anyCtx = ctx;
|
const anyCtx = ctx;
|
||||||
if (typeof anyCtx.inject === "function") anyCtx.inject(["permissionPresets", "agents"], (childCtx) => {
|
if (anyCtx.permissionPresets && anyCtx.agents) mountAutoReviewListeners(anyCtx);
|
||||||
|
else if (typeof anyCtx.inject === "function") anyCtx.inject(["permissionPresets", "agents"], (childCtx) => {
|
||||||
mountAutoReviewListeners(childCtx);
|
mountAutoReviewListeners(childCtx);
|
||||||
});
|
});
|
||||||
if (!flags.readerEnabled) {
|
if (!flags.readerEnabled) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "dsh-better-chat",
|
"name": "dsh-better-chat",
|
||||||
"version": "1.0.2",
|
"version": "1.0.1",
|
||||||
"description": "DSH 聊天增强插件:审批回车批准 / Esc 拒绝、权限 UI、插件商店更新,以及 reading view(合并自 dsh-better-display)",
|
"description": "DSH 聊天增强插件:审批回车批准 / Esc 拒绝、权限 UI、插件商店更新,以及 reading view(合并自 dsh-better-display)",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
11
src/host.ts
11
src/host.ts
|
|
@ -139,15 +139,10 @@ export function apply(ctx: Context, options?: { readonly flags?: Flags }): void
|
||||||
const flags = options?.flags ?? loadFlags();
|
const flags = options?.flags ?? loadFlags();
|
||||||
log.info('[dsh-better-chat] loaded', { readerEnabled: flags.readerEnabled });
|
log.info('[dsh-better-chat] loaded', { readerEnabled: flags.readerEnabled });
|
||||||
|
|
||||||
// Cordis throws when a service is read before it is declared in `inject`
|
|
||||||
// ("cannot get property \"permissionPresets\" without inject"), so never probe the
|
|
||||||
// services on the context directly: that read aborted apply() on a clean
|
|
||||||
// profile and the host reported "1 entry did not activate". A scoped
|
|
||||||
// `ctx.inject` mounts the listeners once both services exist and unmounts
|
|
||||||
// them when they go away; a plain object context (unit tests) has no inject
|
|
||||||
// and is simply skipped.
|
|
||||||
const anyCtx = ctx as any;
|
const anyCtx = ctx as any;
|
||||||
if (typeof anyCtx.inject === 'function') {
|
if (anyCtx.permissionPresets && anyCtx.agents) {
|
||||||
|
mountAutoReviewListeners(anyCtx);
|
||||||
|
} else if (typeof anyCtx.inject === 'function') {
|
||||||
anyCtx.inject(['permissionPresets', 'agents'], (childCtx: any) => {
|
anyCtx.inject(['permissionPresets', 'agents'], (childCtx: any) => {
|
||||||
mountAutoReviewListeners(childCtx);
|
mountAutoReviewListeners(childCtx);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -243,10 +243,7 @@ test('host auto-review default: switches fresh blank sessions and skips used/sub
|
||||||
}
|
}
|
||||||
const agents = { list: () => [{ session: session1 }] }
|
const agents = { list: () => [{ session: session1 }] }
|
||||||
|
|
||||||
// Cordis 只在 inject 声明的服务可用时才把带服务的上下文交给回调;这里同步调用
|
applyHost({
|
||||||
// 即可复现实机行为。直接读 ctx.permissionPresets 会在真实 Context 上抛
|
|
||||||
// `cannot get property "permissionPresets" without inject`。
|
|
||||||
const ctxStub: any = {
|
|
||||||
permissionPresets,
|
permissionPresets,
|
||||||
agents,
|
agents,
|
||||||
effect(run: () => void) { run() },
|
effect(run: () => void) { run() },
|
||||||
|
|
@ -254,9 +251,7 @@ test('host auto-review default: switches fresh blank sessions and skips used/sub
|
||||||
listeners.set(event, fn)
|
listeners.set(event, fn)
|
||||||
return () => { listeners.delete(event) }
|
return () => { listeners.delete(event) }
|
||||||
},
|
},
|
||||||
inject(_deps: string[], callback: (child: any) => void) { callback(ctxStub) },
|
} as any, { flags: { readerEnabled: false } })
|
||||||
}
|
|
||||||
applyHost(ctxStub, { flags: { readerEnabled: false } })
|
|
||||||
|
|
||||||
// Before 'auto' is registered in permissionPresets.names, nothing is switched yet.
|
// Before 'auto' is registered in permissionPresets.names, nothing is switched yet.
|
||||||
assert.deepEqual(setCalls, [])
|
assert.deepEqual(setCalls, [])
|
||||||
|
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
import assert from 'node:assert/strict'
|
|
||||||
import { test } from 'vitest'
|
|
||||||
import { Context } from '@deepseek-ai/cordis'
|
|
||||||
import * as host from '../src/host.js'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Regression: dsh-better-chat 1.0.1 read `ctx.permissionPresets` before declaring
|
|
||||||
* it in `inject`. Cordis throws `cannot get property "permissionPresets" without
|
|
||||||
* inject` on that read, so a clean profile (§ only provides webServer) failed the
|
|
||||||
* host activation with "1 entry did not activate". The plugin must activate and
|
|
||||||
* leave the auto-review wiring to a scoped `ctx.inject` callback.
|
|
||||||
*/
|
|
||||||
function createContext(services: Record<string, unknown>): Context {
|
|
||||||
const ctx = new Context()
|
|
||||||
for (const [name, value] of Object.entries(services)) {
|
|
||||||
ctx.provide(name as never)
|
|
||||||
ctx.set(name as never, value as never)
|
|
||||||
}
|
|
||||||
return ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
test('host plugin activates when permissionPresets/agents are absent', async () => {
|
|
||||||
const ctx = createContext({ webServer: { register: () => () => undefined } })
|
|
||||||
const fiber = ctx.plugin(host as never)
|
|
||||||
await fiber
|
|
||||||
assert.equal(fiber.state, 2, 'fiber should be ACTIVE, not FAILED/PENDING')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('host plugin wires the auto-review default through inject', async () => {
|
|
||||||
const setCalls: Array<[string, string]> = []
|
|
||||||
const ctx = createContext({
|
|
||||||
webServer: { register: () => () => undefined },
|
|
||||||
permissionPresets: {
|
|
||||||
names: ['read-only', 'auto'],
|
|
||||||
current: () => 'workspace-write',
|
|
||||||
set: (session: { id: string }, name: string) => setCalls.push([session.id, name]),
|
|
||||||
},
|
|
||||||
agents: {
|
|
||||||
list: () => [{
|
|
||||||
session: { id: 'fresh-1', header: { id: 'fresh-1' }, snapshotEvents: () => [] },
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
const fiber = ctx.plugin(host as never)
|
|
||||||
await fiber
|
|
||||||
assert.equal(fiber.state, 2)
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 50))
|
|
||||||
assert.deepEqual(setCalls, [['fresh-1', 'auto']], 'blank top-level session should default to auto review')
|
|
||||||
})
|
|
||||||
Loading…
Reference in New Issue