@oxy-hq/cli 0.12.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +605 -68
  2. package/dist/main.mjs +12125 -3088
  3. package/dist/main.mjs.map +1 -1
  4. package/dist/{mcp-CJWQm-yd.mjs → mcp-vlYd5Bms.mjs} +2 -2
  5. package/dist/{mcp-CJWQm-yd.mjs.map → mcp-vlYd5Bms.mjs.map} +1 -1
  6. package/json-schemas/agent-test.json +47 -2
  7. package/json-schemas/agentic.json +77 -0
  8. package/json-schemas/config.json +2 -1
  9. package/json-schemas/topic.json +252 -0
  10. package/json-schemas/view.json +473 -0
  11. package/package.json +2 -2
  12. package/skills/oxy-agents/SKILL.md +29 -26
  13. package/skills/oxy-agents/references/quick-reference.md +4 -6
  14. package/skills/oxy-agents/templates/agentic-template.yml +2 -1
  15. package/skills/oxy-airway-pipelines/SKILL.md +27 -2
  16. package/skills/oxy-automations/SKILL.md +42 -28
  17. package/skills/oxy-cli/SKILL.md +15 -7
  18. package/skills/oxy-custom-apps/SKILL.md +293 -7
  19. package/skills/oxy-custom-apps/references/app-calls.md +98 -0
  20. package/skills/oxy-custom-apps/references/phone-layout.md +16 -2
  21. package/skills/oxy-custom-apps/references/sandbox-agent-loop.md +8 -8
  22. package/skills/oxy-evals/SKILL.md +60 -36
  23. package/skills/oxy-evals/references/diagnosis.md +7 -5
  24. package/skills/oxy-evals/references/results-json.md +23 -15
  25. package/skills/oxy-evals/references/writing-expected.md +3 -2
  26. package/skills/oxy-experiments/SKILL.md +4 -3
  27. package/skills/oxy-semantic-modeling/SKILL.md +14 -12
  28. package/template/.claude/hooks/oxyc-cloud-session.sh +40 -8
  29. package/template/.github/workflows/publish.yaml +5 -5
  30. package/template/.github/workflows/validate.yaml +125 -199
  31. package/template/README.md +50 -21
  32. package/template/_gitignore +4 -4
  33. package/template/config.yml +2 -2
@@ -7,7 +7,7 @@ description: >-
7
7
  file that is silently not an automation, a task that validates but fails with "unknown task
8
8
  type", SQL that receives JSON instead of a table, or an automation run landing
9
9
  `completed_with_errors`. Covers the file-naming trap, task-type gotchas, running SQL and
10
- automations from the `oxy` CLI, and where the authoritative reference lives.
10
+ automations on a deployment with `oxyc run`, and where the authoritative reference lives.
11
11
  ---
12
12
 
13
13
  # Oxy automations
@@ -28,10 +28,15 @@ The canonical extension is **`.automation.yml`**.
28
28
  spreads. One production workspace has 18 automations, and every one of them
29
29
  is still `.procedure.yml`.
30
30
  - `.workflow.yml` is **no longer a recognised file kind at all**. A file with
31
- that name is silently not an automation, and `oxy run` refuses it.
32
- - `oxy migrate-automations` renames legacy files (and rewrites references to
33
- them); `--dry-run` previews. It is the only thing that reads `.workflow.yml`
34
- files for that purpose.
31
+ that name is silently not an automation, and `oxyc run` refuses it.
32
+ - `oxyc migrate-automations [path]` renames legacy files (and rewrites
33
+ references to them in every `.yml` / `.yaml` / `.sql` file); `--dry-run`
34
+ previews. It is local only, needs no login, and is the only thing that reads
35
+ `.workflow.yml` files for that purpose. It never overwrites: a file whose
36
+ `.automation.yml` target already exists, or a `.procedure.yml` beside a
37
+ `.workflow.yml` of the same name, is reported and skipped (still exit 0), so
38
+ read its warnings and resolve those by hand. The Rust
39
+ `oxy migrate-automations` only prints this command now.
35
40
 
36
41
  **Write new files as `.automation.yml`.** Do not copy the extension from a
37
42
  neighbouring file in the workspace you are editing — that is how the legacy name
@@ -52,7 +57,7 @@ Routes follow the same split: `/automations/:id` is canonical;
52
57
 
53
58
  - **A misspelled `type:` passes validation and fails only at run time.** An
54
59
  unrecognised task type — `type: sql`, `type: execute` — is read as an
55
- "unknown" step rather than rejected, so `oxy validate` reports the file valid
60
+ "unknown" step rather than rejected, so `oxyc validate` reports the file valid
56
61
  and the run fails on that step with `unknown task type`. Check every `type:`
57
62
  against the task-types page by eye, then *run* the automation; validation
