---
name: build-xopc-local-app
description: Build and iteratively improve a user-owned local XOPC app while preserving its stable extension identity, UI sandbox, and Phase 1 capability boundary.
metadata:
  i18n:
    en:
      name: "Build XOPC Local App"
      description: "Build and iteratively improve a user-owned local XOPC app while preserving its stable extension identity, UI sandbox, and Phase 1 capability boundary."
    zh-CN:
      name: "构建 XOPC 本地应用"
      description: "构建并迭代改进用户拥有的 XOPC 本地应用，同时保持稳定的扩展身份、UI 沙箱和第一阶段能力边界。"
  xopc:
    emoji: "🧩"
    activates_capabilities:
      - extension-authoring
    requires_tools:
      - read_file
      - write_file
      - exec_command
---

# Build a local XOPC app

Use this skill inside a Project created for a Local App. Treat `APP_BRIEF.md`, `.xopc/app.json`, and
`xopc.extension.json` as the app contract. Convert the user's latest request into a small observable UI
change, preserve working behaviour, and leave the draft previewable after every iteration.

## Required workflow

1. Read `APP_BRIEF.md`, `.xopc/app.json`, `.xopc/acceptance.json`, `xopc.extension.json`, and the
   current `ui/` implementation.
2. Restate the requested behaviour as observable acceptance checks. Add or update a declarative
   scenario in `.xopc/acceptance.json` for each critical journey changed by the request.
3. Edit the smallest coherent set of files. Phase 1 apps are UI-only; do not add backend routes,
   shell execution, network access, or undeclared permissions. Never edit the manifest `main` field
   or `.xopc/runtime/local-ui.js`; xopc owns that trusted gateway runtime entry.
4. Keep the extension `id`, page `path`, and UI `entrypoint` stable. Do not rename them during an
   iteration.
5. Run `node "$XOPC_LOCAL_APP_SKILL_DIR/scripts/validate-local-app.mjs" . --smoke` when that environment
   variable is available (it checks manifest, CSP/inline-handler rules, syntax, a11y focusability,
   acceptance `data-xopc-test-id` references, and runs headless smoke checks). Fix any errors before
   finishing. Otherwise validate the same contract directly.
6. Report what changed, what was verified, and whether the draft is ready for the user to install.

## Interface constraints

- Use semantic HTML, keyboard-accessible controls, visible `:focus-visible` states, and `aria-live`
  for async feedback. Prefer native `<button type="button">` over `<div role="button">`; if a custom
  `role="button"` element is unavoidable, always include `tabindex="0"` and Enter/Space handlers.
  Every icon-only button must have an `aria-label`.
- Support light and dark color schemes without assuming access to the host DOM.
- Keep scripts and styles local. The preview CSP blocks network access, inline `<script>` blocks,
  and inline event attributes (`onclick=`, `onchange=`, etc. — including inside `innerHTML` templates);
  always bind events via `addEventListener`.
- The iframe / mobile WebView permits scripts with an opaque or virtual origin. Use the bundled
  `@xopcai/extension-ui-sdk` client: prefer `client.records` (with `ui.collections` declared in
  `xopc.extension.json`) for structured data shared with Ada and Automations, and `client.storage`
  for lightweight preferences; never use `localStorage`, `sessionStorage`, or IndexedDB. Bundle the
  SDK into a local `ui/` asset, await `client.whenReady()`, and disable controls until ready.
- Build mobile-first layouts that fit `390x844` without horizontal overflow, honor host CSS vars
  `--xopc-safe-top`, `--xopc-safe-bottom`, and `--xopc-tabbar-inset`, keep interactive touch targets
  >= 44px, and tag online-only actions with `data-requires-online` so they degrade cleanly when the
  host computer is offline.
- Native form submission is blocked by the sandbox. Use `type="button"` actions and explicit keyboard
  handlers for Enter. Do not rely on a submit button or form `submit` listener to run app actions.
- Ask before expanding permissions. A permission change must be visible in the install review.
- Mark interactive UI sections and scenario targets with stable `data-xopc-test-id` values so both automated acceptance and App Studio visual annotation mode (`点选修改`) can pinpoint components reliably. Never encode executable JavaScript in acceptance scenarios.
- On the first build turn, briefly present a concise 3-part plan (UI modules, structured `records` collections, and required capabilities/automations) before writing files, then implement and validate so the user immediately sees the live preview in App Studio.
- For mobile-initiated builds (`[Space Mobile Create …]` or `[Space Mobile Refine …]` prompts), bias to action with safe local-only defaults instead of multi-turn text interviews. Also emit:
  - `.xopc/seed-records.json`: a JSON object mapping declared collection names to 2–3 realistic starter records in the user's locale so first launch is never an empty screen;
  - `.xopc/suggestions.json`: `{ "suggestedRefinements": ["...", "...", "..."] }` with 3 short (<= 8 CJK chars or <= 4 words) context-aware refinement chips tailored to what this app can add next.

For the exact file contract and completion checklist, read `references/app-contract.md`.
