MCPcopy
hub / github.com/HKUDS/OpenHarness / create_default_command_registry

Function create_default_command_registry

src/openharness/commands/registry.py:406–2297  ·  view source on GitHub ↗

Create the built-in command registry.

(
    plugin_commands: Iterable[PluginCommandDefinition] | None = None,
)

Source from the content-addressed store, hash-verified

404
405
406def create_default_command_registry(
407 plugin_commands: Iterable[PluginCommandDefinition] | None = None,
408) -> CommandRegistry:
409 """Create the built-in command registry."""
410 registry = CommandRegistry()
411
412 async def _help_handler(_: str, context: CommandContext) -> CommandResult:
413 del context
414 return CommandResult(message=registry.help_text())
415
416 async def _exit_handler(_: str, context: CommandContext) -> CommandResult:
417 del context
418 return CommandResult(should_exit=True)
419
420 async def _clear_handler(_: str, context: CommandContext) -> CommandResult:
421 context.engine.clear()
422 return CommandResult(message="Conversation cleared.", clear_screen=True)
423
424 async def _status_handler(_: str, context: CommandContext) -> CommandResult:
425 usage = context.engine.total_usage
426 state = context.app_state.get() if context.app_state is not None else None
427 manager = AuthManager()
428 return CommandResult(
429 message=(
430 f"Messages: {len(context.engine.messages)}\n"
431 f"Usage: input={usage.input_tokens} output={usage.output_tokens}\n"
432 f"Profile: {manager.get_active_profile()}\n"
433 f"Effort: {state.effort if state is not None else load_settings().effort}\n"
434 f"Passes: {state.passes if state is not None else load_settings().passes}"
435 )
436 )
437
438 async def _version_handler(_: str, context: CommandContext) -> CommandResult:
439 del context
440 try:
441 version = importlib.metadata.version("openharness")
442 except importlib.metadata.PackageNotFoundError:
443 version = "0.1.7"
444 return CommandResult(message=f"OpenHarness {version}")
445
446 async def _context_handler(_: str, context: CommandContext) -> CommandResult:
447 settings = load_settings()
448 prompt = build_runtime_system_prompt(
449 settings,
450 cwd=context.cwd,
451 include_project_memory=context.include_project_memory,
452 )
453 return CommandResult(message=prompt)
454
455 async def _summary_handler(args: str, context: CommandContext) -> CommandResult:
456 max_messages = 8
457 if args:
458 try:
459 max_messages = max(1, int(args))
460 except ValueError:
461 return CommandResult(message="Usage: /summary [MAX_MESSAGES]")
462 summary = summarize_messages(context.engine.messages, max_messages=max_messages)
463 return CommandResult(message=summary or "No conversation content to summarize.")

Calls 4

registerMethod · 0.95
CommandRegistryClass · 0.85
SlashCommandClass · 0.85