feat: adapt to DSH 0.1.7-alpha.1 and yield the read-only previews

DSH 0.1.7-alpha.1 is 1299 commits past 0.1.6-alpha.2 and rewrites four
contracts this plugin was built on. The peer floor moves to
^0.1.7-alpha.1 (semver's prerelease rule means ^0.1.6-alpha.2 can never
match a 0.1.7 prerelease); 0.1.6-alpha.2 and earlier stay on v0.19.1.
Released as 0.21.0-alpha.1 (dist-tag alpha).

Hard breaks:
- dsh-settings was rewritten: register(ns, schema) is gone, a form is
  addressed by the plugin row's Loader entry id and read from the
  module's exported Config. The preferences are merged into Config and
  marked volatile — which requires DSH's own schemastery, because only
  that build wraps a volatile field in the cosmokit reference the
  loader's volatile commit walks. With the public package a settings
  write reports success and revision 1 while the effective value never
  changes.
- ui-primitives renamed its whole icon family (IconXxx14/16 ->
  IconXxxRegular/Medium): 26 imported symbols, 17 files. The failing
  mode is render-time, not load-time. Five call sites that relied on the
  old 14px default now pass size={14} explicitly.
- Session format v4 rejects source.kind === 'plugin'; the side-chat
  boundary injection now writes plugin:dsh-better-sidebar, the same kind
  DSH's own v3->v4 migration produces, so historical threads survive.
  Tool results moved to role 'tool' with top-level content/isError; all
  four parsers accept both shapes.
- The client session snapshot dropped subagentsByParent/jobsBySession
  and the on-demand subagent-catalog observation API. The Tasks page
  reads projectionsBySession and a new jobs.list route.

Yields and convergence:
- The read-only previews go to DSH's documentpreview (Office->PDF, a
  spreadsheet worker, zoom, per-directory refresh); editor.canOpen
  refuses those 26 extensions. Markdown, HTML (with its sandbox
  switches) and the editable code buffer stay.
- The host browser kind is desktop-profile-only now, so the web e2e
  lanes expect no browser entry and assert its absence.
- Link takeover claims only urlTarget links and passes the rest to the
  host, fixing a regression from the 0.1.6 round: the fallback pointed
  at a 'browser' type the plugin no longer registers, so http links in
  its own markdown did nothing.

Also fixed, found along the way:
- The file tree refreshes live (new directory watch over the plugin's
  own socket), since the plugin owns the `files` kind.
- ctx.sessions.list has no `current` field at either tag; the three
  readers were dead. They now use ctx.sidebarRight.mounted.
- package.json.files was missing lib/client-locale.js.
- Two genuinely dead call sites: sessions.openSubagent/open/
  refreshSubagents do not exist on the current baseline, so the
  topology click, the jump-back and the retry were all no-ops.
- The test harness window shim lacked addEventListener, which the 0.1.7
  primitives call at module-evaluation time; and the e2e token exchange
  needs Playwright's request stack, not Node's fetch.
This commit is contained in:
Menghuan1918 committed 2026-09-22 17:09:08 +08:00
1 parent de99fd4cfb
commit 6586e3e2d3
96 files changed
+4567 -2080

No files matched your search