58
63
  alone proves nothing here. (A wrong *field* inside a known type, such as
@@ -73,28 +78,37 @@ Routes follow the same split: `/automations/:id` is canonical;
73
78
  as `completed_with_errors`, not as a failed run. Code and dashboards that only
74
79
  check for "failed" will report it as a success.
75
80
 
76
- ## Running locally with `oxy run`
77
-
78
- `oxy run <file>` takes a `.sql` file, an `.automation.yml`, or a
79
- `.procedure.yml` — nothing else.
80
-
81
- - **SQL files:** `oxy run report.sql --database warehouse -v start=2024-01-01
82
- -v region=west`. `--database` picks a database from `config.yml` (default:
83
- the configured default database). `-v` / `--variables` fills Jinja
84
- placeholders, and those `-v` values are the **entire** template context —
85
- nothing else (no database or schema objects) is available inside the SQL.
86
- `--dry-run` previews the rendered SQL without executing it.
87
- - **No `-v` means no rendering at all.** Run a templated `.sql` file without a
88
- single `-v` and its `{{ … }}` placeholders reach the warehouse literally, as
89
- a syntax error. Pass at least one variable whenever the file has
90
- placeholders.
91
- - **`--dry-run` and `-v` are ignored for automations.** Both apply to `.sql`
92
- files only. `oxy run x.automation.yml --dry-run` executes the automation for
93
- real — every write, every `http_request` — and uses the file's own
94
- `variables:` defaults whatever `-v` says. To check an automation without side
95
- effects, run its SQL files individually with `--dry-run`.
96
- - `--retry` and `--retry-from <step>` are accepted but currently have no effect
97
- on an automation run; a failed run is re-run from the top.
81
+ ## Running one with `oxyc run`
82
+
83
+ `oxyc run <file> --workspace <id>` (`npm i -g @oxy-hq/cli`) takes a `.sql` file,
84
+ an `.automation.yml`, or a `.procedure.yml` — nothing else. It runs **on the
85
+ deployment**, never on this machine. The Rust `oxy run` is gone: it now prints
86
+ the `oxyc` command and exits `2`.
87
+
88
+ - **An automation runs what is deployed, not your edit.** The server runs the
89
+ definition it has compiled for the workspace's served revision, on the worker
90
+ fleet. Push the change first, or try a branch with
91
+ `oxyc preview run <branch> procedure <ref> --workspace <id>` (its writes are
92
+ held). An automation the deployment does not have exits `5` before anything
93
+ starts.
94
+ - **`-v name=value` sets the run's variables**, overriding the file's own
95
+ `variables:` defaults. Every value arrives as a string.
96
+ - **SQL files:** `oxyc run report.sql --database warehouse -v start=2024-01-01
97
+ region=west --workspace <id>`. The file's text is sent, and runs against the
98
+ deployed database of that name with the workspace's secrets and your
99
+ identity. `--database` is required when the workspace has more than one
100
+ database (`config.yml`'s `defaults.database` is not visible to `oxyc`).
101
+ - **`-v` renders only `{{ name }}`, and only when given.** Any other Jinja
102
+ (`{% … %}`, filters, expressions) or a placeholder with no value exits `2`
103
+ and sends nothing. Run a templated file without a single `-v` and its
104
+ `{{ … }}` reach the warehouse literally, as a syntax error.
105
+ - **There is no dry run.** `--dry-run`, `--retry` and `--retry-from` are gone.
106
+ A run executes for real — every write, every `http_request`. To try an
107
+ automation without side effects, use the branch preview above.
108
+ - A result stops at 10,000 rows. `--json` prints the rows (header row first)
109
+ or the run's final snapshot. Exit `1` the run failed, was cancelled or timed
110
+ out, or `--timeout` ran out (the run carries on: re-running starts a second
111
+ one); `6` the query failed; `7` retryable, before anything started.
98
112
 
99
113
  ## Before you write one
100
114
 
@@ -76,6 +76,11 @@ never sent to the server as a literal.
76
76
  oxyc flags list # feature flags: kill switch, per-org overrides, A/B splits (staff)
77
77
  oxyc login-link --next /ide # one-time URL that signs a browser in as your token
78
78
  oxyc workspace clone <id> # clone the workspace's repository to edit locally; push to deploy
79
+ oxyc airway run <ref> --workspace <id> # run a deployed pipeline and stream it; also backfill, coverage, leases
80
+ oxyc sync [db] --workspace <id> # write .databases/ schema files into the checkout (server introspects the deployed config)
81
+ oxyc looker test <name> --workspace <id> # check a Looker integration's credentials; exit 9 when they fail
82
+ oxyc evals run <file> --workspace <id> # LLM-judged evals on the deployment; exit 9 under --min-accuracy
83
+ oxyc agentic run <agent> -q "<q>" --workspace <id> # ask a deployed agent, stream the run; also answer, events, list
79
84
  oxyc guide # this page, to paste into a context file
80
85
 
81
86
  `oxyc workspace clone <workspace-id>` is how you change a workspace: authoring
@@ -85,16 +90,19 @@ subdirectory when the workspace lives in one), and opens it in VS Code or Cursor
85
90
  only from an interactive terminal (`--open code|cursor|none`; an agent gets the
86
91
  command printed instead). Edit, commit, push: **a push to the default branch
87
92
  compiles and deploys**; to try a branch first, `oxyc preview create <branch>
88
- --workspace <id> --wait` (staff). Exit `5` means the workspace has no repository
93
+ --workspace <id> --wait` (staff). To check a pushed branch compiles without
94
+ serving it, `oxyc compile <branch> --workspace <id> --wait` (exit `9` on file
95
+ failures, `--json` for the `failures` array) — what a customer repo's CI runs. Exit `5` means the workspace has no repository
89
96
  yet (connect one in Settings), `6` a failed `git clone`, `8` a non-empty `--dir`.
90
97
 
91
98
  `oxyc validate` is the one command that works entirely offline. It checks
92
- `config.yml`, `.automation.yml`, `.agentic.yml` and
93
- `.agent.test.yml` against the schemas the Rust config types generate. It is
94
- STRUCTURAL only — `oxy validate` additionally checks an automation's
95
- `database:` names against `config.yml`, but it too is structural for
96
- `.agentic.yml` (`databases:` and `llm.ref` are not resolved), so an agent both
97
- accept can still fail at run time.
99
+ `config.yml`, `.automation.yml`, `.agentic.yml`, `.agent.test.yml`, `.view.yml`
100
+ and `.topic.yml` against the schemas the Rust types generate, then as the
101
+ runtime does once a file loads: an automation's `database:` and `integration:`
102
+ names and an agent's `databases:` and `llm.ref` against `config.yml`, an
103
+ automation's rules (non-empty `tasks:`, timeouts, export formats), and a view's
104
+ removed features and `{{variables.x}}` syntax. Exit `9` on any finding. It
105
+ replaced `oxy validate`, which now only prints the `oxyc` command.
98
106
 
99
107
  To look at a deployed environment in a browser, navigate your browser tool to
100
108
  `$(oxyc login-link --env dev --next /ide)`. It is a one-time link that signs
@@ -213,6 +213,23 @@ indexes or foreign keys — publish refuses a migration carrying one. So:
213
213
  statements that must land together go in one `ctx.oltp.tx`. The store is
214
214
  provisioned per org by an operator; until then calls fail naming that step.
215
215
 
216
+ **Where `ctx.env` comes from.** The app's own secrets (its Secrets panel,
217
+ `oxyc env secret set`), plus any shared secret an admin has shared with the
218
+ app in Settings → Organization → Secrets — read under the secret's own name, so one
219
+ `SLACK_BOT_TOKEN` can serve every app that needs it and rotates once. The app's
220
+ own value of a key wins over a shared one. Nothing else of the workspace is
221
+ visible, and the manifest cannot ask for more: declaring a key in `env` only
222
+ makes it show as missing until someone sets or shares it. `ctx.secrets.set`
223
+ refuses a key the run read from a shared workspace secret; rotate it in Settings.
224
+
225
+ **A function that calls Oxygen's own org routes** (kiosks at
226
+ `/api/orgs/{org}/frontline/devices`, members, apps) holds an organization's
227
+ service-account token in a secret, never a person's: `oxyc tokens create
228
+ --org-service-account <org>/<account> --role admin --set-app-secret <org>/<app>
229
+ --key <KEY> --env <env>`. An owner or admin of the org approves it in the
230
+ browser, and the token goes into the app's secret without being printed. Legacy
231
+ `oxy_…` API keys authenticate nothing.
232
+
216
233
  **Not a store:** `ctx.secrets` holds credentials you rotate. A cursor, a
217
234
  counter or a JSON blob is a record. `oxyc validate` warns about it, about
218
235
  keys in Airhouse migrations, and lists every customer-warehouse write exception.
@@ -230,6 +247,68 @@ async function completeChecklist(ctx, runId: string, storeGuid: string) {
230
247
  }
231
248
  ```
232
249
 
250
+ ## Asking another app
251
+
252
+ To use another app's data or rule, call its function (`ctx.apps.call`) instead of copying its tables; both manifests declare it. See [references/app-calls.md](references/app-calls.md).
253
+
254
+ ## React when a table changes
255
+
256
+ A function can run when an Airhouse table changes, with no one calling it:
257
+
258
+ ```jsonc
259
+ "functions": {
260
+ "on-lines-changed": {
261
+ "route": false,
262
+ "on": { "table": "pokehouse:bookkeeping.platform_report_lines" }
263
+ }
264
+ }
265
+ ```
266
+
267
+ The table is `<database>:<schema>.<table>`; leave the database out for your own
268
+ `app_<writer>` schema. It fires once per **snapshot** that inserted into or
269
+ deleted from the table, so a pipeline that writes the table fires it, as does
270
+ `ctx.airhouse`. Wrap the handler in `onEvent` from `@oxy-hq/sdk/events` and
271
+ narrow with `isTableChange(event)`:
272
+
273
+ ```ts
274
+ export default onEvent(async (event, ctx) => {
275
+ if (!isTableChange(event)) return;
276
+ const { snapshotId, inserted, deleted, updated, rows } = event.data; // row-image counts (`updated` counts pre/post-image pairs), rows when small
277
+ const page = rows ?? (await ctx.tables.changes(event)); // { inserted, deleted, hasMore }
278
+ // Re-derive what you keep from the table.
279
+ });
280
+ ```
281
+
282
+ - **Inserts and deletes both fire**, and an update arrives as a pre-image/post-image
283
+ pair. A table that replaces rows (delete a period, insert it again) fires for
284
+ both statements, so a handler that adds up `inserted` double counts. Treat an
285
+ event as "this table changed, re-derive", not as a delta, unless the table is
286
+ append-only. Delivery is at least once.
287
+ - `rows` is there up to 1,000 rows and 64 KB; past that, call
288
+ `ctx.tables.changes(event, { limit, offset })` (10,000 a side a call, `hasMore`).
289
+ It answers only for the event that started this run.
290
+ - **Do not write the table you watch.** The host refuses a write to it from that
291
+ function with an `EventLoop` error. A loop through two tables is caught by a
292
+ circuit breaker that pauses a subscription over 150 deliveries in 5 minutes and
293
+ pages; `oxyc events resync <org>/<app> <function>` resumes it (and skips what
294
+ changed meanwhile).
295
+ - **Compaction is not a change.** Airhouse's compactor writes snapshots; only
296
+ inserts and deletes fire.
297
+ - **The table's columns are a contract.** Removing, renaming or retyping one marks
298
+ the watch broken (it pages and stops delivering until it holds again), and an
299
+ `airhouseMigrations` file that does so to a table a production function watches
300
+ is refused at publish. Adding a column is fine. `resync` clears broken and
301
+ `behind_horizon` (the next snapshot expired); `--backfill` runs the handler once
302
+ with `event.data.backfill === true`.
303
+ - **Environments.** A watch reads the environment's own `app_<writer>__<env>`
304
+ copy when it has the table, else production's, read-only. A non-production watch
305
+ records nothing until the environment's events switch is on (then it starts
306
+ from now). Airhouse caches snapshot reads up to a minute, so an event can lag
307
+ a write by that much.
308
+ `oxyc events ls` shows each watch's cursor, lag and state.
309
+ - Unit test with `createTestEvents().tableChange({ table, snapshotId, inserted,
310
+ deleted })` and `createTestContext(manifest, { tableChanges: { [event.id]: { inserted: [...] } } })`.
311
+
233
312
  ## Telling people something
