---
name: frevana-agent-app-runner
description: Prepare a Frevana Agent App share link and run its packaged jobs inside Codex or Claude Code using Frevana login and credits.
---

# Run a Frevana Agent App

This workflow uses Frevana Runner to run an Agent App in the current chat. It does not require Frevana Desktop to be installed or running.

If this chat cannot run commands on the user's computer (for example, a web chat with only a hosted sandbox), stop before installation. In the user's language, ask them to paste the same prompt into a desktop session with local command access, such as ChatGPT Desktop or Claude Code on desktop. Do not ask them to paste this guide or upload App files.

## Install or reuse the runner

Use Python 3.10 or newer on the user's computer. Keep the runner in a user-owned virtual environment at `~/.frevana/agent-app-runner/venvs/0.1.2` (under the user's home directory on Windows too). If this environment already has `frevana-agent-app-runner` version `0.1.2` and its CLI works, reuse it. Otherwise create the environment if needed and install the pinned package from PyPI. The wheel supplies the CLI and its Python modules. Updating the runner reuses the existing authorization and App cache; do not log out or reinstall the App to update it.

On macOS or Linux, choose a Python 3.10+ interpreter for `python3`:

```sh
runner_env="$HOME/.frevana/agent-app-runner/venvs/0.1.2"
python3 -m venv "$runner_env"
"$runner_env/bin/python" -m pip install "frevana-agent-app-runner==0.1.2"
"$runner_env/bin/frevana-runner" --help
```

On Windows, use PowerShell with a Python 3.10+ interpreter:

```powershell
$runnerEnv = Join-Path $HOME '.frevana/agent-app-runner/venvs/0.1.2'
py -3 -m venv $runnerEnv
& "$runnerEnv/Scripts/python.exe" -m pip install "frevana-agent-app-runner==0.1.2"
& "$runnerEnv/Scripts/frevana-runner.exe" --help
```

Use that environment's full executable path wherever the steps below say `frevana-runner`. If Python or package installation is unavailable, tell the user which prerequisite failed before continuing.

## Prepare the App and run a task

1. Run `frevana-runner prepare "<share URL>"`. The first run opens the official Frevana consent page. If the browser stays closed, give the user the authorization URL printed by the CLI. Complete authorization within 10 minutes; if it expires, rerun `prepare` for a new link rather than refreshing the old page. The callback returns to this computer. The CLI keeps renewal credentials in the system credential store. The `/agentapp/s/<share_code>` URL, with or without `/preview` or a language prefix, selects the environment automatically: `dev-www.frevana.com` uses dev; `www.frevana.com` and `frevana.com` use production. Keep the browser on this computer. The preflight checks the `agent_app_external_run` scenario; the server checks download permissions on the actual request. If the scenario is unavailable or the download returns HTTP 403, report the CLI error and wait for the environment administrator to restore access. Keep the existing authorization and rerun `prepare` afterward; newly assigned API permissions do not require another login.
2. A successful `prepare` makes the App ready to use. It downloads and verifies the shared App snapshot when needed, registers or reuses the authorized account's App instance, and returns its local `pack_root`, share, App and snapshot IDs, `app_instance_id`, and job list. Instance IDs are saved under `~/.frevana/agent-app/ids`, separately for each environment, account and server `share_id`. The same account and share reuse the instance across repeated preparation, snapshot updates, Runner upgrades and renewed authorization while that local cache remains. A registration failure stops preparation; report its error before running a task. Read `skillpack.json`, `job.json`, and referenced skills and scripts from that local directory. Use the manifest for context and examples and the enabled jobs for their actual instructions. Follow relevant references inside `skills/`, including skills omitted from the manifest list. `app.html` is the original UI. Files under `data/` and the local job results preserve outputs.
3. Identify the user's task from the conversation before executing a job:
   - If the task is clear, select the matching job and ask only for missing required inputs or prerequisites. If everything is available, continue without showing a task menu or asking the user to repeat their request.
   - If the user only asked to install the App or pasted the share prompt, tell them the App is ready after `prepare` succeeds. When no concrete task can be inferred, briefly explain what the App can do in the user's language. Offer up to three concrete tasks, each with its expected output and required inputs or saved data, then ask the user to choose or describe another goal. Ground suggestions in enabled jobs, their instructions and examples; combine duplicate internal jobs by user-facing outcome rather than listing technical job names. Wait for the user's choice. A share link or a generic request to use the App does not select the first job or authorize a paid task.
   - If the request is outside the App's capabilities, explain the limitation and offer the closest supported tasks, if any. Wait for the user to choose; do not invent capabilities or silently substitute a different task.
