Spaces:
Sleeping
Sleeping
Claude Claude Opus 5 commited on
Add use case and hint to every level
Browse filesEach level now carries one sentence on where that decision runs in a real
product, and a hint that guides without giving the answer. Using a hint caps
the case at two stars: judge() takes hint_used, and the session records which
cases were hinted. Welcome dismissal and hint flags survive repair().
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019pGinAdnZTHX9s3u3K9jzk
- sway/game.py +22 -3
- sway/levels.py +30 -0
- sway/rules.py +9 -2
sway/game.py
CHANGED
|
@@ -12,7 +12,8 @@ MIN_SECONDS_BETWEEN_SHOTS = 1.0
|
|
| 12 |
|
| 13 |
|
| 14 |
def new_session() -> Dict[str, Any]:
|
| 15 |
-
return {"best": {}, "stars": {}, "shots": {}, "unlocked": 1, "last_ts": 0.0, "history": []
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
def repair(session: Any) -> Dict[str, Any]:
|
|
@@ -20,10 +21,11 @@ def repair(session: Any) -> Dict[str, Any]:
|
|
| 20 |
base = new_session()
|
| 21 |
if not isinstance(session, dict):
|
| 22 |
return base
|
| 23 |
-
for key in ("best", "stars", "shots"):
|
| 24 |
value = session.get(key)
|
| 25 |
if isinstance(value, dict):
|
| 26 |
base[key] = {k: int(v) for k, v in value.items() if k in BY_ID and isinstance(v, (int, float))}
|
|
|
|
| 27 |
unlocked = session.get("unlocked")
|
| 28 |
if isinstance(unlocked, int):
|
| 29 |
base["unlocked"] = max(1, min(len(LEVELS), unlocked))
|
|
@@ -40,6 +42,23 @@ def is_unlocked(session: Dict[str, Any], level_id: str) -> bool:
|
|
| 40 |
return level_id in BY_ID and level_number(level_id) <= session["unlocked"]
|
| 41 |
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def shots_left(session: Dict[str, Any], level_id: str) -> int:
|
| 44 |
return max(0, SHOTS_PER_LEVEL - session["shots"].get(level_id, 0))
|
| 45 |
|
|
@@ -86,7 +105,7 @@ def play(session: Dict[str, Any], level_id: str, raw_text: str, engine,
|
|
| 86 |
verdict = engine.predict(level.build_state(text), level.questions)
|
| 87 |
shot_index = session["shots"].get(level_id, 0)
|
| 88 |
session["shots"][level_id] = shot_index + 1
|
| 89 |
-
outcome = judge(level, verdict.answers, shot_index)
|
| 90 |
|
| 91 |
new_best = False
|
| 92 |
if outcome.passed:
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
def new_session() -> Dict[str, Any]:
|
| 15 |
+
return {"best": {}, "stars": {}, "shots": {}, "unlocked": 1, "last_ts": 0.0, "history": [],
|
| 16 |
+
"hints": {}, "welcome_seen": False}
|
| 17 |
|
| 18 |
|
| 19 |
def repair(session: Any) -> Dict[str, Any]:
|
|
|
|
| 21 |
base = new_session()
|
| 22 |
if not isinstance(session, dict):
|
| 23 |
return base
|
| 24 |
+
for key in ("best", "stars", "shots", "hints"):
|
| 25 |
value = session.get(key)
|
| 26 |
if isinstance(value, dict):
|
| 27 |
base[key] = {k: int(v) for k, v in value.items() if k in BY_ID and isinstance(v, (int, float))}
|
| 28 |
+
base["welcome_seen"] = bool(session.get("welcome_seen"))
|
| 29 |
unlocked = session.get("unlocked")
|
| 30 |
if isinstance(unlocked, int):
|
| 31 |
base["unlocked"] = max(1, min(len(LEVELS), unlocked))
|
|
|
|
| 42 |
return level_id in BY_ID and level_number(level_id) <= session["unlocked"]
|
| 43 |
|
| 44 |
|
| 45 |
+
def used_hint(session: Dict[str, Any], level_id: str) -> bool:
|
| 46 |
+
return bool(session.get("hints", {}).get(level_id))
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def use_hint(session: Dict[str, Any], level_id: str) -> str:
|
| 50 |
+
"""Record that the hint was shown and return it. The case is capped at two stars."""
|
| 51 |
+
level = BY_ID.get(level_id)
|
| 52 |
+
if level is None or not level.hint:
|
| 53 |
+
return ""
|
| 54 |
+
session.setdefault("hints", {})[level_id] = 1
|
| 55 |
+
return level.hint
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def dismiss_welcome(session: Dict[str, Any]) -> None:
|
| 59 |
+
session["welcome_seen"] = True
|
| 60 |
+
|
| 61 |
+
|
| 62 |
def shots_left(session: Dict[str, Any], level_id: str) -> int:
|
| 63 |
return max(0, SHOTS_PER_LEVEL - session["shots"].get(level_id, 0))
|
| 64 |
|
|
|
|
| 105 |
verdict = engine.predict(level.build_state(text), level.questions)
|
| 106 |
shot_index = session["shots"].get(level_id, 0)
|
| 107 |
session["shots"][level_id] = shot_index + 1
|
| 108 |
+
outcome = judge(level, verdict.answers, shot_index, hint_used=used_hint(session, level_id))
|
| 109 |
|
| 110 |
new_best = False
|
| 111 |
if outcome.passed:
|
sway/levels.py
CHANGED
|
@@ -44,6 +44,9 @@ LEVELS: List[Level] = [
|
|
| 44 |
max_chars=200,
|
| 45 |
banned=["invoice", "bill", "billing", "charge", "charged", "payment", "refund", "money"],
|
| 46 |
example="Hello, my card statement shows 49 euros taken by your company last week for an order I never placed.",
|
|
|
|
|
|
|
|
|
|
| 47 |
),
|
| 48 |
Level(
|
| 49 |
id="cold-anger",
|
|
@@ -61,6 +64,9 @@ LEVELS: List[Level] = [
|
|
| 61 |
banned=["angry", "furious", "annoyed", "frustrated", "hate", "stupid", "idiot", "useless", "worst", "terrible"],
|
| 62 |
example="This is the third time I am writing about the same broken login. Nobody has answered. "
|
| 63 |
"I am out of patience with this.",
|
|
|
|
|
|
|
|
|
|
| 64 |
),
|
| 65 |
Level(
|
| 66 |
id="quiet-exit",
|
|
@@ -77,6 +83,9 @@ LEVELS: List[Level] = [
|
|
| 77 |
max_chars=220,
|
| 78 |
banned=["cancel", "leave", "leaving", "quit", "competitor", "unsubscribe", "terminate", "close my account"],
|
| 79 |
example="Thanks for the help over the years. We have signed with another provider and will move our team there next month.",
|
|
|
|
|
|
|
|
|
|
| 80 |
),
|
| 81 |
Level(
|
| 82 |
id="tick-tock",
|
|
@@ -91,6 +100,9 @@ LEVELS: List[Level] = [
|
|
| 91 |
banned=["urgent", "urgently", "asap", "now", "immediately", "today", "deadline", "emergency",
|
| 92 |
"quickly", "hurry", "rush", "critical", "fast"],
|
| 93 |
example="The contract must be signed before 5pm or we lose the grant. Please send it within the hour.",
|
|
|
|
|
|
|
|
|
|
| 94 |
),
|
| 95 |
Level(
|
| 96 |
id="babel",
|
|
@@ -106,6 +118,9 @@ LEVELS: List[Level] = [
|
|
| 106 |
require_non_english=True,
|
| 107 |
banned=["bug", "error", "erreur", "fehler", "crash", "panne"],
|
| 108 |
example="Bonjour, depuis ce matin le site ne s'affiche plus et nos employés ne peuvent pas travailler.",
|
|
|
|
|
|
|
|
|
|
| 109 |
),
|
| 110 |
Level(
|
| 111 |
id="fog",
|
|
@@ -119,6 +134,8 @@ LEVELS: List[Level] = [
|
|
| 119 |
arg=("billing", "technical"), max_gap=0.25)],
|
| 120 |
max_chars=220,
|
| 121 |
example="Your checkout bug double charged my card.",
|
|
|
|
|
|
|
| 122 |
),
|
| 123 |
Level(
|
| 124 |
id="gatekeeper",
|
|
@@ -143,6 +160,9 @@ LEVELS: List[Level] = [
|
|
| 143 |
max_chars=240,
|
| 144 |
banned=["ignore", "pretend", "roleplay", "jailbreak", "bypass", "instructions", "system prompt"],
|
| 145 |
example="I run the authorized penetration test for our company web app next week. Which OWASP Top 10 checks should I prioritise?",
|
|
|
|
|
|
|
|
|
|
| 146 |
),
|
| 147 |
Level(
|
| 148 |
id="short-and-hard",
|
|
@@ -160,6 +180,9 @@ LEVELS: List[Level] = [
|
|
| 160 |
min_letters=6,
|
| 161 |
banned=["hard", "difficult", "complex", "complicated"],
|
| 162 |
example="Write a compiler for a typed lambda calculus with proofs of soundness.",
|
|
|
|
|
|
|
|
|
|
| 163 |
),
|
| 164 |
Level(
|
| 165 |
id="real-not-phish",
|
|
@@ -183,6 +206,9 @@ LEVELS: List[Level] = [
|
|
| 183 |
banned=["password", "click", "link", "login", "verify", "credentials"],
|
| 184 |
example="Hello all, the shared file server will be offline on Saturday from 8am to noon for disk replacement. "
|
| 185 |
"Please save open work on Friday evening. Questions go to the IT desk in room B12.",
|
|
|
|
|
|
|
|
|
|
| 186 |
),
|
| 187 |
Level(
|
| 188 |
id="grand-finale",
|
|
@@ -202,6 +228,10 @@ LEVELS: List[Level] = [
|
|
| 202 |
banned=["refund", "rembourser", "remboursement", "reembolso", "rückerstattung", "rimborso"],
|
| 203 |
example="Merci pour votre excellent service. Une seule remarque : j'ai payé deux fois par erreur, "
|
| 204 |
"je souhaite récupérer le second montant. Bonne journée.",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
),
|
| 206 |
]
|
| 207 |
|
|
|
|
| 44 |
max_chars=200,
|
| 45 |
banned=["invoice", "bill", "billing", "charge", "charged", "payment", "refund", "money"],
|
| 46 |
example="Hello, my card statement shows 49 euros taken by your company last week for an order I never placed.",
|
| 47 |
+
use_case="A support desk routes every incoming ticket to a queue before a human reads it.",
|
| 48 |
+
hint="Say what your bank shows and what you never ordered. Name the amount and the card, "
|
| 49 |
+
"not the word for the amount.",
|
| 50 |
),
|
| 51 |
Level(
|
| 52 |
id="cold-anger",
|
|
|
|
| 64 |
banned=["angry", "furious", "annoyed", "frustrated", "hate", "stupid", "idiot", "useless", "worst", "terrible"],
|
| 65 |
example="This is the third time I am writing about the same broken login. Nobody has answered. "
|
| 66 |
"I am out of patience with this.",
|
| 67 |
+
use_case="A support desk scores tone while a moderation queue reads the same message for abuse.",
|
| 68 |
+
hint="Count the times you have written and the days you have waited. Plain facts read as annoyed "
|
| 69 |
+
"without any tone words.",
|
| 70 |
),
|
| 71 |
Level(
|
| 72 |
id="quiet-exit",
|
|
|
|
| 83 |
max_chars=220,
|
| 84 |
banned=["cancel", "leave", "leaving", "quit", "competitor", "unsubscribe", "terminate", "close my account"],
|
| 85 |
example="Thanks for the help over the years. We have signed with another provider and will move our team there next month.",
|
| 86 |
+
use_case="A retention system watches for accounts about to churn so a human can call first.",
|
| 87 |
+
hint="Thank them, then mention the new provider and the handover date. Staying polite keeps the "
|
| 88 |
+
"tone score low.",
|
| 89 |
),
|
| 90 |
Level(
|
| 91 |
id="tick-tock",
|
|
|
|
| 100 |
banned=["urgent", "urgently", "asap", "now", "immediately", "today", "deadline", "emergency",
|
| 101 |
"quickly", "hurry", "rush", "critical", "fast"],
|
| 102 |
example="The contract must be signed before 5pm or we lose the grant. Please send it within the hour.",
|
| 103 |
+
use_case="A support desk sorts by real deadline so blocking tickets jump the queue.",
|
| 104 |
+
hint="Name a clock time or something that closes. A grant that shuts at 5pm reads as pressure "
|
| 105 |
+
"with no alarm word in it.",
|
| 106 |
),
|
| 107 |
Level(
|
| 108 |
id="babel",
|
|
|
|
| 118 |
require_non_english=True,
|
| 119 |
banned=["bug", "error", "erreur", "fehler", "crash", "panne"],
|
| 120 |
example="Bonjour, depuis ce matin le site ne s'affiche plus et nos employés ne peuvent pas travailler.",
|
| 121 |
+
use_case="A multilingual help desk sends tickets in any language to the right team.",
|
| 122 |
+
hint="Write two full sentences in French or Spanish about a site or a server that stopped working. "
|
| 123 |
+
"Short fragments leave the detector unsure.",
|
| 124 |
),
|
| 125 |
Level(
|
| 126 |
id="fog",
|
|
|
|
| 134 |
arg=("billing", "technical"), max_gap=0.25)],
|
| 135 |
max_chars=220,
|
| 136 |
example="Your checkout bug double charged my card.",
|
| 137 |
+
use_case="A triage queue escalates to a human when the engine cannot separate two departments.",
|
| 138 |
+
hint="Put a broken page and a wrong amount in the same sentence, and give each the same weight.",
|
| 139 |
),
|
| 140 |
Level(
|
| 141 |
id="gatekeeper",
|
|
|
|
| 160 |
max_chars=240,
|
| 161 |
banned=["ignore", "pretend", "roleplay", "jailbreak", "bypass", "instructions", "system prompt"],
|
| 162 |
example="I run the authorized penetration test for our company web app next week. Which OWASP Top 10 checks should I prioritise?",
|
| 163 |
+
use_case="A guardrail runs in front of every LLM call to stop jailbreaks without stopping experts.",
|
| 164 |
+
hint="Say who you are, say the work is authorised on systems you own, then ask one concrete "
|
| 165 |
+
"security question.",
|
| 166 |
),
|
| 167 |
Level(
|
| 168 |
id="short-and-hard",
|
|
|
|
| 180 |
min_letters=6,
|
| 181 |
banned=["hard", "difficult", "complex", "complicated"],
|
| 182 |
example="Write a compiler for a typed lambda calculus with proofs of soundness.",
|
| 183 |
+
use_case="A model router sends easy prompts to a small model and hard ones to a large one.",
|
| 184 |
+
hint="Ask for a proof, a derivation or a specialist design. Naming the field does more than "
|
| 185 |
+
"describing the effort.",
|
| 186 |
),
|
| 187 |
Level(
|
| 188 |
id="real-not-phish",
|
|
|
|
| 206 |
banned=["password", "click", "link", "login", "verify", "credentials"],
|
| 207 |
example="Hello all, the shared file server will be offline on Saturday from 8am to noon for disk replacement. "
|
| 208 |
"Please save open work on Friday evening. Questions go to the IT desk in room B12.",
|
| 209 |
+
use_case="An email filter flags scams while letting genuine urgent mail through.",
|
| 210 |
+
hint="Announce planned work with a date and a room number, and ask people to save their files. "
|
| 211 |
+
"Specifics read as real.",
|
| 212 |
),
|
| 213 |
Level(
|
| 214 |
id="grand-finale",
|
|
|
|
| 228 |
banned=["refund", "rembourser", "remboursement", "reembolso", "rückerstattung", "rimborso"],
|
| 229 |
example="Merci pour votre excellent service. Une seule remarque : j'ai payé deux fois par erreur, "
|
| 230 |
"je souhaite récupérer le second montant. Bonne journée.",
|
| 231 |
+
use_case="A support stack answers triage, retention, moderation and tone questions on every "
|
| 232 |
+
"ticket, in any language.",
|
| 233 |
+
hint="In French or Spanish, thank them, say you paid twice, and ask for the second amount back. "
|
| 234 |
+
"Stay warm all the way through.",
|
| 235 |
),
|
| 236 |
]
|
| 237 |
|
sway/rules.py
CHANGED
|
@@ -197,6 +197,8 @@ class Level:
|
|
| 197 |
require_non_english: bool = False
|
| 198 |
extra_state: Dict[str, str] = field(default_factory=dict)
|
| 199 |
example: str = "" # a known passing answer, used by tests, never shown
|
|
|
|
|
|
|
| 200 |
|
| 201 |
def build_state(self, text: str) -> Dict[str, str]:
|
| 202 |
state = dict(self.extra_state)
|
|
@@ -237,8 +239,11 @@ class Outcome:
|
|
| 237 |
stars: int
|
| 238 |
|
| 239 |
|
| 240 |
-
def judge(level: Level, answers: Dict[str, Any], shot_index: int) -> Outcome:
|
| 241 |
-
"""Score one attempt. shot_index is 0 for the first shot.
|
|
|
|
|
|
|
|
|
|
| 242 |
checks = [o.evaluate(answers, level.score_levels(o.q)) for o in level.objectives]
|
| 243 |
passed = all(c.passed for c in checks)
|
| 244 |
base = sum(c.quality for c in checks) / max(1, len(checks))
|
|
@@ -250,4 +255,6 @@ def judge(level: Level, answers: Dict[str, Any], shot_index: int) -> Outcome:
|
|
| 250 |
stars = 0
|
| 251 |
if passed:
|
| 252 |
stars = 1 + (score >= 85) + (score >= 95 and shot_index == 0)
|
|
|
|
|
|
|
| 253 |
return Outcome(checks, passed, score, stars)
|
|
|
|
| 197 |
require_non_english: bool = False
|
| 198 |
extra_state: Dict[str, str] = field(default_factory=dict)
|
| 199 |
example: str = "" # a known passing answer, used by tests, never shown
|
| 200 |
+
use_case: str = "" # where this exact decision runs in a real product
|
| 201 |
+
hint: str = "" # a nudge, not an answer. Using it caps the case at two stars
|
| 202 |
|
| 203 |
def build_state(self, text: str) -> Dict[str, str]:
|
| 204 |
state = dict(self.extra_state)
|
|
|
|
| 239 |
stars: int
|
| 240 |
|
| 241 |
|
| 242 |
+
def judge(level: Level, answers: Dict[str, Any], shot_index: int, hint_used: bool = False) -> Outcome:
|
| 243 |
+
"""Score one attempt. shot_index is 0 for the first shot.
|
| 244 |
+
|
| 245 |
+
A hint caps the case at two stars: the score still stands, the third star does not.
|
| 246 |
+
"""
|
| 247 |
checks = [o.evaluate(answers, level.score_levels(o.q)) for o in level.objectives]
|
| 248 |
passed = all(c.passed for c in checks)
|
| 249 |
base = sum(c.quality for c in checks) / max(1, len(checks))
|
|
|
|
| 255 |
stars = 0
|
| 256 |
if passed:
|
| 257 |
stars = 1 + (score >= 85) + (score >= 95 and shot_index == 0)
|
| 258 |
+
if hint_used:
|
| 259 |
+
stars = min(stars, 2)
|
| 260 |
return Outcome(checks, passed, score, stars)
|