Compare commits

..

7 Commits

Author SHA1 Message Date
92c3eb0ab2 feat(cli): Show profile in cron list
Some checks failed
Forge CI / smoke-and-build (pull_request) Failing after 1m5s
Part of #334. Displays profile name in job list when set.
2026-04-14 01:31:51 +00:00
3e7eec0b88 feat(cli): Add profile handling to cron_create and cron_edit
Part of #334. Passes profile parameter to cron API in create and edit commands.
2026-04-14 01:31:16 +00:00
3ba2907d37 feat(cli): Add --profile argument to cron create/edit
Part of #334. Adds --profile/-p argument to cron create and edit commands.
2026-04-14 01:30:54 +00:00
4b90f9a7f1 feat(cron): Add profile parameter to cronjob tool
Part of #334. Adds profile field to cronjob tool and passes it to create_job.
2026-04-14 01:29:59 +00:00
de80911ab9 feat(cron): Load profile-specific config.yaml
Part of #334. When job has profile set, loads config.yaml from profiles/PROFILE/config.yaml.
2026-04-14 01:25:49 +00:00
4dcfa11593 feat(cron): Add profile-scoped execution to scheduler
Part of #334. Loads profile-specific .env and config.yaml when job has profile set. Sets HERMES_ACTIVE_PROFILE environment variable.
2026-04-14 01:24:31 +00:00
464d0b89fb feat(cron): Add profile parameter to create_job
Part of #334. Adds profile field to job structure for profile-scoped execution.
2026-04-14 01:22:31 +00:00
7 changed files with 54 additions and 161 deletions

View File

