← Commit history
Publish 1.2.0
7 files changed
+302−10
README.md+11−1@@ -237,7 +237,7 @@ works (MediaRecorder, WebAudio, Canvas, WebGL, fetch, etc.) but remember: - **No cookies / no localStorage expectations**, webviews are fresh every session. Persist state to disk via your CLI, not the browser. -### 6. Graceful shutdown+### 6. Graceful shutdown, self-shutdown, and caller identity Apps should have a `/shutdown` endpoint (or equivalent) that the UI can call when the user is done. On receiving it, the server:@@ -248,6 +248,16 @@ call when the user is done. On receiving it, the server: Never leave the server running after the user is done, it holds a port, shows a zombie tab, and confuses future invocations. +**A `/shutdown` endpoint alone is NOT a lifecycle plan: agents forget to+call it** (13 zombie hero-studio instances accumulated in 3 days proving+this). Every app server must ALSO reap itself after 24h idle, require an+AI-thread name from every caller (refusing anonymous calls with a teaching+reprimand), require a `reason` on disruptive verbs, and register itself so+`<app> ls` finds it and `start` reuses a live instance instead of spawning+a duplicate. Full rules, refusal payloads, and the Node reference+implementation: read the **`app-creator-server-lifecycle`** sub-skill+before wiring any server's main loop.+ ### 7a. Always use relative URLs inside the webview (CRITICAL) Apps hosted through the Coder `/proxy/<port>/` prefix MUST use relative
SKILL.md+11@@ -6,6 +6,17 @@ description: > # App Creator Use when the user wants to build a new Adom "app", a mini web server that renders its UI in a Hydrogen webview tab. +## Sub-skill: server lifecycle (REQUIRED reading before wiring a server)++`app-creator-server-lifecycle` covers the lifecycle rules every app server+must build in: idle self-shutdown (24h reaper with lossless per-thread+snapshots), mandatory AI-thread caller identity with teaching refusals+(`caller_identity_required`), `reason` on disruptive verbs, the instance+registry (`<app> ls`, reuse-instead-of-respawn, `--port auto`), and+version-drift detection. Load it whenever you are building a server, or when+an Adom app refuses a call with `caller_identity_required` or+`reason_required`.+ ## Boundary with ai-driven-apps (in adom-ui-design) THIS skill owns CREATING the app: scaffolding, project layout, the server + webview skeleton, the
install.sh+2−1@@ -6,10 +6,11 @@ mkdir -p "$SKILLS_DIR/app-creator" if [ -f "$PKG_DIR/SKILL.md" ]; then cp "$PKG_DIR/SKILL.md" "$SKILLS_DIR/app-creator/SKILL.md" fi+# Sub-skills: app-creator-server-lifecycle (and any future skills/*/ dirs) for skill_dir in "$PKG_DIR/skills"/*/; do [ -d "$skill_dir" ] || continue skill_name=$(basename "$skill_dir") mkdir -p "$SKILLS_DIR/$skill_name" cp -r "$skill_dir"* "$SKILLS_DIR/$skill_name/" done-echo "Installed app-creator"+echo "Installed app-creator (+ sub-skills: app-creator-server-lifecycle)"
package.json+49−2@@ -1,11 +1,58 @@ { "slug": "app-creator",- "version": "1.0.3",+ "version": "1.2.0", "type": "skill", "description": "Use when the user wants to build a new Adom \"app\", a mini web server that renders its UI in a Hydrogen webview tab.", "dependencies": {}, "scripts": { "install": "./install.sh", "uninstall": "./uninstall.sh"- }+ },+ "title": "App Creator",+ "tags": [+ "skill",+ "app",+ "webview",+ "hydrogen",+ "server",+ "lifecycle"+ ],+ "hero": {+ "headline": "App Creator",+ "subhead": "Build a mini web server that renders its UI in a Hydrogen webview tab"+ },+ "discovery_triggers": [+ "make an app",+ "create an app",+ "build an app",+ "build an adom app",+ "build a webview app",+ "hydrogen app",+ "mini web server",+ "tool with a UI",+ "app conventions",+ "clean up my servers",+ "zombie server",+ "server lifecycle",+ "ai thread name for my server"+ ],+ "discovery_pitch": "Build a new Adom app (a mini web server with a Hydrogen webview UI) following the required conventions: brand, AI-drivability, and server lifecycle (idle self-shutdown, AI-thread caller identity, instance registry).",+ "sample_prompts": [+ {+ "label": "New app",+ "prompt": "Create a new Adom app for visualizing my BOM by vendor"+ },+ {+ "label": "Scaffold",+ "prompt": "Scaffold a Hydrogen webview app with a status HUD and a server-sent-events feed"+ },+ {+ "label": "Wrap a CLI",+ "prompt": "Build me an Adom mini app that wraps the parts-search CLI in a UI"+ },+ {+ "label": "Lifecycle",+ "prompt": "Make my app's server shut itself down when idle and require an ai-thread name from callers"+ }+ ] }
page.json+39−5@@ -4,18 +4,32 @@ "slug": "app-creator", "title": "App Creator", "brief": "Use when the user wants to build a new Adom \"app\", a mini web server that renders its UI in a Hydrogen webview tab.",- "version": "1.1.1",- "tags": [],+ "version": "1.2.0",+ "tags": [+ "skill",+ "app",+ "webview",+ "hydrogen",+ "server",+ "lifecycle"+ ], "license": "MIT", "sample_prompts": [ {+ "label": "New app", "prompt": "Create a new Adom app for visualizing my BOM by vendor" }, {+ "label": "Scaffold", "prompt": "Scaffold a Hydrogen webview app with a status HUD and a server-sent-events feed" }, {+ "label": "Wrap a CLI", "prompt": "Build me an Adom mini app that wraps the parts-search CLI in a UI"+ },+ {+ "label": "Lifecycle",+ "prompt": "Make my app's server shut itself down when idle and require an ai-thread name from callers" } ], "source_path": "SKILL.md",@@ -32,12 +46,32 @@ "headline": "App Creator", "subhead": "Use when the user wants to build a new Adom \"app\", a mini web server that renders its UI in a Hydrogen webview tab." },- "discovery_triggers": [],- "discovery_pitch": null,+ "discovery_triggers": [+ "make an app",+ "create an app",+ "build an app",+ "build an adom app",+ "build a webview app",+ "hydrogen app",+ "mini web server",+ "tool with a UI",+ "app conventions",+ "clean up my servers",+ "zombie server",+ "server lifecycle",+ "ai thread name for my server"+ ],+ "discovery_pitch": "Build a new Adom app (a mini web server with a Hydrogen webview UI) following the required conventions: brand, AI-drivability, and server lifecycle (idle self-shutdown, AI-thread caller identity, instance registry).", "metadata": {}, "created_at": "2026-05-28T05:29:45.880Z", "updated_at": "2026-05-28T05:29:45.880Z", "sub_skills": [], "parent_app": null,- "org": "adom"+ "org": "adom",+ "description": "Use when the user wants to build a new Adom \"app\", a mini web server that renders its UI in a Hydrogen webview tab.",+ "dependencies": {},+ "scripts": {+ "install": "./install.sh",+ "uninstall": "./uninstall.sh"+ } }
skills/app-creator-server-lifecycle/SKILL.mdadded+188@@ -0,0 +1,188 @@+---+name: app-creator-server-lifecycle+description: >+ Server lifecycle rules for every Adom app: idle self-shutdown (the reaper),+ caller identity (every AI thread names itself on every call, and the server+ refuses anonymous callers with a teaching reprimand), reasons on disruptive+ verbs, the per-thread instance registry, reuse-instead-of-respawn, and+ version-drift detection after package updates. Read when building any app+ server, and when you hit caller_identity_required or reason_required from+ an Adom app. Trigger words: server lifecycle, clean up my servers, zombie+ server, leaked server, orphaned server, idle shutdown, self shutdown, ttl,+ reaper, ai-thread name, aiThread, caller identity, X-Adom-Thread,+ caller_identity_required, reason_required, instance registry, list+ instances, reuse instance, already running on port, duplicate instance,+ stale instance, version drift, port auto, too many node servers.+---+Parent skill: **app-creator**++# Server lifecycle: clean up after yourself, and know who is calling++Adom apps are mini web servers that AI threads spawn freely. Without lifecycle+rules they accumulate: the motivating incident (2026-08-11) was **13 zombie+hero-studio instances** left running over 3 days. Twelve were on stale code+after a package update (their install dir had been deleted underneath them),+three were duplicate studios posing the same wiki page because each new thread+forgot the last thread's instance, and all of them were silently clobbering one+shared state-snapshot file. Only one had ever heard of `/shutdown`, and nobody+called it.++The lesson is structural, not behavioral: **agents forget, so servers must+manage themselves.** A `/shutdown` endpoint that a well-behaved caller is+supposed to hit is not a lifecycle plan. These six rules are.++## Rule 1: Every caller identifies its AI thread, on every call++Adom Bridge (ab) and pup bridge already enforce this pattern; apps follow the+same conventions (see `adom-bridge-caller-identity` for the origin story).++- **Spawn**: `<app> start --ai-thread "kicad-bridge dev"`. The flag is+ required, not optional.+- **Every state-changing HTTP request**: carry the thread name in the+ `X-Adom-Thread` header, or as a top-level `aiThread` field in the JSON body.+ Read-only endpoints (`GET /state`, `GET /console`) stay open so debugging is+ never gated.+- **Identity is self-reported and is never authorization.** It is a label for+ attribution, logging, and instance management. Never grant privilege based+ on it.++Why per-call and not an env var: a real container runs many concurrent AI+threads sharing one shell environment. A shared `ADOM_AI_THREAD` export means+every thread claims the same name (plausible and wrong beats absent), and+concurrent threads race to overwrite it. Per-call identity is the only form+that attributes correctly. The env var is acceptable only in single-agent+containers (CI, dedicated job boxes).++## Rule 2: Anonymous callers get a teaching refusal, not silence++When a state-changing request arrives with no thread identity, refuse it, and+make the refusal TEACH. The caller is an AI: your error text is a prompt it+will read and obey. A bare 400 wastes a round trip; a reprimand that names the+exact fix converts the failure into compliance on the very next call.++```json+{+ "ok": false,+ "errorCode": "caller_identity_required",+ "error": "This server requires every AI caller to identify its thread.",+ "hint": "Retry with header 'X-Adom-Thread: <your thread name>' or add a top-level \"aiThread\" field to your JSON body. Example: curl -X POST localhost:8846/state -H 'X-Adom-Thread: kicad-bridge dev' -d '{...}'. Pick a short human-readable name for THIS conversation and reuse it on every call."+}+```++Return HTTP 400 with `errorCode: caller_identity_required` (the same code ab+uses, so callers that already know ab's contract recognize it instantly).++## Rule 3: Disruptive verbs require a reason++Any endpoint that interrupts the human or destroys state (foregrounding a+window, overwriting a file, killing a job, publishing, deleting) additionally+requires a `reason` string in the request body. Missing reason gets the same+teaching treatment, `errorCode: reason_required`, with a hint naming the field.++Log `thread + verb + reason` to the server's console ring buffer, and surface+it in any activity view or toast the app has. The point is that the human can+always answer "which conversation did that, and why" without asking around.+pup bridge's window-foreground verb is the reference example: identity on+every call, reason on the disruptive ones.++## Rule 4: Idle self-shutdown (the reaper), default 24 hours++Track a `lastActivity` timestamp on every HTTP request. A timer checks it once+a minute; when the server has been idle past the TTL it reaps itself:++1. Finish pending work (file writes, running renders).+2. Write a final state snapshot to disk (Rule 5 makes this lossless).+3. Remove the Hydrogen webview tab (`adom-cli hydrogen workspace remove-tab`).+4. Remove its registry entry (Rule 6) and `process.exit(0)`.++```js+// Node reference implementation+const TTL_H = Number(process.env.APP_TTL_HOURS || argVal('--ttl') || 24);+const KEEP_ALIVE = process.argv.includes('--keep-alive');+let lastActivity = Date.now();+// in the request handler, first line:+// lastActivity = Date.now();+if (!KEEP_ALIVE) setInterval(() => {+ if (Date.now() - lastActivity > TTL_H * 3600e3) {+ saveSnapshot(); // Rule 5: lossless+ deregisterInstance(); // Rule 6+ removeWebviewTab();+ process.exit(0);+ }+}, 60e3).unref();+```++24h is the right default for interactive tools: a user slowly finishing a task+over days keeps touching the server, and every touch resets the clock; a+thread that generated its artifact and moved on stops touching it, and the+server is gone a day later. `--keep-alive` opts out for genuine daemons;+`--ttl <hours>` tunes it. Do not special-case "done" events (like a generate+button): idle-reset subsumes them.++## Rule 5: Reaping must be lossless: per-thread snapshot + resurrection++The reaper is only safe if being reaped costs one relaunch, never lost work.++- On every state change (debounced) and on reap, persist state to a snapshot+ file **keyed by the owning thread**, e.g.+ `~/.adom/instances/<app-slug>/snapshots/<thread-slug>.json`.+- On `start --ai-thread X`, if a snapshot for X exists, restore it and say so+ in the boot log.+- **Never share one snapshot file across instances.** Hero-studio did (13+ writers, one `state-snapshot.json`), and instances restored each other's+ state after restarts. Per-thread keying is what makes parallel instances+ actually isolated, not just isolated in memory.++## Rule 6: A registry makes instances discoverable, reusable, and auditable++Each instance writes a registry entry at boot and keeps it fresh:++```+~/.adom/instances/<app-slug>/<thread-slug>.json+{ "pid": 12345, "port": 8849, "thread": "kicad-bridge dev",+ "task": "adom/kicad-bridge", "version": "0.16.1",+ "startedAt": "...", "lastActivity": "..." }+```++Three behaviors hang off it:++- **`<app> ls`** lists instances, liveness-checks each pid, prunes dead+ entries, and prints port, thread, task, idle time, and version. This is the+ command an AI runs before spawning anything.+- **Reuse instead of respawn.** `start --ai-thread X` checks the registry+ first: a live instance for X means print+ `OK: already running on port 8849 (started 2h ago, task adom/kicad-bridge). Use that instance.`+ and exit 0. This is the fix for "the AI forgot it has one open." If a+ DIFFERENT thread already has an instance on the same task, warn but allow;+ duplicate-task is usually a mistake, not always.+- **Port allocation.** `--port auto` (bind port 0 or scan a range) and print+ the chosen port as structured output. Manual port picking across parallel+ threads is how collisions and wrong-port confusion happen.++## Rule 7: Surface version drift after package updates++A long-lived instance keeps running the code it loaded at boot. When the+package updates on disk, the fleet goes stale silently: in the motivating+incident, instances ran 3-day-old code whose install directory had been+deleted, so every snapshot write was silently failing into a void.++- Record the package `version` in the registry entry at boot.+- `<app> ls` compares each entry against the on-disk package version and flags+ mismatches: `WARN: port 8847 runs 0.9.0, disk has 0.16.1. Shut it down and respawn.`+- After any `adompkg update`, run `<app> ls` and cycle stale instances.++## Checklist for every app server you build++- [ ] `--ai-thread` required at spawn; `X-Adom-Thread` / `aiThread` required+ on state-changing requests+- [ ] Anonymous state-changing calls get the `caller_identity_required`+ teaching refusal (hint shows the exact retry)+- [ ] Disruptive verbs require `reason`; thread + reason logged and surfaced+- [ ] Idle reaper on by default (24h TTL, `--keep-alive` / `--ttl` overrides)+- [ ] Reap sequence: pending work, snapshot, remove tab, deregister, exit 0+- [ ] Snapshots keyed per thread, restored on same-thread start; never one+ shared snapshot file+- [ ] Registry entry at `~/.adom/instances/<slug>/`; `<app> ls` implemented+- [ ] `start` reuses a live same-thread instance instead of respawning+- [ ] `--port auto` supported+- [ ] `ls` flags version drift against the on-disk package
uninstall.sh+2−1@@ -1,4 +1,5 @@ #!/bin/bash set -e rm -rf "$HOME/.claude/skills/app-creator"-echo "Uninstalled app-creator"+rm -rf "$HOME/.claude/skills/app-creator-server-lifecycle"+echo "Uninstalled app-creator (+ sub-skills)"