+52 -23
View File
@@ -1,9 +1,10 @@
import { describe, expect, it } from 'vitest'
import {
collectBranchIds, countSubagentDescendants, detectNewDirectSubagent,
countSubagentDescendants, detectNewDirectSubagent,
directSubagentCount, rootAncestor,
} from '../src/client/subagent-detect.ts'
import type { SidebarSessionList, SidebarSubagentCatalog } from '../src/context-types.ts'
import { isKnownLeaf, subagentCatalogs } from '../src/client/subagent-catalog.ts'
import type { SidebarSessionList, SidebarSubagentCatalogEntry } from '../src/context-types.ts'
describe('subagent detection over the sessions list feed', () => {
/** A list snapshot carrying the given direct subagent children of `parent`. */
@@ -22,7 +23,7 @@ describe('subagent detection over the sessions list feed', () => {
running: running.includes(id),
}
}
return { current: parent, byId }
return { byId }
}
it('counts only the direct subagent children of the given session', () => {
@@ -87,9 +88,8 @@ describe('subagent detection over the sessions list feed', () => {
expect(directSubagentCount(byId, 'p1')).toBe(1)
expect(countSubagentDescendants(byId, 'p1')).toEqual({ count: 1, runningCount: 0 })
// A side thread appearing under an empty session never trips 0 → N.
const before: SidebarSessionList = { current: 'p2', byId: { p2: { id: 'p2', displayTitle: 'P2' } } }
const before: SidebarSessionList = { byId: { p2: { id: 'p2', displayTitle: 'P2' } } }
const after: SidebarSessionList = {
current: 'p2',
byId: {
p2: { id: 'p2', displayTitle: 'P2' },
s2: { id: 's2', displayTitle: 'Side: New thread', origin: 'subagent', parentId: 'p2' },
@@ -106,9 +106,8 @@ describe('subagent detection over the sessions list feed', () => {
// AUTO_OPEN_DEBOUNCE_MS and re-evaluates the ORIGINAL baseline against
// the live snapshot; once the title frame has landed the same baseline
// yields no trigger. These two assertions pin exactly that dependency.
const baseline: SidebarSessionList = { current: 'p2', byId: { p2: { id: 'p2', displayTitle: 'P2' } } }
const baseline: SidebarSessionList = { byId: { p2: { id: 'p2', displayTitle: 'P2' } } }
const firstFrame: SidebarSessionList = {
current: 'p2',
byId: {
p2: { id: 'p2', displayTitle: 'P2' },
s2: { id: 's2', displayTitle: 'DSH-better-sidebar', origin: 'subagent', parentId: 'p2' },
@@ -116,7 +115,6 @@ describe('subagent detection over the sessions list feed', () => {
}
expect(detectNewDirectSubagent(baseline, firstFrame, 'p2')).toBe(true) // the race
const settled: SidebarSessionList = {
current: 'p2',
byId: {
p2: { id: 'p2', displayTitle: 'P2' },
s2: { id: 's2', displayTitle: 'Side: New thread', origin: 'subagent', parentId: 'p2' },
@@ -142,21 +140,52 @@ describe('subagent detection over the sessions list feed', () => {
expect(rootAncestor(byId, undefined)).toBeUndefined()
})
it('collects every catalog branch of the topology, cycle-safe', () => {
const child = (id: string, hasChildren: boolean): SidebarSubagentCatalog['entries'][number] => ({
kind: 'child', id, activity: 'inactive', hasChildren, mode: 'one-shot',
it('derives branch disclosure from the child\'s own projection catalog', () => {
// DSH 0.1.7's catalog row is `{id, createdAt, mode, label?}` — the 0.1.6
// `hasChildren` boolean is gone, so the topology infers it from the
// child's OWN `subagentCatalog` projection: a child whose catalog loaded
// EMPTY is a known leaf, and everything else keeps its level open.
const row = (id: string, over: Partial<SidebarSubagentCatalogEntry> = {}): SidebarSubagentCatalogEntry => ({
id, createdAt: 1_000, mode: 'one-shot', ...over,
})
const catalogs: Record<string, SidebarSubagentCatalog> = {
root: { entries: [child('a', true), child('b', false)], parentAvailable: true, state: 'ready', error: null },
a: { entries: [child('c', false)], parentAvailable: true, state: 'ready', error: null },
}
expect(collectBranchIds(catalogs, 'root')).toEqual(['a'])
expect(collectBranchIds(catalogs, undefined)).toEqual([])
// A cycle terminates (each branch id collected at most once, no hang).
const cyclic: Record<string, SidebarSubagentCatalog> = {
root: { entries: [child('a', true)], parentAvailable: true, state: 'ready', error: null },
a: { entries: [child('root', true)], parentAvailable: true, state: 'ready', error: null },
}
expect(collectBranchIds(cyclic, 'root')).toEqual(['a', 'root'])
const catalogs = subagentCatalogs({
root: {
values: { subagentCatalog: [row('branch'), row('leaf')] },
state: 'ready',
error: null,
},
// The branch has a child of its own; the leaf's catalog loaded empty.
branch: {
values: { subagentCatalog: [row('grand', { mode: 'continuable', label: 'Grand' })] },
state: 'ready',
error: null,
},
leaf: { values: { subagentCatalog: [] }, state: 'ready', error: null },
})
expect(catalogs.root?.entries.map(entry => entry.id)).toEqual(['branch', 'leaf'])
expect(catalogs.root?.state).toBe('ready')
expect(isKnownLeaf(catalogs, 'leaf')).toBe(true)
expect(isKnownLeaf(catalogs, 'branch')).toBe(false)
// A catalog that has not landed (absent from the snapshot, idle without a
// value, still loading, or failed) is NOT a known leaf: the level stays
// reserved instead of flapping shut.
expect(isKnownLeaf(catalogs, 'not-in-snapshot')).toBe(false)
const pending = subagentCatalogs({
idle: { values: {}, state: 'idle', error: null },
loading: { values: {}, state: 'loading', error: null },
failed: { values: {}, state: 'error', error: { code: 'boom', message: 'boom' } },
cached: { values: { subagentCatalog: [row('a')] }, state: 'idle', error: null },
})
expect(pending.idle).toMatchObject({ state: 'loading', entries: [] })
expect(isKnownLeaf(pending, 'idle')).toBe(false)
expect(isKnownLeaf(pending, 'loading')).toBe(false)
// A failed catalog keeps the level open (there may be children) and
// carries the failure the retry row renders.
expect(pending.failed).toMatchObject({ state: 'error', error: { message: 'boom' } })
expect(isKnownLeaf(pending, 'failed')).toBe(false)
// An idle row WITH a value is the persisted checkpoint's catalog.
expect(pending.cached).toMatchObject({ state: 'ready', entries: [expect.objectContaining({ id: 'a' })] })
// A host with no projection store at all leaves every catalog empty.
expect(subagentCatalogs(undefined)).toEqual({})
})
})