234
313
 
235
314
  Name **people**; the platform reaches them. Don't build a recipient table, a
@@ -292,12 +371,148 @@ by, so declare it with the first `ctx.notify`, not later:
292
371
  undeclared function, a misspelt field and any `oxy.` kind — every problem at
293
372
  once; a catalogue kind no function sends is a warning.
294
373
 
374
+ **Acting in Oxygen itself: `ctx.oxygen`, never a stored key.** A function that
375
+ needs the platform (the org's kiosk devices, a source upload) asks for it under
376
+ `"oxygen"` in its manifest entry and calls `ctx.oxygen.*`:
377
+
378
+ ```jsonc
379
+ "tablets": { "route": true, "oxygen": { "frontline": { "devices": "manage" } } },
380
+ "webhook": { "oxygen": { "sourceUploads": { "pipelines": ["ubereats_transactions"] } } }
381
+ ```
382
+
383
+ ```ts
384
+ const link = await ctx.oxygen.frontline.devices.create({ name, locationId, returnTo });
385
+ await ctx.oxygen.sourceUploads.report({ file, fileName, pipeline: "ubereats_transactions", workflowId });
386
+ ```
387
+
388
+ - **The manifest asks; an org owner or admin approves**, under Apps in the organization's
389
+ API tokens settings, or on the page `/<org>/oxygen-access/<appId>`. Until then the call
390
+ throws `AppAccessNotApproved`: show the user that, never a stack trace. Publishing never
391
+ waits for the approval.
392
+ - **An upload names its pipeline**, as the manifest lists it; each pipeline is approved on
393
+ its own, and Oxygen finds where it lives. Never name a workspace.
394
+ - **No key, no network.** The host does it in-process as the app's own service account,
395
+ with no token for the app to hold. Never put an Oxygen API token in an app secret to
396
+ call Oxygen's API from a function: that is what this replaced.
397
+ - **Production only** (`EnvironmentRefused` elsewhere). Any trigger may call it; the
398
+ audit row records the app, the function, the trigger and the person when there is one.
399
+ - **Oxygen checks the app, not the person.** Anyone the function serves can reach the
400
+ action through it, so the function decides who may ask (as Store Ops' `tablets` does
401
+ with `reachOf`).
402
+
295
403
  **The dock.** Wrap the app in `<OxyShell>` (every `create-oxy-app` template
296
- does) so it shows Oxygen's rail: HQ, Chat and the viewer's other apps, each
297
- opening in this tab and warmed on hover. Pass `hideTopBar` if the app draws its
298
- own header. Link to another app with a plain `<a href>`, never `target="_blank"`;
404
+ does) so it shows Oxygen's rail: Home and the viewer's apps, each drawn as its
405
+ grey mark, opening in this tab and warmed on hover. From SDK 2.34.0 the shell has no
406
+ Chat entry and no Ask (no top-bar button, no ⌘K), as Oxygen's own chrome has none. Pass `hideTopBar` if the app draws its
407
+ own header. From SDK 2.33.0 the viewer opens and closes the rail from its
408
+ toggle, and the app's column narrows by 176px while it is open: lay screens out
409
+ to shrink (`min-width: 0` on flex children), never for a fixed width. Link to another app with a plain `<a href>`, never `target="_blank"`;
299
410
  moving between apps is meant to feel like one product.
