Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 12:03:20 +08:00

130 lines
3.9 KiB
Python

"""Base class for headroom learn plugins.
Each coding agent (Claude Code, Codex, Gemini, Cursor, etc.) implements
a LearnPlugin that bundles scanning, writing, and detection into one unit.
"""
from __future__ import annotations
from abc import ABC, abstractmethod
from .models import ProjectInfo, SessionData
from .writer import ContextWriter
class ConversationScanner(ABC):
"""Base class for scanning conversation logs from any agent system.
Subclasses implement log format parsing for specific tools (Claude Code,
Cursor, Codex, etc.) and produce normalized ToolCall sequences.
"""
@abstractmethod
def discover_projects(self) -> list[ProjectInfo]:
"""Discover all projects with conversation data."""
...
@abstractmethod
def scan_project(
self, project: ProjectInfo, max_workers: int = 1, include_subagents: bool = True
) -> list[SessionData]:
"""Scan all sessions for a project, returning normalized tool calls."""
...
class LearnPlugin(ABC):
"""A self-contained learn plugin for a single coding agent.
Bundles identity, detection, scanning, and writer creation.
Plugins are discovered automatically from headroom.learn.plugins.*
or via ``headroom.learn_plugin`` entry points for external packages.
Example::
class MyAgentPlugin(LearnPlugin, ConversationScanner):
@property
def name(self) -> str:
return "myagent"
@property
def display_name(self) -> str:
return "My Agent"
def detect(self) -> bool:
return Path("~/.myagent/sessions").expanduser().exists()
def discover_projects(self) -> list[ProjectInfo]: ...
def scan_project(
self,
project: ProjectInfo,
max_workers: int = 1,
include_subagents: bool = True,
) -> list[SessionData]: ...
def create_writer(self) -> ContextWriter:
from headroom.learn.writer import GeminiWriter
return GeminiWriter() # or a custom writer
# Module-level instance for auto-discovery
plugin = MyAgentPlugin()
"""
# --- Identity ---
@property
@abstractmethod
def name(self) -> str:
"""Short lowercase identifier used in CLI (e.g., 'claude', 'cursor')."""
...
@property
@abstractmethod
def display_name(self) -> str:
"""Human-readable name (e.g., 'Claude Code', 'Cursor')."""
...
@property
def description(self) -> str:
"""One-line description for --help output."""
return f"{self.display_name} coding agent"
# --- Detection ---
@abstractmethod
def detect(self) -> bool:
"""Return True if this agent has data on the current machine.
Called during auto-detection. Must be cheap (stat checks only, no I/O).
"""
...
# --- Scanning ---
@abstractmethod
def discover_projects(self) -> list[ProjectInfo]:
"""Discover all projects with conversation data for this agent."""
...
@abstractmethod
def scan_project(
self, project: ProjectInfo, max_workers: int = 1, include_subagents: bool = True
) -> list[SessionData]:
"""Scan all sessions for a project, returning normalized data.
Args:
project: The project to scan.
max_workers: Number of threads for parallel file scanning.
1 (default) = serial. >1 = concurrent.
include_subagents: Also scan nested subagent/workflow transcripts
where the agent system writes them (Claude Code).
Ignored by agents without a nested transcript layout.
"""
...
# --- Writing ---
@abstractmethod
def create_writer(self) -> ContextWriter:
"""Return the appropriate ContextWriter for this agent."""
...