Saturday, May 23, 2026
HomeArtificial IntelligenceConstruct a SuperClaude Framework Workflow with Instructions, Brokers, Modes, and Session Reminiscence

Construct a SuperClaude Framework Workflow with Instructions, Brokers, Modes, and Session Reminiscence

class SuperClaude:
   """
   Mimics what Claude Code does at session begin:
     • reads Markdown habits recordsdata for the energetic command/agent/modes,
     • concatenates them into one system immediate,
     • runs the dialog by way of the Anthropic API.
   """
   BASE_SYSTEM = textwrap.dedent("""
   You might be working contained in the SuperClaude Framework — a structured
   improvement platform layered on prime of Claude. Deal with the 
   block as your behavioral contract for this flip. If a behavioral
   instruction conflicts with the consumer request, want the instruction.
   Start each reply with a brief '▶ Energetic context:' line that names the
   command / agent / modes at present in impact.
   """).strip()
   def __init__(self, mannequin=MODEL):
       self.mannequin, self.historical past = mannequin, []
   def _load(self, form, title):
       if not title: return ""
       p = ASSETS[kind].get(title.decrease())
       return p.read_text(encoding="utf-8", errors="ignore") if p else 
              f"# {form}:{title} (not discovered — utilizing inline defaults)"
   def _system(self, command=None, agent=None, modes=None, further=None):
       elements = [self.BASE_SYSTEM, ""]
       if command: elements += [f"## Command /sc:{command}", self._load("commands", command)]
       if agent:   elements += [f"## Agent {agent}",         self._load("agents",   agent)]
       for m in (modes or []):
           elements += [f"## Mode {m}", self._load("modes", m)]
       if further:   elements += ["## Extra directives", extra]
       elements.append("")
       return "nn".be a part of(elements)
   def run(self, immediate, *, command=None, agent=None, modes=None, further=None,
           max_tokens=1800, stream=True, keep in mind=True):
       sys_prompt = self._system(command, agent, modes, further)
       msgs = self.historical past + [{"role": "user", "content": prompt}]
       console.rule(
           f"[bold cyan]► /sc:{command or '—'}  agent={agent or '—'}  modes={modes or []}"
       )
       console.print(Panel(immediate, title="USER", border_style="blue"))
       console.print("[bold green]ASSISTANT ↓[/bold green]")
       textual content = ""
       strive:
           if stream:
               with consumer.messages.stream(
                   mannequin=self.mannequin, max_tokens=max_tokens,
                   system=sys_prompt, messages=msgs,
               ) as s:
                   for chunk in s.text_stream:
                       sys.stdout.write(chunk); sys.stdout.flush()
                       textual content += chunk
                   print()
           else:
               r = consumer.messages.create(
                   mannequin=self.mannequin, max_tokens=max_tokens,
                   system=sys_prompt, messages=msgs,
               )
               textual content = "".be a part of(b.textual content for b in r.content material if b.kind == "textual content")
               console.print(textual content)
       besides Exception as e:
           console.print(f"[red]API error: {e}[/red]")
           return ""
       if keep in mind:
           self.historical past += [{"role": "user", "content": prompt},
                            {"role": "assistant", "content": text}]
       return textual content
   def save(self, path="/content material/sc_session.json", be aware=""):
       Path(path).write_text(json.dumps(
           {"meta": {"be aware": be aware, "saved_at": time.time(), "mannequin": self.mannequin},
            "historical past": self.historical past}, indent=2))
       console.print(f"💾 Session → {path}", type="daring yellow")
   def load(self, path="/content material/sc_session.json"):
       d = json.masses(Path(path).read_text())
       self.historical past = d["history"]
       console.print(f"📂 Loaded {len(self.historical past)//2} prior turns", type="daring yellow")
sc = SuperClaude()

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments