# Building a custom app

Source: https://docs.autessa.com/docs/autessascript/guides/custom-apps

> The Custom Apps V2 lifecycle from a script: create, edit files outside the script, publish, and poll the build — plus rollback and the read-only kit.

# Building a custom app

The Custom Apps V2 lifecycle from a script: create, edit files outside the script, publish, and poll the build — plus rollback and the read-only kit.

**The decision:** you are building or changing a hosted custom app from a script or an agent.
What is the safe edit-to-live loop?

## The lifecycle

1. **Create** the app with `autessa.app.create` (or `autessa.app.clone` from an existing
   one). Read it back with `autessa.app.get` / `autessa.app.all`, and change its settings
   with `autessa.app.update`.
2. **Edit its files outside the script.** Scripts cannot read or write app source files:
   the file and workspace operations are not on `globalThis.autessa`. Edit files in the app
   editor, with the `autessa` CLI's app commands (`app pull` / `app push`, `app files ...`),
   or — inside the copilot — with its dedicated app-file tools.
3. **Publish** the saved draft with `autessa.app.publish`.
4. **Poll the publish** with `autessa.app.publishStatus`. Polling is **mandatory**: the
   first poll that sees the build succeed finalizes the publish. On FAILED, the status carries
   the build error so you can fix the file — closing the edit→publish→fix loop.

## Decision rules

- **`src/autessa/**` and the lockfile are read-only.** Those files are the app's SDK kit and its
  pinned dependencies — reading them teaches you the app's available surface, but writes are
  refused.
- **Roll back a bad publish** with `autessa.app.rollback`, which restores an earlier
  version's source onto the draft; `autessa.app.versions` lists what you can roll back to.
- **Control who reaches it** with `autessa.app.share` (and custom domains with
  `autessa.app.domains.add` / `status` / `verify` / `remove`).

## What a running app can reach

- **Internal apps (default hosting) act exactly as the person using them.** The app sees the
  tables, rows, and columns that person sees and runs only the tools and agents they can run.
  Roles given to the app don't apply.
- **Public and sign-in apps are limited to what the person who last saved the app's permissions
  can access.** Saving checks every table, tool, agent, and envelope against your access. To
  give visitors a table, you must see every row and column of it; if you don't, ask a table
  admin to save it, or assign the app an AutessaDB role that shows each visitor only their rows.
- **If the saver later loses access**, the affected parts stop working for visitors and the app
  is flagged `permissionsNeedResave` with `permissionsIssues` explaining why. Save the
  permissions again with enough access to fix it.
- **Admin endpoints an app may call come from a fixed allowlist**
  (`/custom-apps-v2/poweruser-endpoint-options`) and act as the visitor, never the owner.

See *Who an app acts as* in the custom apps API reference.

## Worked example

Save the changed files (app editor or `autessa app push`), then from a script call
`autessa.app.publish` and loop on `autessa.app.publishStatus` until `terminal`. If it ends
FAILED, read the error, fix the file the same way, and publish again.

## See also

- *data-placement* — the AutessaDB tables a custom app reads and writes.
- *sharing-permissions* — who can edit and publish an app, and the app's table security.

## Related

- [Autessa SDK overview](/docs/autessascript/sdk.md)

