@feltdb/feltkit 0.3.29 → 0.3.30

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 (155) hide show
  1. package/dist/app.d.ts +74 -2
  2. package/dist/app.js +95 -1
  3. package/dist/app.js.map +1 -1
  4. package/dist/appboundry/build.js.map +1 -1
  5. package/dist/appboundry/guest-tenancy.d.ts +2 -2
  6. package/dist/appboundry/guest-tenancy.js.map +1 -1
  7. package/dist/appboundry/guest.js +4 -1
  8. package/dist/appboundry/guest.js.map +1 -1
  9. package/dist/appboundry/host.js +3 -0
  10. package/dist/appboundry/host.js.map +1 -1
  11. package/dist/authorize.d.ts +23 -1
  12. package/dist/authorize.js +37 -0
  13. package/dist/authorize.js.map +1 -1
  14. package/dist/cli/deploy-appboundry.d.ts +1 -1
  15. package/dist/cli/deploy-appboundry.js.map +1 -1
  16. package/dist/cli/deploy.js.map +1 -1
  17. package/dist/cli/main.js +27 -1
  18. package/dist/cli/main.js.map +1 -1
  19. package/dist/cli/skills.js.map +1 -1
  20. package/dist/client/index.js.map +1 -1
  21. package/dist/dashboard/assets/index-9rMS3yBm.js +15 -0
  22. package/dist/dashboard/assets/index-DkiYTUMR.css +1 -0
  23. package/dist/dashboard/index.html +2 -2
  24. package/dist/docs.d.ts +1 -1
  25. package/dist/docs.js +3 -0
  26. package/dist/docs.js.map +1 -1
  27. package/dist/errors.js.map +1 -1
  28. package/dist/event-stage.js.map +1 -1
  29. package/dist/execution.d.ts +186 -0
  30. package/dist/execution.js +105 -0
  31. package/dist/execution.js.map +1 -0
  32. package/dist/index.d.ts +5 -0
  33. package/dist/index.js +4 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/measure/index.js.map +1 -1
  36. package/dist/platform/approvals.js.map +1 -1
  37. package/dist/platform/artifacts.js.map +1 -1
  38. package/dist/platform/changes.d.ts +54 -54
  39. package/dist/platform/changes.js.map +1 -1
  40. package/dist/platform/deployments.d.ts +32 -32
  41. package/dist/platform/exec.js.map +1 -1
  42. package/dist/platform/platform.js.map +1 -1
  43. package/dist/platform/releases.js.map +1 -1
  44. package/dist/platform/server.js.map +1 -1
  45. package/dist/platform/workspaces.js.map +1 -1
  46. package/dist/react/auth.d.ts +10 -10
  47. package/dist/react/auth.js +1 -1
  48. package/dist/react/auth.js.map +1 -1
  49. package/dist/react/context.d.ts +1 -1
  50. package/dist/react/index.js.map +1 -1
  51. package/dist/runtime/accounts.js.map +1 -1
  52. package/dist/runtime/activity.d.ts +1 -1
  53. package/dist/runtime/activity.js.map +1 -1
  54. package/dist/runtime/agent.d.ts +3 -3
  55. package/dist/runtime/agent.js +9 -3
  56. package/dist/runtime/agent.js.map +1 -1
  57. package/dist/runtime/application-authority.d.ts +13 -2
  58. package/dist/runtime/application-authority.js +18 -6
  59. package/dist/runtime/application-authority.js.map +1 -1
  60. package/dist/runtime/audit.js.map +1 -1
  61. package/dist/runtime/authboundry.d.ts +17 -0
  62. package/dist/runtime/authboundry.js +8 -1
  63. package/dist/runtime/authboundry.js.map +1 -1
  64. package/dist/runtime/authority.d.ts +10 -0
  65. package/dist/runtime/authority.js +17 -0
  66. package/dist/runtime/authority.js.map +1 -1
  67. package/dist/runtime/backup-environment.js.map +1 -1
  68. package/dist/runtime/backup.js.map +1 -1
  69. package/dist/runtime/changes.js.map +1 -1
  70. package/dist/runtime/claims.js.map +1 -1
  71. package/dist/runtime/collections.js.map +1 -1
  72. package/dist/runtime/content.d.ts +27 -2
  73. package/dist/runtime/content.js +55 -5
  74. package/dist/runtime/content.js.map +1 -1
  75. package/dist/runtime/context.d.ts +153 -0
  76. package/dist/runtime/contract.js +5 -1
  77. package/dist/runtime/contract.js.map +1 -1
  78. package/dist/runtime/credentials.d.ts +31 -2
  79. package/dist/runtime/credentials.js +55 -3
  80. package/dist/runtime/credentials.js.map +1 -1
  81. package/dist/runtime/crypto-token.js.map +1 -1
  82. package/dist/runtime/data.js.map +1 -1
  83. package/dist/runtime/decisions.js.map +1 -1
  84. package/dist/runtime/deployment.js.map +1 -1
  85. package/dist/runtime/execution-host.d.ts +54 -0
  86. package/dist/runtime/execution-host.js +54 -0
  87. package/dist/runtime/execution-host.js.map +1 -0
  88. package/dist/runtime/generation.js.map +1 -1
  89. package/dist/runtime/instance.js.map +1 -1
  90. package/dist/runtime/integrations.d.ts +8 -6
  91. package/dist/runtime/integrations.js +48 -5
  92. package/dist/runtime/integrations.js.map +1 -1
  93. package/dist/runtime/invocations.d.ts +313 -0
  94. package/dist/runtime/invocations.js +493 -0
  95. package/dist/runtime/invocations.js.map +1 -0
  96. package/dist/runtime/loader.js.map +1 -1
  97. package/dist/runtime/local-authority.d.ts +50 -0
  98. package/dist/runtime/local-authority.js +214 -0
  99. package/dist/runtime/local-authority.js.map +1 -0
  100. package/dist/runtime/oauth-credentials.d.ts +40 -3
  101. package/dist/runtime/oauth-credentials.js +133 -25
  102. package/dist/runtime/oauth-credentials.js.map +1 -1
  103. package/dist/runtime/outbox.js +3 -0
  104. package/dist/runtime/outbox.js.map +1 -1
  105. package/dist/runtime/projects.d.ts +1 -1
  106. package/dist/runtime/readiness.js +11 -0
  107. package/dist/runtime/readiness.js.map +1 -1
  108. package/dist/runtime/runtime.d.ts +48 -5
  109. package/dist/runtime/runtime.js +139 -17
  110. package/dist/runtime/runtime.js.map +1 -1
  111. package/dist/runtime/services.d.ts +37 -0
  112. package/dist/runtime/services.js +191 -3
  113. package/dist/runtime/services.js.map +1 -1
  114. package/dist/runtime/sessions.js.map +1 -1
  115. package/dist/runtime/state-contract.js.map +1 -1
  116. package/dist/runtime/storage-check.js.map +1 -1
  117. package/dist/runtime/targets.d.ts +1 -1
  118. package/dist/runtime/tenancy.js.map +1 -1
  119. package/dist/runtime/transactions.d.ts +15 -0
  120. package/dist/runtime/transactions.js +5 -0
  121. package/dist/runtime/transactions.js.map +1 -1
  122. package/dist/schema.js.map +1 -1
  123. package/dist/server/admin.d.ts +51 -51
  124. package/dist/server/admin.js +11 -0
  125. package/dist/server/admin.js.map +1 -1
  126. package/dist/server/components.js.map +1 -1
  127. package/dist/server/index.js +39 -0
  128. package/dist/server/index.js.map +1 -1
  129. package/dist/server/management.js.map +1 -1
  130. package/dist/server/mcp.d.ts +59 -37
  131. package/dist/server/mcp.js +24 -1
  132. package/dist/server/mcp.js.map +1 -1
  133. package/dist/server/operators.js.map +1 -1
  134. package/dist/server/ports.d.ts +7 -0
  135. package/dist/server/ports.js +17 -0
  136. package/dist/server/ports.js.map +1 -1
  137. package/dist/server/production.js.map +1 -1
  138. package/dist/server/project.js.map +1 -1
  139. package/dist/server/session-http.js.map +1 -1
  140. package/dist/server/tenancy.js.map +1 -1
  141. package/dist/surfaces.d.ts +153 -0
  142. package/dist/surfaces.js +228 -0
  143. package/dist/surfaces.js.map +1 -0
  144. package/dist/testing/index.js.map +1 -1
  145. package/docs/CONNECTIONS.md +151 -0
  146. package/docs/EXECUTION.md +271 -0
  147. package/docs/GUARANTEES.md +54 -2
  148. package/docs/INVOCATIONS.md +170 -0
  149. package/docs/README.md +5 -2
  150. package/package.json +19 -15
  151. package/skills/.claude-plugin/marketplace.json +1 -1
  152. package/skills/.claude-plugin/plugin.json +1 -1
  153. package/skills/feltkit-services/SKILL.md +1 -1
  154. package/dist/dashboard/assets/index-BehzsQOa.css +0 -1
  155. package/dist/dashboard/assets/index-UuZ63NA6.js +0 -15
