Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /jhoetter_hof-engine /hof /cli /commands /fn.py
| """hof fn -- call and manage functions. | |
| Usage: | |
| hof fn list List all registered functions | |
| hof fn describe <name> Human-readable tool contract (when-to-use, related tools) | |
| hof fn schema <name> Show function schema | |
| hof fn <name> Call a function (no args); human-readable output | |
| hof fn <name> --json '{"key": ...}' Call with JSON input (-j is input, not output) | |
| hof fn <name> --format json Machine JSON output (for scripts) | |
| """ | |
| from __future__ import annotations | |
| import asyncio | |
| import json | |
| import os | |
| import click | |
| from rich.console import Console | |
| from rich.table import Table as RichTable | |
| from hof.cli.commands import bootstrap | |
| from hof.cli.result_render import render_function_result | |
| console = Console() | |
| class FnGroup(click.Group): | |
| """Custom Click group that treats unknown commands as function names.""" | |
| def resolve_command(self, ctx: click.Context, args: list[str]): | |
| try: | |
| return super().resolve_command(ctx, args) | |
| except click.UsageError: | |
| return args[0], args[0], args[1:] | |
| def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None: | |
| cmd = super().get_command(ctx, cmd_name) | |
| if cmd is not None: | |
| return cmd | |
| return _make_call_command(cmd_name) | |
| def _make_call_command(function_name: str) -> click.Command: | |
| def call_fn(input_json: str | None, output_format: str) -> None: | |
| _call_function(function_name, input_json, output_format) | |
| return call_fn | |
| def _call_function(function_name: str, input_json: str | None, output_format: str = "auto") -> None: | |
| from hof.cli.api_client import get_client | |
| if output_format == "auto": | |
| env_fmt = os.environ.get("HOF_FN_FORMAT", "").strip().lower() | |
| if env_fmt in ("json",): | |
| output_format = env_fmt | |
| kwargs = json.loads(input_json) if input_json else {} | |
| client = get_client() | |
| if client: | |
| try: | |
| data = client.call_function(function_name, kwargs) | |
| result = data.get("result", data) | |
| render_function_result(result, fmt=output_format, console=console) | |
| return | |
| except Exception as exc: | |
| console.print(f"[red]API error: {exc}[/]") | |
| raise SystemExit(1) | |
| bootstrap() | |
| from hof.core.registry import registry | |
| meta = registry.get_function(function_name) | |
| if meta is None: | |
| console.print(f"[red]Function '{function_name}' not found.[/]") | |
| raise SystemExit(1) | |
| if meta.is_async: | |
| result = asyncio.run(meta.fn(**kwargs)) | |
| else: | |
| result = meta.fn(**kwargs) | |
| render_function_result(result, fmt=output_format, console=console) | |
| def app() -> None: | |
| """Call and manage functions.""" | |
| def list_functions() -> None: | |
| """List all registered functions.""" | |
| from hof.cli.api_client import get_client | |
| client = get_client() | |
| if client: | |
| functions = client.list_functions() | |
| else: | |
| bootstrap() | |
| from hof.core.registry import registry | |
| functions = [meta.to_dict() for meta in registry.functions.values()] | |
| table = RichTable(title="Registered Functions") | |
| table.add_column("Name", style="cyan") | |
| table.add_column("Description") | |
| table.add_column("Tags") | |
| table.add_column("Async") | |
| for fn_def in functions: | |
| desc = (fn_def.get("tool_summary") or fn_def.get("description") or "").strip() | |
| table.add_row( | |
| fn_def["name"], | |
| desc[:60] + "..." if len(desc) > 60 else desc, | |
| ", ".join(fn_def.get("tags", [])) or "-", | |
| "yes" if fn_def.get("is_async") else "no", | |
| ) | |
| console.print(table) | |
| def describe_function(function_name: str) -> None: | |
| """Show summary, when-to-use hints, related tools, and parameters (agent/CLI contract).""" | |
| from hof.agent.tooling import ( | |
| format_function_describe_from_static_meta, | |
| format_function_describe_text, | |
| ) | |
| from hof.cli.api_client import get_client | |
| client = get_client() | |
| if client: | |
| try: | |
| data = client.function_schema(function_name) | |
| except Exception as exc: | |
| console.print(f"[red]API error: {exc}[/]") | |
| raise SystemExit(1) | |
| console.print(format_function_describe_from_static_meta(data)) | |
| return | |
| bootstrap() | |
| from hof.core.registry import registry | |
| meta = registry.get_function(function_name) | |
| if meta is None: | |
| console.print(f"[red]Function '{function_name}' not found.[/]") | |
| raise SystemExit(1) | |
| console.print(format_function_describe_text(function_name, meta)) | |
| def show_schema(function_name: str) -> None: | |
| """Show the input/output schema of a function.""" | |
| from hof.cli.api_client import get_client | |
| client = get_client() | |
| if client: | |
| data = client.function_schema(function_name) | |
| else: | |
| bootstrap() | |
| from hof.core.registry import registry | |
| meta = registry.get_function(function_name) | |
| if meta is None: | |
| console.print(f"[red]Function '{function_name}' not found.[/]") | |
| raise SystemExit(1) | |
| data = meta.to_dict() | |
| console.print_json(json.dumps(data, default=str)) | |
Xet Storage Details
- Size:
- 5.87 kB
- Xet hash:
- 1845904b577e60a1abd062d43a301e391d7ad49d2c586c1675032d173363d187
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.