@feltdb/feltkit 0.3.29 → 0.3.31
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/app.d.ts +101 -11
- package/dist/app.js +131 -3
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.js +2 -0
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest-tenancy.d.ts +2 -2
- package/dist/appboundry/guest-tenancy.js.map +1 -1
- package/dist/appboundry/guest.js +27 -2
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.js +3 -0
- package/dist/appboundry/host.js.map +1 -1
- package/dist/authorize.d.ts +47 -4
- package/dist/authorize.js +37 -0
- package/dist/authorize.js.map +1 -1
- package/dist/cli/deploy-appboundry.d.ts +1 -1
- package/dist/cli/deploy-appboundry.js.map +1 -1
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/main.js +27 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/skills.js.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/dashboard/assets/index-9rMS3yBm.js +15 -0
- package/dist/dashboard/assets/index-DkiYTUMR.css +1 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +4 -0
- package/dist/docs.js.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/event-stage.js.map +1 -1
- package/dist/execution.d.ts +186 -0
- package/dist/execution.js +105 -0
- package/dist/execution.js.map +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/measure/index.js.map +1 -1
- package/dist/platform/approvals.js.map +1 -1
- package/dist/platform/artifacts.js.map +1 -1
- package/dist/platform/changes.d.ts +54 -54
- package/dist/platform/changes.js.map +1 -1
- package/dist/platform/deployments.d.ts +32 -32
- package/dist/platform/exec.js.map +1 -1
- package/dist/platform/platform.js.map +1 -1
- package/dist/platform/releases.js.map +1 -1
- package/dist/platform/server.js.map +1 -1
- package/dist/platform/workspaces.js.map +1 -1
- package/dist/policy.d.ts +172 -0
- package/dist/policy.js +311 -0
- package/dist/policy.js.map +1 -0
- package/dist/react/auth.d.ts +10 -10
- package/dist/react/auth.js +1 -1
- package/dist/react/auth.js.map +1 -1
- package/dist/react/context.d.ts +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/accounts.js.map +1 -1
- package/dist/runtime/activity.d.ts +17 -1
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/agent.d.ts +3 -3
- package/dist/runtime/agent.js +9 -3
- package/dist/runtime/agent.js.map +1 -1
- package/dist/runtime/application-authority.d.ts +33 -3
- package/dist/runtime/application-authority.js +74 -14
- package/dist/runtime/application-authority.js.map +1 -1
- package/dist/runtime/assemble.d.ts +13 -0
- package/dist/runtime/assemble.js +29 -1
- package/dist/runtime/assemble.js.map +1 -1
- package/dist/runtime/audit.js.map +1 -1
- package/dist/runtime/authboundry.d.ts +17 -0
- package/dist/runtime/authboundry.js +8 -1
- package/dist/runtime/authboundry.js.map +1 -1
- package/dist/runtime/authority.d.ts +10 -0
- package/dist/runtime/authority.js +17 -0
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/backup-environment.js.map +1 -1
- package/dist/runtime/backup.js.map +1 -1
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/claims.js.map +1 -1
- package/dist/runtime/collections.js.map +1 -1
- package/dist/runtime/content.d.ts +77 -2
- package/dist/runtime/content.js +153 -6
- package/dist/runtime/content.js.map +1 -1
- package/dist/runtime/context.d.ts +207 -3
- package/dist/runtime/contract.js +16 -3
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/credentials.d.ts +31 -2
- package/dist/runtime/credentials.js +55 -3
- package/dist/runtime/credentials.js.map +1 -1
- package/dist/runtime/crypto-token.js.map +1 -1
- package/dist/runtime/data.d.ts +25 -0
- package/dist/runtime/data.js +92 -8
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/decisions.js.map +1 -1
- package/dist/runtime/deployment.js.map +1 -1
- package/dist/runtime/execution-host.d.ts +54 -0
- package/dist/runtime/execution-host.js +54 -0
- package/dist/runtime/execution-host.js.map +1 -0
- package/dist/runtime/generation.js.map +1 -1
- package/dist/runtime/image-variants.d.ts +48 -0
- package/dist/runtime/image-variants.js +295 -0
- package/dist/runtime/image-variants.js.map +1 -0
- package/dist/runtime/instance.js.map +1 -1
- package/dist/runtime/integrations.d.ts +8 -6
- package/dist/runtime/integrations.js +46 -5
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/invocations.d.ts +313 -0
- package/dist/runtime/invocations.js +493 -0
- package/dist/runtime/invocations.js.map +1 -0
- package/dist/runtime/live.d.ts +10 -7
- package/dist/runtime/live.js +24 -12
- package/dist/runtime/live.js.map +1 -1
- package/dist/runtime/loader.js.map +1 -1
- package/dist/runtime/local-authority.d.ts +92 -0
- package/dist/runtime/local-authority.js +396 -0
- package/dist/runtime/local-authority.js.map +1 -0
- package/dist/runtime/oauth-credentials.d.ts +40 -3
- package/dist/runtime/oauth-credentials.js +133 -25
- package/dist/runtime/oauth-credentials.js.map +1 -1
- package/dist/runtime/outbox.js +3 -0
- package/dist/runtime/outbox.js.map +1 -1
- package/dist/runtime/policies.d.ts +89 -0
- package/dist/runtime/policies.js +152 -0
- package/dist/runtime/policies.js.map +1 -0
- package/dist/runtime/projects.d.ts +1 -1
- package/dist/runtime/readiness.js +11 -0
- package/dist/runtime/readiness.js.map +1 -1
- package/dist/runtime/runtime.d.ts +66 -5
- package/dist/runtime/runtime.js +328 -18
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services-rules.d.ts +9 -0
- package/dist/runtime/services-rules.js +47 -1
- package/dist/runtime/services-rules.js.map +1 -1
- package/dist/runtime/services.d.ts +154 -9
- package/dist/runtime/services.js +343 -14
- package/dist/runtime/services.js.map +1 -1
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/runtime/state-contract.js.map +1 -1
- package/dist/runtime/storage-check.js.map +1 -1
- package/dist/runtime/targets.d.ts +1 -1
- package/dist/runtime/tenancy.js.map +1 -1
- package/dist/runtime/transactions.d.ts +15 -0
- package/dist/runtime/transactions.js +5 -0
- package/dist/runtime/transactions.js.map +1 -1
- package/dist/schema.js.map +1 -1
- package/dist/server/admin.d.ts +72 -51
- package/dist/server/admin.js +125 -0
- package/dist/server/admin.js.map +1 -1
- package/dist/server/components.js.map +1 -1
- package/dist/server/index.js +72 -6
- package/dist/server/index.js.map +1 -1
- package/dist/server/management.js.map +1 -1
- package/dist/server/mcp.d.ts +59 -37
- package/dist/server/mcp.js +24 -1
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/operators.d.ts +1 -0
- package/dist/server/operators.js +1 -1
- package/dist/server/operators.js.map +1 -1
- package/dist/server/ports.d.ts +7 -0
- package/dist/server/ports.js +17 -0
- package/dist/server/ports.js.map +1 -1
- package/dist/server/production.js.map +1 -1
- package/dist/server/project.js.map +1 -1
- package/dist/server/session-http.js.map +1 -1
- package/dist/server/tenancy.js.map +1 -1
- package/dist/surfaces.d.ts +153 -0
- package/dist/surfaces.js +228 -0
- package/dist/surfaces.js.map +1 -0
- package/dist/testing/index.d.ts +11 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/index.js.map +1 -1
- package/docs/AGENT-OPERATIONS.md +1 -1
- package/docs/ARCHITECTURE.md +2 -1
- package/docs/CONNECTIONS.md +151 -0
- package/docs/EXECUTION.md +271 -0
- package/docs/GUARANTEES.md +134 -8
- package/docs/INVOCATIONS.md +170 -0
- package/docs/POLICIES.md +121 -0
- package/docs/README.md +6 -2
- package/docs/SECURITY.md +30 -0
- package/docs/TRANSACTIONS.md +4 -0
- package/package.json +27 -19
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-services/SKILL.md +1 -1
- package/dist/dashboard/assets/index-BehzsQOa.css +0 -1
- package/dist/dashboard/assets/index-UuZ63NA6.js +0 -15
|
@@ -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/POLICIES.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Policies
|
|
2
|
+
|
|
3
|
+
FeltKit decides who may call a function in layers. Every layer must allow, and the first refusal
|
|
4
|
+
wins. All of them run at the one execution boundary every interface goes through: HTTP functions,
|
|
5
|
+
AppPort capabilities, MCP tools, agent actions, jobs, approved actions, and AppBoundry artifacts.
|
|
6
|
+
|
|
7
|
+
| Order | Layer | Declared with | Decides |
|
|
8
|
+
|---|---|---|---|
|
|
9
|
+
| 1 | Roles | `roles` and each function's `access` | May this caller call this function at all? Checked before the arguments are read. |
|
|
10
|
+
| 2 | Approval | `approval: "required"` | A non-person caller needs a person's approval for this exact action. |
|
|
11
|
+
| 3 | Ownership | `owner` on the function | The record named by an argument belongs to the caller. |
|
|
12
|
+
| 4 | **Policies** | `app.policy(rule)`, plus managed versions | Owner, shared-with, record state, input, role, tenant role, agent delegation. |
|
|
13
|
+
| 5 | Hook | `feltkit({ authorize })` | Anything else, in code. It sees the policy decision. |
|
|
14
|
+
|
|
15
|
+
Evaluation is deterministic. No model takes part in any decision. Delegated authority is decided by
|
|
16
|
+
AuthBoundry, the owner of delegation, whose decision id is kept as evidence.
|
|
17
|
+
|
|
18
|
+
## Declaring policies
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { app, docs } from "./app.js";
|
|
22
|
+
import * as d from "./docs.js";
|
|
23
|
+
|
|
24
|
+
app.policy({
|
|
25
|
+
id: "docs.read.owner-or-shared",
|
|
26
|
+
effect: "allow",
|
|
27
|
+
functions: [d.read], // definitions, not strings: renaming breaks the import
|
|
28
|
+
resource: { collection: docs, id: "docId" }, // the record, loaded by the "docId" argument
|
|
29
|
+
when: [{ any: [{ owner: "ownerId" }, { sharedWith: "sharedWith" }, { role: "admin" }] }],
|
|
30
|
+
});
|
|
31
|
+
app.policy({ id: "docs.remove.kept", description: "published documents are kept", effect: "deny",
|
|
32
|
+
functions: [d.remove], resource: { collection: docs, id: "docId" }, when: [{ field: "status", eq: "published" }] });
|
|
33
|
+
app.policy({ id: "refund.small", effect: "allow", functions: [refund], principals: { roles: ["member"] },
|
|
34
|
+
resource: { collection: invoices, id: "invoiceId" }, when: [{ owner: "ownerId" }, { arg: "amount", gt: 0, lte: 100 }],
|
|
35
|
+
evidence: "durable" });
|
|
36
|
+
app.policy({ id: "docs.publish.delegated", effect: "allow", functions: [d.publish], principals: { types: ["agent", "service"] },
|
|
37
|
+
resource: { collection: docs, id: "docId" }, when: [{ delegated: { capability: "docs.publish", onBehalfOf: { field: "ownerId" } } }] });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Conditions:
|
|
41
|
+
|
|
42
|
+
| Condition | Holds when |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `{ owner: "<field>" }` | the resource's field is the caller's id |
|
|
45
|
+
| `{ owner: "<field>", via: { collection, field } }` | the resource's field references a record whose `field` is the caller's id (e.g. `createdBy` → `participants.principalId`) |
|
|
46
|
+
| `{ sharedWith: "<field>" }` | the resource's field is a list containing the caller's id |
|
|
47
|
+
| `{ field: "<f>", eq / ne / in / notIn / lt / lte / gt / gte }` | the resource's field compares as given |
|
|
48
|
+
| `{ arg: "<a>", …same operators }` | the validated argument compares as given |
|
|
49
|
+
| `{ role: r \| [r…] }` | the caller holds the application role |
|
|
50
|
+
| `{ tenantRole: r \| [r…] }` | the caller's role in their current workspace is one of these |
|
|
51
|
+
| `{ delegated: { capability, onBehalfOf: { field, via? } \| { arg } } }` | the caller is an agent or service, and AuthBoundry allows the application's executor to exercise `capability` for that person (a delegation that exists, is in force, and covers it) |
|
|
52
|
+
| `{ any: [...] }`, `{ not: c }` | composition |
|
|
53
|
+
|
|
54
|
+
`principals` limits which callers a rule applies to: `types`, `roles`, and `anonymous: true`.
|
|
55
|
+
|
|
56
|
+
## Semantics
|
|
57
|
+
|
|
58
|
+
- **Deny overrides.** If an applicable deny rule's conditions all hold, the call is refused, whatever else allows it.
|
|
59
|
+
- **Deny by default once governed.** A function named by any allow rule runs only if an applicable
|
|
60
|
+
allow rule's conditions all hold. A function no policy names is decided by the other layers only.
|
|
61
|
+
- **Unevaluable means not held.** A missing record, a missing field, or an authority that cannot be
|
|
62
|
+
reached never allows. A deny rule that depends on it does not apply. So an unreachable AuthBoundry
|
|
63
|
+
refuses a delegated call.
|
|
64
|
+
- A person acts with their own authority. A `delegated` condition never holds for a `user` principal.
|
|
65
|
+
- A refusal is `FORBIDDEN` (`UNAUTHORIZED` for an anonymous caller). Its details name the deny rule
|
|
66
|
+
that `matched`, or each allow rule's first `unmet` condition.
|
|
67
|
+
|
|
68
|
+
## Managed policies: changed without a redeploy
|
|
69
|
+
|
|
70
|
+
A managed version is a complete, immutable set of rules stored in the application's own FeltDB. The
|
|
71
|
+
active version applies on top of the code policies. It adds rules and cannot remove a code rule.
|
|
72
|
+
Activating, or deactivating, takes effect on the next call in every process: the active pointer is
|
|
73
|
+
read for each decision (compare-and-swap writes, cached only by its record version).
|
|
74
|
+
|
|
75
|
+
Managed rules name functions as `"<module>:<export>"`, and may also name an integration operation
|
|
76
|
+
by its capability (`"registry.lookup"`). Every rule is validated against the deployed project when
|
|
77
|
+
it is stored and again when it is activated. A rule that names a missing function or collection is
|
|
78
|
+
refused.
|
|
79
|
+
|
|
80
|
+
| Route (admin API) | Development | Production |
|
|
81
|
+
|---|---|---|
|
|
82
|
+
| `GET /policies`, `/policies/versions`, `/policies/history`, `GET /decisions` | admin token | `feltkit.operations.read` |
|
|
83
|
+
| `POST /policies/simulate` `{ function, principal, args }` | admin token | `feltkit.operations.read` |
|
|
84
|
+
| `POST /policies/versions` `{ rules, note? }` | admin token | **`feltkit.policies.manage`** |
|
|
85
|
+
| `POST /policies/active` `{ version: n \| null }` | admin token | **`feltkit.policies.manage`** |
|
|
86
|
+
|
|
87
|
+
Changing policy changes who may do what, so production requires its own permission, separate from
|
|
88
|
+
`feltkit.operations.write`. History records the signed-in operator, and a client-chosen `by` is refused.
|
|
89
|
+
|
|
90
|
+
## Simulation and evidence
|
|
91
|
+
|
|
92
|
+
- `runtime.simulatePolicy({ function, principal, args })`, or `POST /policies/simulate`, runs the
|
|
93
|
+
policies in force against the real records. Nothing runs and nothing is recorded.
|
|
94
|
+
- Decision evidence (`_feltkit_decisions`, append-only) records:
|
|
95
|
+
- every refusal, from any layer (role, approval, ownership, policy or hook) and for signed-in callers;
|
|
96
|
+
- every allow of a rule marked `evidence: "durable"`.
|
|
97
|
+
|
|
98
|
+
Each record names the layer, the policy version (`code:<digest>[+managed:<n>]`), the matched and
|
|
99
|
+
unmet rules, AuthBoundry's delegation decisions, and the argument names. It never holds argument
|
|
100
|
+
values. A durable allow whose record cannot be written does not run.
|
|
101
|
+
- The activity log carries the policy decision too (`authority.policy`).
|
|
102
|
+
|
|
103
|
+
## Integration operations
|
|
104
|
+
|
|
105
|
+
An integration operation reaches the same managed policies and hook (`kind: "integration"`), whether
|
|
106
|
+
it is called through its AppPort/MCP capability or through `ctx.integrations.invoke`. A refused call
|
|
107
|
+
never reaches the remote API.
|
|
108
|
+
|
|
109
|
+
## Testing
|
|
110
|
+
|
|
111
|
+
`createTestApp()` exposes `app.policies.simulate(fn, who, args)`, `app.policies.decisions(filter)`,
|
|
112
|
+
and `app.policies.store` (create and activate managed versions).
|
|
113
|
+
|
|
114
|
+
## Limits (current)
|
|
115
|
+
|
|
116
|
+
- **AppBoundry artifacts** enforce the code policies they carry, with the same evaluator.
|
|
117
|
+
- Managed versions live in the host's FeltDB and are not part of `appboundry-guest/1`, so an
|
|
118
|
+
artifact does not apply them.
|
|
119
|
+
- A `delegated` condition has no authority to ask in the guest, so it does not hold there.
|
|
120
|
+
- Code policies cannot name integration operations: managed rules can.
|
|
121
|
+
- Managed versions add rules. Removing a code rule needs a deploy.
|
package/docs/README.md
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
# FeltKit 0.3.
|
|
1
|
+
# FeltKit 0.3.31 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.
|
|
4
|
+
Public copy: https://cdn.jsdelivr.net/npm/@feltdb/feltkit@0.3.31/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
|
+
- [POLICIES.md](POLICIES.md): Declarative policies (owner, sharing, state, input, roles, delegation), managed versions without a redeploy, simulation, decision evidence
|
|
11
12
|
- [EXTENSION-HOSTS.md](EXTENSION-HOSTS.md): Running the app in a browser extension: ownership, token storage, session end, lifecycle, gaps
|
|
13
|
+
- [INVOCATIONS.md](INVOCATIONS.md): Surfaces and invocations: registering entry points, the feltkit.invocation/1 contract, the durable lifecycle, dispatch and recovery
|
|
14
|
+
- [EXECUTION.md](EXECUTION.md): Placement-neutral execution: the control plane and execution environments, the execution contract, adapters, placement, authority and evidence
|
|
15
|
+
- [CONNECTIONS.md](CONNECTIONS.md): People's own connections to integrations (credential.owner: person): connecting, isolation, AuthBoundry at every call (reference implementation)
|
|
12
16
|
- [AGENT-OPERATIONS.md](AGENT-OPERATIONS.md): Agents: MCP, tasks, proposals, approvals, and evidence
|
|
13
17
|
- [GENERATION.md](GENERATION.md): Model generation in an application: actions, streaming, tools as proposals, in-app approvals, caller context
|
|
14
18
|
- [RESOLVER.md](RESOLVER.md): Model references: change the model a deployed app uses through Resolver, without a redeploy
|
package/docs/SECURITY.md
CHANGED
|
@@ -112,6 +112,11 @@ Every entry point was exercised by `packages/sdk/test/auth.test.ts`.
|
|
|
112
112
|
|
|
113
113
|
### Credentials and API keys
|
|
114
114
|
|
|
115
|
+
- **Agent credentials (local authority).** Each registered agent's AuthBoundry credential is kept in
|
|
116
|
+
custody (`credential-ref:authboundry-local-agent:<agent>`), resolved only for that agent's decisions,
|
|
117
|
+
never recorded, logged or returned. An agent caller can decide only as itself; registering agents needs
|
|
118
|
+
`feltkit.authority.agents` and is refused to agents (docs/LOCAL-AUTHORITY.md).
|
|
119
|
+
|
|
115
120
|
- Service credentials are references (`credential-ref:<id>`) resolved only inside the
|
|
116
121
|
effect that needs them, from `FELTKIT_CREDENTIAL_<ID>` when it is set, else (development
|
|
117
122
|
and test) from the environment's encrypted vault. Studio shows whether each reference is
|
|
@@ -163,6 +168,28 @@ Every entry point was exercised by `packages/sdk/test/auth.test.ts`.
|
|
|
163
168
|
`integrations.test.ts` (discovery without authority, no credential in records),
|
|
164
169
|
`platform.test.ts` (production routes).
|
|
165
170
|
|
|
171
|
+
## File links
|
|
172
|
+
|
|
173
|
+
- A file link is a capability: holding it downloads that file until it expires (≤ 1 hour). The function
|
|
174
|
+
that issues it authorizes the resource first; the route reads no session, so links work as `<img src>`.
|
|
175
|
+
Only the SHA-256 of a token is stored.
|
|
176
|
+
- **Default:** `Cache-Control: private, no-store`, a new URL every call.
|
|
177
|
+
- **Cacheable links (`cache: true`, opt-in):** `private, max-age=<remaining>, immutable`, ETag/304.
|
|
178
|
+
- Tokens are HMAC-SHA256 of { file, content, variant, disposition, principal, workspace, window } under a
|
|
179
|
+
random per-process key that is never stored. Another principal never receives the same URL, and no
|
|
180
|
+
URL is derived from the bytes alone, so identical bytes in two workspaces never share an address.
|
|
181
|
+
- **Accepted risk:** a browser that already downloaded a file keeps showing its copy until `max-age`
|
|
182
|
+
runs out (at most the link's `expiresInSeconds`, ≤ 1 hour), after a removal or a loss of access.
|
|
183
|
+
`private` keeps it out of shared caches; new downloads through the link stop at once.
|
|
184
|
+
- A link serves only the content it was issued for: a record that comes to name other bytes refuses it.
|
|
185
|
+
- **Image variants** are served only through a link to their original, so they are authorized exactly as
|
|
186
|
+
it is. Decoding untrusted images: the format is sniffed from the bytes (never the declared type), the
|
|
187
|
+
pixel count is checked from the header before decoding (`services.files.maxVariantPixels`), the JPEG
|
|
188
|
+
decoder runs with its own resolution and memory limits, and anything that fails is served as the
|
|
189
|
+
original, saying so. The codecs are pure JavaScript (no native code). Every download, variant or not,
|
|
190
|
+
keeps `Content-Security-Policy: …; sandbox`; reasons in `X-FeltKit-Variant-Reason` are FeltKit's own
|
|
191
|
+
text, reduced to printable ASCII.
|
|
192
|
+
|
|
166
193
|
## Known gaps
|
|
167
194
|
|
|
168
195
|
- No rate limiting on FeltKit's own endpoints. Put a reverse proxy in front of
|
|
@@ -179,5 +206,8 @@ Every entry point was exercised by `packages/sdk/test/auth.test.ts`.
|
|
|
179
206
|
- Production operator sessions cannot be listed or revoked from Studio; there is no MFA
|
|
180
207
|
and no external identity-provider integration beyond the `auth.authenticate` hook.
|
|
181
208
|
- Production Studio has no rate limiting of its own, like every FeltKit endpoint.
|
|
209
|
+
- The first download of an image variant decodes on the server's event loop. With a large
|
|
210
|
+
`maxVariantPixels`, many first downloads at once slow other requests; the default (24 MP) and the files
|
|
211
|
+
byte cap (1 MiB by default) bound it.
|
|
182
212
|
|
|
183
213
|
Report vulnerabilities privately to the repository owner.
|
package/docs/TRANSACTIONS.md
CHANGED
|
@@ -251,6 +251,10 @@ export const assistant = app.agent("assistant", {
|
|
|
251
251
|
if (text.includes("@assistant")) ctx.afterCommit.agent("assistant", { roomId });
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
+
An agent's handler that asks AuthBoundry (`ctx.authority.decide`) decides **as the agent**, with its
|
|
255
|
+
own credential, when the application uses a local authority (docs/LOCAL-AUTHORITY.md, "Several agents"):
|
|
256
|
+
only a person's grant to that agent allows it, never a grant to the executor or to another agent.
|
|
257
|
+
|
|
254
258
|
### Triggers, and why these two
|
|
255
259
|
|
|
256
260
|
- **`ctx.afterCommit.agent(name, input)`** is the general one. The application decides, in the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feltdb/feltkit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.31",
|
|
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",
|
|
@@ -54,24 +54,27 @@
|
|
|
54
54
|
"prepack": "npm run build"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@appport/authorization": "1.
|
|
57
|
+
"@appport/authorization": "1.2.0",
|
|
58
58
|
"@appport/integration": "1.2.5",
|
|
59
59
|
"@appport/protocol": "1.5.0",
|
|
60
60
|
"@appport/resolver-client": "0.3.0",
|
|
61
61
|
"@appport/schema": "1.1.6",
|
|
62
|
-
"@appport/sdk": "1.
|
|
63
|
-
"@appport/server": "1.3.
|
|
64
|
-
"@appport/services": ">=0.
|
|
62
|
+
"@appport/sdk": "1.9.0",
|
|
63
|
+
"@appport/server": "1.3.3",
|
|
64
|
+
"@appport/services": ">=0.19.0 <1.0.0",
|
|
65
65
|
"@feltdb/core": ">=0.21.0 <1.0.0",
|
|
66
|
-
"create-feltkit": "0.3.
|
|
67
|
-
"esbuild": "0.
|
|
66
|
+
"create-feltkit": "0.3.31",
|
|
67
|
+
"esbuild": "0.28.2",
|
|
68
68
|
"express": "4.22.3",
|
|
69
|
+
"jpeg-js": "0.4.4",
|
|
69
70
|
"mailerport": ">=0.1.0 <1.0.0",
|
|
70
|
-
"
|
|
71
|
+
"pngjs": "7.0.0",
|
|
72
|
+
"tsx": "4.23.15"
|
|
71
73
|
},
|
|
72
74
|
"peerDependencies": {
|
|
73
75
|
"react": ">=18",
|
|
74
|
-
"vite": ">=5"
|
|
76
|
+
"vite": ">=5",
|
|
77
|
+
"@authboundry/local": ">=0.1.0"
|
|
75
78
|
},
|
|
76
79
|
"peerDependenciesMeta": {
|
|
77
80
|
"react": {
|
|
@@ -79,25 +82,30 @@
|
|
|
79
82
|
},
|
|
80
83
|
"vite": {
|
|
81
84
|
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"@authboundry/local": {
|
|
87
|
+
"optional": true
|
|
82
88
|
}
|
|
83
89
|
},
|
|
84
90
|
"devDependencies": {
|
|
85
|
-
"@appport/testing": "1.2.
|
|
91
|
+
"@appport/testing": "1.2.6",
|
|
92
|
+
"@authboundry/local": "0.1.0",
|
|
86
93
|
"@mailerport/service": "0.1.0",
|
|
87
94
|
"@feltdb/webllm": ">=0.20.0 <1.0.0",
|
|
88
95
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
89
|
-
"@stack-ui/core": "0.
|
|
90
|
-
"@stack-ui/react": "0.
|
|
91
|
-
"@stack-ui/tokens": "0.
|
|
96
|
+
"@stack-ui/core": "0.9.0",
|
|
97
|
+
"@stack-ui/react": "0.9.0",
|
|
98
|
+
"@stack-ui/tokens": "0.9.0",
|
|
92
99
|
"@types/node": "22.19.1",
|
|
93
|
-
"@types/
|
|
94
|
-
"@types/react
|
|
100
|
+
"@types/pngjs": "6.0.5",
|
|
101
|
+
"@types/react": "19.3.0",
|
|
102
|
+
"@types/react-dom": "19.3.0",
|
|
95
103
|
"@vitejs/plugin-react": "5.1.0",
|
|
96
|
-
"react": "19.
|
|
97
|
-
"react-dom": "19.
|
|
98
|
-
"typescript": "
|
|
104
|
+
"react": "19.3.1",
|
|
105
|
+
"react-dom": "19.3.1",
|
|
106
|
+
"typescript": "7.0.2",
|
|
99
107
|
"vite": "7.3.7",
|
|
100
|
-
"vitest": "
|
|
108
|
+
"vitest": "5.1.0"
|
|
101
109
|
},
|
|
102
110
|
"homepage": "https://www.npmjs.com/package/@feltdb/feltkit"
|
|
103
111
|
}
|
|
@@ -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.
|
|
4
|
+
"version": "0.3.31",
|
|
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.
|
|
146
|
+
`@feltdb/feltkit` 0.3.x with `@appport/services` 0.19.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.
|