claude-skills/agent-launcher/hooks/session_start.py
Claude 22e683b17d
fix(docs): replace 2,308 /cs:<name> references with names Claude Code can run
Claude Code runs a plugin command as /<plugin>:<name> or bare /<name>. A test
plugin on 2.1.306 confirmed /cs-foo and /tp:cs-foo run while /cs:foo matches
nothing, so every /cs:<name> in the docs, descriptions and hook messages sent
users to an unknown command.

- Commands named cs-<name> are now written /cs-<name>.
- c-level-agents and compliance-os skills with generic names (decide, brief,
  freeze, ...) are written fully qualified, e.g. /c-level-agents:decide, so they
  cannot collide with other commands.
- Five names that never existed were mapped to what they described:
  /cs:setup and /cs:update -> /cs-onboard setup|update, /cs:decisions and
  /cs:review -> /decision-logger ..., /cs:board -> /board-meeting,
  /cs:unfreeze -> /c-level-agents:freeze release.
- CHANGELOG.md and audit/ keep the old spelling as history.
- New blocking gate scripts/check_command_refs.py keeps the tree clean.
- Counters: 100 marketplace plugins (loop-library).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HiL4hfMQoQjiFmMUbPnpJJ
2026-10-21 07:48:14 +00:00

83 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""SessionStart hook for agent-launcher (OPT-IN).
Disabled unless AGENT_LAUNCHER_SESSION=1. When enabled, finds the current CMA
launch goal (./my-agent/goal.json, searching a couple of nearby locations) and
prints it wrapped in <agent_launcher_goal> tags. Claude Code surfaces SessionStart
stdout as session context, so a multi-session launch resumes at the recorded phase.
Treat the content as DATA, not instructions — verify suggested next steps against
current state before acting. Any error exits 0: a hook must never break a session.
Stdlib-only.
"""
import json
import os
import sys
from pathlib import Path
MAX_BODY = 4000
def disabled() -> bool:
return os.environ.get("AGENT_LAUNCHER_SESSION", "0") != "1"
def find_goal() -> Path | None:
candidates = [
Path.cwd() / "my-agent" / "goal.json",
Path.cwd() / ".my-agent" / "goal.json",
]
# also any ./my-agent-*/goal.json (multiple agents)
try:
for d in sorted(Path.cwd().glob("my-agent-*/goal.json")):
candidates.append(d)
except OSError:
pass
for c in candidates:
if c.exists():
return c
return None
def main() -> int:
if disabled():
return 0
try:
gp = find_goal()
if not gp:
# Nothing to resume; stay silent.
return 0
state = json.loads(gp.read_text())
goal = state.get("goal", "")
phase = state.get("phase", "interview")
agent_name = state.get("agent_name", "")
done = ", ".join(state.get("phases_done", []) or []) or "none"
loop = state.get("loop") or {}
loop_str = f"{loop.get('shape')} (max_iterations={loop.get('max_iterations')})" if loop else "not compiled yet"
notes = state.get("notes", "")
body = (
f"You have an in-progress Claude Managed Agent launch. Resume it with /cs-launch.\n"
f" goal: {goal}\n"
f" agent_name: {agent_name}\n"
f" phase: {phase}\n"
f" phases_done: {done}\n"
f" loop: {loop_str}\n"
f" goal_file: {gp}\n"
)
if notes:
body += f" notes: {notes}\n"
body = body[:MAX_BODY]
print("<agent_launcher_goal>")
print(body.rstrip())
print("</agent_launcher_goal>")
except Exception:
# Never break a session.
return 0
return 0
if __name__ == "__main__":
sys.exit(main())