11import {
22 INTERNAL_COMMANDS ,
3- listMcpExposedCommandNames ,
3+ listCliCommandNames ,
4+ type CliCommandName ,
45 PUBLIC_COMMANDS ,
56} from '../../command-catalog.ts' ;
67import type { CommandCapability } from '../capabilities.ts' ;
@@ -15,6 +16,10 @@ import { resolvePostActionObservationSupport } from './post-action-observation.t
1516import type { PostActionObservationSupport } from './post-action-observation.ts' ;
1617import type { CommandDescriptor , CommandTimeoutPolicy } from './types.ts' ;
1718
19+ type RawCommandDescriptor = Omit < CommandDescriptor , 'mcpExposed' > & {
20+ mcpExposed ?: boolean ;
21+ } ;
22+
1823// ---------------------------------------------------------------------------
1924// Daemon request-policy trait bundles — copied VERBATIM from
2025// src/daemon/daemon-command-registry.ts (DAEMON_COMMAND_DESCRIPTORS).
@@ -396,6 +401,7 @@ const RAW_COMMAND_DESCRIPTORS = [
396401 onTimeout : 'reset-daemon' ,
397402 } ,
398403 batchable : false ,
404+ mcpExposed : false ,
399405 } ,
400406 {
401407 name : PUBLIC_COMMANDS . batch ,
@@ -694,9 +700,26 @@ const RAW_COMMAND_DESCRIPTORS = [
694700 timeoutPolicy : DEFAULT_TIMEOUT_POLICY ,
695701 batchable : true ,
696702 } ,
697- ] as const satisfies readonly Omit < CommandDescriptor , 'mcpExposed' > [ ] ;
698703
699- const MCP_EXPOSED_COMMAND_NAMES = new Set < string > ( listMcpExposedCommandNames ( ) ) ;
704+ // -- local client-backed CLI/MCP commands (no daemon route/capability) --
705+ {
706+ name : 'debug' ,
707+ timeoutPolicy : DEFAULT_TIMEOUT_POLICY ,
708+ batchable : false ,
709+ } ,
710+ {
711+ name : 'metro' ,
712+ timeoutPolicy : DEFAULT_TIMEOUT_POLICY ,
713+ batchable : false ,
714+ } ,
715+ {
716+ name : 'session' ,
717+ timeoutPolicy : DEFAULT_TIMEOUT_POLICY ,
718+ batchable : false ,
719+ } ,
720+ ] as const satisfies readonly RawCommandDescriptor [ ] ;
721+
722+ const CLI_COMMAND_NAMES = new Set < string > ( listCliCommandNames ( ) ) ;
700723
701724/**
702725 * The additive single source of truth (ADR-0008, Phase 1 step 1). Proven
@@ -708,16 +731,46 @@ const MCP_EXPOSED_COMMAND_NAMES = new Set<string>(listMcpExposedCommandNames());
708731 */
709732export const commandDescriptors = RAW_COMMAND_DESCRIPTORS . map ( ( descriptor ) => ( {
710733 ...descriptor ,
711- mcpExposed : MCP_EXPOSED_COMMAND_NAMES . has ( descriptor . name ) ,
734+ mcpExposed : resolveMcpExposure ( descriptor ) ,
712735} ) ) satisfies readonly CommandDescriptor [ ] ;
713736
714737/** The literal union of every registered command name. */
715738export type Command = ( typeof commandDescriptors ) [ number ] [ 'name' ] ;
716739
740+ export function listMcpExposedCommandNames ( ) : CliCommandName [ ] {
741+ return commandDescriptors
742+ . filter ( ( descriptor ) => isMcpExposedCliCommand ( descriptor ) )
743+ . map ( ( descriptor ) => descriptor . name as CliCommandName )
744+ . sort ( ) ;
745+ }
746+
747+ export function listCapabilityCheckedCommandNames ( ) : CliCommandName [ ] {
748+ return commandDescriptors
749+ . filter ( ( descriptor ) => isCapabilityCheckedCliCommand ( descriptor ) )
750+ . map ( ( descriptor ) => descriptor . name as CliCommandName )
751+ . sort ( ) ;
752+ }
753+
717754const COMMAND_DESCRIPTOR_BY_NAME : ReadonlyMap < string , CommandDescriptor > = new Map (
718755 commandDescriptors . map ( ( descriptor ) => [ descriptor . name , descriptor ] ) ,
719756) ;
720757
758+ function isCliCommandName ( command : string ) : command is CliCommandName {
759+ return CLI_COMMAND_NAMES . has ( command ) ;
760+ }
761+
762+ function resolveMcpExposure ( descriptor : RawCommandDescriptor ) : boolean {
763+ return descriptor . mcpExposed ?? CLI_COMMAND_NAMES . has ( descriptor . name ) ;
764+ }
765+
766+ function isMcpExposedCliCommand ( descriptor : CommandDescriptor ) : boolean {
767+ return descriptor . mcpExposed && isCliCommandName ( descriptor . name ) ;
768+ }
769+
770+ function isCapabilityCheckedCliCommand ( descriptor : CommandDescriptor ) : boolean {
771+ return Boolean ( descriptor . capability ) && isCliCommandName ( descriptor . name ) ;
772+ }
773+
721774const TIMEOUT_POLICY_BY_COMMAND : ReadonlyMap < string , CommandTimeoutPolicy > = new Map (
722775 commandDescriptors . map ( ( descriptor ) => [ descriptor . name , descriptor . timeoutPolicy ] ) ,
723776) ;
0 commit comments