import { computed, handler, NAME, pattern, Stream, type TrustedActionWrite, UI, type VNode, Writable, } from "commonfabric"; export const TRUSTED_DIRECT_COMMAND_SURFACE = "TrustedDirectCommandSurface"; const CAPTURE_COMMAND_ACTION = "TrustedCaptureDirectCommand"; const PREPARE_BRIEF_ACTION = "TrustedPrepareResearchBrief"; const AUTHORIZE_SEND_ACTION = "TrustedAuthorizeResearchSend"; export const captureTrustedDirectCommand = handler< void, { commandInput: Writable; capturedCommand: Writable; preparedBrief: Writable; } >((_, { commandInput, capturedCommand, preparedBrief }) => { capturedCommand.set(commandInput.get().trim()); preparedBrief.set(""); }); export const prepareTrustedResearchBrief = handler< void, { capturedCommand: Writable; preparedBrief: Writable; } >((_, { capturedCommand, preparedBrief }) => { const command = capturedCommand.get().trim(); preparedBrief.set( command ? `Prepared outbound draft: concise summary for "${command}". The send action stays separately gated.` : "", ); }); export const commitTrustedResearchSend = handler< void, { capturedCommand: Writable; preparedBrief: Writable; authorizedSend: Writable; } >((_, { capturedCommand, preparedBrief, authorizedSend }) => { const command = capturedCommand.get().trim(); const preview = preparedBrief.get().trim(); authorizedSend.set( preview ? `Authorized outbound message for "${command}": ${preview}` : "", ); }); export interface TrustedDirectCommandSurfaceInput { commandInput: Writable; capturedCommand: Writable; preparedBrief: Writable; authorizedSend: Writable; } export interface TrustedDirectCommandSurfaceOutput { [NAME]: string; [UI]: VNode; commandInput: string; capturedCommand: TrustedActionWrite< string, typeof captureTrustedDirectCommand, typeof CAPTURE_COMMAND_ACTION, typeof TRUSTED_DIRECT_COMMAND_SURFACE >; preparedBrief: TrustedActionWrite< string, typeof prepareTrustedResearchBrief, typeof PREPARE_BRIEF_ACTION, typeof TRUSTED_DIRECT_COMMAND_SURFACE >; authorizedSend: TrustedActionWrite< string, typeof commitTrustedResearchSend, typeof AUTHORIZE_SEND_ACTION, typeof TRUSTED_DIRECT_COMMAND_SURFACE >; captureCommand: Stream; prepareBrief: Stream; authorizeSend: Stream; } export const TrustedDirectCommandSurface = pattern< TrustedDirectCommandSurfaceInput, TrustedDirectCommandSurfaceOutput >(({ commandInput, capturedCommand, preparedBrief, authorizedSend }) => { const captureCommand = captureTrustedDirectCommand({ commandInput, capturedCommand, preparedBrief, }); const prepareBrief = prepareTrustedResearchBrief({ capturedCommand, preparedBrief, }); const authorizeSend = commitTrustedResearchSend({ capturedCommand, preparedBrief, authorizedSend, }); return { [NAME]: computed(() => "Trusted Direct Command Surface"), [UI]: ( Trusted direct command This reviewed surface captures a bounded agent command, prepares a draft, and requires a separate release click to send it. Direct command Capture direct command Prepare brief Authorize research send Captured command
{capturedCommand}
Prepared brief
{preparedBrief}
Committed outbound action
{authorizedSend}
), commandInput, capturedCommand, preparedBrief, authorizedSend, captureCommand, prepareBrief, authorizeSend, }; });