43 lines
1.6 KiB
Python
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()
|