# Building JOLT apps: guide for AI coding assistants

This guide is part of **JUMP** (JOLT Universal Model Playbook). It tells an AI assistant how to write code for a JOLT project. Read it before you change anything in this folder.

The authoritative JOLT API is the typings file in this project: **`.jolt/types/jolt.d.ts`**. Office.js typings are in `.jolt/types/office-js.d.ts`. If this guide and the typings disagree, the typings win. Full documentation: https://jolt.technologylearningcompany.com/

## What JOLT is

JOLT runs HTML/CSS/JavaScript apps inside Excel, Word and PowerPoint. A JOLT **project** is a small static website: a set of text files stored inside the Office document, or published to a URL.

- **JADE** is the editor inside Office.
- **JET** is the task pane that runs apps.
- **JUICE** is the VS Code extension. The developer edits the project as local files, and every save reloads the app in JET inside Office. You are probably running in VS Code with JUICE.

The developer runs code. You can't run it yourself, because it executes in an Office task pane. When you need to verify something, ask the developer to save (which restarts the app in JET) or to run a function with **▶ Run in Office**, the CodeLens above each exported function. Then ask them to tell you what JUICE's output panel shows. `jolt.print` and `console.*` output and errors appear there.

### If you received the project as a zip

JADE (Options → Get Help from your AI) gives the developer the project as a zip and takes your result back the same way. When you are done:
- Return a zip of the **whole** project with the same layout (`jolt.json` at the top, or inside one folder). JADE replaces the project with the zip's contents, so a file you leave out is deleted.
- You don't need to include `AGENTS.md`, `CLAUDE.md` or `.jolt/`. JADE ignores them.
- Keep files as UTF-8 text.

## Project layout

```
jolt.json        project settings (required; marks the folder as a JOLT project)
index.html       the entry page that JET renders
styles.css       linked from the page
main.js          ES modules; folders are fine (lib/util.js)
```

**Files that are not part of the project** stay local. They are never embedded in the document or published:
- dotfiles and dot-folders (`.git`, `.jolt`, …);
- `node_modules/`, `dist/`, `jade-classic/`;
- `jsconfig.json`, `package.json`, `package-lock.json`, `AGENTS.md`, `CLAUDE.md`;
- binary files.

Project files must be text, so reference images by URL or as data URIs. Each file can be at most 2 MB.

### jolt.json

```json
{
  "name": "My JOLT App",
  "entry": "index.html",
  "autoRun": "main.js#autoRun",
  "imports": { "lodash/": "https://esm.sh/lodash-es@4/" }
}
```

| Field | Meaning |
|---|---|
| `name` | Shown on the app's tab in JET. |
| `entry` | The page JET renders. If it is missing, JET lists the automations as buttons instead. |
| `autoRun` | `file#export`, called once after the page is mounted. A function with one parameter receives the host context. `jolt.startArg` holds the argument the app was started with (`my-app:alpha` in JET, or `?arg=alpha`), else `undefined`. |
| `imports` | Import map: bare names or `prefix/` → URLs or project files. |
| `launchUrl` | If set, JET runs the app at that URL instead. Leave it alone unless asked. |

Keep any keys you don't recognise.

## How the page is mounted (this differs from a normal web page)

JET does **not** load `index.html` as its own document. It mounts the page into the task pane:

- `<link rel="stylesheet" href="styles.css">` becomes an inline `<style>`, and `<style>` elements are copied.
  - Other `<head>` content is dropped, and so are attributes on `<html>` and `<body>`.
  - The children of `<body>` are copied into the app's root element.
- `<script type="module">`, with `src` or inline, loads through JOLT's module loader. Imports between project files work.
- Classic scripts also run. Scripts run in document order, after the markup is in place.
- Each app runs in a frame of its own, rendered into that frame's `<body>` (`jolt.root`). In JET there is one tab per app, and several apps can run at once; a function run from JADE runs the same way, in a frame in JADE's Output View. The frame shares Office.js with the pane: `Office` and `Excel`/`Word`/`PowerPoint` work as usual, and JET removes the app's Office event handlers when its tab closes.

