orchestrata_ultimate.core.base.traces

Reference › orchestrata_ultimate › core › base › traces

The @traces decorator, which ties a class or function to a specification, a user story and requirement ids. It is the most widely imported module in the project: nearly every package, among them agents, kernel, gateway and gates, uses it to annotate code, so the requirements traceability matrix can be built from the source (see the core narrative). It sits in the base layer with no project imports, and it was moved here from core.tracing.traceability to remove upward imports from layer 0.

traces(spec, story, reqs) returns a decorator that attaches the values to the target as a __traces__ attribute and returns the target itself. It raises ValueError when reqs is empty or when any id fails _validate_req_id, which accepts the REQ- patterns and US-NNN-NNN story ids. The scanners in tracing.scanner read the same annotations from the syntax tree without importing the code.

At a glance

Source src/orchestrata_ultimate/core/base/traces.py
Lines of code 72
Classes 0
Functions 2
Imports (internal) none
Imported by orchestrata_ultimate.agents.communication, orchestrata_ultimate.agents.constraints, orchestrata_ultimate.agents.escalation, orchestrata_ultimate.agents.exceptions, orchestrata_ultimate.agents.hierarchy, orchestrata_ultimate.agents.intent_adapter, orchestrata_ultimate.agents.interfaces, orchestrata_ultimate.agents.kernel_handler, orchestrata_ultimate.agents.lifecycle, orchestrata_ultimate.agents.pool, orchestrata_ultimate.agents.prolog_bridge, orchestrata_ultimate.agents.runtime, orchestrata_ultimate.agents.task_executor, orchestrata_ultimate.agents.tool_registry, orchestrata_ultimate.agents.volk_registry, orchestrata_ultimate.agents.volks.analyst.agent, orchestrata_ultimate.agents.volks.analyst.parsers, orchestrata_ultimate.agents.volks.architect.architect_context, orchestrata_ultimate.agents.volks.architect.architect_project, orchestrata_ultimate.agents.volks.architect.volk, orchestrata_ultimate.agents.volks.base, orchestrata_ultimate.agents.volks.codedirector.implementation, orchestrata_ultimate.agents.volks.codedirector.review, orchestrata_ultimate.agents.volks.codedirector.review_checks, orchestrata_ultimate.agents.volks.codedirector.scaffold.generator, orchestrata_ultimate.agents.volks.codedirector.scaffold.parser, orchestrata_ultimate.agents.volks.codedirector.volk, orchestrata_ultimate.agents.volks.compliance._pipeline, orchestrata_ultimate.agents.volks.compliance.volk, orchestrata_ultimate.agents.volks.concierge.volk, orchestrata_ultimate.agents.volks.junior.volk, orchestrata_ultimate.agents.volks.persona, orchestrata_ultimate.agents.volks.pm.budget, orchestrata_ultimate.agents.volks.pm.goal_registry, orchestrata_ultimate.agents.volks.pm.goal_report, orchestrata_ultimate.agents.volks.pm.volk, orchestrata_ultimate.agents.volks.qa._autofix, orchestrata_ultimate.agents.volks.qa._testgen, orchestrata_ultimate.agents.volks.qa.volk, orchestrata_ultimate.agents.volks.ux.volk, orchestrata_ultimate.context.assembler, orchestrata_ultimate.context.budget, orchestrata_ultimate.context.providers.artifact_digest, orchestrata_ultimate.context.providers.ast_context, orchestrata_ultimate.context.providers.mission_context, orchestrata_ultimate.context.providers.plan_context, orchestrata_ultimate.context.providers.semantic_context, orchestrata_ultimate.context.providers.trimming, orchestrata_ultimate.context.usage_log, orchestrata_ultimate.core.artifact_store, orchestrata_ultimate.core.config.manager, orchestrata_ultimate.core.domain.goal, orchestrata_ultimate.core.env_bootstrap, orchestrata_ultimate.core.graph.adapters.bolt_async, orchestrata_ultimate.core.graph.adapters.bolt_sync, orchestrata_ultimate.core.graph.interfaces, orchestrata_ultimate.core.infra_config, orchestrata_ultimate.core.logging, orchestrata_ultimate.core.monitoring.engine, orchestrata_ultimate.core.packet.compat … and 456 more
Tests that import it tests/agents/test_kernel_handler_ack_only.py, tests/agents/test_message_volk_delivery_status.py, tests/agents/test_postman_adapter.py, tests/agents/volks/concierge/test_volk.py, tests/agents/volks/qa/test_llm_review.py, tests/agents/volks/qa/test_testgen.py, tests/agents/volks/test_base_memory_fold.py, tests/agents/volks/test_memory_context.py, tests/claude/test_session_close_rtm.py, tests/core/test_traceability.py, tests/cxp/test_reply_router.py, tests/drivers/test_aider_driver.py, tests/e2e/test_full_pipeline.py, tests/gateway/handlers/test_config.py, tests/gateway/handlers/test_workflow.py, tests/gateway/test_cli_behavioral.py, tests/gateway/test_cxp_send_receipt_check.py, tests/gateway/test_gateway_metrics.py, tests/gateway/test_heartbeat_presence.py, tests/gateway/test_mcp_registration_installer.py, tests/gateway/test_mcp_transport.py, tests/gateway/test_method_table.py, tests/gateway/test_volk_status_event_broadcast.py, tests/generated_core/test_base_traces_generated.py, tests/governance/test_tabling_safety.py … and 96 more

