mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-09 08:21:50 +00:00
feat(skills): add design-md skill for Google's DESIGN.md spec (#14876)
* feat(config): make tool output truncation limits configurable Port from anomalyco/opencode#23770: expose a new `tool_output` config section so users can tune the hardcoded truncation caps that apply to terminal output and read_file pagination. Three knobs under `tool_output`: - max_bytes (default 50_000) — terminal stdout/stderr cap - max_lines (default 2000) — read_file pagination cap - max_line_length (default 2000) — per-line cap in line-numbered view All three keep their existing hardcoded values as defaults, so behaviour is unchanged when the section is absent. Power users on big-context models can raise them; small-context local models can lower them. Implementation: - New `tools/tool_output_limits.py` reads the section with defensive fallback (missing/invalid values → defaults, never raises). - `tools/terminal_tool.py` MAX_OUTPUT_CHARS now comes from get_max_bytes(). - `tools/file_operations.py` normalize_read_pagination() and _add_line_numbers() now pull the limits at call time. - `hermes_cli/config.py` DEFAULT_CONFIG gains the `tool_output` section so `hermes setup` writes defaults into fresh configs. - Docs page `user-guide/configuration.md` gains a "Tool Output Truncation Limits" section with large-context and small-context example configs. Tests (18 new in tests/tools/test_tool_output_limits.py): - Default resolution with missing / malformed / non-dict config. - Full and partial user overrides. - Coercion of bad values (None, negative, wrong type, str int). - Shortcut accessors delegate correctly. - DEFAULT_CONFIG exposes the section with the right defaults. - Integration: normalize_read_pagination clamps to the configured max_lines. * feat(skills): add design-md skill for Google's DESIGN.md spec Built-in skill under skills/creative/ that teaches the agent to author, lint, diff, and export DESIGN.md files — Google's open-source (Apache-2.0) format for describing a visual identity to coding agents. Covers: - YAML front matter + markdown body anatomy - Full token schema (colors, typography, rounded, spacing, components) - Canonical section order + duplicate-heading rejection - Component property whitelist + variants-as-siblings pattern - CLI workflow via 'npx @google/design.md' (lint/diff/export/spec) - Lint rule reference including WCAG contrast checks - Common YAML pitfalls (quoted hex, negative dimensions, dotted refs) - Starter template at templates/starter.md Package verified live on npm (@google/design.md@0.1.1).
This commit is contained in:
parent
379b2273d9
commit
983bbe2d40
8 changed files with 601 additions and 5 deletions
|
|
@ -292,10 +292,15 @@ def normalize_read_pagination(offset: Any = DEFAULT_READ_OFFSET,
|
|||
Tool schemas declare minimum/maximum values, but not every caller or
|
||||
provider enforces schemas before dispatch. Clamp here so invalid values
|
||||
cannot leak into sed ranges like ``0,-1p``.
|
||||
|
||||
The upper bound on ``limit`` comes from ``tool_output.max_lines`` in
|
||||
config.yaml (defaults to the module-level ``MAX_LINES`` constant).
|
||||
"""
|
||||
from tools.tool_output_limits import get_max_lines
|
||||
max_lines = get_max_lines()
|
||||
normalized_offset = max(1, _coerce_int(offset, DEFAULT_READ_OFFSET))
|
||||
normalized_limit = _coerce_int(limit, DEFAULT_READ_LIMIT)
|
||||
normalized_limit = max(1, min(normalized_limit, MAX_LINES))
|
||||
normalized_limit = max(1, min(normalized_limit, max_lines))
|
||||
return normalized_offset, normalized_limit
|
||||
|
||||
|
||||
|
|
@ -414,12 +419,14 @@ class ShellFileOperations(FileOperations):
|
|||
|
||||
def _add_line_numbers(self, content: str, start_line: int = 1) -> str:
|
||||
"""Add line numbers to content in LINE_NUM|CONTENT format."""
|
||||
from tools.tool_output_limits import get_max_line_length
|
||||
max_line_length = get_max_line_length()
|
||||
lines = content.split('\n')
|
||||
numbered = []
|
||||
for i, line in enumerate(lines, start=start_line):
|
||||
# Truncate long lines
|
||||
if len(line) > MAX_LINE_LENGTH:
|
||||
line = line[:MAX_LINE_LENGTH] + "... [truncated]"
|
||||
if len(line) > max_line_length:
|
||||
line = line[:max_line_length] + "... [truncated]"
|
||||
numbered.append(f"{i:6d}|{line}")
|
||||
return '\n'.join(numbered)
|
||||
|
||||
|
|
|
|||
|
|
@ -1805,7 +1805,8 @@ def terminal_tool(
|
|||
pass
|
||||
|
||||
# Truncate output if too long, keeping both head and tail
|
||||
MAX_OUTPUT_CHARS = 50000
|
||||
from tools.tool_output_limits import get_max_bytes
|
||||
MAX_OUTPUT_CHARS = get_max_bytes()
|
||||
if len(output) > MAX_OUTPUT_CHARS:
|
||||
head_chars = int(MAX_OUTPUT_CHARS * 0.4) # 40% head (error messages often appear early)
|
||||
tail_chars = MAX_OUTPUT_CHARS - head_chars # 60% tail (most recent/relevant output)
|
||||
|
|
|
|||
92
tools/tool_output_limits.py
Normal file
92
tools/tool_output_limits.py
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
"""Configurable tool-output truncation limits.
|
||||
|
||||
Ported from anomalyco/opencode PR #23770 (``feat(truncate): allow
|
||||
configuring tool output truncation limits``).
|
||||
|
||||
OpenCode hardcoded ``MAX_LINES = 2000`` and ``MAX_BYTES = 50 * 1024``
|
||||
as tool-output truncation thresholds. Hermes-agent had the same
|
||||
hardcoded constants in two places:
|
||||
|
||||
* ``tools/terminal_tool.py`` — ``MAX_OUTPUT_CHARS = 50000`` (terminal
|
||||
stdout/stderr cap)
|
||||
* ``tools/file_operations.py`` — ``MAX_LINES = 2000`` /
|
||||
``MAX_LINE_LENGTH = 2000`` (read_file pagination cap + per-line cap)
|
||||
|
||||
This module centralises those values behind a single config section
|
||||
(``tool_output`` in ``config.yaml``) so power users can tune them
|
||||
without patching the source. The existing hardcoded numbers remain as
|
||||
defaults, so behaviour is unchanged when the config key is absent.
|
||||
|
||||
Example ``config.yaml``::
|
||||
|
||||
tool_output:
|
||||
max_bytes: 100000 # terminal output cap (chars)
|
||||
max_lines: 5000 # read_file pagination + truncation cap
|
||||
max_line_length: 2000 # per-line length cap before '... [truncated]'
|
||||
|
||||
The limits reader is defensive: any error (missing config file, invalid
|
||||
value type, etc.) falls back to the built-in defaults so tools never
|
||||
fail because of a malformed config.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
# Hardcoded defaults — these match the pre-existing values, so adding
|
||||
# this module is behaviour-preserving for users who don't set
|
||||
# ``tool_output`` in config.yaml.
|
||||
DEFAULT_MAX_BYTES = 50_000 # terminal_tool.MAX_OUTPUT_CHARS
|
||||
DEFAULT_MAX_LINES = 2000 # file_operations.MAX_LINES
|
||||
DEFAULT_MAX_LINE_LENGTH = 2000 # file_operations.MAX_LINE_LENGTH
|
||||
|
||||
|
||||
def _coerce_positive_int(value: Any, default: int) -> int:
|
||||
"""Return ``value`` as a positive int, or ``default`` on any issue."""
|
||||
try:
|
||||
iv = int(value)
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
if iv <= 0:
|
||||
return default
|
||||
return iv
|
||||
|
||||
|
||||
def get_tool_output_limits() -> Dict[str, int]:
|
||||
"""Return resolved tool-output limits, reading ``tool_output`` from config.
|
||||
|
||||
Keys: ``max_bytes``, ``max_lines``, ``max_line_length``. Missing or
|
||||
invalid entries fall through to the ``DEFAULT_*`` constants. This
|
||||
function NEVER raises.
|
||||
"""
|
||||
try:
|
||||
from hermes_cli.config import load_config
|
||||
cfg = load_config() or {}
|
||||
section = cfg.get("tool_output") if isinstance(cfg, dict) else None
|
||||
if not isinstance(section, dict):
|
||||
section = {}
|
||||
except Exception:
|
||||
section = {}
|
||||
|
||||
return {
|
||||
"max_bytes": _coerce_positive_int(section.get("max_bytes"), DEFAULT_MAX_BYTES),
|
||||
"max_lines": _coerce_positive_int(section.get("max_lines"), DEFAULT_MAX_LINES),
|
||||
"max_line_length": _coerce_positive_int(
|
||||
section.get("max_line_length"), DEFAULT_MAX_LINE_LENGTH
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def get_max_bytes() -> int:
|
||||
"""Shortcut for terminal-tool callers that only need the byte cap."""
|
||||
return get_tool_output_limits()["max_bytes"]
|
||||
|
||||
|
||||
def get_max_lines() -> int:
|
||||
"""Shortcut for file-ops callers that only need the line cap."""
|
||||
return get_tool_output_limits()["max_lines"]
|
||||
|
||||
|
||||
def get_max_line_length() -> int:
|
||||
"""Shortcut for file-ops callers that only need the per-line cap."""
|
||||
return get_tool_output_limits()["max_line_length"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue