@feltdb/feltkit 0.3.37 → 0.5.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.
- package/dist/agent-engine.d.ts +93 -0
- package/dist/agent-engine.js +40 -0
- package/dist/agent-engine.js.map +1 -0
- package/dist/app.d.ts +306 -7
- package/dist/app.js +289 -28
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.d.ts +7 -0
- package/dist/appboundry/build.js +25 -1
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest.js +8 -0
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.d.ts +21 -0
- package/dist/appboundry/host.js +25 -0
- package/dist/appboundry/host.js.map +1 -1
- package/dist/appboundry/runtime.js +1 -0
- package/dist/appboundry/runtime.js.map +1 -1
- package/dist/boards/index.d.ts +1258 -0
- package/dist/boards/index.js +1410 -0
- package/dist/boards/index.js.map +1 -0
- package/dist/boards/model.d.ts +177 -0
- package/dist/boards/model.js +177 -0
- package/dist/boards/model.js.map +1 -0
- package/dist/boards/react.d.ts +18 -0
- package/dist/boards/react.js +339 -0
- package/dist/boards/react.js.map +1 -0
- package/dist/cli/deploy-appboundry-self-hosted.js +2 -2
- package/dist/cli/deploy.js +19 -6
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/main.js +70 -5
- package/dist/cli/main.js.map +1 -1
- package/dist/client/index.d.ts +454 -4
- package/dist/client/index.js +371 -3
- package/dist/client/index.js.map +1 -1
- package/dist/clock.d.ts +24 -0
- package/dist/clock.js +49 -0
- package/dist/clock.js.map +1 -0
- package/dist/cron.d.ts +18 -0
- package/dist/cron.js +67 -0
- package/dist/cron.js.map +1 -0
- package/dist/dashboard/assets/index-iIj7SL77.js +15 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +4 -0
- package/dist/docs.js.map +1 -1
- package/dist/eve/index.d.ts +77 -0
- package/dist/eve/index.js +128 -0
- package/dist/eve/index.js.map +1 -0
- package/dist/event-stage.js +2 -0
- package/dist/event-stage.js.map +1 -1
- package/dist/index.d.ts +17 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/native/build.d.ts +112 -0
- package/dist/native/build.js +472 -0
- package/dist/native/build.js.map +1 -0
- package/dist/native/index.d.ts +67 -0
- package/dist/native/index.js +113 -0
- package/dist/native/index.js.map +1 -0
- package/dist/native/instance.d.ts +3 -0
- package/dist/native/instance.js +18 -0
- package/dist/native/instance.js.map +1 -0
- package/dist/policy.d.ts +9 -1
- package/dist/policy.js +16 -3
- package/dist/policy.js.map +1 -1
- package/dist/presence.d.ts +85 -0
- package/dist/presence.js +37 -0
- package/dist/presence.js.map +1 -0
- package/dist/quota.d.ts +72 -0
- package/dist/quota.js +143 -0
- package/dist/quota.js.map +1 -0
- package/dist/react/agent-control.d.ts +191 -0
- package/dist/react/agent-control.js +366 -0
- package/dist/react/agent-control.js.map +1 -0
- package/dist/react/auth.d.ts +15 -1
- package/dist/react/auth.js +28 -5
- package/dist/react/auth.js.map +1 -1
- package/dist/react/hooks.d.ts +88 -0
- package/dist/react/hooks.js +188 -0
- package/dist/react/hooks.js.map +1 -0
- package/dist/react/index.d.ts +5 -75
- package/dist/react/index.js +4 -145
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/activity.d.ts +8 -0
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/agent-control.d.ts +28 -0
- package/dist/runtime/agent-control.js +43 -2
- package/dist/runtime/agent-control.js.map +1 -1
- package/dist/runtime/agent-run.d.ts +166 -0
- package/dist/runtime/agent-run.js +431 -0
- package/dist/runtime/agent-run.js.map +1 -0
- package/dist/runtime/agent.d.ts +158 -1
- package/dist/runtime/agent.js +345 -12
- package/dist/runtime/agent.js.map +1 -1
- package/dist/runtime/assemble.js +15 -2
- package/dist/runtime/assemble.js.map +1 -1
- package/dist/runtime/authority.d.ts +47 -0
- package/dist/runtime/authority.js +13 -2
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/capabilities.js +2 -1
- package/dist/runtime/capabilities.js.map +1 -1
- package/dist/runtime/changes.d.ts +17 -0
- package/dist/runtime/changes.js +65 -2
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/context.d.ts +123 -0
- package/dist/runtime/contract.js +9 -3
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/events.js +17 -1
- package/dist/runtime/events.js.map +1 -1
- package/dist/runtime/integrations.js +7 -7
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/invocations.d.ts +19 -2
- package/dist/runtime/invocations.js +16 -3
- package/dist/runtime/invocations.js.map +1 -1
- package/dist/runtime/policies.d.ts +5 -2
- package/dist/runtime/policies.js.map +1 -1
- package/dist/runtime/presence-host.d.ts +84 -0
- package/dist/runtime/presence-host.js +303 -0
- package/dist/runtime/presence-host.js.map +1 -0
- package/dist/runtime/providers.d.ts +5 -1
- package/dist/runtime/providers.js +11 -5
- package/dist/runtime/providers.js.map +1 -1
- package/dist/runtime/required-capabilities.d.ts +73 -0
- package/dist/runtime/required-capabilities.js +69 -0
- package/dist/runtime/required-capabilities.js.map +1 -0
- package/dist/runtime/resource-access.d.ts +137 -0
- package/dist/runtime/resource-access.js +177 -0
- package/dist/runtime/resource-access.js.map +1 -0
- package/dist/runtime/runtime.d.ts +143 -1
- package/dist/runtime/runtime.js +853 -44
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/sessions.d.ts +12 -0
- package/dist/runtime/sessions.js +16 -1
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/runtime/tenancy.d.ts +68 -1
- package/dist/runtime/tenancy.js +150 -0
- package/dist/runtime/tenancy.js.map +1 -1
- package/dist/runtime/transactions.d.ts +3 -1
- package/dist/runtime/transactions.js.map +1 -1
- package/dist/runtime/workers.d.ts +123 -0
- package/dist/runtime/workers.js +291 -0
- package/dist/runtime/workers.js.map +1 -0
- package/dist/server/eve.d.ts +287 -0
- package/dist/server/eve.js +1071 -0
- package/dist/server/eve.js.map +1 -0
- package/dist/server/index.d.ts +2 -19
- package/dist/server/index.js +102 -5
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp.d.ts +15 -22
- package/dist/server/mcp.js +40 -3
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/project.js +26 -8
- package/dist/server/project.js.map +1 -1
- package/dist/server/tenancy.d.ts +9 -0
- package/dist/server/tenancy.js +62 -1
- package/dist/server/tenancy.js.map +1 -1
- package/dist/server/watch.d.ts +10 -0
- package/dist/server/watch.js +88 -0
- package/dist/server/watch.js.map +1 -0
- package/dist/testing/index.d.ts +4 -5
- package/dist/testing/index.js +3 -2
- package/dist/testing/index.js.map +1 -1
- package/docs/AGENT-CONTROL.md +166 -4
- package/docs/APPBOUNDRY.md +73 -0
- package/docs/ARCHITECTURE.md +6 -2
- package/docs/AUTH.md +37 -0
- package/docs/COMPONENTS.md +71 -0
- package/docs/EVE-COMPOSITION.md +75 -0
- package/docs/GUARANTEES.md +4 -4
- package/docs/NATIVE-AGENTS.md +353 -0
- package/docs/NATIVE.md +137 -0
- package/docs/PRESENCE-AND-SIGNALING-PROPOSAL.md +152 -0
- package/docs/README.md +6 -2
- package/docs/SECURITY.md +71 -3
- package/docs/TRANSACTIONS.md +48 -0
- package/docs/UPSTREAM-GAPS.md +16 -2
- package/package.json +42 -16
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-agent/SKILL.md +1 -1
- package/skills/feltkit-build/SKILL.md +11 -1
- package/skills/feltkit-data/SKILL.md +1 -1
- package/skills/feltkit-operations/SKILL.md +1 -1
- package/skills/feltkit-services/SKILL.md +1 -1
- package/dist/dashboard/assets/index-BhxrvY37.js +0 -15
package/docs/NATIVE.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Native iOS and Android apps as a FeltKit host
|
|
2
|
+
|
|
3
|
+
A FeltKit application can run as a native iOS and Android app, written with React Native components (Expo). It is the same application: the same functions, collections, authorization, AppPort capabilities and agents, on the same instance. It is not a WebView around the web app, and not a second application model. The native app is a **host** for the application's client, as the [browser extension](EXTENSION-HOSTS.md) is: it carries screens and talks to an instance with a bearer session.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npx feltkit build ios # Expo project + compiled Hermes bundle
|
|
7
|
+
npx feltkit build android
|
|
8
|
+
npx feltkit build ios --compile # + the native project, built for the iOS Simulator
|
|
9
|
+
npx feltkit build android --compile --release --instance https://tasks.example.com
|
|
10
|
+
npx feltkit build web # the existing build, unchanged (also: `feltkit build`)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## What a build produces (and what it never claims)
|
|
14
|
+
|
|
15
|
+
The command prints, and `--json` returns, exactly one `kind`:
|
|
16
|
+
|
|
17
|
+
| kind | What was done | What it is |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| `project` (`--prepare`) | The Expo project was generated into `.feltkit/native`. | Nothing compiled. |
|
|
20
|
+
| `bundle` (default) | + dependencies installed, the screens typechecked, the JavaScript compiled to Hermes bytecode (`expo export`). | Proves the app and the FeltKit client bundle for that platform. **Not an installable app.** |
|
|
21
|
+
| `native` (`--compile`) | + `expo prebuild`, then Xcode (iOS Simulator) or Gradle (Android APK). Debug loads JavaScript from Metro; `--release` embeds the bundle. | **Never store-signed.** An iOS Simulator app runs on the Simulator only; an Android APK is signed with the debug key. |
|
|
22
|
+
|
|
23
|
+
Not done by FeltKit: signing, provisioning, App Store Connect, Google Play. `eas.json` is generated in the Expo project for `npx eas-cli build` (EAS is optional; nothing here requires a cloud service). Local development builds are `--compile` (Debug) plus `npx expo start` in `.feltkit/native`.
|
|
24
|
+
|
|
25
|
+
If the machine cannot compile, the build says precisely what is missing instead of guessing (Xcode, CocoaPods, the Android SDK, a JDK), and keeps the `bundle` it did produce.
|
|
26
|
+
|
|
27
|
+
## What you write
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
feltkit/ functions, collections, capabilities (the backend: unchanged)
|
|
31
|
+
shared/rules.ts what both UIs decide: permissions, error wording (optional, plain TypeScript)
|
|
32
|
+
src/ the web screens (React DOM)
|
|
33
|
+
native/App.tsx the native screens (React Native) ← required for ios/android
|
|
34
|
+
native/native.json name, bundleIdentifier, package, scheme, instance, extra native modules (optional)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`native/App.tsx` default-exports a component that receives `NativeAppProps` and uses `@feltdb/feltkit/native`: the same hooks as `@feltdb/feltkit/react` (`useQueryState`, `useMutation`, `useSession`, `useConnectionState`, …) and the same generated `api`. See `examples/tasks`: `src/App.tsx` (web) and `native/App.tsx` (native) share `feltkit/_generated/api` and `shared/rules.ts`, and nothing else.
|
|
38
|
+
|
|
39
|
+
Share application semantics, not components: the DOM components of `@feltdb/feltkit/react` (sign-in screens, the agent control bar) render `<div>`s and are not available natively; `@feltdb/feltkit/native` does not import them.
|
|
40
|
+
|
|
41
|
+
### The generated host
|
|
42
|
+
|
|
43
|
+
`.feltkit/native/` (derived, like `.feltkit/build/`; gitignore it) holds the Expo project: pinned dependencies, `app.json`, `metro.config.js`, `eas.json`, and `host.tsx`, which:
|
|
44
|
+
|
|
45
|
+
- creates the client with `createNativeClient`: a bearer session kept in secure storage (`expo-secure-store`: Keychain / Keystore), `expo/fetch` for the streaming change feed, and reconnect on foreground (`AppState` → `client.wake()`);
|
|
46
|
+
- shows loading, and a failure screen with **Try again** when the instance is unreachable or serves another application;
|
|
47
|
+
- hands e-mail links that open the app (`<scheme>://…#feltkit-magic-link=…`) to `handleDeepLink`.
|
|
48
|
+
|
|
49
|
+
Metro reads the screens, `shared/` and `feltkit/` from the project itself (one copy), and resolves `react`, `react-native` and `expo*` only from the Expo project (a second React copy breaks hooks).
|
|
50
|
+
|
|
51
|
+
### Environment
|
|
52
|
+
|
|
53
|
+
The instance the app talks to is, in order: `--instance`, `FELTKIT_URL`, `native/native.json` `instance`. It must be https, or http for `localhost` and the Android emulator's `10.0.2.2`; credentials in the address are refused. With none, a development build uses `localhost:3000` (`10.0.2.2:3000` on Android). `--release` requires an https instance and turns off the local-network exception in the iOS app.
|
|
54
|
+
|
|
55
|
+
## The application artifact
|
|
56
|
+
|
|
57
|
+
A native app is **not** part of the AppBoundry artifact (`feltkit build --target appboundry`), and the artifact does not change. The artifact is the *server* side: its WASM module, manifest, permissions and collections. A native app is a client of whichever instance serves that application, so the same deployed instance serves web, iOS and Android, and a native release needs no backend release.
|
|
58
|
+
|
|
59
|
+
The unit a native app is built from is the project: `feltkit/`, `shared/`, `native/` and `package.json` (name, version). The Expo project is derived from it and is regenerated freely. This is the smallest extension of the existing model: no second application model, and no new deployable.
|
|
60
|
+
|
|
61
|
+
Identity and version:
|
|
62
|
+
|
|
63
|
+
- **Version** comes from `package.json` (`1.2.3`); the build number is derived (`10203`), so a higher version is always a higher build.
|
|
64
|
+
- **Identity** is `native/native.json` (`bundleIdentifier`, `package`, `scheme`); without it a development default (`dev.feltkit.<application>`) is used and the build warns, because a store identity is yours to choose.
|
|
65
|
+
- **Reproducibility.** Dependencies are pinned to exact versions in one table (`NATIVE_PINS` in the SDK: Expo SDK 58's own set), extra modules need exact versions in `native.json`, and `.feltkit/native/feltkit-native.json` records a digest of the generated files and the application's sources: equal inputs give an equal digest (tested). A lockfile is not kept (gap N5).
|
|
66
|
+
|
|
67
|
+
## Compatibility matrix
|
|
68
|
+
|
|
69
|
+
Verified against the source and, where stated, by running it. "Verified" means evidence below, not the package name.
|
|
70
|
+
|
|
71
|
+
| Component | Web | Node | React Native | Required changes |
|
|
72
|
+
|---|---|---|---|---|
|
|
73
|
+
| **Client** (`@feltdb/feltkit/client`) | Yes (cookie or bearer) | Yes (bearer; tested) | **Yes, with adapters.** Imports nothing; uses only `fetch`, `AbortController`, `URL`, `TextDecoder`. Bundles unchanged for iOS and Android (Hermes). | `fetch` must stream: React Native's does not expose `response.body`, so the host passes `expo/fetch` (`createNativeClient`). `online` / `visibilitychange` do not exist: added `client.wake()`. Token store: `secureTokenStore`. |
|
|
74
|
+
| **React hooks** (`useQueryState`, `useMutation`, …) | Yes | n/a | **Yes.** Only `react` imports. | Split `react/index.tsx` into `hooks.tsx` (shared) and the DOM components; `@feltdb/feltkit/native` re-exports the hooks. |
|
|
75
|
+
| **React DOM components** (`auth.tsx`, `agent-control.tsx`) | Yes | n/a | **No**: they render `<div>`, `document`, `sessionStorage`. | None possible. Native screens are written natively (the principle: share semantics, not components). |
|
|
76
|
+
| **FeltDB client** (`@feltdb/core`) | n/a: never in a browser | Yes (server) | **Not used.** No client code imports it (`grep` of `src/client`, `src/react`, `src/native`). | None. FeltDB stays the authoritative state on the instance; the native app reaches it only through the application's functions, as the web app does. Evidence: the live-instance test. |
|
|
77
|
+
| **AppPort SDK** (`@appport/*`) | n/a (server) | Yes | **Not used on-device.** The app speaks FeltKit's HTTP API; AppPort capabilities are invoked by HTTP (`POST /appport`) with the same bearer session. | None. Tested: a capability invoked with the session the native client stored. |
|
|
78
|
+
| **Authentication** | Cookie session (HttpOnly) or bearer | Bearer | **Bearer in the Keychain / Keystore.** Password, sign-up, dev sign-in, e-mail code, session token, magic link via deep link. | Provider sign-in (`signInWith`) needs the instance to return to a native scheme: **gap N1**. Links that carry a session are refused by `handleDeepLink`. |
|
|
79
|
+
| **Capabilities / authorization** | Server-enforced | Server-enforced | Server-enforced; the screen only hides what the server would refuse (`shared/rules.ts`). | None. Tested: a viewer reads and is refused a write (`FORBIDDEN`). |
|
|
80
|
+
| **Files** | `client.uploadFile(link, Blob\|ArrayBuffer\|Uint8Array)` | Same | The client method works with the same inputs; **no picker or camera adapter exists** (gap N3). | An adapter over `expo-document-picker` / `expo-image-picker` returning a `Blob` or `Uint8Array`. |
|
|
81
|
+
| **Notifications** | In-app inbox (`services.notifications`) | n/a | The inbox is readable through the same functions. **Push is not supported**: the instance has no push channel (no APNs/FCM code in `src/`) (gap N2). | A server delivery channel and a device-token registration capability, then `expo-notifications`. |
|
|
82
|
+
| **Application runtime** | Vite + React | Server (`feltkit start`) | **Host only**: the backend never runs on the device. | `feltkit build ios\|android` (this document). |
|
|
83
|
+
| **Background work** | Service worker (extension) | Workers on the instance | Not supported: iOS/Android suspend the app and its sockets; reconnect on foreground catches up in one round trip (tested at the client). | Background sync would need a queue of offline writes (gap N4). |
|
|
84
|
+
|
|
85
|
+
**Compatible as-is:** the client, the hooks, the generated `api`, authorization, AppPort over HTTP. **Needs adapters:** secure storage, streaming fetch, app state, deep links (`createNativeClient`, `handleDeepLink`). **Needs platform-specific implementations:** screens; pickers and camera; push. **Cannot work natively:** the DOM components, and anything of the backend (it is not meant to).
|
|
86
|
+
|
|
87
|
+
## What is validated
|
|
88
|
+
|
|
89
|
+
Run `npm run test -w @feltdb/feltkit` (`test/native.test.ts`) and the commands below.
|
|
90
|
+
|
|
91
|
+
| Claim | Evidence |
|
|
92
|
+
|---|---|
|
|
93
|
+
| Existing web build works | `feltkit build web` / `feltkit build` on `examples/tasks`; the whole existing suite passes. |
|
|
94
|
+
| Native project generated | `feltkit build ios --prepare`, `android --prepare`; `generateFiles` determinism test. |
|
|
95
|
+
| JavaScript for both platforms compiles to Hermes bytecode | `feltkit build ios` and `feltkit build android` on `examples/tasks`: the screens typecheck against React Native's types, and Metro bundles the screens, `shared/rules.ts`, `feltkit/_generated/api` and the SDK client (≈1.6 MB `.hbc` each). |
|
|
96
|
+
| iOS native build | `feltkit build ios --compile` (Debug, 25 s Xcode) and `--compile --release --instance https://…` (Release, 45 s Xcode) both produced `Tasks.app` for the iOS Simulator on Xcode 27. |
|
|
97
|
+
| The app runs natively and talks to an instance | The Debug app, installed on an iPhone 16 Pro Simulator with `feltkit dev`'s instance and Metro running: it launched in Hermes, signed in as the first dev user, and rendered the seeded project and its three tasks with the connection shown as `live` ([screenshot](evidence/native-ios-simulator.png)). The instance was started through `startDev` because `feltkit dev` refuses Node 24. Not automated (gap N6): there was no tapping, so creating and toggling tasks on the device was not exercised. |
|
|
98
|
+
| Android native build | Blocked here by the environment: no Android SDK (`ANDROID_HOME` unset) and no JDK. The build reports exactly that; the Gradle path is **not exercised**. |
|
|
99
|
+
| Client works with the native adapters against a real instance | `native.test.ts`: sign in (token written to the secure store), `watchQuery` over the streaming feed, a mutation arriving live, an AppPort capability with the stored session, sign-out clears the store, a viewer refused a write. Runs in Node with a fake secure store and fetch, **not in Hermes**. |
|
|
100
|
+
| Reconnect on foreground | `native.test.ts`: `wake()` ends a back-off at once. |
|
|
101
|
+
| Deep links | `native.test.ts`: reset / invitation / error / magic link handled; a session in a link refused. |
|
|
102
|
+
| Shared logic is not duplicated | `src/App.tsx` and `native/App.tsx` both import `shared/rules.ts` (`can`, `describe`) and `feltkit/_generated/api`; the rules were moved out of the web app, not copied. |
|
|
103
|
+
|
|
104
|
+
### Build evidence
|
|
105
|
+
|
|
106
|
+
Recorded when this was written (macOS, Xcode 27, Node 24.9; the repository asks for Node 26, which this machine lacks, so the SDK's own tests ran on 24):
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
$ feltkit build ios → bundle typecheck 0.5 s, Hermes 4-5 s, 1.6 MB
|
|
110
|
+
$ feltkit build android → bundle 1.6 MB
|
|
111
|
+
$ feltkit build ios --compile --release --instance https://tasks.example.com
|
|
112
|
+
→ native pods 22 s, xcodebuild Release 45 s, Tasks.app (unsigned, Simulator)
|
|
113
|
+
$ feltkit build ios --compile → native xcodebuild Debug 25 s
|
|
114
|
+
$ feltkit build android --compile → refused: Android SDK not set up; no JDK (bundle kept)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Environment finding: Homebrew's CocoaPods failed here because the shell's chruby `GEM_PATH` leaked into it ("Could not find 'nkf'"). The build now runs `pod` without Ruby gem variables (`podEnv`, tested) and reports "installed but does not run" separately from "not installed".
|
|
118
|
+
|
|
119
|
+
## Gap register
|
|
120
|
+
|
|
121
|
+
| # | Gap | Evidence | Needed |
|
|
122
|
+
|---|---|---|---|
|
|
123
|
+
| N1 | Sign-in with a provider (GitHub, Google) is not available natively. | `server/oauth.ts` `returnTarget` accepts a web path or `https://<id>.chromiumapp.org/…` only. | The instance trusts the app's scheme as a return target (as `auth.extensions` does) and the host opens `expo-web-browser` auth sessions; then `signInWith` for native. |
|
|
124
|
+
| N2 | No push notifications. | No APNs/FCM code in `src/`. | A delivery channel on the instance, device-token registration as a capability, `expo-notifications` in the host. |
|
|
125
|
+
| N3 | No camera, media or file-picker adapter. | Not implemented; `uploadFile` accepts `Blob`/`Uint8Array`, unexercised on a device. | Adapter over `expo-image-picker` / `expo-document-picker`; a device test. |
|
|
126
|
+
| N4 | No offline writes or background sync. Reads are live only while connected; queries show the last data and the app shows `offline`. | The client has no outbox. | An outbox of idempotent mutations (the instance already has idempotency keys) replayed on reconnect. |
|
|
127
|
+
| N5 | No lockfile for the generated project, so transitive versions can drift. | `npm install` runs in `.feltkit/native`. | Keep `native/package-lock.json` and restore it before install (the SDK path is machine-specific in `file:` form: use the published package). |
|
|
128
|
+
| N6 | Android compile and any Android run were not exercised; the iOS run was a manual screenshot, not automated interaction. | Environment: no Android SDK, JDK. | Run `feltkit build android --compile` where the SDK is installed; UI automation on the Simulator/emulator. |
|
|
129
|
+
| N7 | App Store / Google Play distribution, signing, and EAS builds are not run or tested. | `eas.json` is generated only. | A credentialed `eas build` pass; documented per store. |
|
|
130
|
+
| N8 | Deep links: only the e-mail links; no universal/app links (`https://` associated domains). | `handleDeepLink`, scheme only. | Associated-domains configuration and a hosted `apple-app-site-association` / `assetlinks.json`. |
|
|
131
|
+
|
|
132
|
+
## Recommended next slice
|
|
133
|
+
|
|
134
|
+
1. **Run it on a device or emulator** (N6): boot the Simulator against `feltkit dev`, drive sign-in → create task → toggle, screenshot it, and make that a CI job on macOS; same for an Android emulator.
|
|
135
|
+
2. **Provider sign-in and links (N1, N8)**: one change on the instance (trust the app's scheme/links) unlocks the broker flow (`providers: { github: { broker: true } }`) for native with `expo-web-browser`.
|
|
136
|
+
3. **Push (N2)**: the highest-value native capability, and the first that needs a server change.
|
|
137
|
+
4. **Offline outbox (N4)** on top of idempotency keys.
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Presence, expiry and transient messages
|
|
2
|
+
|
|
3
|
+
Status: **implemented in 0.4.0** (unpublished until released), on the currently pinned FeltDB and AppPort. The
|
|
4
|
+
evidence below is from a real application (rkendel1/meetings), which built each of these itself. What shipped,
|
|
5
|
+
and where it differs from the proposal:
|
|
6
|
+
|
|
7
|
+
| # | Shipped as | Tests |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| P1 | `app.presence(name, shape, { ttlMs, onEnd, history })`, `ctx.presence.join/renew/end/history`, `ctx.db` showing live leases only; `bind: "session"` for resident agents. `onEnd` names an `app.agent`. | `test/presence.test.ts` |
|
|
10
|
+
| P2 | `app.channel(name, { message, access: { send, receive }, authorize: { send?, receive }, maxBytes, quota })` and `await ctx.channels.send(channel, scope, message)` in mutations; clients subscribe as to any event (`client.subscribe`, `useEvent`). | `test/channels.test.ts` |
|
|
11
|
+
| P3 | `quota` on functions (`per: "principal" \| "function" \| "arg:<name>" \| "principal+arg:<name>"`) and `feltkit({ quotas })`. | `test/quotas.test.ts` |
|
|
12
|
+
|
|
13
|
+
Differences from the proposal: P1's `onEnd` runs an `app.agent` (its own principal, at least once) instead of a
|
|
14
|
+
mutation "as the platform"; P3's counters are per process and in memory, so they do not survive a restart (see
|
|
15
|
+
docs/SECURITY.md, "Quotas"); P1 leases are ordinary FeltDB records until FeltDB's record TTL and ephemeral
|
|
16
|
+
collections can carry them. The "Also found" items below are fixed (`test/mcp-session-errors.test.ts`,
|
|
17
|
+
`test/dev-watch.test.ts`). The original proposal follows.
|
|
18
|
+
|
|
19
|
+
Three capabilities, each one an application had to build itself:
|
|
20
|
+
|
|
21
|
+
| # | Capability | Owning package | App code it replaces (meetings) |
|
|
22
|
+
|---|---|---|---|
|
|
23
|
+
| P1 | Presence: session-bound, expiring leases | FeltDB (lease records, expiry), FeltKit (API, session binding, live re-evaluation) | `feltkit/_presence.ts` + settlement in every call-touching mutation |
|
|
24
|
+
| P2 | Transient messages: scoped, authorized, not durable | AppPort (authorized, scoped events; UPSTREAM-GAPS A8, FK-GAP-004), then FeltKit | `feltkit/signals.ts` (a relay through durable records, deleted on read) |
|
|
25
|
+
| P3 | Quotas: per-principal limits on a function | FeltKit runtime (AppPort error semantics: `RATE_LIMITED`, `retryAfterMs`) | the signaling budget in `feltkit/signals.ts` |
|
|
26
|
+
|
|
27
|
+
## P1. Presence
|
|
28
|
+
|
|
29
|
+
### The gap (evidence)
|
|
30
|
+
|
|
31
|
+
- **No expiry.** FeltDB records do not expire, and a live query does not re-run because time passed. The
|
|
32
|
+
app keeps `lastSeenAt` per connection, treats `now - lastSeenAt > 45 s` as gone, and *settles* lazily:
|
|
33
|
+
every join, leave or check-in marks expired connections and ends calls whose last person is gone
|
|
34
|
+
(`settle()`). A crashed participant stays visible until someone else's next write, up to 45 s + one
|
|
35
|
+
check-in interval: **measured 60 s** (scripts/e2e-session-expiry.mjs).
|
|
36
|
+
- **No link between a session and the records it holds.** When a session ends (sign-out elsewhere,
|
|
37
|
+
revocation, expiry), FeltKit knows at once; the app does not. Measured (scripts/e2e-termination.mjs):
|
|
38
|
+
the participant's own browser stops media in ~11–12 s (its next heartbeat gets `UNAUTHORIZED`), but
|
|
39
|
+
**everyone else keeps a media connection open for 50–56 s**, until the presence expires. A client that
|
|
40
|
+
ignores the app keeps sending media for that long. Revocations the app *does* see (host removal,
|
|
41
|
+
access change) terminate in ~255 ms, including against a non-cooperating client.
|
|
42
|
+
- **It is subtle to get right.** The meetings audit found three lifecycle defects in the hand-built version
|
|
43
|
+
(a reload ended a solo call and split its recap; an expired connection was told it was "removed";
|
|
44
|
+
ghost tiles after a reload), each needing tests with a controlled clock.
|
|
45
|
+
|
|
46
|
+
### Why the application should not own it
|
|
47
|
+
|
|
48
|
+
Expiry needs a clock-driven write or a time-aware read that the application cannot schedule per record;
|
|
49
|
+
binding to sessions needs the session store, which applications cannot and should not read. Every
|
|
50
|
+
collaborative application (cursors, typing indicators, device sessions, multiplayer, calls) needs the
|
|
51
|
+
same thing.
|
|
52
|
+
|
|
53
|
+
### Contract (proposed)
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
// Declared like a collection; records are leases.
|
|
57
|
+
export const peers = app.presence("peers", { callId: s.ref(calls), name: s.string(), mic: s.boolean() }, {
|
|
58
|
+
ttlMs: 45_000, // a lease not renewed within ttlMs ends with reason "expired"
|
|
59
|
+
history: true, // ended leases are kept (who was present, when, why it ended)
|
|
60
|
+
onEnd: "calls:settle", // a mutation run (as the platform, at most once per lease) when one ends
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const lease = await ctx.presence.join(peers, { callId, name, mic: true }); // bound to the caller's session
|
|
64
|
+
await ctx.presence.renew(peers, lease.id, { mic: false }); // only by its holder
|
|
65
|
+
await ctx.presence.end(peers, lease.id, "left" | "removed"); // holder: left; others need access
|
|
66
|
+
const live = await ctx.db.find(peers, { callId }); // live leases only, in queries
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Guarantees:
|
|
70
|
+
|
|
71
|
+
1. A lease ends exactly once, with one reason: `left`, `removed`, `expired`, `session-ended`, `replaced`.
|
|
72
|
+
2. **When the holder's session ends, its leases end at once** (`session-ended`), on every surface.
|
|
73
|
+
3. A live query over a presence collection re-runs when a lease ends by time, not only by write.
|
|
74
|
+
4. `onEnd` runs after the end commits, at most once per lease, with the lease and reason.
|
|
75
|
+
5. Ended leases remain readable as history (attendance) when `history: true`.
|
|
76
|
+
|
|
77
|
+
### Regression tests (to write with the implementation)
|
|
78
|
+
|
|
79
|
+
- a lease not renewed for `ttlMs` disappears from a live query without any other write;
|
|
80
|
+
- signing out, revoking the session and session expiry each end the session's leases with `session-ended`,
|
|
81
|
+
observed by another principal's live query within one second;
|
|
82
|
+
- `onEnd` runs once per ended lease under concurrent renew/end/expiry;
|
|
83
|
+
- only the holder renews; another principal's `end` is authorized by the function's access, not by the lease;
|
|
84
|
+
- history keeps reason and times across restart.
|
|
85
|
+
|
|
86
|
+
## P2. Transient messages
|
|
87
|
+
|
|
88
|
+
### The gap (evidence)
|
|
89
|
+
|
|
90
|
+
AppPort events cannot carry per-recipient messages safely: subscriptions are not authorized per
|
|
91
|
+
subscriber or per delivery, and events have no scope (UPSTREAM-GAPS A8; FeltKit's FK-GAP-004 is blocked on
|
|
92
|
+
it). So the meetings app relays WebRTC offers and answers **through durable records**: insert, live query
|
|
93
|
+
by recipient, delete on acknowledgement, delete on departure, with app-built limits (one pending signal
|
|
94
|
+
per pair, 60 per minute per connection, 64 kB, role checks). Every signal is a FeltDB transaction.
|
|
95
|
+
|
|
96
|
+
### Contract (proposed)
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
export const signaling = app.channel("signaling", {
|
|
100
|
+
message: s.object({ kind: s.enum(["offer", "answer"]), sdp: s.string({ maxLength: 65_536 }) }),
|
|
101
|
+
// Who may send to and receive on a scope (here: a connection id), decided per message.
|
|
102
|
+
authorize: { send: "calls:maySignal", receive: "calls:ownsConnection" },
|
|
103
|
+
quota: { per: "principal", limit: 60, windowMs: 60_000 },
|
|
104
|
+
});
|
|
105
|
+
await ctx.channels.send(signaling, toConnectionId, { kind: "offer", sdp }); // at most once, not stored
|
|
106
|
+
useChannel(signaling, myConnectionId, (message, from) => …); // React
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Guarantees: delivered at most once to current, authorized subscribers of the scope; nothing durable;
|
|
110
|
+
authorization at subscribe **and** at each delivery; bounded size; quota enforced by the platform.
|
|
111
|
+
|
|
112
|
+
### Regression tests
|
|
113
|
+
|
|
114
|
+
- a subscriber not authorized for a scope receives nothing, including with a `*` subscription;
|
|
115
|
+
- authorization is re-evaluated per delivery (revoked mid-stream → no further messages);
|
|
116
|
+
- quota exceeded → `RATE_LIMITED` with `retryAfterMs`, other senders unaffected;
|
|
117
|
+
- nothing about a message remains in FeltDB after delivery.
|
|
118
|
+
|
|
119
|
+
## P3. Quotas
|
|
120
|
+
|
|
121
|
+
### The gap (evidence)
|
|
122
|
+
|
|
123
|
+
FeltKit has no rate limiting (SECURITY.md: "put a reverse proxy in front"). A proxy cannot see the
|
|
124
|
+
principal or the meeting, so the app counts signals itself on the sender's presence record (a write per
|
|
125
|
+
signal, contending with its heartbeats). Chat and reactions have no limit at all.
|
|
126
|
+
|
|
127
|
+
### Contract (proposed)
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
app.mutation({ access: "chat.send", quota: { per: "principal", limit: 30, windowMs: 10_000 }, … });
|
|
131
|
+
app.mutation({ quota: [{ per: "principal", limit: 60, windowMs: 60_000 }, { per: "arg:code", limit: 600, windowMs: 60_000 }], … });
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Refused with `RATE_LIMITED` and `details.retryAfterMs` before the handler runs; recorded in the activity log;
|
|
135
|
+
the same on HTTP, AppPort and MCP; counters kept outside the application's transaction.
|
|
136
|
+
|
|
137
|
+
### Regression tests
|
|
138
|
+
|
|
139
|
+
- the (limit+1)th call in a window is refused before the handler runs, on HTTP, `/appport` and `/mcp`;
|
|
140
|
+
- `per: "arg:<name>"` isolates scopes; a refused call commits nothing;
|
|
141
|
+
- counters survive restart; concurrent calls never exceed the limit.
|
|
142
|
+
|
|
143
|
+
## Also found while building the evidence
|
|
144
|
+
|
|
145
|
+
- **MCP dropped idempotency keys** (fixed: `test/mcp-idempotency.test.ts`).
|
|
146
|
+
- **`measure` counted presence, relays and media transports as domain** (fixed: three detectors and the
|
|
147
|
+
ownership check, `test/measure.test.ts`).
|
|
148
|
+
- An expired agent session is refused on `/mcp` with "An agent session token is required", which reads as
|
|
149
|
+
a missing token, not an expired one.
|
|
150
|
+
- `feltkit dev` stopped reloading a function module after a sequence of edits (an edit, then the file
|
|
151
|
+
restored by copy, then `touch`): no "Reloaded functions" line, old code kept serving until restart.
|
|
152
|
+
Not yet reduced to a reproduction.
|
package/docs/README.md
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
# FeltKit 0.
|
|
1
|
+
# FeltKit 0.5.0 documentation
|
|
2
2
|
|
|
3
3
|
Shipped with `@feltdb/feltkit`. In a project: `node_modules/@feltdb/feltkit/docs/`, or run `npx feltkit docs`.
|
|
4
|
-
Public copy: https://cdn.jsdelivr.net/npm/@feltdb/feltkit@0.
|
|
4
|
+
Public copy: https://cdn.jsdelivr.net/npm/@feltdb/feltkit@0.5.0/docs/README.md
|
|
5
5
|
|
|
6
6
|
- [ARCHITECTURE.md](ARCHITECTURE.md): How FeltKit is put together: one FeltDB instance, AppPort, AppPort Services
|
|
7
7
|
- [GUARANTEES.md](GUARANTEES.md): What FeltKit guarantees, and its known limitations
|
|
8
8
|
- [TRANSACTIONS.md](TRANSACTIONS.md): Mutations, ctx.db.sequence and ctx.afterCommit: the transaction contract
|
|
9
9
|
- [SECURITY.md](SECURITY.md): Authorization, sessions, credentials, and production Studio
|
|
10
10
|
- [AUTH.md](AUTH.md): Accounts, sessions, workspaces (tenancy), invitations, and the React sign-in and workspace screens
|
|
11
|
+
- [PRESENCE-AND-SIGNALING-PROPOSAL.md](PRESENCE-AND-SIGNALING-PROPOSAL.md): Presence leases, session binding and transient messages: the app.presence API and its status
|
|
11
12
|
- [POLICIES.md](POLICIES.md): Declarative policies (owner, sharing, state, input, roles, delegation), managed versions without a redeploy, simulation, decision evidence
|
|
12
13
|
- [SIGN-IN-BROKER.md](SIGN-IN-BROKER.md): Sign in with GitHub and Google with nothing to register: the FeltKit broker, the assertion it signs, the extension flow, running and rotating it
|
|
13
14
|
- [EXTENSION-HOSTS.md](EXTENSION-HOSTS.md): Running the app in a browser extension: ownership, token storage, session end, lifecycle, gaps
|
|
15
|
+
- [NATIVE.md](NATIVE.md): Running the app as a native iOS and Android app (Expo / React Native): feltkit build ios|android, what it produces, the compatibility matrix, validation, gaps
|
|
14
16
|
- [INVOCATIONS.md](INVOCATIONS.md): Surfaces and invocations: registering entry points, the feltkit.invocation/1 contract, the durable lifecycle, dispatch and recovery
|
|
15
17
|
- [EXECUTION.md](EXECUTION.md): Placement-neutral execution: the control plane and execution environments, the execution contract, adapters, placement, authority and evidence
|
|
16
18
|
- [LOCAL-AUTHORITY.md](LOCAL-AUTHORITY.md): The private AuthBoundry beside the application (authority.local): grants, agents, per-agent delegation and the agentCallers opt-in
|
|
17
19
|
- [CONNECTIONS.md](CONNECTIONS.md): People's own connections to integrations (credential.owner: person): connecting, isolation, AuthBoundry at every call (reference implementation)
|
|
18
20
|
- [AGENT-OPERATIONS.md](AGENT-OPERATIONS.md): Agents: MCP, tasks, proposals, approvals, and evidence
|
|
21
|
+
- [EVE-COMPOSITION.md](EVE-COMPOSITION.md): Composing FeltKit with EVE: the run lives in FeltDB through a FeltDB World; collisions, approvals as AppPort approvals, open questions
|
|
22
|
+
- [NATIVE-AGENTS.md](NATIVE-AGENTS.md): Native agents: app.agent with instructions and tools, run in the app's own runtime; engines, durability, authority, approvals, limits
|
|
19
23
|
- [AGENT-CONTROL.md](AGENT-CONTROL.md): Steering a running agent: update signals, submitted updates at safe boundaries, pause, resume, interrupt, stop
|
|
20
24
|
- [GENERATION.md](GENERATION.md): Model generation in an application: actions, streaming, tools as proposals, in-app approvals, caller context
|
|
21
25
|
- [RESOLVER.md](RESOLVER.md): Model references: change the model a deployed app uses through Resolver, without a redeploy
|
package/docs/SECURITY.md
CHANGED
|
@@ -229,10 +229,75 @@ bounded). It is null when nothing was evaluated. It is evidence only, never an i
|
|
|
229
229
|
keeps `Content-Security-Policy: …; sandbox`; reasons in `X-FeltKit-Variant-Reason` are FeltKit's own
|
|
230
230
|
text, reduced to printable ASCII.
|
|
231
231
|
|
|
232
|
+
## Quotas (rate limits)
|
|
233
|
+
|
|
234
|
+
- **Functions.** `quota: { per, limit, windowMs }` on a function, and `feltkit({ quotas })` for every function, limit
|
|
235
|
+
how often a caller runs it: per principal, per function (everyone together), per argument value (`arg:<name>`), or
|
|
236
|
+
per principal and argument. Checked at the execution boundary every interface shares (HTTP, AppPort, MCP, agents,
|
|
237
|
+
jobs, components), after the role check and argument validation and before the policies, the authorize hook and
|
|
238
|
+
the handler, so a refused call reads nothing and writes nothing. Refusal: `RATE_LIMITED` with
|
|
239
|
+
`details.retryAfterMs` and the quota that refused; HTTP 429 with `Retry-After` on `/api` and `/appport`; an MCP tool
|
|
240
|
+
error. Recorded in the activity log as a denial (not as a durable decision record: an abusive caller must not be
|
|
241
|
+
able to make the server write).
|
|
242
|
+
- **Channels** (`app.channel`) take the same `quota` per sender.
|
|
243
|
+
- **Public routes.** Guest sign-in (`POST /api/auth/guest`, 30/min) and tenant resolution
|
|
244
|
+
(`GET /api/tenants/resolve`, 120/min) are limited per client address; password sign-in and e-mail challenges keep
|
|
245
|
+
their own limits (docs/AUTH.md).
|
|
246
|
+
- **Counting.** Sliding windows in the server process (src/quota.ts): exact within a process, never above the limit
|
|
247
|
+
under concurrency, empty after a restart, and per process (two processes behind a balancer each allow `limit`).
|
|
248
|
+
Anonymous callers count per client address (`auth.session.trustProxy` decides which header is believed).
|
|
249
|
+
- **Not covered:** FeltKit's other routes (static files, Studio, `/appport/events` streams) and volumetric attacks.
|
|
250
|
+
Keep a reverse proxy or platform limit in front of production for those.
|
|
251
|
+
|
|
252
|
+
## Guests, agent grants and transient messages
|
|
253
|
+
|
|
254
|
+
- **Guests** (`auth.guests`, docs/AUTH.md "Guests"): a guest link's token is 256 bits, stored as a SHA-256 digest,
|
|
255
|
+
shown once. A guest session is resolved from its link on every request: a withdrawn or expired link is a 401 on the
|
|
256
|
+
next request. A guest holds only its link's role (from `auth.guests.roles`), reaches only functions that declare
|
|
257
|
+
`resource: { …, guests: true }` and only for its record (another record is NOT_FOUND), never actions, tenancy or
|
|
258
|
+
durable work (work it queued does not run as it). Its display name is its own words.
|
|
259
|
+
- **Agent grants**: a function with `resource: { …, agents: "grant" }` refuses every agent and service without a live
|
|
260
|
+
grant for that record. Only a person issues grants; revocation applies on the next call.
|
|
261
|
+
- **Channels**: the sender is checked (permission, send rule, size, quota) before the message is accepted; each
|
|
262
|
+
recipient is checked by the channel's receive rule at subscribe and before every delivery, wildcard subscriptions
|
|
263
|
+
included. Messages are never written to FeltDB or logged.
|
|
264
|
+
- **Public tenant resolution** answers a slug's or domain's branding only (presentation fields validated on write); it
|
|
265
|
+
reveals that a slug exists, which is what a public address is.
|
|
266
|
+
|
|
267
|
+
Every refusal by these layers is durable decision evidence (`_feltkit_decisions`, layers `resource` and `channel`).
|
|
268
|
+
|
|
269
|
+
## Workers, work grants, approvals and visibility (0.4.0)
|
|
270
|
+
|
|
271
|
+
- **Workers** (`ctx.grants.registerWorker`): a runner's own principal `worker:<name>` (type `agent`), never a person
|
|
272
|
+
or the service that registered it. Registering needs `feltkit.workers.write` and gives the worker no permission the
|
|
273
|
+
registrar does not hold. Its token is a session resolved from the registration on every request: revoking the
|
|
274
|
+
worker (`ctx.grants.revokeWorker`) ends its sessions and grants, and its very next call is a 401.
|
|
275
|
+
- **Work grants** (AppPort delegated authority, spec §12.5): a worker calls nothing without a live grant it names
|
|
276
|
+
(`x-appport-grant`, the AppPort envelope's `invocation.grantRef`, MCP `_meta["dev.appport/invocation"]`), issued to
|
|
277
|
+
it, covering the capability, for one actor and optionally one work item. AppPort's `delegatedAuthorityAuthorizer`
|
|
278
|
+
checks it on `/appport` and `/mcp`, and FeltKit checks the same records with the same rules at its execution
|
|
279
|
+
boundary on `/api`, so no surface skips it. Refusals are FORBIDDEN with `details.reason` (`GRANT_REQUIRED`,
|
|
280
|
+
`GRANT_REVOKED`, `GRANT_WORK_ITEM_MISMATCH`, `GRANT_ACTOR_MISMATCH`, …). A grant scoped to a work item reaches only
|
|
281
|
+
that record on a function bound to one (`resource`), and only that platform invocation. A person grants only for
|
|
282
|
+
themselves and only what they may call; a service names the actor. Handlers read `ctx.auth.invocation.verified`,
|
|
283
|
+
never the claim; the verified actor is recorded with the worker in activity and the audit record.
|
|
284
|
+
- **Approvals of exact calls** (`ctx.grants.approve`): only a signed-in person who may make the call approves it, for
|
|
285
|
+
one capability and exactly one input (`actionDigest`), optionally for one worker and work item. A non-person runs an
|
|
286
|
+
`approval: "required"` function only with such an approval (`x-appport-approval`); a changed input
|
|
287
|
+
(`APPROVAL_NOT_COVERED`), a revoked or expired approval, or another worker's use of it is refused. People still
|
|
288
|
+
call these functions directly, as before.
|
|
289
|
+
- **Visibility**: `internal` functions answer FUNCTION_NOT_FOUND on every surface and are never published; `worker` and
|
|
290
|
+
`service` functions refuse every other caller (layer `visibility`). An AppBoundry build refuses visibility, since
|
|
291
|
+
its host would dispatch them to anyone.
|
|
292
|
+
|
|
293
|
+
Refusals are durable decision evidence (layers `grant` and `visibility`). Grants, approvals and registrations live in
|
|
294
|
+
`_feltkit_resource_access`; there is no secret in them (a worker's token is a session, stored as the session store
|
|
295
|
+
stores every session).
|
|
296
|
+
|
|
232
297
|
## Known gaps
|
|
233
298
|
|
|
234
|
-
-
|
|
235
|
-
production deployments.
|
|
299
|
+
- Rate limits cover functions, channels and the public guest and tenant routes (above), counted per process. Other
|
|
300
|
+
routes have none: put a reverse proxy in front of production deployments.
|
|
236
301
|
- Session tokens in the browser are kept in `localStorage`; an XSS in your frontend can
|
|
237
302
|
read them.
|
|
238
303
|
- CORS is not enabled: the API is same-origin. Cross-origin clients need a proxy.
|
|
@@ -244,7 +309,10 @@ bounded). It is null when nothing was evaluated. It is evidence only, never an i
|
|
|
244
309
|
production.
|
|
245
310
|
- Production operator sessions cannot be listed or revoked from Studio; there is no MFA
|
|
246
311
|
and no external identity-provider integration beyond the `auth.authenticate` hook.
|
|
247
|
-
- Production Studio has no rate limiting of its own
|
|
312
|
+
- Production Studio has no rate limiting of its own.
|
|
313
|
+
- Workers are registered by application code; there is no Studio screen or CLI for them yet, and a worker's
|
|
314
|
+
registration lives at most 30 days (register it again). An approval binds the capability and its input, and
|
|
315
|
+
resources only through the input that names them.
|
|
248
316
|
- The first download of an image variant decodes on the server's event loop. With a large
|
|
249
317
|
`maxVariantPixels`, many first downloads at once slow other requests; the default (24 MP) and the files
|
|
250
318
|
byte cap (1 MiB by default) bound it.
|
package/docs/TRANSACTIONS.md
CHANGED
|
@@ -361,3 +361,51 @@ const history = await events.history(ctx, "invoice", id); // in order
|
|
|
361
361
|
history by `at` as well, or move it before switching. An anonymous caller is recorded as actor `anonymous`.
|
|
362
362
|
- **Where it runs.** It works in FeltKit and in AppBoundry artifacts. An artifact with a trail requires
|
|
363
363
|
`transactions@1`, because of the sequence.
|
|
364
|
+
|
|
365
|
+
## 10. Across boundaries: app writes, dispatch intent, and external effects through a crash
|
|
366
|
+
|
|
367
|
+
Sections 4–8 give each mechanism's own contract. This is what holds when a process stops (or a commit or a
|
|
368
|
+
call is lost) at each boundary between them, for the shape an application uses to make an external effect
|
|
369
|
+
from a state change: a mutation writes and stages the dispatch (`ctx.afterCommit.jobs.enqueue`), a job runs
|
|
370
|
+
an action, the action records and makes the effect (`ctx.effect`, below), and writes what came of it.
|
|
371
|
+
|
|
372
|
+
```
|
|
373
|
+
mutation ──commit──▶ outbox pending ──perform──▶ job created ──run──▶ action ──begin()──▶ effect ──▶ outcome ──▶ follow-up write
|
|
374
|
+
(1) (2) (3) (4) (5) (6) (7) (8)
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
| Stop or loss at | What is durable afterwards | What recovery does | Guarantee | Evidence |
|
|
378
|
+
|---|---|---|---|---|
|
|
379
|
+
| (1) before or during the mutation's commit | nothing: no writes, no outbox record, no sequence number | nothing to recover | atomic: all or nothing | §7; `test/transactions.test.ts`, `test/outbox.test.ts` |
|
|
380
|
+
| (1) the commit landed, its answer was lost | the writes, the outbox record | a same-key retry is answered from AppPort's record (`EFFECT_OUTCOME_UNKNOWN`) or refused by FeltDB's transaction-id binding | the writes commit once | `test/appport-adoption.test.ts` (A5) |
|
|
381
|
+
| (2) committed, the outbox record not yet performed | `pending` | the services worker performs it (30 s) | created once (Decision C) | `test/outbox.test.ts`, `tests/e2e/outbox-lifecycle.test.mjs` |
|
|
382
|
+
| (3) the record claimed, the job not yet created | `performing` | taken over after 300 s; creation and the done mark are one transaction | created once | as above |
|
|
383
|
+
| (4) the job's action stops before `begin()` | the job (Services retries it) | the job runs again | at least once, which is safe: nothing began | `test/action-effects.test.ts` |
|
|
384
|
+
| (5)–(6) after `begin()`, before or during the effect | `_feltkit_provider_calls` record `started`, no outcome | the job's next attempt **does not begin the effect again** (one record per job: `OUTCOME_UNKNOWN`); after `FELTKIT_PROVIDER_STRANDED_AFTER_SECONDS` the call is stranded, listed and settleable | at most once; the outcome is unknown until verified or settled | `test/action-effects.test.ts` ("a process that stops between begin() and the outcome…") |
|
|
385
|
+
| (6) the effect gave no definite answer | `unknown` | never repeated: a keyed AppPort retry gets the recorded answer, a retried job is refused at `begin()` | at most once | `test/action-effects.test.ts`, `test/integrations.test.ts` |
|
|
386
|
+
| (7) the effect failed (`effectFailed(...)`) | `failed` | an AppPort retry with the same key runs again (the key is released) | a known failure is retryable | `test/action-effects.test.ts` |
|
|
387
|
+
| (8) the effect succeeded, the follow-up write did not commit | `succeeded` (or `started`, if the stop came first) | the job's retry is refused at `begin()` (the effect is not repeated); the follow-up is not redone | **the effect is never repeated; the follow-up write may be missing** | below |
|
|
388
|
+
|
|
389
|
+
`ctx.effect` (an action's external effect, ActionCtx.effect) is AppPort's `runEffectful` over the same recorder
|
|
390
|
+
as providers' calls: `begin()` records `started` durably before the effect, and the outcome after it. Its record
|
|
391
|
+
id is the AppPort request id for a capability call (AppPort's idempotency answers retries), and one id per job
|
|
392
|
+
for a job's action, so a job's attempts share one record. `appport.invocation.status@1` answers "what happened
|
|
393
|
+
to my call?" from these records for the caller's own calls, and a person who may make the call settles it
|
|
394
|
+
(`client.settleCall`, `/api/provider-calls`).
|
|
395
|
+
|
|
396
|
+
**Found and fixed (0.4.0):** a mutation that opted into `retry: { sequenceConflicts }` was re-run on a sequence
|
|
397
|
+
conflict when it had used no `ctx.services`, even if it had called out through `ctx.integrations.invoke`: the
|
|
398
|
+
external call was then made again by every re-run. An attempt that calls `ctx.integrations` is now never re-run,
|
|
399
|
+
as for `ctx.services` (`test/transactions.test.ts`: without the fix all ten concurrent calls re-ran and committed).
|
|
400
|
+
|
|
401
|
+
**Not solved, by design (reported):**
|
|
402
|
+
- *An effect made inside a mutation.* `ctx.integrations.invoke` from a mutation runs while its transaction is
|
|
403
|
+
open: if the commit is then refused, the effect happened and the writes did not. It is recorded
|
|
404
|
+
(`_feltkit_integration_calls`), but nothing reconciles it with the refused writes. Make effects from an action,
|
|
405
|
+
dispatched with `ctx.afterCommit.jobs.enqueue`. Refusing it would break existing applications; FeltKit
|
|
406
|
+
documents it instead.
|
|
407
|
+
- *(8), a lost follow-up write.* After a stop between a successful effect and the action's own write of what came
|
|
408
|
+
of it, FeltKit keeps the effect from repeating but cannot redo the write: the action's output was never recorded.
|
|
409
|
+
The application finds such calls with `appport.invocation.status` (`succeeded`) or the call board and writes
|
|
410
|
+
the result then; an effect whose result is needed later should be looked up from the external system by a key
|
|
411
|
+
the action chose (the job id), not inferred from FeltKit's records.
|
package/docs/UPSTREAM-GAPS.md
CHANGED
|
@@ -88,9 +88,9 @@ A1–A4 are closed by the released `@appport/core` 1.4.0 / `@appport/sdk` 1.4.0
|
|
|
88
88
|
| A2 | A key sent to a capability without `idempotency: "supported"` was silently dropped | Refused in development (`IDEMPOTENCY_KEY_UNSUPPORTED`), logged in production (`unsupportedIdempotencyKey`) | The agent sends its attempt key only to capabilities that declare support (it used to send one to every consequential application capability, which development now refuses). Mutations keep declaring `"supported"`: that is the feature, not a workaround | Closed |
|
|
89
89
|
| A3 | Idempotency types not re-exported by `@appport/sdk`; no lookup by request id | Types, helpers, errors and `SessionStore` exported from `@appport/sdk`; optional `findByRequestId` | The structural `IdempotencyRecord` and `SessionStore` / `CreateSessionInput` copies are deleted; the stores implement the published interfaces | Closed |
|
|
90
90
|
| A4 | Only memory stores ship | By design no database-backed stores; `runIdempotencyStoreConformance` / `runSessionStoreConformance` | FeltKit keeps its FeltDB stores and runs both suites against them on local and memory FeltDB storage, with `requireClaims` and `requireFindByRequestId` (`npm run test:conformance -w @feltdb/feltkit`) | Closed |
|
|
91
|
-
| A5 | A handler cannot report "outcome unknown" itself. Any error it throws releases the claim, so when an integration handler throws `OUTCOME_UNKNOWN` (the API gave no definite answer), or a mutation's FeltDB commit is unconfirmed (`COMMIT_OUTCOME_UNKNOWN`), a same-key replay reaches the handler again | — | Integrations: `runtime/integrations.ts` refuses that replay from its own call record (`_feltkit_integration_calls`) with AppPort's `IdempotencyOutcomeUnknownError`; the call record stays, it is also the evidence of the external request. Mutations: the FeltDB transaction id is derived from AppPort's replay key (`idempotencyStorageKey`), so FeltDB's transaction-id binding refuses the replay (`IDEMPOTENCY_CONFLICT` → FeltKit `OUTCOME_UNKNOWN`, `committed: true`) instead of writing again; tests "A5: …" in `test/appport-adoption.test.ts` | Open. Ask: a way for a handler to end a request with its claim kept, e.g. an error flag (`keepIdempotencyClaim`) or a documented error reason the runtime treats as unknown |
|
|
91
|
+
| A5 | A handler cannot report "outcome unknown" itself. Any error it throws releases the claim, so when an integration handler throws `OUTCOME_UNKNOWN` (the API gave no definite answer), or a mutation's FeltDB commit is unconfirmed (`COMMIT_OUTCOME_UNKNOWN`), a same-key replay reaches the handler again | — | Integrations: `runtime/integrations.ts` refuses that replay from its own call record (`_feltkit_integration_calls`) with AppPort's `IdempotencyOutcomeUnknownError`; the call record stays, it is also the evidence of the external request. Mutations: the FeltDB transaction id is derived from AppPort's replay key (`idempotencyStorageKey`), so FeltDB's transaction-id binding refuses the replay (`IDEMPOTENCY_CONFLICT` → FeltKit `OUTCOME_UNKNOWN`, `committed: true`) instead of writing again; tests "A5: …" in `test/appport-adoption.test.ts` | Open. Ask: a way for a handler to end a request with its claim kept, e.g. an error flag (`keepIdempotencyClaim`) or a documented error reason the runtime treats as unknown Resolved for FeltKit in 0.4.0 with `@appport/core` 1.13: FeltKit throws `outcomeUnknown()`, which AppPort records under the key (a replay gets the same answer); `test/appport-adoption.test.ts` (A5). |
|
|
92
92
|
| A6 | `handleRequest` validates a request's input before it asks the authorizer, so a caller without the capability's permission and with invalid input gets `INVALID_INPUT` (learning the input contract) instead of `FORBIDDEN`, and the refusal is not a denial | — | The capability's input schema, which FeltKit supplies (`runtime/capabilities.ts`), runs FeltKit's policy check first: `handleRequest` / `handleStreamRequest` are wrapped to carry the caller (AsyncLocalStorage), and the gate throws AppPort's `FORBIDDEN` / `UNAUTHORIZED` from `validate()`, which AppPort answers and reports as a denial. FeltKit's own call path authorizes again. Test: "authority before arguments on AppPort too" in `test/auth.test.ts` | Open. Ask: authorize before validating input when `authorization` does not depend on the input (or an authorizer flag to be consulted first) |
|
|
93
|
-
| A7 | `HttpBinding` (mapped mode) answers 500 for any code outside AppPort's standard set, including namespaced extension codes and codes a capability's integration contract declares (`failures[].code`), with no way for the application to give them a status | — | FeltKit wraps the binding and sets the status for the codes it returns itself (`FELTKIT_APPPORT_STATUS`: `feltkit.FAILED_PRECONDITION` 409, `UPSTREAM_REJECTED
|
|
93
|
+
| A7 | `HttpBinding` (mapped mode) answers 500 for any code outside AppPort's standard set, including namespaced extension codes and codes a capability's integration contract declares (`failures[].code`), with no way for the application to give them a status | — | FeltKit wraps the binding and sets the status for the codes it returns itself (`FELTKIT_APPPORT_STATUS`: `feltkit.FAILED_PRECONDITION` 409, `feltkit.UPSTREAM_REJECTED` 502, `feltkit.UNAVAILABLE`/`feltkit.NOT_CONFIGURED` 503; an unknown outcome is AppPort's own `CONFLICT`), from the same table as its own HTTP API; `packages/sdk/test/error-contract.test.ts` | Open (found 2026-11-03). Ask: an option mapping extension codes to statuses, or using a declared failure's class |
|
|
94
94
|
| A8 | Subscriptions are not authorized by the application's `Authorizer`. `server/src/connection.ts#subscribe` checks the event's declared permissions against `session.permissions` only: a connection identified by a principal (FeltKit's are; FeltKit grants from its policy, never from `session.permissions`) cannot subscribe to any permissioned event, and **a subscription to `*` requires nothing and receives every event, including events the session may not observe** (spec §21.7 says it must not be delivered). Events also have no scope, so a per-tenant event (presence in one workspace) reaches every subscriber | — | FeltKit does not use AppPort events yet (FK-GAP-004 is blocked on this). Reproduction: `packages/server/test/subscriptions.test.ts` on `rkendel1/appport` branch `claude/scoped-event-authorization` | Open (found 2026-11-05). Ask: authorize subscribe *and each delivery* through the application's `Authorizer` (event ref as the capability, `{ scope }` as input), and an optional `scope` on events and subscriptions |
|
|
95
95
|
| A9 | `AuthorizationDecision` can deny only with `UNAUTHORIZED` or `FORBIDDEN`. A policy that hides what exists (an unknown id and a forbidden one answered alike, as `NOT_FOUND`) cannot say so in a decision | — | `feltkit({ authorize })` lets the hook throw `fail("NOT_FOUND", …)`, recorded as a denial (`authority.resource`) | Open (found 2026-11-05). Ask: an optional `NOT_FOUND` denial code (or a `conceal: true` flag) on the decision |
|
|
96
96
|
| A10 | The HTTP event stream (`GET /appport/events`) names every subscription `sub_sse_<index>` (`@appport/server` 1.2.0 and 1.3.0, `http.ts#events`), and the application's event bus keys subscriptions by that id across connections. A second client's subscription replaces the first's, which silently stops receiving events | — | FeltKit gives each subscription its own bus id (`runtime.ts`, wrapping `application.subscribe`); the connection still echoes the client's id. `test/events.test.ts` (two clients, one scope) | **Closed upstream; workaround removed.** `@appport/server` registers each subscription under a connection-scoped id (`connection.js`: `${connection}:${subscriptionId}`). FeltKit's wrapper is deleted; `test/events.test.ts` (several clients, one scope) passes on 1.3.2 without it |
|
|
@@ -273,3 +273,17 @@ AppBoundry host**: an artifact's `ctx.db.find`/`count` are answered by AppBoundr
|
|
|
273
273
|
`createArtifactTestApp` host is fixed here; whether AppBoundry's host reads FeltDB with `find()` (and so
|
|
274
274
|
truncates at 100 on 0.18 or refuses past 1,000 on 0.20) is not verified. Ask AppBoundry to run the
|
|
275
275
|
1,001-record scenarios of `test/large-collections.test.ts` against its host.
|
|
276
|
+
|
|
277
|
+
## 0.4.0: what FeltKit built on the pinned releases, to move onto upstream work in progress
|
|
278
|
+
|
|
279
|
+
These were implemented on the currently pinned `@feltdb/core`, `@appport/*` and `@appport/services`, with their
|
|
280
|
+
contracts kept so the storage or transport can move without an application change.
|
|
281
|
+
|
|
282
|
+
| FeltKit (0.4.0) | Built on today | Moves to | What changes |
|
|
283
|
+
|---|---|---|---|
|
|
284
|
+
| Presence leases (`app.presence`) | An ordinary collection with lease fields; expiry ended by a timer on the runtime's clock; session ends from `_feltkit_session_ends` | FeltDB record TTL (D1) and ephemeral collections (D2) | Live leases become expiring ephemeral records; the end becomes FeltDB's TTL event (no timer, and no journal entry for a renew). Reasons, `onEnd` and history stay. |
|
|
285
|
+
| Quota counters | Sliding windows in the process | FeltDB expiring records (D1) | Counters span processes and survive restarts (the one P3 regression still `todo`). |
|
|
286
|
+
| Channels (`app.channel`) | AppPort events; the channel's receive rule evaluated in FeltKit's Authorizer, which AppPort 1.11 already calls at subscribe and per delivery | AppPort Authorizer-authorized subscriptions | The receive rule can be declared to AppPort itself; FeltKit keeps the send side. |
|
|
287
|
+
| Agent control live state | FeltKit's own SSE (`…/control/events`) | AppPort `appport.agent.changed@1` / MCP resource notifications | Clients could follow control state over AppPort or MCP. |
|
|
288
|
+
| Agent grants and component work | `_feltkit_resource_access`; `ctx.afterCommit.work` claimed by components | AppPort Services service-principal jobs | A media worker's durable work could run as a Services job under the component's service principal. |
|
|
289
|
+
| `app.agent` on AppBoundry (FK-GAP-013) | Not implemented: the host protocol cannot run guest code as another principal after a call | An AppBoundry host interface for that | The build keeps refusing `app.agent` (and presence, channels, guest and agent bindings) until then. |
|