@@ -376,6 +376,7 @@ def create_job(
provider: Optional[str] = None,
base_url: Optional[str] = None,
script: Optional[str] = None,
profile: Optional[str] = None,
) -> Dict[str, Any]:
"""
Create a new cron job.
@@ -395,6 +396,9 @@ def create_job(
script: Optional path to a Python script whose stdout is injected into the
prompt each run. The script runs before the agent turn, and its output
is prepended as context. Useful for data collection / change detection.
profile: Optional profile name for profile-scoped execution. When set, the job
runs with that profile's config.yaml and .env, and HERMES_ACTIVE_PROFILE
is set. Enables parallel execution without cross-contamination.
Returns:
The created job dict
@@ -425,6 +429,8 @@ def create_job(
normalized_base_url = normalized_base_url or None
normalized_script = str(script).strip() if isinstance(script, str) else None
normalized_script = normalized_script or None
normalized_profile = str(profile).strip() if isinstance(profile, str) else None
normalized_profile = normalized_profile or None
label_source = (prompt or (normalized_skills[0] if normalized_skills else None)) or "cron job"
job = {
@@ -455,6 +461,8 @@ def create_job(
# Delivery configuration
"deliver": deliver,
"origin": origin, # Tracks where job was created for "origin" delivery
# Profile configuration
"profile": normalized_profile, # Profile for scoped execution
}
jobs = load_jobs()

View File

@@ -682,6 +682,26 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]:
os.environ["HERMES_SESSION_CHAT_ID"] = str(origin["chat_id"])
if origin.get("chat_name"):
os.environ["HERMES_SESSION_CHAT_NAME"] = origin["chat_name"]
# Profile-scoped execution: load profile-specific config
profile = job.get("profile")
if profile:
os.environ["HERMES_ACTIVE_PROFILE"] = profile
profile_dir = _hermes_home / "profiles" / profile
if profile_dir.exists():
# Load profile-specific .env
profile_env = profile_dir / ".env"
if profile_env.exists():
try:
load_dotenv(str(profile_env), override=True, encoding="utf-8")
logger.info("Job '%s': Loaded profile .env from %s", job_id, profile_env)
except Exception as e:
logger.warning("Job '%s': Failed to load profile .env: %s", job_id, e)
# Profile config will be loaded later in the config section
logger.info("Job '%s': Running with profile '%s'", job_id, profile)
else:
logger.warning("Job '%s': Profile directory not found: %s", job_id, profile_dir)
# Re-read .env and config.yaml fresh every run so provider/key
# changes take effect without a gateway restart.
from dotenv import load_dotenv
@@ -700,10 +720,21 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]:
model = job.get("model") or os.getenv("HERMES_MODEL") or ""
# Load config.yaml for model, reasoning, prefill, toolsets, provider routing
# If profile is set, load profile-specific config
_cfg = {}
try:
import yaml
_cfg_path = str(_hermes_home / "config.yaml")
profile = job.get("profile")
if profile:
profile_cfg_path = _hermes_home / "profiles" / profile / "config.yaml"
if profile_cfg_path.exists():
_cfg_path = str(profile_cfg_path)
logger.info("Job '%s': Loading profile config from %s", job_id, _cfg_path)
else:
_cfg_path = str(_hermes_home / "config.yaml")
logger.debug("Job '%s': Profile config not found, using default: %s", job_id, _cfg_path)
else:
_cfg_path = str(_hermes_home / "config.yaml")
if os.path.exists(_cfg_path):
with open(_cfg_path) as _f:
_cfg = yaml.safe_load(_f) or {}

View File

@@ -90,6 +90,10 @@ def cron_list(show_all: bool = False):
print(f" Deliver: {deliver_str}")
if skills:
print(f" Skills: {', '.join(skills)}")
# Show profile if set
profile = job.get("profile")
if profile:
print(color(f" Profile: {profile}", Colors.MAGENTA))
script = job.get("script")
if script:
print(f" Script: {script}")

View File

@@ -4550,6 +4550,10 @@ For more help on a command:
cron_create.add_argument("--repeat", type=int, help="Optional repeat count")
cron_create.add_argument("--skill", dest="skills", action="append", help="Attach a skill. Repeat to add multiple skills.")
cron_create.add_argument("--script", help="Path to a Python script whose stdout is injected into the prompt each run")
cron_create.add_argument(
"--profile", "-p",
help="Profile name for profile-scoped execution (loads profile's config.yaml and .env)"
)
# cron edit
cron_edit = cron_subparsers.add_parser("edit", help="Edit an existing scheduled job")
@@ -4564,6 +4568,10 @@ For more help on a command:
cron_edit.add_argument("--remove-skill", dest="remove_skills", action="append", help="Remove a specific attached skill. Repeatable.")
cron_edit.add_argument("--clear-skills", action="store_true", help="Remove all attached skills from the job")
cron_edit.add_argument("--script", help="Path to a Python script whose stdout is injected into the prompt each run. Pass empty string to clear.")
cron_edit.add_argument(
"--profile", "-p",
help="Set profile for profile-scoped execution"
)
# lifecycle actions
cron_pause = cron_subparsers.add_parser("pause", help="Pause a scheduled job")

View File

@@ -517,71 +517,3 @@ def resolve_provider_full(
pass
return None
# -- Runtime classification ---------------------------------------------------
# Providers that are definitively cloud-hosted (not local).
# Used by _classify_runtime() to distinguish cloud vs unknown.
_CLOUD_PREFIXES: frozenset[str] = frozenset(HERMES_OVERLAYS.keys()) | frozenset({
# Common aliases that normalize to cloud providers
"openai", "gemini", "google", "google-gemini", "google-ai-studio",
"claude", "claude-code", "copilot", "github", "github-copilot",
"glm", "z-ai", "z.ai", "zhipu", "zai",
"kimi", "kimi-coding", "moonshot",
"minimax", "minimax-china", "minimax_cn",
"deep-seek",
"dashscope", "aliyun", "qwen", "alibaba-cloud", "alibaba",
"hf", "hugging-face", "huggingface-hub", "huggingface",
"ai-gateway", "aigateway", "vercel-ai-gateway",
"opencode-zen", "zen",
"opencode-go-sub",
"kilocode", "kilo-code", "kilo-gateway", "kilo",
})
# Providers that are definitively local (self-hosted, no external API).
_LOCAL_PROVIDERS: frozenset[str] = frozenset({
"ollama", "local",
"vllm", "llamacpp", "llama.cpp", "llama-cpp", "lmstudio", "lm-studio",
})
def _classify_runtime(provider: Optional[str], model: str) -> str:
"""Classify a provider/model pair into a runtime category.
Returns one of:
``"cloud"`` — the request targets a known remote/hosted provider.
``"local"`` — the request targets a self-hosted/local inference server.
``"unknown"`` — provider is unrecognised or not specified without enough
context to determine the runtime type.
Edge-case rules (in order):
1. If *provider* is set and is a known local provider → ``"local"``.
2. If *provider* is set and is a known cloud provider → ``"cloud"``.
3. If *provider* is set but **not** in either known set → ``"unknown"``.
(Previously fell through to ``"local"`` — this was the bug.)
4. If *provider* is empty/None, inspect the model string for a recognised
cloud prefix (e.g. ``"openai/gpt-4o"`` → ``"cloud"``).
5. Everything else → ``"unknown"``.
"""
p = (provider or "").strip().lower()
if p:
# Rule 1: known local provider
if p in _LOCAL_PROVIDERS:
return "local"
# Rule 2: known cloud provider
if p in _CLOUD_PREFIXES:
return "cloud"
# Rule 3: provider is set but unrecognised — do NOT default to "local"
return "unknown"
# Rule 4: no provider — try to infer from the model string
m = (model or "").strip().lower()
if "/" in m:
model_prefix = m.split("/", 1)[0]
if model_prefix in _CLOUD_PREFIXES:
return "cloud"
# Rule 5: insufficient context
return "unknown"

View File

@@ -1,92 +0,0 @@
"""Tests for _classify_runtime() edge cases.
Covers the bug reported in #556: unknown provider with a model string
incorrectly returned "local" instead of "unknown".
"""
import pytest
from hermes_cli.providers import _classify_runtime
class TestClassifyRuntimeLocalProviders:
def test_ollama_no_model(self):
assert _classify_runtime("ollama", "") == "local"
def test_ollama_with_model(self):
assert _classify_runtime("ollama", "llama3:8b") == "local"
def test_local_provider_no_model(self):
assert _classify_runtime("local", "") == "local"
def test_local_provider_with_model(self):
assert _classify_runtime("local", "my-model") == "local"
def test_vllm_provider(self):
assert _classify_runtime("vllm", "meta/llama-3") == "local"
def test_llamacpp_provider(self):
assert _classify_runtime("llamacpp", "mistral") == "local"
class TestClassifyRuntimeCloudProviders:
def test_anthropic_provider(self):
assert _classify_runtime("anthropic", "claude-opus-4-6") == "cloud"
def test_openrouter_provider(self):
assert _classify_runtime("openrouter", "anthropic/claude-opus-4-6") == "cloud"
def test_nous_provider(self):
assert _classify_runtime("nous", "hermes-3") == "cloud"
def test_gemini_provider(self):
assert _classify_runtime("gemini", "gemini-pro") == "cloud"
def test_deepseek_provider(self):
assert _classify_runtime("deepseek", "deepseek-chat") == "cloud"
class TestClassifyRuntimeUnknownProviders:
"""Regression tests for #556: unknown provider should return 'unknown', not 'local'."""
def test_unknown_provider_with_model(self):
"""Core bug: 'custom' provider with model must not return 'local'."""
assert _classify_runtime("custom", "my-model") == "unknown"
def test_unknown_provider_no_model(self):
"""Unknown provider with no model should return 'unknown'."""
assert _classify_runtime("custom", "") == "unknown"
def test_arbitrary_provider_with_model(self):
"""Any unrecognised provider string with a model returns 'unknown'."""
assert _classify_runtime("my-private-llm", "some-model") == "unknown"
def test_arbitrary_provider_no_model(self):
assert _classify_runtime("my-private-llm", "") == "unknown"
def test_whitespace_only_provider_treated_as_empty(self):
"""Provider with only whitespace is treated as absent."""
# No model either → unknown
assert _classify_runtime(" ", "") == "unknown"
class TestClassifyRuntimeEmptyProvider:
def test_empty_provider_cloud_prefixed_model(self):
"""Empty provider with cloud-prefixed model returns 'cloud'."""
assert _classify_runtime("", "openrouter/gpt-4o") == "cloud"
def test_none_provider_cloud_prefixed_model(self):
assert _classify_runtime(None, "anthropic/claude-opus-4-6") == "cloud"
def test_empty_provider_no_model(self):
assert _classify_runtime("", "") == "unknown"
def test_none_provider_no_model(self):
assert _classify_runtime(None, "") == "unknown"
def test_empty_provider_non_cloud_prefixed_model(self):
"""No provider, model without a recognized prefix → unknown."""
assert _classify_runtime("", "my-model") == "unknown"
def test_empty_provider_model_with_unknown_prefix(self):
"""Model prefix that isn't a known cloud provider → unknown."""
assert _classify_runtime("", "myprivate/llm-7b") == "unknown"

View File

@@ -233,6 +233,7 @@ def cronjob(
base_url: Optional[str] = None,
reason: Optional[str] = None,
script: Optional[str] = None,
profile: Optional[str] = None,
task_id: str = None,
) -> str:
"""Unified cron job management tool."""
@@ -270,6 +271,7 @@ def cronjob(
provider=_normalize_optional_job_value(provider),
base_url=_normalize_optional_job_value(base_url, strip_trailing_slash=True),
script=_normalize_optional_job_value(script),
profile=_normalize_optional_job_value(profile),
)
return json.dumps(
{