mirror of
https://github.com/usestrix/strix.git
synced 2026-08-21 18:52:47 +02:00
The SDK harness is the only path now; legacy host-side code is gone. File names no longer carry the ``sdk_`` distinction. Deleted legacy host-side modules: - strix/agents/StrixAgent/ (template moved to strix/agents/prompts/) - strix/agents/base_agent.py, state.py - strix/llm/llm.py, config.py - strix/runtime/docker_runtime.py, runtime.py - strix/tools/executor.py, agents_graph/agents_graph_actions.py - strix/interface/sdk_dispatch.py + the env-flag dispatch in cli.py Renamed (drop ``sdk_`` prefix): - strix/sdk_entry.py → strix/entry.py - strix/agents/sdk_factory.py → strix/agents/factory.py - strix/agents/sdk_prompt.py → strix/agents/prompt.py - strix/tools/<x>/<x>_sdk_tool[s].py → strix/tools/<x>/tool[s].py - strix/tools/_legacy_adapter.py → strix/tools/_state_adapter.py - ``_legacy`` aliases inside the wrappers → ``_impl`` CLI + TUI now call ``run_strix_scan`` directly — they build the sandbox image / sources_path locally and rely on ``session_manager.cleanup`` (called inside ``run_strix_scan``'s finally) for teardown. Three TUI handlers that reached into legacy multi-agent globals (``_agent_instances``, ``send_user_message_to_agent``, ``stop_agent``) are now no-ops with a TODO; reconnecting them to the ``AgentMessageBus`` is a follow-up. Tracer.get_total_llm_stats no longer reaches into the deleted ``agents_graph_actions`` globals — the orchestration hooks now feed the tracer via ``Tracer.record_llm_usage`` (live + completed buckets). finish_scan's ``_check_active_agents`` and load_skill's runtime ``_agent_instances`` reach-in are no-op stubs; the ``AgentMessageBus`` is the source of truth post-migration. llm/utils.py rewritten to keep only the streaming-parser helpers (``normalize_tool_format``, ``parse_tool_invocations``, ``fix_incomplete_tool_call``, ``format_tool_call``, ``clean_content``). ``STRIX_MODEL_MAP`` moved to ``llm/multi_provider_setup.py`` (its only remaining caller). Per-file ruff ignores added for legacy interface modules (TUI / main / CLI / utils / streaming_parser / tool_components) and tracer.py — pre-existing PLC0415/BLE001/PLR0915 patterns are out of scope. Tests: 287/287 passing. Renamed test files to drop ``sdk_`` prefix. ``test_tracer.py::test_get_total_llm_stats_aggregates_live_and_completed`` rewritten to feed ``Tracer.record_llm_usage`` instead of legacy globals. Test file annotations added so pre-commit's strict mypy passes.
119 lines
3.7 KiB
Python
119 lines
3.7 KiB
Python
"""Jinja-based system-prompt renderer.
|
|
|
|
Loads ``strix/agents/prompts/system_prompt.jinja`` (508 lines — the
|
|
multi-section production prompt with skills, tools, scan modes, etc.)
|
|
and renders it with the caller's per-run context (scan mode, whitebox,
|
|
interactive, scope authorization block).
|
|
|
|
References:
|
|
- HARNESS_WIKI.md §4.1 (system prompt assembly)
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
|
|
|
from strix.skills import load_skills
|
|
from strix.tools import get_tools_prompt
|
|
from strix.utils.resource_paths import get_strix_resource_path
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
_PROMPT_DIRNAME = "prompts"
|
|
|
|
|
|
def _resolve_skills(
|
|
*,
|
|
requested: list[str] | None,
|
|
scan_mode: str = "deep",
|
|
is_whitebox: bool = False,
|
|
) -> list[str]:
|
|
"""Build the deduped, ordered skills list for the prompt render.
|
|
|
|
Order:
|
|
|
|
1. Whatever the caller asked for, in order.
|
|
2. ``scan_modes/<mode>`` (always).
|
|
3. Whitebox-specific skills if applicable.
|
|
"""
|
|
ordered: list[str] = list(requested or [])
|
|
ordered.append(f"scan_modes/{scan_mode}")
|
|
if is_whitebox:
|
|
ordered.append("coordination/source_aware_whitebox")
|
|
ordered.append("custom/source_aware_sast")
|
|
|
|
deduped: list[str] = []
|
|
seen: set[str] = set()
|
|
for skill in ordered:
|
|
if skill and skill not in seen:
|
|
deduped.append(skill)
|
|
seen.add(skill)
|
|
return deduped
|
|
|
|
|
|
def render_system_prompt(
|
|
*,
|
|
skills: list[str] | None = None,
|
|
scan_mode: str = "deep",
|
|
is_whitebox: bool = False,
|
|
interactive: bool = False,
|
|
system_prompt_context: dict[str, Any] | None = None,
|
|
) -> str:
|
|
"""Render the system prompt.
|
|
|
|
Args:
|
|
skills: Skills the caller wants preloaded into the prompt
|
|
context (the agent can also load more at runtime via the
|
|
``load_skill`` tool).
|
|
scan_mode: ``"deep" | "fast" | ...``. Maps to ``scan_modes/<mode>``
|
|
skill.
|
|
is_whitebox: When True, the source-aware whitebox skill stack
|
|
is loaded too.
|
|
interactive: When True, the prompt renders the interactive-mode
|
|
communication rules block.
|
|
system_prompt_context: Free-form dict that the template's
|
|
``system_prompt_context`` variable receives — carries the
|
|
scan-scope authorization block.
|
|
|
|
Returns the rendered prompt string. If anything goes wrong (template
|
|
missing, render failure), returns an empty string and logs — a
|
|
missing prompt is survivable, a hard failure during agent
|
|
construction is not.
|
|
"""
|
|
try:
|
|
prompt_dir = get_strix_resource_path("agents", _PROMPT_DIRNAME)
|
|
skills_dir = get_strix_resource_path("skills")
|
|
env = Environment(
|
|
loader=FileSystemLoader([prompt_dir, skills_dir]),
|
|
autoescape=select_autoescape(
|
|
enabled_extensions=(),
|
|
default_for_string=False,
|
|
),
|
|
)
|
|
|
|
skills_to_load = _resolve_skills(
|
|
requested=skills,
|
|
scan_mode=scan_mode,
|
|
is_whitebox=is_whitebox,
|
|
)
|
|
skill_content = load_skills(skills_to_load)
|
|
env.globals["get_skill"] = lambda name: skill_content.get(name, "")
|
|
|
|
rendered = env.get_template("system_prompt.jinja").render(
|
|
get_tools_prompt=get_tools_prompt,
|
|
loaded_skill_names=list(skill_content.keys()),
|
|
interactive=interactive,
|
|
system_prompt_context=system_prompt_context or {},
|
|
**skill_content,
|
|
)
|
|
except Exception:
|
|
logger.exception("render_system_prompt failed; returning empty prompt")
|
|
return ""
|
|
else:
|
|
return str(rendered)
|