So:
- **Find elements with `jolt.$(sel)` and `jolt.$$(sel)`**, not `document.getElementById` or `document.querySelector`. They search the app's own page, and they're the portable way to find its elements.
- **Don't style `html`, `body` or `:root`**, which hit the pane's own page or nothing at all. Wrap the app in a top-level element (`<main class="app">`) and style that.
- **Don't use inline handlers** (`onclick="doThing()"`). Module functions aren't globals. Attach listeners in code: `jolt.$("#go").addEventListener("click", go)`.
- **Wire up the page in the `autoRun` export**, which runs after the page is mounted. A module's top-level code also runs after the markup is in place.

## Modules and imports

- Project `.js` files are real **ES modules** in strict mode. Declare every variable; there are no implicit globals.
- **Relative imports need the extension**: `import { f } from "./lib/util.js"`, not `"./lib/util"`.
- **Circular imports between project files aren't supported.** If two modules need each other, move the shared code into a third module.
- **Bare names** resolve in this order: `imports` in `jolt.json`, then the bundled VanJS (`"van"` or `"vanjs-core"`, 1.6), then `https://esm.sh/<name>`.
  - Always pin a version, as in `import dayjs from "dayjs@1.11.13"`.
  - The first load from a new site asks the user to trust it.
- **There is no build step**, so TypeScript, JSX and npm packages in `node_modules` don't work.
  - Use plain JS with JSDoc types.
  - For components, use VanJS or `htm` with Preact from esm.sh.
- A UMD or global-only library loads with `await jolt.loadScript(url)` or a `<script src>` in the page.
- `jolt` is a global. `import { jolt } from "jolt"` also works.

## Functions, automations and Office

- JADE's function picker and JUICE's **▶ Run in Office** list **exported function declarations**: `export function f()`, `export async function f(context)` or `export const f = () => …`. Functions exported only through `export { f }` aren't listed.
- **No parameters**: the function is called with no arguments.
- **Exactly one parameter**: the function runs inside `Excel.run`, `Word.run` or `PowerPoint.run` and receives the request context. The parameter's name doesn't matter.
- From code, use `jolt.run(async (context) => { …; await context.sync(); })` to get a context. Use `jolt.call("file.js", "name")` to run another file's export the same way.
- Mark user-facing commands as **automations** with a JSDoc tag directly above the export:
  ```js
  /** @automation Clean up — Trim spaces in the selected cells. */
  export async function cleanUp(context) { … }
  ```
  The title comes before the separator (`—`, ` - ` or `:`) and the description after it. `jolt.automations()` lists them, and JET shows them as buttons when there's no entry page.
- Office.js works as usual:
  - `load` the properties you read, then `await context.sync()`;
  - batch your writes;
  - keep the number of `sync` calls small.
- `jolt.host` is `"excel"`, `"word"`, `"powerpoint"` or `"browser"`. Guard host-specific code.

## Excel worksheet functions (=JOLT.RUN)

In Excel, a cell can call a project function: `=JOLT.RUN("TAX", B2, 0.07)`.
- `"NAME"` calls the export `NAME` of `functions.js`, or of the file named by `"functions"` in `jolt.json`. `"lib/x.js#NAME"` calls another file's export.
- When the project is saved, JOLT also gives each export of the functions file a workbook name (a `LAMBDA`), so `=TAX(B2, 0.07)` works too.
  - Use clear parameter names; they show in Excel's autocomplete.
  - Avoid names Excel already uses (`round`, `sum`) or that look like cells (`tax1`): those exports get no name.
- `"vscode:NAME"` calls the files JUICE is sending, while JET is connected (development only). `"https://site/lib.js#NAME"` calls a module on a site.
- Arguments: a single cell arrives as its value; a range arrives as an array of rows (`[[1, 2], [3, 4]]`).
- Return a value, or an array: a list fills a row, and a list of rows fills a block. `async` is fine.
- Throw an `Error` to show `#VALUE!` with your message.
- Keep these functions pure and fast; Excel may call them often. They run in JET's page, so **the `jolt` API is not available**. They can import project files and libraries, and use `fetch`.
- Each computer enables a workbook's functions once in JET (the cells show `#N/A` until then), and again after the code changes. Code the user saves from JADE or JUICE is enabled automatically.
- These are not automations: don't give them a `context` parameter or an `@automation` tag.

## The jolt API (summary; see `.jolt/types/jolt.d.ts`)

