How shared code is authored on the AIMEAT platform: served browser SDK libs, cortex libs, sandboxed extensions and library packs, each with its own source layout, build and gate. Use before writing or editing anything under src/static/sdk-libs/, public/cortex-bundled/, src/data/library-packs, public/lib/, an extension manifest, or when deciding where a piece of reusable code belongs.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Aimeat Library Authoring?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/miikkij-aimeat-library-authoring)
---
name: aimeat-library-authoring
description: How shared code is authored on the AIMEAT platform: served browser SDK libs, cortex libs, sandboxed extensions and library packs, each with its own source layout, build and gate. Use before writing or editing anything under src/static/sdk-libs/, public/cortex-bundled/, src/data/library-packs, public/lib/, an extension manifest, or when deciding where a piece of reusable code belongs.
---
# Authoring shared code
Four kinds of shared code, four different homes. Putting one in the wrong place is the recurring
mistake, so start by naming which one you are writing.
| Kind | Runs where | Source | Reached as |
|---|---|---|---|
| **Served SDK lib** | the browser | `src/static/sdk-libs/<name>/` (ESM) | `/v1/libs/aimeat-<name>.js` |
| **Cortex lib** | the browser | its own package, installed on the node | `/v1/cortex/<pack>/libs/<file>.js`, or exactly `/v1/cortex/<owner>/<pack>/libs/<file>.js` |
| **Extension** | the node, QuickJS WASM sandbox | manifest + `scripts/` | `/v1/ext/<name>/<action>`, or exactly `/v1/ext/<owner>%2F<name>/<action>` |
| **Library pack** | the browser (vendored third-party) | `public/lib/` + registry entry | `/lib/<name>@<major>.js` |
**The owner is part of the address too** (since 2026-10-25, `src/services/component/address.ts`):
every bare address keeps working, and answers keep `name` and add `owner` and `full_name`. A name
another account removed is retired: the next install by someone else lands as `<owner>/<name>`, and
only the full address reaches it. Two accounts holding the same name make the bare name answer 409
AMBIGUOUS_NAME; the full name always works.
**Two prefixes, never mixed:** AIMEAT SDK libs load from `/v1/libs/`, vendored styling and
third-party packs from `/lib/`. Mixing them 404s.
## Served SDK libs (`/v1/libs/aimeat-*.js`)
One directory per lib under `src/static/sdk-libs/` (`_core` and `dist` are not libs; count them there rather than trusting a number here). Authored as **componentized, JSDoc-typed ESM** under `src/static/sdk-libs/<name>/`,
sharing code through `_core/`, **under 800 lines per file**, esbuild-bundled to a classic IIFE with
`pnpm build:sdk`, and served with a per-node config prelude by `src/routes/libs.ts`. Guarded by
`check:sdk` (bundle in sync with sources), which runs in `pnpm check:fast`, `pnpm ready` and CI, and `typecheck:sdk`, which runs in the pre-commit hook. A stale bundle therefore passes a commit and is caught by `pnpm check:fast`, so run `pnpm build:sdk` before you commit.
- **Never author a served lib as JavaScript inside a TypeScript template string.** That was the old
`lib-*.ts` / `auth-lib-part*.ts` pattern, removed 2026-07-19. Edit the ESM source and rebuild.
- **No backticks in a served lib's JSDoc** while any template-string path remains. A stray one
closes the literal and typecheck fails with TS1005.
- **The bundle is cached: restart the dev server** or you are testing the previous build.
- A lib is the right home for behaviour every app would otherwise re-implement. When an app needs
something the platform should own, fix the lib rather than the app; the fix then reaches every app.
## Cortex libs
Browser IIFE installed on the node as a pack (manifest + `libs/`). The manifest wants
`spec.version`, a `filename`, `exports` as a list of strings and a **string** `api_surface` (a YAML
block scalar); anything else is refused naming the field. Every lib component's `filename` needs
its source under `libs` in the same call (`{ manifest, libs: { "x.js": "..." } }`), or the install
is refused; it serves from the bare name.
- **The seeder is version-aware:** editing a bundled cortex `.js` without bumping the yaml
`spec.version` will not refresh an installed node.
- Updating is `PUT /v1/cortex/<name>` with `{manifest, libs}`.
- **A cortex pack cannot import a served SDK lib**, and the portal under `public/js/` cannot either.
When one needs a function a lib already has, it keeps a copy whose header names the original,
and a unit test feeds both the same inputs: `test/unit/cortex-surface-parse-amount.test.ts` holds
two copies of `parseAmount` to `commerce/amount.js`. A third hand-written variant is how
`'1,500.00'` came to read as 1.5 in three places at once.
- Cortex is the layer that reads extension data and calls extension actions. It never bypasses the
extension, and an app never bypasses cortex.
## Extensions
Server-side, sandboxed. `export default async function(ctx, input) { ... }` per action.
**The full `ctx` table, and which run gets which member, is the node's build-extension prompt**
(`GET /v1/prompts/build-extension`, source `src/services/builder/extension-prompt.ts`).
`test/unit/build-extension-prompt.test.ts` runs a script in the sandbox and fails when a member the
guest receives is missing from that table, so change the table in the same commit as the sandbox.
- **Write manifest schemas in YAML block style.** A flow mapping containing a comma breaks the
scalar, the rest is read as a new key, and the action schema becomes garbage that fails validation
as a 500 on install. Quote a description containing `: `; an install that does not parse answers
with the line and column.
- **Declare what the code may do beyond its own memory**: `capabilities: [network, ai, email, payments]`
at the top level of the manifest. The installer approves that list and the sandbox gives the code
nothing else: without `network`, `ctx.fetch` throws `CAPABILITY_NOT_DECLARED`, and without the
others `ctx.ai`, `ctx.email` and `ctx.buy` are `undefined`. A manifest without the field gets the
list from a broad word match on the scripts (`fetch`, `ai`, `email`, `buy`), so a computed name
gets nothing. The bridge's `__*` globals are deleted before the author's code runs (since 2026-10-05).
A top-level `network: { hosts: [api.example.com] }` limits `ctx.fetch` to those exact hostnames, a
redirect elsewhere included, and the approval lists them (since 2026-10-08). `ctx.fetch` reads at
most 4 MB of one answer unless the manifest raises it with `limits: { fetch_max_mb }` (clamped to
32 MB, stored on the record as `limits.fetchMaxBytes`), and `ctx.fetch(url, { gunzip: true })`
inflates a gzipped answer under the same ceiling (since 2026-10-09). `ctx.fetch(url, { timeoutMs })`
gives one call its own deadline (100 ms to 30 s) and throws `FETCH_TIMEOUT` past it, which the
script catches; a run that calls several addresses gives one, because without it a single address
that never answers holds the call until the whole run times out (since 2026-10-13). The sandbox has
no `Intl` and no time-zone data, so calendar arithmetic is `ctx.calendar` (occurrences, freeSlots,
toInstant, fromInstant, normalize, fromICS, toICS): host calls into the served `aimeat-calendar`
library, on every code path, no capability to declare, refusals thrown as `CALENDAR: …`
(since 2026-10-13). A host that differs
per install (a customer's own server) is a config field named in
`network: { host_fields: { SERVER_HOST: required } }` (or `optional`): the package's config-needs
asks it, its value (one hostname or IPv4, optional `:port`) joins that install's list, and the owner
changes it with `aimeat_extension_config_set`, no new version (since 2026-10-09).
- `aimeat_extension_install` does not upsert: pass `update: true` (it survives the presigned path).
- **An action that records a person's own decision says `decision: person`** (approve, reject,
accept a sale, commit a bid). An agent's call then runs nothing and answers 202 with an approval
request the person allows with one press; a schedule or workflow step is refused `PERSON_DECIDES`,
and no app tool may bind the action. The person, and an app the person uses, call it as usual.
- **The node does not check `input` against the action's `input` schema.** The schema is published
for callers and the market; the script checks the fields it reads.
- **On a schedule, a workflow step or an `ai.start` `on_done` action, a normal return is a success
whatever it contains.** A missing capability or a failed precondition must `throw`. Test the method
(`ctx.wallet.consume`), not the object: `ctx.wallet` is always an object.
- An `undefined` or `null` argument to a `ctx` call throws, naming the method and the position
(until 2026-09-13 it crossed the bridge as the text "undefined").
- `ctx.ai.start` starts a background model call, billed to the extension's owner, and is absent on a
schedule and a workflow step. Its answer is written to the owner's namespace, out of `ctx.memory`'s
reach: the `on_done` action gets it as `input.result`, and `ctx.ai.result(job_id)` reads it later. For a synchronous paid answer, call the provider through `ctx.fetch`
with a `type: secret` config or a `{{secret:NAME}}` header. A secret nobody set is `undefined` in
`ctx.config` (until 2026-09-13 it read as the descriptor object or the mask, both truthy).
- An extension can itself be an AI provider: `provides.ai_provider` in the manifest and one `ai.<op>`
action per op, in the node's fixed shapes (the extension-building prompt lists them). Run as a
provider, `ctx.fetch` reaches only the declared hosts and the node adds the owner's key there, over
https only; the script never reads a key.
- `ctx.memory` is the extension's own sovereign `ext:{name}` namespace, and a key is **public unless
the write passes `{ visibility: 'private' }`**. The flag belongs on every write that holds personal
data (a write without it stores the key public again), and a code fix does not re-secure rows
already stored. An owner-only view is a private key served through an action that compares
`ctx.extension.owner` with `ctx.caller.owner`.
- `ctx.workspace` is how an extension reaches an organism workspace, and it does so **as the caller**:
the manifest declares `workspace: { read: true, write: true }` at the top level, and `index`, `get`,
`write`, `writeDoc` and `publish` then run the same operations `aimeat_workspace_read/_write/_publish`
run, with the same refusals (membership, the contributor grant, `memory:write` on an agent or app
token, the locked schema, `ifVersion`, the publish gate) thrown as `CODE: message`. It is absent
without the declaration; check `if (!ctx.workspace)`. A schedule or a workflow step gets only
`appendRows`, `readRows` and `readRow` (one row by its id, `null` when there is none), and only with `workspace: { rows: true }`: they reach a ROW space whose
manifest names the extension as `installer/name` in `objectTypes[].extensions`, they do not act as
the caller (a row records `ext:<name>`), and a repeated `rowId` replaces the row. On a MEMORY-backed
record space the same field means something else: a space that names extensions takes an agent's
write (draft, publish, revert, delete, archive, copy, import) only when it arrives through one of
them, and refuses the agent's direct write with `ACCESS_DENIED`; a person in person and a hosted
app still write directly, and a list with no valid entry closes the space to every agent (since
2026-10-13, after an agent wrote past an app's tool on aimeat.io). An agent whose session holds
`organism:direct` (`*` covers it) writes such a space directly and may change its list; nobody
else alters or removes a list that is there, the workspace's creator's own agent included. An app
adds its extension to a space of a workspace it built earlier with
`AIMEAT.organism.nameExtensions(orgId, wsId, space, ['installer/name'])`, which adds only, and
only extensions its own account installed (since 2026-10-14). Do not reach a
workspace through `ctx.fetch` or `ctx.memory`: the first cannot reach the node and the second is
fenced to `ext:`. Many records go through `publishRecords` (up to 1000, with `dryRun` and
`createOnly`) and come out through `deleteRecords` (up to 2000, into the bin, needs `memory:delete` on a token),
ONE call each: a run has 500 calls and 5 seconds by default, and `write` + `publish` per record
cannot finish 500 records. A space that only grows (closed claims, finished tickets) is kept
small with `archiveRecords` (up to 500, undoable, the organism's creator or an admin, and
`organism:write` on a token): an archived record leaves every read, and a workspace read costs
time per record, so 771 closed claims made every read of one workspace slow. Archived records
count toward an archived memory key limit of their own (10 000 per identity by default,
`AIMEAT_MEMORY_MAX_ARCHIVED_KEYS`): past it the call throws `QUOTA_EXCEEDED` and archives none of
the ids, so a space that archives for ever also deletes the archived records it no longer needs.
- **A collector writes one key per PERIOD, never one per item fetched.** The namespace has the
same budget as any principal: 1024 kB per value, 1000 keys by default. One alert-map extension on
this node keeps a whole day of alerts in `alerts.byDate.{date}` at a 74 kB median and is fine; a
news collector kept one key per article and reached 1,014 keys, over the shipped ceiling, while a
448 kB `index` key sat in the same namespace proving the megabyte works. The gate before shipping a scheduled collector: if
`keys_per_day × 365` exceeds 1000, fold. Keep a `<prefix>.__index` key listing the periods held so
a reader finds them without a scan.
- The sandbox has no `Date.now()` you should trust for reproducibility: take `input.now` or `ctx.now()`.
## Library packs (vendored third-party)
Registry `src/data/library-packs.ts` (+ `library-packs/{sdk,cortex,vendored}.ts`) is the **single
source every AI-facing list derives from**: the build-app prompt, `GET /v1/libs`, the bootstrap
`sdk_libraries` block and the llms.txt table. Drift is E2E-enforced, so add the pack to the registry
rather than to any of those lists.
**Version policy (`public/lib/VENDORED.md`): the major-pinned filename IS the contract.** Minor and
patch replace the file in place with a changelog entry written *for an AI*; a major is a NEW file and the old one
is never removed. Cortex wrappers are append-only within a name; a breaking change takes a `-v2` name.
Each pack has a `modelTier`: `any` (pin matches what models know), `frontier` (the pin breaks
against the version dominant in training data, so a weak model writes the old API and crashes) or
`needs-doc` (AIMEAT-authored, no priors, must fetch the doc). A frontier pack must have an
`apiCaveat`, and that caveat is inlined into the build prompt because a weak model skips the doc.
## Where a new lesson goes
A trap in a lib the platform serves is platform knowledge: `docs/pitfalls.md` and, when it is
repeatable, a line here. A trap that only bites someone *building an app on top* goes to the appdev
KB via `aimeat_appdev_pitfall_report`. See the `aimeat-app-building` skill for that side.