0ef5fcb1c5
Security / Dependency audit (pip-audit) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Security / Secret scan (gitleaks) (push) Has been cancelled
rust / test (ubuntu) (push) Has been cancelled
rust / simulator e2e (macos-latest) (push) Has been cancelled
rust / simulator e2e (ubuntu-latest) (push) Has been cancelled
rust / simulator e2e (windows-latest) (push) Has been cancelled
rust / wheels (aarch64-apple-darwin) (push) Has been cancelled
rust / wheels (x86_64-unknown-linux-gnu) (push) Has been cancelled
rust / wheels (x86_64-apple-darwin) (push) Has been cancelled
rust / audit (push) Has been cancelled
rust / parity (nightly, allowed to fail during Phase 0) (push) Has been cancelled
CI / commitlint (push) Has been skipped
Dev Containers / validate (.devcontainer/devcontainer.json, default) (push) Failing after 0s
Dev Containers / validate (.devcontainer/memory-stack/devcontainer.json, memory-stack) (push) Failing after 0s
Dev Containers / validate-worktree (push) Failing after 0s
CI / changes (push) Failing after 4s
Deploy Documentation / validate (push) Has been skipped
Deploy Documentation / deploy (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 1s
OpenCode Plugin / typecheck + build + test (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 1s
Release Please / release-please (push) Failing after 1s
Wrap E2E / docker-wrap-e2e (push) Failing after 1s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 1s
Init E2E / docker-init-e2e (push) Failing after 4s
Merge Conflicts / merge-conflicts (push) Failing after 4s
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-wheel-windows (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (3) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / promote-latest (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
183 lines
6.2 KiB
Python
183 lines
6.2 KiB
Python
"""Data models for Headroom Learn — tool-agnostic abstractions.
|
|
|
|
These models normalize tool call data from ANY agent system (Claude Code, Cursor,
|
|
Codex, custom agents) into a common format that analyzers can work with.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
from pathlib import Path
|
|
|
|
# =============================================================================
|
|
# Error Classification
|
|
# =============================================================================
|
|
|
|
|
|
class ErrorCategory(str, Enum):
|
|
"""Classified error categories for tool call failures."""
|
|
|
|
FILE_NOT_FOUND = "file_not_found"
|
|
MODULE_NOT_FOUND = "module_not_found"
|
|
COMMAND_NOT_FOUND = "command_not_found"
|
|
PERMISSION_DENIED = "permission_denied"
|
|
FILE_TOO_LARGE = "file_too_large"
|
|
IS_DIRECTORY = "is_directory"
|
|
SYNTAX_ERROR = "syntax_error"
|
|
RUNTIME_ERROR = "runtime_error"
|
|
TIMEOUT = "timeout"
|
|
NO_MATCHES = "no_matches" # Grep/Glob found nothing
|
|
USER_REJECTED = "user_rejected"
|
|
SIBLING_ERROR = "sibling_error" # Cascade from parallel call failure
|
|
EXIT_CODE = "exit_code"
|
|
CONNECTION_ERROR = "connection_error"
|
|
BUILD_FAILURE = "build_failure"
|
|
UNKNOWN = "unknown"
|
|
|
|
|
|
# =============================================================================
|
|
# Core Data Models (Tool-Agnostic)
|
|
# =============================================================================
|
|
|
|
|
|
@dataclass
|
|
class ToolCall:
|
|
"""A single tool call and its result — normalized from any agent system.
|
|
|
|
This is the fundamental unit of analysis. Scanners produce these,
|
|
analyzers consume them.
|
|
"""
|
|
|
|
name: str # Tool name ("Bash", "Read", "file_search", etc.)
|
|
tool_call_id: str # Unique ID linking call to result
|
|
input_data: dict # Tool input parameters
|
|
output: str # Result content (may be error message)
|
|
is_error: bool # Whether the call failed
|
|
error_category: ErrorCategory = ErrorCategory.UNKNOWN
|
|
msg_index: int = 0 # Position in conversation
|
|
output_bytes: int = 0 # Size of output
|
|
|
|
@property
|
|
def input_summary(self) -> str:
|
|
"""Short summary of tool input for display."""
|
|
if self.name in ("Bash", "bash"):
|
|
cmd: str = self.input_data.get("command", "")
|
|
return cmd[:100] + "..." if len(cmd) > 100 else cmd
|
|
if self.name in ("Read", "read"):
|
|
return str(self.input_data.get("file_path", "?"))
|
|
if self.name in ("Grep", "grep"):
|
|
return str(self.input_data.get("pattern", "?"))
|
|
if self.name in ("Glob", "glob"):
|
|
return str(self.input_data.get("pattern", "?"))
|
|
if self.name in ("Edit", "edit", "Write", "write"):
|
|
return str(self.input_data.get("file_path", "?"))
|
|
return str(self.input_data)[:80]
|
|
|
|
|
|
@dataclass
|
|
class SessionEvent:
|
|
"""Any event in a session — tool calls, user messages, interruptions.
|
|
|
|
Provides richer context than ToolCall alone, enabling
|
|
user preference mining and conversation understanding.
|
|
"""
|
|
|
|
type: str # "tool_call", "user_message", "interruption", "agent_summary"
|
|
msg_index: int
|
|
timestamp: str | None = None
|
|
|
|
# For tool_call type
|
|
tool_call: ToolCall | None = None
|
|
|
|
# For user_message type
|
|
text: str = ""
|
|
|
|
# For agent_summary type (subagent results)
|
|
agent_id: str = ""
|
|
agent_tool_count: int = 0
|
|
agent_tokens: int = 0
|
|
agent_duration_ms: int = 0
|
|
agent_prompt: str = ""
|
|
|
|
|
|
@dataclass
|
|
class SessionData:
|
|
"""Normalized data from a single conversation session."""
|
|
|
|
session_id: str
|
|
tool_calls: list[ToolCall] = field(default_factory=list)
|
|
events: list[SessionEvent] = field(default_factory=list)
|
|
timestamp: datetime | None = None
|
|
total_input_tokens: int = 0
|
|
total_output_tokens: int = 0
|
|
source: str = "main" # "main" | "subagent" | "workflow" — where this transcript came from
|
|
|
|
@property
|
|
def failure_count(self) -> int:
|
|
return sum(1 for tc in self.tool_calls if tc.is_error)
|
|
|
|
@property
|
|
def failure_rate(self) -> float:
|
|
if not self.tool_calls:
|
|
return 0.0
|
|
return self.failure_count / len(self.tool_calls)
|
|
|
|
|
|
@dataclass
|
|
class ProjectInfo:
|
|
"""Information about a project discovered by a scanner."""
|
|
|
|
name: str # Human-readable project name
|
|
project_path: Path # Actual project directory
|
|
data_path: Path # Where conversation logs are stored
|
|
context_file: Path | None = None # CLAUDE.md / .cursorrules / AGENTS.md
|
|
memory_file: Path | None = None # MEMORY.md or equivalent
|
|
|
|
|
|
# =============================================================================
|
|
# Analysis Output Models
|
|
# =============================================================================
|
|
|
|
|
|
class RecommendationTarget(str, Enum):
|
|
"""Where a recommendation should be written."""
|
|
|
|
CONTEXT_FILE = "context_file" # CLAUDE.md, .cursorrules, AGENTS.md
|
|
MEMORY_FILE = "memory_file" # MEMORY.md or equivalent
|
|
|
|
|
|
@dataclass
|
|
class Recommendation:
|
|
"""A concrete recommendation to write to a context/memory file."""
|
|
|
|
target: RecommendationTarget
|
|
section: str # Section heading (e.g., "Environment", "Known Large Files")
|
|
content: str # Markdown content for the section
|
|
confidence: float = 0.0 # 0-1, based on evidence strength
|
|
evidence_count: int = 0 # Number of failures supporting this
|
|
estimated_tokens_saved: int = 0 # Projected savings if recommendation is followed
|
|
# Loop weighting (see headroom.learn.loops): set when this recommendation
|
|
# guards against a detected repeated pattern. Loop guardrails are ranked
|
|
# above one-off rules because their waste scales with repetition.
|
|
is_loop_guardrail: bool = False
|
|
loop_occurrences: int = 0 # Repetitions of the loop this rule guards against
|
|
|
|
|
|
@dataclass
|
|
class AnalysisResult:
|
|
"""Output of session analysis — stats + recommendations."""
|
|
|
|
project: ProjectInfo
|
|
total_sessions: int = 0
|
|
total_calls: int = 0
|
|
total_failures: int = 0
|
|
recommendations: list[Recommendation] = field(default_factory=list)
|
|
|
|
@property
|
|
def failure_rate(self) -> float:
|
|
if not self.total_calls:
|
|
return 0.0
|
|
return self.total_failures / self.total_calls
|