4. Once the task is selected and its required inputs are available, explain any Frevana credit usage before starting a paid job. Start a new task through `frevana-runner exec "<share URL>" -- <program> <args...>`. Save the `run_id` from the `frevana_run_started` JSON event on stderr along with the task's work directory and existing job IDs. For every subsequent step, status check, retry or recovery of that same task, use `frevana-runner exec --run-id "<saved RUN_ID>" "<share URL>" -- <program> <args...>`; put `--run-id` before the share URL. An independent task starts without `--run-id` to get a new ID. The working directory is the package root. When desktop job instructions refer to `../../../skills/...`, use the corresponding `skills/...` path under the returned `pack_root`. The CLI supplies the access token, API addresses, `FREVANA_AGENT_RUN_ID` and `FREVANA_AGENT_APP_INSTANCE_ID` to the child process. Skills that support attribution forward these two IDs with their requests. Keep credentials out of prompts, command arguments, output and reports. A package that hardcodes its API origin needs to support `FREVANA_API_BASE_URL` or `FREVANA_API_BASE` for transparent renewal. Check required local programs and any named external tools before starting paid work.
5. For `read_agent_result` use `frevana-runner result "<share URL>" "<job id>"`. To implement `save_agent_result`, pass the complete updated data object as a JSON file with `--save <file>`. The CLI returns the saved file's absolute path. Return the requested result and a link to the local output. Reuse saved results for follow-up questions.

For example, when introducing AEO to a first-time user, recommend a website audit and ask for the website URL; do not start it without a concrete request. Explaining audit findings requires a saved report, carrying out a suggested fix requires a saved action, and drafting an article requires a saved brief. State these prerequisites when suggesting those tasks. Numbered Action or Content Writer jobs are duplicate entry points, not separate suggestions.

For a full AEO audit, use its original `fast` command once, keep the returned `workDir` and RUN_ID, and run `deep --work-dir` with that same directory through `exec --run-id "<saved RUN_ID>"` until the job reports completion. If the outcome of a billed request is unknown, inspect the existing job ID or work directory before resuming. A status query can continue an existing submission. Reusing a RUN_ID groups attribution; it does not deduplicate paid submissions or resume the task itself. Keep paid submissions out of automatic retries.

## Report the run's credit usage

After each script exits, including a nonzero exit, the Runner queries credits attributed so far to that run and App instance. When a matching record exists, stderr includes a `frevana_run_usage` JSON event with `run_id`, `team_id`, and `credits_consumed`. When delivering results or explaining partial progress, briefly report the latest value as the task's cumulative credits used so far. Do not add successive values together: a resumed task's query already includes earlier charges. The value is a current attributed total, not a price estimate or proof that an asynchronous task has finished.

To check again after an asynchronous task completes or when the user asks, run `frevana-runner usage "<share URL>" "<saved RUN_ID>"`. It returns the matching record array, or `[]` when no record matches. It does not execute a skill, register an instance or submit paid work. Saved run identities live under `~/.frevana/agent-app/runs`, isolated by environment, account and share; use the original RUN_ID and share when continuing.

If there is no usage event or the query returns `[]`, omit any consumption message. Older skills may not forward attribution; do not mention missing statistics, suggest upgrading skills, or turn a missing record into zero. An explicit returned `credits_consumed: 0` is a known value. Never infer consumption from changes in the account balance. Automatic lookup failures are silent and preserve the script's output and exit code. An explicit `usage` command reports query errors with exit code 1; explain that error if the user requested the lookup, without changing the task outcome or rerunning paid work.