300
411
 
412
+ **Look.** The design standard for every custom app is the oxygen reference app
413
+ (`oxy-hq/reference-app`; on SDK 2.31.0 from `reference-app@35c2bf5`, oxy-hq/reference-app#20).
414
+ Import `@oxy-hq/sdk/theme.css` (SDK ≥ 2.29) above your own CSS to get it: its palette, square
415
+ corners, frame and control lines, the system face and 44px touch targets, which the shell and
416
+ the phone kit read too. Its selectors weigh nothing, so your own token declarations still win;
417
+ adopting it means deleting them, and deleting any `--oxy-shell-*` or `!important` rules aimed
418
+ at the shell or kit. Without the import, nothing about the app's look changes.
419
+
420
+ **The desk UI comes from the SDK, never copied** (SDK ≥ 2.30). The reference app's
421
+ components, patterns and recipes ship in `@oxy-hq/sdk/ui` with `@oxy-hq/sdk/ui.css`, imported
422
+ after `theme.css` and `shell.css`: `import { SidePanel, LoadError, DefaultTabs, ui } from
423
+ "@oxy-hq/sdk/ui"`. A Tailwind app imports `@oxy-hq/sdk/tailwind.css` before
424
+ `@import "tailwindcss"` so its utilities read the theme. Money, percent, dates and CSV come from
425
+ `@oxy-hq/sdk/format`, which runs in a Function too. Run `checkThemeCss()` from
426
+ `@oxy-hq/sdk/testing` in the app's tests: it fails on CSS that restates an SDK token or keys its
427
+ own mode. Run `expect(formatSdkUiCopies(checkSdkUiCopies("src"))).toBe("")` there too (SDK ≥
428
+ 2.31): it reports each component in `src/` named like an SDK piece, with the import to use. A
429
+ variant kept on purpose says why in the file that defines it, `// oxy-ui-local: <Name> -- <why>`
430
+ (the reason is required). A local that only holds a component (`const Glyph = app.glyph`)
431
+ defines nothing and passes from SDK 2.31.1; 2.31.0 reported it, so rename it there. A piece the SDK lacks is built in the app from the `ui` recipes; a
432
+ defect in a shared piece is fixed in the SDK, so every app gets it.
433
+
434
+ SDK 2.31 adds, each opt-in: `Panel`'s fold (`foldable`, `open`, `defaultOpen`), `header`,
435
+ optional `title`, landmark (`as`, `label`, `headingLevel`) and `density="compact"`;
436
+ `Sparkline`'s one series (`sparkPoints`), `width` / `height`, `fluid`, `area`, `color`, `x` and
437
+ `readout`; `StatusDot wordHidden`; `DefaultTabs`' `disabled`, `stretch` and per-tab `hint`;
438
+ `HoverHint focusable`; `Stat`'s `tipMark` and `valueAt`; `MetricCell`'s `quiet` step;
439
+ `TryAgainButton`; `useModalFocus(ref, open, { auto: true })`; `topBarFrom` `sm` / `lg` / `2xl`;
440
+ `useOxyMode()` in `@oxy-hq/sdk/shell`. An app that kept its own panel fold, KPI tile, dot-only
441
+ status or Try again for want of one imports the SDK's and deletes its copy.
442
+
443
+ SDK 2.32 adds, each opt-in: `PanelTable`'s `phoneCard` (each row a card on a phone: title,
444
+ status and chevron on one line, subtitle, every figure, a column's `phoneWide` across) and
445
+ `rowProps` (per-row `data-*`, `title`, `tabIndex` and handlers); `Subnav`'s `showHeadings` and
446
+ `header`; `StatGrid phonePairs` and `PhoneKpiStrip oddLastAcross` (two to a row, an odd last
447
+ tile across); `AlertStrip`'s per-alert `hint` and `check` tone (the theme's `--status-check`);
448
+ `Sparkline`'s `domain`, `band`, `reference` (with `from`), `baseline` and `endTone`. An app that
449
+ kept a local PanelTable, Subnav, StatGrid, KPI row, AlertStrip or Sparkline for one of these
450
+ imports the SDK's and deletes its copy.
451
+
452
+ What the pieces settle, so an app doesn't override them (decisions 81–93):
453
+
454
+ - `SidePanel` keeps its overlay shadow; drop any `shadow-none` (81).
455
+ - One type scale, the reference's: take the closest step; no hand-set sizes, and no redefining
456
+ the size names (82).
457
+ - Hint bubbles open leftward, where `HoverHint` puts them (84).
458
+ - A failed read's message is 13px at either `LoadError` size; drop overrides of it (85).
459
+ - A `Stat` with a `tip` shows its ⓘ on the desk, a Tab stop; `tipMark={false}` only where the
460
+ tip restates what the screen already says (89). On a phone inside `OxyShell` it is the kit's
461
+ tap ⓘ after the label with no `TapHintFrame` from the app (SDK ≥ 2.31.1).
462
+ - A KPI tile is `Stat boxed` in a `StatGrid`; a critical one keeps its error edge (90).
463
+ - Waiting is counted: `LoadingBar` with the read count, `Loading` for a single read; never a
464
+ sweeping bar (91).
465
+ - `TrendChart` labels hold 12px on screen at any width (92).
466
+ - Two warning tiers are `MetricCell`'s `quiet` (the warning tint at 400) and `warning` (600),
467
+ `error` above them (93).
468
+
469
+ Six rules of the design system go beyond the reference:
470
+
471
+ - **Overlays blur the page behind them** (`--scrim`, and `--scrim-blur`, 8px; 0px under
472
+ reduced transparency). A modal `<dialog>` gets the blur from the theme on its own; give
473
+ its `::backdrop` the colour `var(--scrim)`. On any other scrim (a fixed div, a Radix or
474
+ shadcn overlay) put the class `oxy-scrim` and remove its own `bg-*`.
475
+ - **A button the app puts in the top bar (`topBarExtra`) is the reference's secondary**
476
+ (`btnCompactSecondary`: the `--btn-surface` fill, `--border-subtle` edge, full ink,
477
+ `--btn-surface-hover` on hover).
478
+ - **An attention strip on a page whose ground is not the card** insets its label 13px (a
479
+ tile's 1px frame + `--padding-sm-x`, 12px), so it lines up with the tiles below rather than
480
+ sitting on the box's edge; the SDK's `AlertStrip` draws it so.
481
+ - **A side panel on the desk runs the whole window's height and is modal.** A right-hand
482
+ detail panel (the reference's `SidePanel`) runs from the top of the window to the bottom
483
+ (`fixed`, `top: 0`, `bottom: 0`), over the top bar rather than under it, as Store Ops'
484
+ sheet does. While it is open the whole window behind it, the top bar included, is
485
+ scrimmed and blurred as above and inert; focus moves into it, Esc or a click on the scrim
486
+ closes it, and focus returns to the row that opened it. On a phone it stays a
487
+ full-screen view with no scrim.
488
+ - **On a phone, the bottom tab bar's current tab is the accent blue**, icon and label, in
489
+ light and dark, with the label at 600 weight. `PhoneTabBar` draws it in the theme's
490
+ `--link`, which holds 4.5:1 for the label and 3:1 for the icon on the bar. It is the only
491
+ selection drawn in blue: desk navigation, tabs and segmented controls keep the design
492
+ system's monochrome selection. Leave that colour to the kit (give a tab icon no colour
493
+ of its own, so it follows the slot), and a bottom bar the app draws itself follows the
494
+ same rule.
495
+ - **Square corners are for controls and surfaces, not for marks drawn on a map or a
496
+ chart.** A map marker or cell, a pin, and a chart's points and lines keep their own
497
+ shape. Everything else follows the design system, status dots (round, always with a
498
+ word) and count badges (square) included. Where the words beside a dot already say the
499
+ state, `StatusDot wordHidden` shows the dot alone and keeps the word for assistive tech.
500
+
501
+ **Light and dark.** With the theme, the app has both modes and shows the signed-in
502
+ person's, the one Oxygen home shows: `OxyShell` applies it and puts one Light / Dark /
503
+ System switch at the bottom of the rail (the nav sheet's bottom on a phone), and a change
504
+ there changes Oxygen too. Write every colour from the theme's tokens so both modes work;
505
+ never set `.dark` on `<html>` yourself. A screen that must not move, such as a store's
506
+ shared tablet, pins one: `<OxyShell modePin="light">`, `useOxyModePin("light")`, or
507
+ `<html data-oxy-mode-pin="light">` for the whole app. A crew sign-in has no mode and no
508
+ switch. On a staging or sandbox host the switch works for that preview only: it is kept on
509
+ that origin and never changes the person's real mode. The shell keeps
510
+ `<meta name="theme-color">` on the mode's ground, so the app needs no hook of its own for it.
511
+ `--chart-1…5` are the reference's sequential blue ramp; series that are categories take
512
+ `--chart-cat-*`. On a touch screen the shell's own chrome answers taps within 44px; a store's
513
+ enrolled tablet turns that off with `useOxyTouchTargets(false)` (or
514
+ `<OxyShell touchTargets={false}>`).
515
+
301
516
  **Motion.** `shell.css` loads `@oxy-hq/sdk/motion.css` (SDK ≥ 2.24), Oxygen's
302
517
  own motion language, so shadcn dialogs, menus and tooltips already open and
303
518
  close like Oxygen's. Time your own transitions with its tokens
@@ -307,6 +522,7 @@ are 120–240 ms), and give every slide or zoom a `motion-reduce:` counterpart.
307
522
 
308
523
  ```tsx
309
524
  import { OxyShell } from "@oxy-hq/sdk/shell";
525
+ import "@oxy-hq/sdk/theme.css";
310
526
  import "@oxy-hq/sdk/shell.css";
311
527
 
312
528
  <OxyAppProvider>
@@ -571,6 +787,25 @@ oxyc fn dev report --read-through --env dev # reads hit that deployment; wri
571
787
  `createTestContext` from `@oxy-hq/sdk/testing` in vitest, as the functions
572
788
  template does.
573
789
 
790
+ ### Say what a function takes and returns
791
+
792
+ Declare an `Input` (and `Output`) type in the function's entry file, or cast the
793
+ body (`JSON.parse(req.body) as Body`) and annotate the handler's return type.
794
+ `oxyc publish` turns them into the function's `inputSchema` / `outputSchema` in
795
+ the uploaded manifest. The staff console shows them as a field table, and Run now
796
+ checks its input against `inputSchema` before sending it. JSDoc becomes the field
797
+ description, and `@minimum`, `@maxLength`, `@pattern`, `@format` and
798
+ `@asType integer` become constraints.
799
+
800
+ - **Plain data types only:** interfaces, aliases, literals, unions, arrays,
801
+ `Record`, `Date`, relative type imports. A generic, intersection or tuple is a
802
+ publish **warning** naming the line, and that function ships without a schema.
803
+ - **A schema written in `oxy-app.json` wins**, and `null` turns generation off.
804
+ It must use the JSON Schema 2020-12 subset `OxyAppJsonSchema` lists (no
805
+ `$ref`) and stay under 16 KiB, or the publish is refused (`oxyc validate` says
806
+ so first).
807
+ - **Advisory:** a call that does not fit still runs.
808
+
574
809
  ## Publishing
575
810
 
576
811
  **These commands are a person's, or an agent's on a token that person
@@ -650,7 +885,12 @@ nobody the plan.
650
885
  retargets a publish.
651
886
  - **Credential:** `OXY_TOKEN`, then `oxyc login`'s cache — or, in a GitHub
652
887
  Actions job with `id-token: write`, the job's OIDC identity.
653
- `oxyc init-ci` writes a workflow that publishes with no stored secret.
888
+ `oxyc init-ci` writes a workflow that publishes with no stored secret, and
889
+ has an org owner or admin approve its service account and trust policy once.
890
+ In a Claude Code remote session it asks and exits (`--no-wait` is the default
891
+ there): relay the link it prints — add `--approver <their email>` so they are
892
+ pushed it — end the turn, and run `oxyc init-ci --force` once they have
893
+ approved. A run that finds both in place asks nobody.
654
894
  - Promote / roll back / unpublish from the oxy admin app-detail console;
655
895
  every publish is audited (who shipped each build, when).
656
896
  - **What is live now:** `oxyc apps show <org>/<app>` prints the live build, the
@@ -707,9 +947,53 @@ approves once, from any device.
707
947
  every later command. To iterate in a sandbox, mint
708
948
  `--sandbox-agent --app <org>/<app>` into the same file instead. A token
709
949
  lasts 8 hours by default (`--hours`, up to 168). On exit `4`, mint again.
950
+
951
+ **Or a network secret, which nobody approves per session.** The
952
+ environment's owner adds one in its settings: Allowed websites
953
+ `app.oxygen-hq.com` (and `*.oxy.tech`), header `Authorization`, prefix
954
+ `Bearer`, and a personal access token or service account token as the
955
+ value. They also set `OXY_TOKEN=from-proxy` in its environment variables.
956
+ The proxy then adds the token to each request after it leaves the VM, so it
957
+ is never in a file, a variable or your context, and `oxyc` sends none.
958
+ The hook checks it with `oxyc whoami` and says if it is not attached. On
959
+ exit `4`, report it: the secret's hosts, header or token are wrong, and
960
+ only the owner can fix them. Do not mint a token over it unasked. A sandbox
961
+ still needs an `--sandbox-agent` token minted into the file, which replaces
962
+ the sentinel.
710
963
  4. **Ship** with the commands above, each with `--token-env OXY_TOKEN`.
711
964
  `promote` and `rollback` need `--yes`, because there is no terminal to ask.
712
965
 
966
+ **Sharing the setup with a team.** The repo already shares what it can: the
967
+ hook and its settings entry reach every teammate who clones it. The cloud
968
+ environment cannot be shared that way. Claude Code has no file that defines
969
+ an environment's network access, variables or secrets. The way to share one
970
+ is an **organization environment**, which only an Owner of the team's Claude
971
+ organization creates (claude.ai admin settings → Cloud environments). Members
972
+ can read its variables but not its secrets, and one secret value serves
973
+ everyone who uses it. So set it up in two layers:
974
+
975
+ - **One shared environment, with no token in it.** The Owner creates an
976
+ organization environment with **Limited** network access. It allows
977
+ `app.oxygen-hq.com`, `*.oxy.tech` and the default package managers, and its
978
+ setup script runs `npm install -g @oxy-hq/cli`. Teammates pick it, and each
979
+ session gets its credential from step 3: the person approves their own
980
+ token, which ends in hours and is recorded as theirs.
981
+ - **A personal environment, for someone who wants no approval per session.**
982
+ They create their own environment with the same network access. They add
983
+ their own network secret, with their own personal access token (`oxy_pat_…`,
984
+ from Settings → Organization → API tokens → Personal access tokens), and
985
+ `OXY_TOKEN=from-proxy`. What
986
+ they do is still recorded as them.
987
+
988
+ Two things to avoid:
989
+
990
+ - **A network secret on the shared environment.** Every member's session then
991
+ acts as whoever owns that token, staff access included, and Oxy's audit log
992
+ shows all of it as that one person.
993
+ - **A browser session token as a secret's value.** If `oxyc whoami` says the
994
+ credential is "a browser session", the secret holds a session token, which
995
+ expires much sooner than a personal access token. Replace it.
996
+
713
997
  **A token approved by device code never carries staff or partner access.**
714
998
  `--standing --no-browser` is a usage error (exit `2`). The token from step 3
715
999
  reaches only what the approver's org memberships do. That is enough when they
@@ -729,9 +1013,10 @@ belong to the app's org. Staff shipping a customer's app have three ways:
729
1013
  plan, the deprecated promoting publish.
730
1014
  - **Mint the standing token where a browser opens.** On the engineer's own
731
1015
  machine, run `oxyc tokens create --agent --standing --hours <n>`. They put
732
- the value in the cloud environment's variables as `OXY_TOKEN`. Anyone who
733
- uses that environment can read it, so keep `--hours` short and revoke the
734
- token when the task is done.
1016
+ the value in the cloud environment as a network secret, with
1017
+ `OXY_TOKEN=from-proxy` (step 3). As a plain `OXY_TOKEN` variable instead,
1018
+ anyone who uses that environment can read it. Either way, keep `--hours`
1019
+ short and revoke the token when the task is done.
735
1020
  - **Leave the ship step to the engineer.** Hand back the sandbox's build and
736
1021
  the `oxyc promote --from dev-<handle>` command.
737
1022
 
@@ -826,5 +1111,6 @@ the sandbox with `--semantic-branch <branch>`, or set the planes above — see
826
1111
  | [references/verifying-in-the-browser.md](references/verifying-in-the-browser.md) | You changed something a person sees (`src/**`, or a function a card calls) and need to prove it on the published page. |
827
1112
  | [references/reading-data.md](references/reading-data.md) | You need a deployment's live data while building: an agent's own `--agent` token, `oxyc api` / `routes` / `schema`, and `oxyc proxy` for `pnpm dev` against cloud data. |
828
1113
  | [references/performance-and-usage.md](references/performance-and-usage.md) | You write an Oxy Function, a bulk action, caching or idempotency keys — or need to know what Oxy does for load speed and usage tracking, and the opt-outs. |
1114
+ | [references/app-calls.md](references/app-calls.md) | One app needs another app's data or rule: `callable`, `calls`, `ctx.apps.call` / `send`, `ctx.caller`, `AppCallError`, the same-environment rule, limits and testing. |
829
1115
  | [references/phone-layout.md](references/phone-layout.md) | A screen people open on a phone: when to build a phone view, the `usePhoneLayout()` pattern, what each desktop part becomes, and how to check it. |
830
1116
  | [references/minimal-starter.md](references/minimal-starter.md) | You are writing an app by hand instead of scaffolding it, or need the smallest correct layout. |
@@ -0,0 +1,98 @@
1
+ # One app calling another
2
+
3
+ An app's function can call a function of another app in the same organization, and wait for the answer (`ctx.apps.call`) or just queue the call (`ctx.apps.send`). Use it when another app owns the data or the rule: ask it, instead of copying its tables.
4
+
5
+ ## Declare it on both sides
6
+
7
+ The callee marks the function callable. Nothing else about the function changes; it stays an ordinary function with its own routes, schedule and timeout.
8
+
9
+ ```jsonc
10
+ // locations/oxy-app.json
11
+ { "functions": { "lookup": { "callable": true } } }
12
+ ```
13
+
14
+ The caller lists every (app, function) pair it may call, at the top level of its own `oxy-app.json`. Keys are app slugs, values are non-empty lists of function names with no repeats, 64 pairs at most in total.
15
+
16
+ ```jsonc
17
+ // orders/oxy-app.json
18
+ { "calls": { "locations": ["lookup"] } }
19
+ ```
20
+
21
+ `oxyc validate` checks the shape. `oxyc publish` warns, and does not fail, when a declared target does not exist yet or is not `callable`, so two apps can ship in either order; the call itself fails until both sides are live.
22
+
23
+ ## Call it
24
+
25
+ ```ts
26
+ import { isAppCallError } from "@oxy-hq/sdk/apps";
27
+
28
+ const place = await ctx.apps.call<{ id: string; name: string }>(
29
+ "locations", "lookup", { code }, { timeoutMs: 5000 }
30
+ );
31
+
32
+ const { eventId } = await ctx.apps.send("billing", "charge", { orderId }, { key: orderId, delaySeconds: 30 });
33
+ ```
34
+
35
+ - `call<T>(app, fn, body?, { timeoutMs? })` returns the callee's JSON answer. `send(app, fn, body?, { delaySeconds?, key? })` returns `{ eventId }` at once; the same `key` is the same send.
36
+ - Body and answer are JSON, under the existing request body limit.
37
+ - A `send` made on a token that expires is refused (`AppCallRefused`) when `delaySeconds` would run to or past that expiry, since the delivery would find the credential gone and kill the send. The message names the delay and says the credential this run is on expires first: shorten the delay. A login session, a token that never expires and a run as the system are not limited this way.
38
+ - Using `ctx.apps` with no top-level `calls`, or on a pair `calls` does not list, is refused (`AppsCapabilityMissing`, `AppCallRefused`). `oxyc validate` and `oxyc publish` lint literal calls for both.
39
+
40
+ ## Same environment, never production by fallback
41
+
42
+ Production calls the target's production build, staging calls its staging build, and a sandbox calls the target's same sandbox. A call never falls back to production: if the target has nothing deployed in that environment it fails with `not_deployed`.
43
+
44
+ ## Identity: the callee runs as itself
45
+
46
+ A `call` made while a person is behind the chain runs as that person: `ctx.user` is them, with their role, teams and reach resolved again for the callee's app, and the platform first checks they may open the target app (a member who cannot open an app restricted to a team cannot reach it through yours). A call from a background run (a schedule, an event, a webhook) runs as the system identity, as those runs do. A `send` is delivered later, as the same person when one sent it: the platform checks again, at delivery, that the credential they sent it with is still valid (a revoked or expired token fails) and that they may open the target app, and if not the delivery dies with a `sender_refused` error and your function never runs. A `send` from a background run is delivered as the system identity (`ctx.user.kind === "system"`). `ctx.caller` says who called, for attribution and logs only:
47
+
48
+ ```ts
49
+ ctx.caller; // null, or { app, function, invocationId, actor }
50
+ ```
51
+
52
+ `ctx.caller` is `null` unless another app's call or send started this invocation. `actor` is the person behind a `call` or a delivered `send` (their id), or `null` when no person was behind it.
53
+
54
+ ## Errors
55
+
56
+ A failed call throws `AppCallError` from `@oxy-hq/sdk/apps`, with `.kind`, `.message` (the text) and `.hostMessage` (the host's whole `<Label>: <text>`):
57
+
58
+ | `kind` | Meaning |
59
+ | --- | --- |
60
+ | `refused` | Your manifest does not declare the call, or the names are empty. |
61
+ | `not_found` | No such app or function. |
62
+ | `not_callable` | The function exists but is not marked `callable`. |
63
+ | `not_deployed` | The target has no build in this environment. |
64
+ | `timeout` | The budget ran out before an answer. |
65
+ | `failed` | The callee threw or answered an error; its message is passed through, cut to 500 characters. |
66
+ | `busy` | The target could not take the call right now; retry later. |
67
+ | `depth_exceeded` | The chain of calls and events is more than 8 deep. |
68
+ | `cycle` | The target function is already on this chain of synchronous calls (A.f → B.g → A.f); the message names the chain. A call into a different function of an app already on the chain is allowed. |
69
+
70
+ ```ts
71
+ try {
72
+ await ctx.apps.call("locations", "lookup", { code });
73
+ } catch (e) {
74
+ if (isAppCallError(e) && e.kind === "not_found") return Response.json({}, { status: 404 });
75
+ throw e;
76
+ }
77
+ ```
78
+
79
+ ## Limits
80
+
81
+ - **Depth 8**, shared with events: a call made by a function that an event or another call started counts one deeper, and a chain past 8 is refused with `depth_exceeded`.
82
+ - **Budget**: the callee's timeout is the smallest of your `timeoutMs`, the callee function's own `timeoutSeconds`, and what is left of the caller's time.
83
+ - Each call is its own invocation (mode `call`), with the caller's invocation as its parent: `oxyc invocations list` shows `parent <id>` on it and `--json` carries `parent_invocation_id`.
84
+
85
+ ## Not supported
86
+
87
+ - Reading another app's OLTP records, or a transaction shared across apps. Call a function of the owning app that does the read, and return what you need.
88
+
89
+ ## Testing
90
+
91
+ `createTestContext` from `@oxy-hq/sdk/testing` takes `apps` (handlers keyed `"<app>/<function>"`) and `caller`. A call with no handler throws `not_found`; the declared-pair rules are enforced as in production; `state.apps.sent` lists each `send`.
92
+
93
+ ```ts
94
+ const t = createTestContext(manifest, {
95
+ function: "place",
96
+ apps: { "locations/lookup": () => ({ id: "l1", name: "Main" }) },
97
+ });
98
+ ```