users.json gains lang (auto|en|fr) and the guest's last-seen browserLang; /api/me returns it (the owner: en), PUT /api/me and the owner's user update accept it, and the guest's page in Settings → Users gets a Language row. core/i18n.tr() localizes for a French guest: the sign-in and invitation mails, the app's own pushes and feeds, the errors a guest can hit, the New-project form, and one line in the guest run's system prompt so Claude answers in French (tu, ask-form --lang fr). What's new entries are written in French from now on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
5.4 KiB
Python
107 lines
5.4 KiB
Python
"""What's new — the guests' feature carousel, from a session's side.
|
|
|
|
A session that ships a major ai-agent feature puts a *What's new entry* block
|
|
at the end of the form it asks (``ai-agent whats-new fields`` prints it: the
|
|
entry pre-filled — title, bullets, a live mockup editor — for Gabriel to keep,
|
|
edit or decline), then, once the feature is deployed, publishes what he
|
|
answered with ``ai-agent whats-new add --form <id>``. Stdlib only.
|
|
|
|
Entries are written in **French** — title, bullets and the mockup's text,
|
|
tutoiement — since every guest is French (Gabriel's call, 2026-11-01); the
|
|
form around them stays English (it is Gabriel's)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import html
|
|
import json
|
|
import subprocess
|
|
|
|
GROUP = "What's new entry"
|
|
KEYS = ("whatsnew_add", "whatsnew_title", "whatsnew_body", "whatsnew_mockup",
|
|
"whatsnew_mockup_notes")
|
|
|
|
# The mockup's live editor: a preview in a shadow root (the mockup's own
|
|
# <style> stays inside it; the form's theme variables still reach it) over
|
|
# the source in a folded textarea. Reports the HTML as a string.
|
|
_EDITOR = (
|
|
"<div id=pv style=\"border:1px dashed hsl(var(--border));border-radius:10px;padding:6px\"></div>"
|
|
"<details id=dt style=\"margin-top:8px\"><summary style=\"cursor:pointer;font:12px system-ui;"
|
|
"color:hsl(var(--muted-foreground))\">Edit the mockup's HTML</summary>"
|
|
"<textarea id=src spellcheck=false style=\"box-sizing:border-box;width:100%;height:220px;"
|
|
"margin-top:6px;font:11px/1.4 ui-monospace,monospace;border:1px solid hsl(var(--border));"
|
|
"border-radius:8px;padding:8px;background:hsl(var(--background));color:hsl(var(--foreground))\">"
|
|
"</textarea></details>"
|
|
"<script>const D=@@MOCKUP@@;"
|
|
"const R=pv.attachShadow({mode:'open'});"
|
|
"const fit=()=>askForm.setHeight(document.documentElement.scrollHeight+4);"
|
|
"const draw=h=>{R.innerHTML=h;requestAnimationFrame(fit)};"
|
|
"const init=v=>{const h=typeof v==='string'&&v.trim()?v:D;src.value=h;draw(h);askForm.setValue(h)};"
|
|
"init(askForm.value);askForm.onInit(init);"
|
|
"src.oninput=()=>{draw(src.value);askForm.setValue(src.value)};dt.ontoggle=fit;</script>"
|
|
)
|
|
|
|
|
|
def fields(title: str, body: str, mockup: str = "") -> list[dict]:
|
|
"""The ask-form block to append at the end of a form's spec (the
|
|
clarifier appends it verbatim): add it? → title → bullets → mockup →
|
|
changes to the mockup, all pre-filled, all hidden once unticked."""
|
|
cond = {"key": "whatsnew_add", "equals": True}
|
|
out = [
|
|
{"type": "markdown", "group": GROUP,
|
|
"text": "A guest-facing **What's new** entry for this feature — shown in the "
|
|
"carousel guests get when they open the app. Everything below is "
|
|
"pre-filled; edit what you want."},
|
|
{"key": "whatsnew_add", "type": "checkbox", "group": GROUP, "default": True,
|
|
"label": "Add this feature to the guests' What's new"},
|
|
{"key": "whatsnew_title", "type": "text", "group": GROUP, "label": "Title (French)",
|
|
"default": title, "showIf": cond, "requiredIf": cond},
|
|
{"key": "whatsnew_body", "type": "textarea", "group": GROUP,
|
|
"label": "Description (markdown bullets, French)", "default": body,
|
|
"showIf": cond, "requiredIf": cond},
|
|
]
|
|
if mockup:
|
|
out.append({
|
|
"key": "whatsnew_mockup", "type": "widget", "schema": "string", "group": GROUP,
|
|
"label": "Mockup", "default": mockup, "showIf": cond,
|
|
"help": "Live preview — open *Edit the mockup's HTML* to change it. Drawn "
|
|
"with the app's theme colours, light or dark.",
|
|
"html": _EDITOR.replace("@@MOCKUP@@", json.dumps(mockup).replace("</", "<\\/"))})
|
|
out.append({
|
|
"key": "whatsnew_mockup_notes", "type": "textarea", "group": GROUP,
|
|
"label": "Or describe changes to the mockup",
|
|
"placeholder": "e.g. show it over the conversation list", "showIf": cond})
|
|
return out
|
|
|
|
|
|
def form_answers(form_id: str) -> dict:
|
|
"""The answers of an ask-form, straight from the tool (``ask-form get``):
|
|
never the clarifier's report, which may have escaped the mockup's HTML."""
|
|
try:
|
|
r = subprocess.run(["ask-form", "get", form_id], capture_output=True,
|
|
text=True, timeout=30)
|
|
except (OSError, subprocess.TimeoutExpired) as e:
|
|
raise ValueError(f"ask-form get {form_id}: {e}") from None
|
|
if r.returncode != 0:
|
|
raise ValueError(f"ask-form get {form_id}: {(r.stderr or r.stdout).strip()[:200]}")
|
|
return answers_of(json.loads(r.stdout))
|
|
|
|
|
|
def answers_of(doc: dict) -> dict:
|
|
"""The answers object, from either an ``ask-form get``/``wait`` document
|
|
or the bare answers."""
|
|
return doc.get("answers") if isinstance(doc.get("answers"), dict) else doc
|
|
|
|
|
|
def entry_from(answers: dict) -> dict | None:
|
|
"""``{title, body, mockup, notes}`` from a form's What's new block, or
|
|
None when Gabriel unticked it (or the form had no such block)."""
|
|
if not answers.get("whatsnew_add"):
|
|
return None
|
|
mockup = answers.get("whatsnew_mockup") or ""
|
|
if isinstance(mockup, str) and mockup.lstrip().startswith("<"):
|
|
mockup = html.unescape(mockup) # a copy that went through an HTML report
|
|
return {"title": (answers.get("whatsnew_title") or "").strip(),
|
|
"body": (answers.get("whatsnew_body") or "").strip(),
|
|
"mockup": mockup if isinstance(mockup, str) else "",
|
|
"notes": (answers.get("whatsnew_mockup_notes") or "").strip()}
|