@@ -0,0 +1,271 @@
1
+ # Placement-neutral execution
2
+
3
+ An invocation has the same identity, lifecycle, authority and evidence wherever its work runs.
4
+ **FeltKit's control plane is authoritative; the computer is replaceable.**
5
+
6
+ ## Control plane and execution plane
7
+
8
+ | | Owns | Where |
9
+ |---|---|---|
10
+ | **Control plane** (FeltKit) | the invocation, its executions and attempts, the authority work runs under, placement, leases and fencing, dispatch and recovery, evidence | `runtime/invocations.ts`, the after-commit outbox, the services worker |
11
+ | **Execution plane** (an environment) | running the work, and reporting what happened through the control plane's fenced operations | an `ExecutionAdapter` (`runtime/execution-host.ts`) |
12
+
13
+ An environment gains **no authority** by being registered, trusted or Boundry-operated. It can
14
+ disappear: the lifecycle and its evidence are in FeltKit's platform state
15
+ (`_feltkit_invocations`, `_feltkit_outbox`), never in a worker's memory, files or queue.
16
+
17
+ ## Identities
18
+
19
+ | | Id | Stable across |
20
+ |---|---|---|
21
+ | Invocation | `inv_…` | everything: retries, recovery, re-dispatch |
22
+ | Execution | `exe_…` (the invocation's n-th; one today) | attempts and re-dispatches |
23
+ | Attempt | `att_…_<n>` | nothing: each claim is a new attempt |
24
+
25
+ ## The execution contract: `feltkit.execution/1`
26
+
27
+ This is what an environment receives (`ExecutionRequest`, `src/execution.ts`), kept as small as the
28
+ platform needs:
29
+
30
+ | Field | Meaning |
31
+ |---|---|
32
+ | `invocation`, `execution` | the identities above |
33
+ | `work` | `{ operation, version }`: the job type the application declares; version `"1"` until operations are versioned |
34
+ | `input` | references only: the invocation, and the application's small payload. Never a host path. |
35
+ | `authority` | `{ requestedBy, runAs, onBehalfOf, checked, delegation }`: computed by the control plane before placement, see below |
36
+ | `requirements` | `{ needs, deadlineMs, memoryMb?, concurrency? }`: what the work needs |
37
+ | `placement` | `{ allow?, deny?, prefer? }`: where it may and may not run. Constraints and a preference, never permission. |
38
+
39
+ **The result and evidence** are recorded per attempt (`AttemptRecord`):
40
+
41
+ - the environment and worker that claimed it (`{ id, via, run }`);
42
+ - its outcome:
43
+ - `running`, `succeeded`, `failed`, `awaiting_approval`, `cancelled`;
44
+ - `unknown`, for an attempt that lost its claim without reporting, or reported an ambiguous external
45
+ outcome;
46
+ - its error, and a result reference (at most 4 KB);
47
+ - bounded evidence events: `claimed`, `progress`, `succeeded`, `failed`, `awaiting_approval`,
48
+ `cancelled`, `abandoned`.
49
+
50
+ ## The adapter boundary
51
+
52
+ ```ts
53
+ interface ExecutionAdapter {
54
+ readonly environment: EnvironmentDescriptor; // id, kind, version, provides, limits, cancellation, available
55
+ dispatch(request: ExecutionRequest, staging: { effects: AfterCommit }): { outboxId: string; job: string };
56
+ }
57
+ ```
58
+
59
+ **Dispatch** stages exactly one after-commit effect in the caller's transaction.
60
+
61
+ - There is **one outbox**. Every environment is reached through it, so dispatch is durable,
62
+ performed once and recovered for every environment alike.
63
+ - Recovery's dispatch logic (pending, done or failed; re-dispatch) works on that outbox record and
64
+ is not adapter-specific.
65
+
66
+ **Reporting** goes through the control plane's fenced operations, whatever the environment:
67
+
68
+ - `ctx.invocations.start(id, { environment?, worker? })` opens an attempt. A claimant from an
69
+ environment other than the one the execution was placed in is refused (`WRONG_ENVIRONMENT`).
70
+ - `progress(id, { claim, note?, data? })` records evidence and renews the lease (a heartbeat).
71
+ - `transition(id, completed | failed | awaiting_approval, { claim, … })` closes the attempt.
72
+ - `cancel(id)` is the person's own. It is cooperative today: the work sees it at its next report.
73
+
74
+ **The adapter in use: `managed`.** It is exactly the path FeltKit already had, behind the interface:
75
+
76
+ 1. The outbox enqueues an AppPort Services job.
77
+ 2. The services worker runs the declared handler, as the principal the work runs as.
78
+ 3. The handler reports through `ctx.invocations`.
79
+
80
+ Its descriptor: `kind: "managed"`, it provides `feltkit.function` and `appport.services`, its deadline
81
+ limit is 15 minutes, and it states no memory or concurrency limit (it can't promise one).
82
+
83
+ ## Placement
84
+
85
+ ```ts
86
+ runtime.execution.register(adapter); // an environment becomes placeable (grants nothing)
87
+ runtime.execution.policy = { id, version, order: ["managed", …] }; // the operator's: allowed, in preference order
88
+ runtime.execution.resolver = resolvePlacement; // replaceable; deterministic; returns no authority
89
+ ```
90
+
91
+ The default resolver (`resolvePlacement`) evaluates every registered environment against:
92
+
93
+ - **the policy:** not in `order` means not allowed;
94
+ - **the work's constraints:** `allow`, `deny` (by id or kind);
95
+ - **its requirements:** `needs`, the deadline, and memory and concurrency (an environment that can't
96
+ promise a limit can't take work that needs one);
97
+ - **availability.**
98
+
99
+ Then it decides:
100
+
101
+ - The eligible environments are ordered by the policy.
102
+ - An eligible `prefer` is selected. An ineligible one is explained, not obeyed.
103
+ - Otherwise the first eligible environment is selected.
104
+ - If nothing is eligible, the result is `UNPLACEABLE`, with every reason.
105
+
106
+ The same inputs, in any order, give the same decision.
107
+
108
+ In application code, constraints are optional on `accept`, and most applications pass none:
109
+
110
+ ```ts
111
+ await ctx.invocations.accept({ surface: "share", envelope, dispatch: { job: "work.run", requirements: { deadlineMs: 120_000 }, placement: { deny: ["device"] } } });
112
+ ```
113
+
114
+ **Unplaceable work is refused at accept** (`FAILED_PRECONDITION`, `details.reason: "UNPLACEABLE"`,
115
+ `details.decision`). Nothing is recorded or dispatched.
116
+
117
+ ## Authority is independent of placement
118
+
119
+ 1. **At accept, before placement.** The work runs as the accepting principal, which must hold its
120
+ function's `access`. If it doesn't, the work is `FORBIDDEN`, and nothing is placed or dispatched.
121
+ The record keeps three things apart, so none is mistaken for another:
122
+ - `requestedBy`: who asked;
123
+ - `runAs`: who the work executes as;
124
+ - `checked`: `[{ permission, source: "roles" }]`, what was verified. That is the requester's
125
+ permission to *start* the work under the application's roles. It is **not** an agent's
126
+ delegated authority over the person's resources: `delegation: "decided-at-execution"`.
127
+ 2. **The resolver takes no authority and returns none.** A preference, a "trusted" environment, or an
128
+ environment that "provides" anything never adds to it.
129
+ 3. **At execution, as before.** The handler runs as that principal (`runtime.call` authorizes the
130
+ function again). Delegated decisions on a person's behalf are AuthBoundry's, asked by the work when
131
+ it runs (`ctx.authority.decide`).
132
+
133
+ ## Durable placement evidence
134
+
135
+ Each execution is stored on the invocation's record (`executions[]`):
136
+
137
+ - the request;
138
+ - **the placement decision** (`feltkit.placement/1`): the policy as applied (id, version **and
139
+ order**), every environment **as described at the time** (`environments`), the requirements and
140
+ constraints, every evaluation with its reasons, the eligible ones, the selected one, why, and when.
141
+ A later change to the live, process-local policy or to an environment's description can't make an
142
+ old decision unexplainable;
143
+ - its own dispatch evidence (`dispatch { job, outboxIds }`, re-dispatches included), so a later
144
+ execution can't rewrite it;
145
+ - the adapter and version;
146
+ - the dispatch time;
147
+ - its attempts.
148
+
149
+ The dispatch it caused is its own outbox record. All of it is written with the record's
150
+ compare-and-set, survives restarts, and is reviewable without any worker. No credential, secret or
151
+ claim token is in it: the claim token is never returned, and Studio redacts it.
152
+
153
+ ## Who executed, under what authority (M1)
154
+
155
+ Each attempt records the decisions made while it ran, and what they established. These fields are
156
+ from FeltKit `runtime/invocations.ts`, filled by `ctx.authority.decide`:
157
+
158
+ - **`decisions[]`.** Each AuthBoundry decision made while the attempt ran, as it was answered:
159
+ capability, on whose behalf, outcome, `decisionId`, `delegationId`, and the executor's proof.
160
+ - They are recorded when made, before the decision is returned, attributed by the request that
161
+ claimed the attempt.
162
+ - They are never reconstructed later from current permissions or delegations. A revocation changes
163
+ the next decision, not the recorded ones.
164
+ - **`executor`.**
165
+ - `proven` (`method: "agent_credential"`) only when **every** decision of the attempt was answered
166
+ with AuthBoundry's proof (A2), naming this executor.
167
+ - Otherwise `asserted`.
168
+ - The `agentCredentialId` is an identifier; the proof is that AuthBoundry authenticated the
169
+ credential for those decisions.
170
+ - **`attribution: { environment: "asserted", worker: "asserted" }`.** An authenticated agent identity
171
+ doesn't prove which computer ran the work. The environment and worker stay asserted until remote
172
+ workers authenticate (M4).
173
+
174
+ **How FeltKit reads the proof** (`executorProofOf`, `runtime/authboundry.ts`). It is proven only if
175
+ FeltKit sent an agent credential **and** the answer says `proven: true` by `agent_credential` for
176
+ exactly this executor, with a credential id. Anything else is `asserted`, including an AuthBoundry
177
+ without A2.
178
+
179
+ **Where the credential comes from.**
180
+
181
+ - `authority.executor.credential` (a custody reference); or
182
+ - with `authority.local`, the executor's own credential. `@authboundry/local` issues it, and FeltKit
183
+ keeps it in custody (`credential-ref:authboundry-local-agent`), stores each renewal, and sends it on
184
+ every decision. The private authority sets `agent_required`, so the executor can no longer be merely
185
+ asserted there.
186
+
187
+ **No secret in records.** Records hold ids only; the secret never leaves custody.
188
+
189
+ **The six distinctions, from one record:**
190
+
191
+ | Distinction | Field |
192
+ |---|---|
193
+ | Who requested | `executions[].request.authority.requestedBy` |
194
+ | For whom | `…authority.onBehalfOf`, and each decision's `onBehalfOf` |
195
+ | Which agent executed | `attempts[].executor` (proven or asserted) |
196
+ | Which authority permitted it | `attempts[].decisions[]` (`decisionId`, `delegationId`) |
197
+ | Which environment ran it | `attempts[].environment` (asserted) |
198
+ | What happened | `attempts[].outcome`, its result or error, and the invocation's outcome |
199
+
200
+ ## Safety
201
+
202
+ - **Workers are disposable.** A worker that disappears leaves a `running` attempt. After its lease
203
+ expires, recovery reports it as `stalled`, and the next `start` reclaims it under the same invocation
204
+ and execution, as a new attempt.
205
+ - **Fencing.** Only the attempt holding the current claim can report or move the invocation. A stale
206
+ worker gets `CLAIM_LOST`.
207
+ - **External effects are not exactly-once.**
208
+ - The outbox recovers dispatch, and the managed adapter's job runs replay a committed attempt, but
209
+ an external side effect can still be ambiguous.
210
+ - An abandoned attempt reads `unknown`, and the next attempt receives `previous` so it can reconcile
211
+ before repeating an effect. FeltKit's integration calls already record unknown outcomes and verify
212
+ them rather than resend.
213
+ - A worker reports an ambiguous outcome as `failed` with `OUTCOME_UNKNOWN`: the attempt reads
214
+ `unknown` and the invocation never reads `completed`.
215
+
216
+ ## Status
217
+
218
+ **Implemented and tested** (`packages/sdk/test/execution.test.ts`, 9 tests; plus `invocations.test.ts`
219
+ and `surfaces.test.ts`):
220
+
221
+ - the contract;
222
+ - the adapter boundary, with the managed adapter;
223
+ - deterministic placement, with structured rejection;
224
+ - authority checked before and independently of placement;
225
+ - durable decisions across a restart;
226
+ - attempts with environment and worker;
227
+ - fencing;
228
+ - recovery by a replacement worker under the same identity;
229
+ - `unknown` for abandoned attempts and ambiguous outcomes;
230
+ - no infrastructure details in the contract;
231
+ - an unrelated application with no placement code.
232
+
233
+ **Implemented, but not under production conditions:**
234
+
235
+ - A second environment exists only as a **controlled fixture** (`fixture-remote`): an in-process job
236
+ standing in for a worker elsewhere. It proves the contract and the control plane's behavior, not
237
+ remote execution.
238
+ - The managed adapter has run only in tests and development.
239
+
240
+ **Designed, not implemented:**
241
+
242
+ - a remote worker protocol (how a worker outside the process authenticates and calls the control
243
+ plane);
244
+ - re-placement: a new execution when the selected environment becomes unavailable (today re-dispatch
245
+ keeps the original placement);
246
+ - preemptive cancellation;
247
+ - versioned operations (`work.version` is `"1"`);
248
+ - environment health beyond the `available` flag.
249
+
250
+ **Blocked:**
251
+
252
+ - AppBoundry artifacts don't host the invocation store, so an artifact can't be the control plane.
253
+ - **Corrected 2026-11-14:** an earlier version said AuthBoundry had no agent-credential proof. It has
254
+ one. `authorize/check` accepts `x-authboundry-agent-credential` (AB
255
+ crates/server/src/agent_credentials.rs), and FeltKit sends it when `authority.executor.credential` is
256
+ set. What remains is narrower:
257
+ - a worker can't call alone (the application's check credential must come with it);
258
+ - `on_behalf_of` with an agent credential is untested;
259
+ - the response doesn't say whether the executor was proven.
260
+
261
+ See docs/AGENT-CAPABILITY-INFRASTRUCTURE.md §5.
262
+
263
+ ## Limits
264
+
265
+ - One execution per invocation.
266
+ - A re-dispatch reuses the original placement even if policy changed.
267
+ - Policy and environments are per process (`runtime.execution`), not stored. Each decision snapshots
268
+ the policy order and the environment descriptors it used, so it explains itself; the live policy
269
+ has no history of its own.
270
+ - An attempt's environment and worker are asserted by its (authenticated) principal. Proving the
271
+ executor per attempt needs an agent credential (docs/AGENT-CAPABILITY-INFRASTRUCTURE.md §5, A1-A2).
@@ -286,6 +286,28 @@ the interface); on AppBoundry's side, the appboundry-host crypto tests in `rkend
286
286
  | Fail closed | A hook that throws (other than a FeltKit `FORBIDDEN`/`UNAUTHORIZED`), returns something other than a boolean or an AppPort decision, or tries to write refuses the call (`INTERNAL`) | same |
287
287
  | Evidence | Denials and allows are recorded in the activity entry's `authority.resource`, beside the role decision and its id | same |
288
288
 
289
+ ### Ownership declared on the function (`owner`)
290
+
291
+ A per-record rule in the hook is keyed by the function's name, so a renamed or moved function
292
+ silently falls out of it (FRAME-GAP-04: Frame's `comments:remove` rule never applied to
293
+ `social:uncomment`, and any member could delete any comment). Declare ownership on the function:
294
+ `owner: { collection, id, field, via? }` (`via: { collection, field }` when `field` is
295
+ `s.ref(via.collection)` and that record's `field` is the principal). The rule is part of the
296
+ function's definition, so it moves with it.
297
+
298
+ | Guarantee | How | Test |
299
+ |---|---|---|
300
+ | Checked when declared | An object that is not this app's collection, an unknown field, an `id` that is not a declared argument, a `via` field that is not `s.ref(via.collection)`, an action, a `public` function, or an unknown member: a `TypeError` when the function is declared. Unknown function options are refused too (a misspelled `ownr` or `aproval` never leaves a function unprotected) | `test/ownership.test.ts` |
301
+ | Every interface, one decision | The same boundary as the hook (`/api`, AppPort, MCP, agent actions, jobs, the AppBoundry guest), after roles and argument validation, before the hook and the handler | same (HTTP AppPort; artifact parity) |
302
+ | Fail closed | No caller `UNAUTHORIZED`; no record `NOT_FOUND`; no owner recorded, a `via` record naming none, or another owner `FORBIDDEN` | same |
303
+ | Decision and effect agree | Read with the call's own reader: tenant-scoped, fenced at commit, tracked live | as the hook |
304
+ | Approval grants no ownership | An approved proposal runs as its proposer, who must own the record | same |
305
+ | Evidence | `authority.resource` on the activity entry, allowed or denied, with the reason | same |
306
+
307
+ The hook still runs after ownership and now receives `definition`, the function itself:
308
+ compare `definition === posts.remove`, not `function === "posts:remove"`, so a rename breaks the
309
+ import instead of the rule.
310
+
289
311
  Not covered: the hook does not run for AppPort Services effects made directly by services
290
312
  (those are authorized by the role policy and the services' own ownership rules), and FeltKit
291
313
  does not evaluate resources with AuthBoundry (UPSTREAM-GAPS).
@@ -327,14 +349,44 @@ no completion is reported as outcome unknown, never as success or failure. Enabl
327
349
  - FeltKit is single-tenant per application: the Services tenant is the application
328
350
  name. Configuration environments map `development`/`test` → `development`,
329
351
  `production` → `production`.
330
- - Files are application-shared: any principal with `files.read` reads every file through
331
- `ctx.services.files`. Per-resource access is the application's: a function checks the resource
352
+ - Files belong to the workspace they were uploaded in (`metadata["feltkit.tenant"]`, set by
353
+ FeltKit): a caller with `files.read` reads the files of its own workspace, or, working in none,
354
+ those uploaded in none; any other is NOT_FOUND. Per-resource access is the application's: a function checks the resource
332
355
  and issues a **file link** (`files.link`, `files.uploadLink`), and the link is the authority for
333
356
  that one transfer. Download links last 5 minutes by default (at most 1 hour) and may be reused
334
357
  until then. Upload links are single use, create the file as the issuing principal (the role
335
358
  snapshot taken at issue), with the metadata the function fixed, and within its `maxBytes`. Only
336
359
  the SHA-256 of a link token is stored (`_feltkit_file_links` on the `feltkit.files` handle).
337
360
  Links are not revoked when membership changes; they expire.
361
+ - **Removing a file does not strand its bytes, and does not release bytes another live file uses,**
362
+ except in one documented window (below: a reference made the instant after the removal, and a
363
+ stop before the bytes are put back), which is recorded, not hidden. A file is
364
+ Services' metadata record and FeltKit's bytes, in separate commits. `files.remove`:
365
+ 1. records the release of the bytes in the outbox (`_feltkit_outbox`, effect `files.release`)
366
+ before anything is deleted;
367
+ 2. soft-deletes the metadata as the caller (Services authorizes `files.delete` and audits it);
368
+ refused or failed, the release is settled `failed` and the bytes are kept;
369
+ 3. releases the bytes once the record is gone and no other live record names the same storage
370
+ key (one that does keeps them: `{ released: false, retained: true, referencedBy }`). "No other
371
+ live record" is AppPort Services' answer (`FileService.references`: a bounded lookup on the
372
+ `files_by_storage_key` index, at any number of files); an incomplete or failed answer releases
373
+ nothing. After removing the bytes it asks again, and puts them back if a record was made to name
374
+ them meanwhile (Services' management API takes any `storageKey`): `{ …, raced: true }`.
375
+
376
+ A stop between the steps leaves a pending release that the outbox's recovery performs after a
377
+ restart. A failed release does not undo the removal. A transient failure is retried by the
378
+ outbox's recovery with backoff (at most 5 attempts); a refusal, an unestablished answer or a live
379
+ file is `failed`, with its error, for `feltkit outbox retry`.
380
+
381
+ Not atomic, and said so: the lookup and the byte removal are separate commits in separate
382
+ products. The one remaining window is a record made to name the bytes between their removal and
383
+ the second lookup *and* a stop before they are put back; the next attempt then records it
384
+ (`{ retained: true, referencedBy, bytesMissing: true }`) instead of hiding it. A Services without
385
+ `FileService.references` releases nothing (`FAILED_PRECONDITION`, bytes kept). Releases are idempotent (bytes already gone are `{ released: false }`) and
386
+ read as FeltKit's `file-release` principal (`files.read` only), never with the caller's authority.
387
+ Bytes no live record references (from before this, from Services' management API, which deletes
388
+ metadata only, or from an interrupted upload) are listed and reclaimed, as recorded releases, by
389
+ `feltkit outbox reclaim-files [--release]`; bytes stored in the last hour are excluded.
338
390
 
339
391
  ## Accounts, sessions and workspaces
340
392
 
@@ -0,0 +1,170 @@
1
+ # Surfaces and invocations
2
+
3
+ Being summoned from where people already work (a website, a browser extension, a phone's share sheet,
4
+ a chat app) is application infrastructure. FeltKit owns it, so an application doesn't build its own:
5
+
6
+ | | What | API |
7
+ |---|---|---|
8
+ | Surface registry | an entry point the application accepts work from, and how work arrives and returns | `app.surface(id, …)` |
9
+ | Invocation contract | what was asked, from where, with what context (data, never instructions), continuing what, returning where | `feltkit.invocation/1`, `normalizeInvocation` |
10
+ | Invocation lifecycle | `received → validating → accepted → running → awaiting_approval → completed \| failed \| cancelled` | `ctx.invocations` |
11
+ | Dispatch and recovery | the work starts once, and a crash never strands it | FeltKit's after-commit outbox and the services worker |
12
+
13
+ What this does **not** own:
14
+
15
+ - **Who the person is.** That's their session, or behind a bridge, the application's own resolution.
16
+ - **What they may do.** That's their roles and, for delegated work, AuthBoundry.
17
+ - **Their external accounts.** Connections are a separate contract.
18
+ - **The application's domain.** Conversations, tasks and results stay in the application's
19
+ collections. An invocation's `outcome.result` is a small reference (at most 4 KB of JSON).
20
+
21
+ ## Registering surfaces
22
+
23
+ ```ts
24
+ export const share = app.surface("share", { version: "1.0.0", delivery: "session", modes: ["summon", "status"],
25
+ context: ["url", "selection", "text", "document"], returns: ["receipt", "app"] });
26
+ export const chat = app.surface("chat", { version: "2.0.0", delivery: "bridge", bridge: { role: "bridge" },
27
+ modes: ["summon", "continue", "status"], context: ["text"], returns: ["event"] });
28
+ ```
29
+
30
+ - **`delivery`.**
31
+ - `session`: the person's own session submits the work.
32
+ - `bridge`: a service holding `bridge.role` submits it, for a person the application resolved.
33
+ - **A registration grants nothing.** Permissions, roles or capabilities on a surface are refused. A
34
+ bridge names a role the application already defines.
35
+ - **The registry's view** (`runtime.invocations.surfaces()`) gives each surface's declaration, when a
36
+ delivery last arrived and which adapter versions were seen. That is the surface's availability. It
37
+ is not the health of any invocation, which is the invocation's own state.
38
+ - **`GET /api/surfaces`** lists the declarations to signed-in clients.
39
+
40
+ ## The contract: `feltkit.invocation/1`
41
+
42
+ ```json
43
+ { "contract": "feltkit.invocation/1", "invocationId": "chosen-once-per-request", "surface": { "id": "share", "version": "1.0.2", "device": "iPhone" },
44
+ "instruction": "Could this company be a customer?", "context": [{ "kind": "url", "url": "https://example.com/", "title": "Example" }],
45
+ "requested": { "capabilities": ["research.run"] }, "correlation": { "conversationId": "c1" }, "returnTo": { "kind": "app" },
46
+ "submittedAt": 1700000000000, "timeZone": "America/New_York" }
47
+ ```
48
+
49
+ `normalizeInvocation(envelope, surface)` checks the envelope against the surface it was delivered
50
+ through.
51
+
52
+ **Refused before anything is stored:**
53
+
54
+ - any field naming who is asking or what they may do (`principal`, `owner`, `user`, `onBehalfOf`,
55
+ `authority`, …);
56
+ - an envelope claiming to come from another surface;
57
+ - context kinds the surface doesn't declare;
58
+ - oversized content (instruction 2,000 characters; text 20,000; documents 256 KB, text types only;
59
+ at most 5 items);
60
+ - URLs that aren't http(s) or that carry credentials;
61
+ - a return page that wasn't shared.
62
+
63
+ **Recorded:**
64
+
65
+ - each context item, with provenance stamped on receipt: surface, adapter version, time, source;
66
+ - `requested.capabilities`, as an advisory hint only;
67
+ - a digest, so a retry is a replay and a reused id with other content is refused.
68
+
69
+ ## The lifecycle: `ctx.invocations`
70
+
71
+ ```ts
72
+ // In a mutation: the record and its dispatch commit with this transaction.
73
+ const receipt = await ctx.invocations.accept({ surface: "share", envelope, dispatch: { job: "work.run" } });
74
+
75
+ // The dispatched job (a mutation registered in services.jobs.handlers, run as the caller):
76
+ export const run = app.mutation({ access: "work.run", args: { invocation: s.string() }, handler: async (ctx, { invocation }) => {
77
+ const c = await ctx.invocations.start(invocation); // claim execution
78
+ if (!c.proceed) return; // cancelled, finished, awaiting approval, or claimed elsewhere
79
+ const id = await ctx.db.insert(results, { /* the application's own data */ });
80
+ await ctx.invocations.transition(invocation, "completed", { claim: c.claim!, result: { resultId: id } });
81
+ } });
82
+
83
+ await ctx.invocations.list({ state: "running" }); // the caller's own (or, for a bridge, what it delivered)
84
+ await ctx.invocations.get(id);
85
+ await ctx.invocations.cancel(id); // the person it is for, only
86
+ await ctx.invocations.resume(id); // after approval: awaiting_approval → running
87
+ ```
88
+
89
+ Over HTTP, with a session:
90
+
91
+ - `GET /api/invocations` (`?state=&surface=&limit=`);
92
+ - `GET /api/invocations/<id>`;
93
+ - `POST /api/invocations/<id>/cancel`.
94
+
95
+ **Visibility.** An invocation is visible to the person it is for and to the principal that delivered
96
+ it. Nobody else sees it: not another person, not an administrator, not another application (each
97
+ application has its own FeltDB instance). The claim token is never shown, and Studio's data explorer
98
+ redacts it.
99
+
100
+ ## Where the work runs
101
+
102
+ Placement, the execution contract (`feltkit.execution/1`), environments and attempt evidence are in
103
+ [EXECUTION.md](EXECUTION.md). `accept` checks the work's authority first, then places it, then
104
+ dispatches it through the selected environment's adapter: all before the commit, all in the record.
105
+
106
+ ## Recoverable by construction
107
+
108
+ **The invariant:** an accepted invocation always has durable evidence of pending dispatch, active
109
+ execution, or a terminal outcome.
110
+
111
+ 1. **Accept.** The invocation record and its dispatch job (an after-commit outbox effect) are staged
112
+ in the caller's mutation transaction, so both commit or neither does.
113
+ - The record id is derived from (person, surface, `invocationId`) and committed with
114
+ `requireAbsent`.
115
+ - A concurrent duplicate is refused with `CONFLICT`, having written nothing. The surface resends,
116
+ and the resend answers the replay (`replayed: true`). Nothing is dispatched twice.
117
+ 2. **Dispatch.** The outbox performs the job once per committed effect: right after the commit or,
118
+ after a crash, from the services worker's outbox recovery.
119
+ 3. **Start.** The job claims execution with a token and a lease (default 5 minutes).
120
+ - While the lease holds, another start is refused (`proceed: false`).
121
+ - After it expires (the holder died), the next start reclaims it as a new attempt.
122
+ 4. **Transitions** are compare-and-set on the record's version. Moving on from `running` needs the
123
+ current claim, so a worker that lost its claim changes nothing (`CLAIM_LOST`).
124
+ 5. **Cancel** is compare-and-set too. With a completion racing it, exactly one commits and the other
125
+ is refused (`FAILED_PRECONDITION`). Terminal states are final; cancelling a cancelled invocation is
126
+ a no-op.
127
+ 6. **Recovery** is part of the services worker (`runServices`). For accepted invocations older than
128
+ the outbox's recovery threshold:
129
+ - **pending dispatch:** left to the outbox's recovery;
130
+ - **dispatch done:** recorded (`dispatch.state: "dispatched"`, the job id);
131
+ - **dispatch failed:** dispatched again, at most 3 times, in one transaction with the record, then
132
+ the invocation fails with `DISPATCH_FAILED`;
133
+ - **expired leases:** reported (`stalled`).
134
+
135
+ A sweep that finds anything is recorded as `invocation.recovery` activity.
136
+
137
+ ## Evidence
138
+
139
+ `packages/sdk/test/invocations.test.ts` has 9 tests, using two independent fixture applications
140
+ (`summon`, `ledger`) that import FeltKit only:
141
+
142
+ 1. Accept, dispatch, run and complete, with no application lifecycle collection.
143
+ 2. Another application uses the same capability, and each application's records are its own.
144
+ 3. Isolation by person and deliverer, for list, get and cancel, and how work may arrive on each kind
145
+ of surface.
146
+ 4. Resubmission, sequential and concurrent: one record, one dispatch; reuse with other content is
147
+ refused.
148
+ 5. A crash between acceptance and dispatch.
149
+ - **Setup:** the durable state a stopped process leaves (record and pending outbox effect,
150
+ committed together, never performed), recreated with the same builder `accept` uses.
151
+ - **Result:** recovered after a restart, the dispatch performed once by two concurrent sweepers,
152
+ and the work run once.
153
+ 6. Repeated dispatch never duplicates work: one live claim, a stale worker can't complete, an
154
+ expired claim is reclaimed as attempt 2.
155
+ 7. Cancellation racing completion, 12 times: exactly one wins, the record names it, the loser is
156
+ refused.
157
+ 8. Terminal states are final.
158
+ 9. A real dispatch failure (the jobs service has no handler for the type) is dispatched again three
159
+ times, then fails with `DISPATCH_FAILED`. Each sweep is recorded.
160
+
161
+ ## Limits
162
+
163
+ - **Live queries aren't notified** when an invocation changes, because the store's writes are outside
164
+ the application's change feed. Poll `GET /api/invocations/<id>`, or have the application publish its
165
+ own event.
166
+ - **Lifecycle moves are separate writes.** `start`, `transition` and `cancel` inside a mutation commit
167
+ on their own, not with the mutation's other writes.
168
+ - **The registry's availability** is when a delivery last arrived. There's no active health probe of
169
+ an adapter.
170
+ - **AppBoundry artifacts.** The store runs in FeltKit's runtime; artifacts don't host it yet.
package/docs/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # FeltKit 0.3.29 documentation
1
+ # FeltKit 0.3.30 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.3.29/docs/README.md
4
+ Public copy: https://cdn.jsdelivr.net/npm/@feltdb/feltkit@0.3.30/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
@@ -9,6 +9,9 @@ Public copy: https://cdn.jsdelivr.net/npm/@feltdb/feltkit@0.3.29/docs/README.md
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
11
  - [EXTENSION-HOSTS.md](EXTENSION-HOSTS.md): Running the app in a browser extension: ownership, token storage, session end, lifecycle, gaps
12
+ - [INVOCATIONS.md](INVOCATIONS.md): Surfaces and invocations: registering entry points, the feltkit.invocation/1 contract, the durable lifecycle, dispatch and recovery
13
+ - [EXECUTION.md](EXECUTION.md): Placement-neutral execution: the control plane and execution environments, the execution contract, adapters, placement, authority and evidence
14
+ - [CONNECTIONS.md](CONNECTIONS.md): People's own connections to integrations (credential.owner: person): connecting, isolation, AuthBoundry at every call (reference implementation)
12
15
  - [AGENT-OPERATIONS.md](AGENT-OPERATIONS.md): Agents: MCP, tasks, proposals, approvals, and evidence
13
16
  - [GENERATION.md](GENERATION.md): Model generation in an application: actions, streaming, tools as proposals, in-app approvals, caller context
14
17
  - [RESOLVER.md](RESOLVER.md): Model references: change the model a deployed app uses through Resolver, without a redeploy
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feltdb/feltkit",
3
- "version": "0.3.29",
3
+ "version": "0.3.30",
4
4
  "description": "FeltKit: one application, one FeltDB instance, one developer experience. SDK, runtime, CLI, and dashboard.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -61,17 +61,18 @@
61
61
  "@appport/schema": "1.1.6",
62
62
  "@appport/sdk": "1.8.1",
63
63
  "@appport/server": "1.3.2",
64
- "@appport/services": ">=0.17.0 <1.0.0",
64
+ "@appport/services": ">=0.18.0 <1.0.0",
65
65
  "@feltdb/core": ">=0.21.0 <1.0.0",
66
- "create-feltkit": "0.3.29",
67
- "esbuild": "0.25.12",
66
+ "create-feltkit": "0.3.30",
67
+ "esbuild": "0.28.2",
68
68
  "express": "4.22.3",
69
69
  "mailerport": ">=0.1.0 <1.0.0",
70
- "tsx": "4.20.6"
70
+ "tsx": "4.23.15"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "react": ">=18",
74
- "vite": ">=5"
74
+ "vite": ">=5",
75
+ "@authboundry/local": ">=0.1.0"
75
76
  },
76
77
  "peerDependenciesMeta": {
77
78
  "react": {
@@ -79,6 +80,9 @@
79
80
  },
80
81
  "vite": {
81
82
  "optional": true
83
+ },
84
+ "@authboundry/local": {
85
+ "optional": true
82
86
  }
83
87
  },
84
88
  "devDependencies": {
@@ -86,18 +90,18 @@
86
90
  "@mailerport/service": "0.1.0",
87
91
  "@feltdb/webllm": ">=0.20.0 <1.0.0",
88
92
  "@modelcontextprotocol/sdk": "1.32.2",
89
- "@stack-ui/core": "0.8.1",
90
- "@stack-ui/react": "0.8.1",
91
- "@stack-ui/tokens": "0.8.1",
93
+ "@stack-ui/core": "0.9.0",
94
+ "@stack-ui/react": "0.9.0",
95
+ "@stack-ui/tokens": "0.9.0",
92
96
  "@types/node": "22.19.1",
93
- "@types/react": "19.2.2",
94
- "@types/react-dom": "19.2.2",
97
+ "@types/react": "19.3.0",
98
+ "@types/react-dom": "19.3.0",
95
99
  "@vitejs/plugin-react": "5.1.0",
96
- "react": "19.2.0",
97
- "react-dom": "19.2.0",
98
- "typescript": "5.9.3",
100
+ "react": "19.3.1",
101
+ "react-dom": "19.3.1",
102
+ "typescript": "7.0.2",
99
103
  "vite": "7.3.7",
100
- "vitest": "3.2.7"
104
+ "vitest": "5.1.0"
101
105
  },
102
106
  "homepage": "https://www.npmjs.com/package/@feltdb/feltkit"
103
107
  }
@@ -10,7 +10,7 @@
10
10
  "name": "feltkit",
11
11
  "source": "./",
12
12
  "description": "Skills for building and operating FeltKit applications.",
13
- "version": "0.3.29"
13
+ "version": "0.3.30"
14
14
  }
15
15
  ]
16
16
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://anthropic.com/claude-code/plugin.schema.json",
3
3
  "name": "feltkit",
4
- "version": "0.3.29",
4
+ "version": "0.3.30",
5
5
  "description": "Skills for building and operating FeltKit applications: project structure and SDK, AppPort Services, FeltDB data and consistency, the FeltKit agent over MCP, and operations. Guidance only: they grant no permission.",
6
6
  "author": {
7
7
  "name": "FeltKit"
@@ -143,6 +143,6 @@ affect other systems. Confirm with the user before doing any of them.
143
143
 
144
144
  ## Compatibility
145
145
 
146
- `@feltdb/feltkit` 0.3.x with `@appport/services` 0.17.0 (shared instance; transactional job and webhook creation; `credential.store` / `credential.status`; `servicesContract` for Managed FeltDB; the inbound event lifecycle and inbound integration management).
146
+ `@feltdb/feltkit` 0.3.x with `@appport/services` 0.18.0 (shared instance; transactional job and webhook creation; `credential.store` / `credential.status`; `servicesContract` for Managed FeltDB; the inbound event lifecycle and inbound integration management).
147
147
  The console is development-only.
148
148
  Verified in Claude Code only.