Files
agentic-resources/session_memory/distribute/claude.py
tegwick 9e28b1b806 session-memory: Claude + Codex + Grok distributors + registry (WP-0007 T02/T03)
Thin per-flavor distributors over the shared base: Claude (CLAUDE.md, optional
skill-stub mode), Codex (AGENTS.md), Grok (.grok/instructions.md). registry maps
flavor->distributor — adding a flavor is one entry + one module. Same agnostic
body renders to distinct per-flavor targets (FR-A3). 7 new tests; suite 117/117.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-07 15:06:15 +02:00

43 lines
1.6 KiB
Python

"""Claude distributor (PRD §6.4 FR-X1; T02).
Renders an approved Solution Pattern into a ``CLAUDE.md`` snippet block. Most logic
is inherited from :class:`BaseDistributor`; the Claude-specific touch is an
optional **skill** rendering mode (``rendering_hints["claude"]["as"] == "skill"``)
that emits a skill-style stub instead of a plain instruction snippet — Claude's
native distribution targets are CLAUDE.md snippets, skills, or hooks.
"""
from __future__ import annotations
from ..curate.schema import SolutionPattern
from .base import BaseDistributor, hint, render_markdown_body
class ClaudeDistributor(BaseDistributor):
flavor = "claude"
target_path = "CLAUDE.md"
def body(self, pattern: SolutionPattern) -> str:
override = hint(pattern, self.flavor, "body")
if override:
return override
if hint(pattern, self.flavor, "as") == "skill":
return self._skill_stub(pattern)
return render_markdown_body(pattern)
@staticmethod
def _skill_stub(pattern: SolutionPattern) -> str:
trigger = "avoid" if pattern.polarity == "problem" else "apply"
lines = [
f"## Skill: {pattern.name}",
"",
f"**When:** situations where you would {trigger}{pattern.problem.strip()}",
"",
"**Steps:**",
]
for r in pattern.resolutions:
lines.append(f"- {r.summary}" + (f"{r.detail}" if r.detail else ""))
for step in r.steps:
lines.append(f" - {step}")
return "\n".join(lines).strip()