Class diagram

No classes; see Functions.

Dependency diagram

Dependency diagram orchestrata_ultimate.core.base.traces

Truncated at 25 nodes: showing 0 of 0 imports and 24 of 516 importers.

API

Functions

Function Signature Summary
_validate_req_id _validate_req_id(req_id: str) -> bool Check if a requirement ID matches the expected format.
traces traces(spec: str = '', story: str = '', reqs: list[str] | None = None) -> Callable[[T], T] Decorator that annotates classes/methods with requirement traceability.

Source

Permalink: https://gitlab.com/MSamy/orchestrata-ultimate-architecture/-/blob/a4cbc2bdf/src/orchestrata_ultimate/core/base/traces.py

"""Traceability decorator — layer-0 safe.

Provides the @traces decorator used to annotate classes and functions
with specification, story, and requirement IDs.  Zero external imports
(moves here from core.tracing.traceability to eliminate layer-0 upward
imports).
"""

from __future__ import annotations

import re
from collections.abc import Callable
from typing import TypeVar

T = TypeVar("T")

_REQ_ID_PATTERN = re.compile(
    r"^REQ-\d{3}-(?:\d{3}(?:-\d{3})?|[A-Z]{2,4}\d*-\d{3}|[A-Z]{2,4}-\d{3}-\d{3}|C\d+|Exit-Criteria-for-Th-\d{3})$"
)
_US_ID_PATTERN = re.compile(r"^US-\d{3}-\d{3}$")


def _validate_req_id(req_id: str) -> bool:
    """Check if a requirement ID matches the expected format."""
    return bool(_REQ_ID_PATTERN.match(req_id) or _US_ID_PATTERN.match(req_id))


def traces(
    spec: str = "",
    story: str = "",
    reqs: list[str] | None = None,
) -> Callable[[T], T]:
    """Decorator that annotates classes/methods with requirement traceability.

    Args:
        spec: Specification ID (e.g., "001", "002").
        story: User story ID (e.g., "US-001", "US-002").
        reqs: List of requirement IDs (e.g., ["REQ-001-001-001"]).

    Returns:
        The original class/function with __traces__ attribute attached.

    Raises:
        ValueError: If reqs is empty or contains invalid IDs.
    """
    if reqs is None:
        reqs = []

    if not reqs:
        raise ValueError("@traces requires at least one requirement ID in reqs=[]")

    for req_id in reqs:
        if not _validate_req_id(req_id):
            raise ValueError(
                f"Invalid requirement ID format: '{req_id}'. "
                f"Expected REQ-NNN-NNN[-NNN], REQ-NNN-ACn-NNN, REQ-NNN-FRn-NNN, "
                f"REQ-NNN-USn-NNN, REQ-NNN-NFRn-NNN, REQ-NNN-Cn (cluster/phase id, "
                f"e.g. REQ-033-C1), or US-NNN-NNN."
            )

    def decorator(obj: T) -> T:
        existing = getattr(obj, "__traces__", None)
        new_entry = {"spec": spec, "story": story, "reqs": list(reqs)}
        if existing is None:
            obj.__traces__ = new_entry  # type: ignore[attr-defined]
        elif isinstance(existing, list):
            existing.append(new_entry)
        else:
            obj.__traces__ = [existing, new_entry]  # type: ignore[attr-defined]
        return obj

    return decorator