feat: slash system / input service / agent scope

This commit is contained in:
imccyu
2026-07-27 03:17:52 +08:00
parent f3a4833dbf
commit a27be43ac1
210 changed files with 15969 additions and 2213 deletions

View File

@@ -56,8 +56,12 @@ export interface SidebarSettingsOwnerProps {
* the New Session button and toggling the column.
*/
export type SidebarRootInjected = {
/** Start or replace the current frontend Session Intent. */
startSession: (workspaceId?: WorkspaceId, prompt?: string) => void
/**
* Start a New Session: with a workspace, reuse-or-create its blank session
* and open it; without one, clear the selection into the New Session pure
* view state (the conversation.empty seat).
*/
startSession: (workspaceId?: WorkspaceId) => void
/** Toggle the sidebar column through the layout service. */
toggleSidebar: () => void
}

View File

@@ -6,14 +6,26 @@ import { SidebarRoot } from './SidebarRoot.tsx'
export type { SidebarRootComponentProps, SidebarRootInjected, SidebarSectionOwnerProps, SidebarSettingsOwnerProps } from './contract/slots.ts'
/** Services required by the sidebar plugin. */
export const inject = ['slots', 'layout', 'workspaces']
export const inject = ['slots', 'layout', 'sessions', 'workspaces']
/** Registers the sidebar shell and its service callbacks.
* @param ctx - Client root context.
*/
export function apply(ctx: ClientContext): void {
const injectProps = (): SidebarRootInjected => ({
startSession: (workspaceId, prompt) => { ctx.workspaces.startSession(workspaceId, prompt) },
// The shell's New Session button targets the most recently active
// Workspace; an explicit Workspace still wins for scoped create actions.
startSession: (workspaceId) => {
const target = workspaceId ?? ctx.workspaces.list.getSnapshot().recentWorkspaceId
if (target === undefined) {
ctx.sessions.clear()
return
}
void ctx.workspaces.connectWorkspace(target).then(
(sessionId) => { ctx.sessions.open(sessionId) },
(reason: unknown) => { console.warn('new session failed:', reason) },
)
},
toggleSidebar: () => { ctx.layout.toggleSidebar() },
})
ctx.effect(

View File

@@ -9,8 +9,10 @@ async function bench(declare = true) {
const ctx = new Context()
await ctx.plugin(SlotsService).await()
const layout = { toggleSidebar: vi.fn() }
const workspaces = { startSession: vi.fn() }
const workspaces = { connectWorkspace: vi.fn(async () => 'blank-1' as never) }
const sessions = { open: vi.fn(), clear: vi.fn() }
ctx.provide('layout', layout)
ctx.provide('sessions', sessions as never)
ctx.provide('workspaces', workspaces as never)
const slots = ctx.get('slots') as SlotsService
if (declare) {
@@ -19,12 +21,12 @@ async function bench(declare = true) {
() => null,
)
}
return { ctx, slots, layout, workspaces }
return { ctx, slots, layout, workspaces, sessions }
}
describe('ui-sidebar apply', () => {
it('declares only the services it uses', () => {
expect(inject).toEqual(['slots', 'layout', 'workspaces'])
expect(inject).toEqual(['slots', 'layout', 'sessions', 'workspaces'])
})
it('registers the shell and declares the browsing-region hole', async () => {
@@ -34,8 +36,13 @@ describe('ui-sidebar apply', () => {
expect(b.slots.spec('sidebar.workspaces')).toEqual({ kind: 'single', scope: 'root' })
const injected = (b.slots.entries('sidebar')[0]!.inject as () => SidebarRootInjected)()
expect(Object.keys(injected)).toEqual(['startSession', 'toggleSidebar'])
injected.startSession('workspace' as never, 'prompt')
expect(b.workspaces.startSession).toHaveBeenCalledWith('workspace', 'prompt')
// Workspace given: reuse-or-create the blank session, then navigate.
injected.startSession('workspace' as never)
expect(b.workspaces.connectWorkspace).toHaveBeenCalledWith('workspace')
await vi.waitFor(() => { expect(b.sessions.open).toHaveBeenCalledWith('blank-1') })
// No workspace (the shell's New Session button): clear into the view state.
injected.startSession()
expect(b.sessions.clear).toHaveBeenCalledOnce()
injected.toggleSidebar()
expect(b.layout.toggleSidebar).toHaveBeenCalledOnce()
})