## When Frevana credits are insufficient

During `exec`, the relay can print a JSON event to stderr with `event: "frevana_credit_required"`, `code: "insufficient_credits"`, `top_up_url`, and `upgrade_url`. It emits at most one event per execution, without changing the script's output or exit code. This observes a rejected request; it does not stop the script, roll back earlier work, or prove that the whole task failed. Check the actual job status and outputs. If the user's requested result is complete, deliver it normally; do not interrupt delivery to sell credits just because the remaining balance is zero.

If work remains and a Frevana credit shortfall is confirmed by that event or an explicit API error:

1. Stop scheduling new paid steps. Inspect existing task IDs, the work directory and output files. Keep the original inputs, RUN_ID and resume information. Say what completed and what remains; only say a result was saved after checking that its file exists. Offer links to usable results now, even if the user decides to top up later.
2. Run `frevana-runner credits "<share URL>"`. It queries the currently authorized account and returns `balance_status`, `available_credits`, `top_up_url`, and `upgrade_url`. A zero balance is known; a missing or failed lookup returns `balance_status: "unknown"`, `available_credits: null`, an `error`, and exit code 1. Never turn an unknown balance into zero. This command neither charges credits nor starts a job. If lookup fails, keep using the returned official links and explain that the balance could not be checked. A permission or login error is not evidence of a credit shortfall.
3. In the user's language, explain which step cannot continue and provide a clickable **Top up credits** link from `top_up_url`, followed by **View upgrade plans** from `upgrade_url`. The existing website handles login and the account's available purchase options. Do not preselect an amount, automatically open checkout, or choose a plan for the user. Always include: **Use the same Frevana account you authorized for this App. After topping up or upgrading, return to this chat and reply "continue"; I will check the balance and existing work before continuing the unfinished steps.**

For example, if image files really exist: "Frevana credits are insufficient to generate the remaining images. The completed images are saved here: [verified output links]. [Top up credits](top_up_url) · [View upgrade plans](upgrade_url). Use the Frevana account authorized for this App. After topping up or upgrading, return to this chat and reply ‘continue’. I will check the balance and existing results before continuing."

Use "insufficient credits", not "zero credits", unless the query actually returned zero. A positive balance can still be too small for the next request. Do not claim that a failed task cost nothing, calculate a task's consumption from balance changes, or promise that a particular purchase will finish the task. Report consumption only from a matching run usage record as described above. Ordinary network, authorization, provider quota and rate-limit errors need their own explanation, not a recharge prompt.

## Continue after a top-up

When the user replies "continue", run `frevana-runner credits "<share URL>"` again, then inspect existing job IDs, work directories and results before submitting paid work. The chat reply does not prove payment succeeded. If the balance is still zero or below a known requirement, explain that the currently authorized account still has insufficient credits and suggest checking the payment's account and fulfillment status; do not immediately ask them to pay again. If the balance is unknown, explain the lookup error and wait to confirm it before new paid work. Existing submitted tasks can still be checked and completed results delivered.

Reuse the App's documented resume command with its original work directory and `exec --run-id "<saved RUN_ID>"`. Query an existing async task before considering a new submission, especially when the earlier submit response was lost. Do not rerun completed steps or silently switch the task to a different authorization. If the App cannot resume, explain what would need to be repeated and ask before repeating paid work. A positive balance with an unknown next-step price permits an attempt under the user's request to continue; it does not guarantee enough credits for the whole task. If that request is refused again, stop new paid steps and explain the remaining shortfall.

## Sign out

Use `frevana-runner logout` to clear local production credentials, or `frevana-runner --environment development logout` for dev. This prints the grant ID and the correct environment's **Authorized apps** account page, where the user can revoke the server authorization. Local logout does not revoke it. A new authorization has its own cache; existing output files remain on disk. Refresh credentials are never passed to packaged scripts.