| Need | Use |
|---|---|
| Output for the developer | `jolt.print(data, heading?)`, `jolt.clear()`; `console.*` also appears |
| The app's page | `jolt.root`, `jolt.$(sel)`, `jolt.$$(sel)`, `jolt.show(htmlOrNode)` |
| Dialogs | `await jolt.alert(msg, title?)`, `await jolt.confirm(msg, {ok, cancel, title})`, `await jolt.prompt(msg, initial?)`; the browser's `alert`/`confirm`/`prompt` **don't work** in Office add-ins |
| Toasts | `jolt.notify(message, "info" \| "success" \| "error")`; errors stay until the user closes them, the others go after a few seconds |
| Data saved in the document | `jolt.storage.get(key)`, `await jolt.storage.set(key, jsonValue)`, `await jolt.storage.remove(key)`, `jolt.storage.keys()` |
| Read project files | `jolt.files.read(path)`, `jolt.files.readJSON(path)`, `jolt.files.list()` |
| Remote code | `await jolt.import(url)` (ES module), `await jolt.loadScript(url)` (classic script) |

- **`jolt.storage`** is per document. Values must be JSON-serialisable, and `set` and `remove` must be awaited. Data is kept only when the user saves the document.
- **Remote code** is allowed only over `https://`. The user is asked once per site whether to trust it.

## Writing style for JOLT projects

- Plain modern JavaScript with JSDoc types, small modules, and named exports.
- **Handle errors where the user acts.** Catch the error in the click handler and show it with `jolt.notify(String(e), "error")`. Use `jolt.print` for developer diagnostics.
- **Build UI with DOM APIs or VanJS** under `jolt.root`. If you build HTML strings, escape any data you put into them.
- Don't add `package.json`, bundlers or TypeScript.

## Done checklist

- [ ] `jolt.json` is valid, and `entry` and `autoRun` point at files and exports that exist.
- [ ] Every relative import includes `.js` and resolves, and there are no circular imports.
- [ ] No implicit globals, `document.getElementById`/`querySelector`, inline `on*=` handlers, `html`/`body` CSS, or browser `alert`/`confirm`/`prompt`.
- [ ] Every remote URL is `https://` and pinned to a version.
- [ ] Commands users run are exported, and tagged `@automation` where they belong in a menu.
- [ ] The developer has saved, seen the app reload in JET, and reported a clean JUICE output panel.

## Publishing to JAM, the app market

JAM (https://jolt.technologylearningcompany.com/jam/) lists free apps that users install into JET with a code such as `jam:owner/app`. Each version is pinned by a SHA-256 fingerprint of all its files. Users can have their own AI review it first, and JET runs only the exact code that was approved.

- **Add the publish fields to `jolt.json`:**
  - `"id": "<github-owner>/<app>"`, in lowercase. The owner must own the source repository.
  - `"version"`: semver, and a new number for every release.
  - `"description"`: one or two plain sentences.
  - `"permissions": { "hosts": ["excel"], "network": ["https://api.example.com"] }`: the Office apps it runs in, and every origin it contacts (none: `[]`).
  - optional `"funding"`: tip URLs, which must also be in the repo's `.github/FUNDING.yml`.
- **Remote code is allowed, but shown.** An app may import from esm.sh or URLs, or use `jolt.import`/`jolt.loadScript`. That code isn't covered by the version's fingerprint, so JET's install screen and the review page list it, and reviewers ask how popular each library is and whether it's pinned. Pin exact versions (`dayjs@1.11.13`), prefer well-known libraries, and avoid addresses built at run time, which can't be reviewed. Copying a library into the project makes it part of the reviewed code. The bundled `van` import isn't remote.
- **Readable source.** No minified or generated bundles: reviewers must be able to read every file.
- **`jolt.storage` for an installed app** is kept per user and app, not in the document.
- **Release:**
  1. Commit and push.
  2. Run `jolt jam release` (or "JUICE: Prepare JAM Release"). It checks the rules above, writes `.jolt/jam/<version>.bundle.json` and prints the registry entry.
  3. Open a pull request on https://github.com/availabooks/jam. It adds `apps/<owner>/<app>/<version>.json` and the bundle as `blobs/<sha256>.json`.

## Playbooks

Task-specific playbooks build on this guide:
- **Reviewing an app before someone runs it:** `review-app.md`. It applies to JAM, a website or an app embedded in a document.
- **Converting a JADE classic app:** `jade-classic/kit/SKILL.md`. JUICE's "Convert JADE Classic App with AI…" command downloads it.
