8c9d4fbc46
- Rename _manifest_util.py → manifest_util.py (module isn't private) - Rename _as_json_object → as_json_object, _parse_git_upstream → parse_git_upstream, _parse_git_gate_config → parse_git_gate_config, _validate_unique_git_names → validate_unique_git_names, _validate_egress_routes → validate_egress_routes (none are private at module boundary — underscore prefix was a carry-over from the old monolithic manifest.py where everything lived in one namespace) - Move _is_ip_literal → util.is_ip_literal (generic, belongs in the top-level util module) - Update all import sites across manifest_*.py, manifest_extends.py, manifest_schema.py; existing callers of manifest.py are unaffected All 867 unit tests pass.
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
"""Internal manifest schema policy helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
# Filename-as-key uses kebab-case ASCII. The first character is a
|
|
# letter so we don't conflict with hidden files / Markdown special
|
|
# names (`.md`, `_template.md`, etc.). Filenames that fail this
|
|
# pattern are skipped with a warning rather than crashing the load.
|
|
_FILENAME_RX = re.compile(r"^[a-z][a-z0-9-]*$")
|
|
|
|
|
|
# Frontmatter keys we accept on each entity. Anything not in these
|
|
# sets dies with a "did you mean" pointer: typos should not silently
|
|
# ghost into an empty config.
|
|
BOTTLE_KEYS = frozenset(
|
|
{"env", "extends", "agent_provider", "git-gate", "egress", "supervise"}
|
|
)
|
|
AGENT_KEYS_REQUIRED = frozenset({"bottle"})
|
|
AGENT_KEYS_OPTIONAL = frozenset({"skills", "git-gate"})
|
|
|
|
# Claude Code subagent fields bot-bottle ignores at launch but does
|
|
# not reject. This lets the same file double as
|
|
# `~/.claude/agents/*.md` without modification.
|
|
CLAUDE_CODE_AGENT_PASSTHROUGH_KEYS = frozenset({
|
|
"name", "description", "model", "color", "memory",
|
|
})
|
|
AGENT_KEYS = (
|
|
AGENT_KEYS_REQUIRED | AGENT_KEYS_OPTIONAL | CLAUDE_CODE_AGENT_PASSTHROUGH_KEYS
|
|
)
|
|
AGENT_MODEL_KEYS = AGENT_KEYS | frozenset({"prompt"})
|
|
|
|
|
|
def entity_name_from_path(path: Path) -> str | None:
|
|
"""Return the entity name implied by the filename, or None if the
|
|
filename does not fit the [a-z][a-z0-9-]* convention."""
|
|
if path.suffix != ".md":
|
|
return None
|
|
stem = path.stem
|
|
if not _FILENAME_RX.match(stem):
|
|
return None
|
|
return stem
|
|
|
|
|
|
def validate_bottle_frontmatter_keys(path: Path, keys: object) -> None:
|
|
_validate_frontmatter_keys("bottle", path, keys, BOTTLE_KEYS)
|
|
|
|
|
|
def validate_agent_frontmatter_keys(path: Path, keys: object) -> None:
|
|
_validate_frontmatter_keys("agent", path, keys, AGENT_KEYS)
|
|
|
|
|
|
def _validate_frontmatter_keys(
|
|
kind: str,
|
|
path: Path,
|
|
keys: object,
|
|
allowed_keys: frozenset[str],
|
|
) -> None:
|
|
from .manifest_util import ManifestError
|
|
|
|
key_set = set(keys)
|
|
unknown = key_set - allowed_keys
|
|
if unknown:
|
|
allowed = ", ".join(sorted(allowed_keys))
|
|
raise ManifestError(
|
|
f"{kind} file {path}: unknown frontmatter key(s) "
|
|
f"{sorted(unknown)}; allowed keys are {allowed}."
|
|
)
|