@feltdb/feltkit 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -2
  3. package/bin/feltkit.js +3 -0
  4. package/dist/app.d.ts +247 -0
  5. package/dist/app.js +181 -0
  6. package/dist/app.js.map +1 -0
  7. package/dist/cli/deploy.d.ts +8 -0
  8. package/dist/cli/deploy.js +125 -0
  9. package/dist/cli/deploy.js.map +1 -0
  10. package/dist/cli/main.d.ts +9 -0
  11. package/dist/cli/main.js +581 -0
  12. package/dist/cli/main.js.map +1 -0
  13. package/dist/cli/output.d.ts +18 -0
  14. package/dist/cli/output.js +87 -0
  15. package/dist/cli/output.js.map +1 -0
  16. package/dist/cli/skills.d.ts +39 -0
  17. package/dist/cli/skills.js +125 -0
  18. package/dist/cli/skills.js.map +1 -0
  19. package/dist/client/index.d.ts +125 -0
  20. package/dist/client/index.js +306 -0
  21. package/dist/client/index.js.map +1 -0
  22. package/dist/dashboard/assets/index--1Tqbv_A.css +1 -0
  23. package/dist/dashboard/assets/index-Bm4qCYpv.js +15 -0
  24. package/dist/dashboard/index.html +16 -0
  25. package/dist/errors.d.ts +33 -0
  26. package/dist/errors.js +56 -0
  27. package/dist/errors.js.map +1 -0
  28. package/dist/index.d.ts +18 -0
  29. package/dist/index.js +12 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/react/index.d.ts +40 -0
  32. package/dist/react/index.js +85 -0
  33. package/dist/react/index.js.map +1 -0
  34. package/dist/runtime/activity.d.ts +110 -0
  35. package/dist/runtime/activity.js +113 -0
  36. package/dist/runtime/activity.js.map +1 -0
  37. package/dist/runtime/agent.d.ts +353 -0
  38. package/dist/runtime/agent.js +1345 -0
  39. package/dist/runtime/agent.js.map +1 -0
  40. package/dist/runtime/authority.d.ts +98 -0
  41. package/dist/runtime/authority.js +240 -0
  42. package/dist/runtime/authority.js.map +1 -0
  43. package/dist/runtime/changes.d.ts +42 -0
  44. package/dist/runtime/changes.js +85 -0
  45. package/dist/runtime/changes.js.map +1 -0
  46. package/dist/runtime/content.d.ts +33 -0
  47. package/dist/runtime/content.js +46 -0
  48. package/dist/runtime/content.js.map +1 -0
  49. package/dist/runtime/context.d.ts +76 -0
  50. package/dist/runtime/context.js +2 -0
  51. package/dist/runtime/context.js.map +1 -0
  52. package/dist/runtime/credentials.d.ts +42 -0
  53. package/dist/runtime/credentials.js +32 -0
  54. package/dist/runtime/credentials.js.map +1 -0
  55. package/dist/runtime/data.d.ts +145 -0
  56. package/dist/runtime/data.js +439 -0
  57. package/dist/runtime/data.js.map +1 -0
  58. package/dist/runtime/decisions.d.ts +131 -0
  59. package/dist/runtime/decisions.js +301 -0
  60. package/dist/runtime/decisions.js.map +1 -0
  61. package/dist/runtime/environment.d.ts +36 -0
  62. package/dist/runtime/environment.js +73 -0
  63. package/dist/runtime/environment.js.map +1 -0
  64. package/dist/runtime/idempotency.d.ts +37 -0
  65. package/dist/runtime/idempotency.js +88 -0
  66. package/dist/runtime/idempotency.js.map +1 -0
  67. package/dist/runtime/instance.d.ts +82 -0
  68. package/dist/runtime/instance.js +253 -0
  69. package/dist/runtime/instance.js.map +1 -0
  70. package/dist/runtime/integrations.d.ts +120 -0
  71. package/dist/runtime/integrations.js +412 -0
  72. package/dist/runtime/integrations.js.map +1 -0
  73. package/dist/runtime/loader.d.ts +15 -0
  74. package/dist/runtime/loader.js +121 -0
  75. package/dist/runtime/loader.js.map +1 -0
  76. package/dist/runtime/projects.d.ts +52 -0
  77. package/dist/runtime/projects.js +141 -0
  78. package/dist/runtime/projects.js.map +1 -0
  79. package/dist/runtime/readiness.d.ts +29 -0
  80. package/dist/runtime/readiness.js +154 -0
  81. package/dist/runtime/readiness.js.map +1 -0
  82. package/dist/runtime/runtime.d.ts +227 -0
  83. package/dist/runtime/runtime.js +664 -0
  84. package/dist/runtime/runtime.js.map +1 -0
  85. package/dist/runtime/services.d.ts +327 -0
  86. package/dist/runtime/services.js +686 -0
  87. package/dist/runtime/services.js.map +1 -0
  88. package/dist/runtime/sessions.d.ts +44 -0
  89. package/dist/runtime/sessions.js +109 -0
  90. package/dist/runtime/sessions.js.map +1 -0
  91. package/dist/schema.d.ts +56 -0
  92. package/dist/schema.js +44 -0
  93. package/dist/schema.js.map +1 -0
  94. package/dist/server/admin.d.ts +141 -0
  95. package/dist/server/admin.js +828 -0
  96. package/dist/server/admin.js.map +1 -0
  97. package/dist/server/http.d.ts +19 -0
  98. package/dist/server/http.js +99 -0
  99. package/dist/server/http.js.map +1 -0
  100. package/dist/server/index.d.ts +54 -0
  101. package/dist/server/index.js +305 -0
  102. package/dist/server/index.js.map +1 -0
  103. package/dist/server/management.d.ts +12 -0
  104. package/dist/server/management.js +177 -0
  105. package/dist/server/management.js.map +1 -0
  106. package/dist/server/mcp.d.ts +214 -0
  107. package/dist/server/mcp.js +135 -0
  108. package/dist/server/mcp.js.map +1 -0
  109. package/dist/server/operators.d.ts +77 -0
  110. package/dist/server/operators.js +162 -0
  111. package/dist/server/operators.js.map +1 -0
  112. package/dist/server/project.d.ts +60 -0
  113. package/dist/server/project.js +344 -0
  114. package/dist/server/project.js.map +1 -0
  115. package/dist/server/public.d.ts +14 -0
  116. package/dist/server/public.js +15 -0
  117. package/dist/server/public.js.map +1 -0
  118. package/dist/testing/index.d.ts +20 -0
  119. package/dist/testing/index.js +65 -0
  120. package/dist/testing/index.js.map +1 -0
  121. package/package.json +91 -4
  122. package/skills/.claude-plugin/marketplace.json +16 -0
  123. package/skills/.claude-plugin/plugin.json +24 -0
  124. package/skills/README.md +44 -0
  125. package/skills/feltkit-agent/SKILL.md +84 -0
  126. package/skills/feltkit-build/SKILL.md +143 -0
  127. package/skills/feltkit-data/SKILL.md +79 -0
  128. package/skills/feltkit-operations/SKILL.md +72 -0
  129. package/skills/feltkit-services/SKILL.md +102 -0
@@ -0,0 +1,79 @@
1
+ ---
2
+ name: feltkit-data
3
+ description: Model, query, and change data in a FeltKit application on FeltDB — collections and schemas, ctx.db.get/find/query/count, insert/patch/replace/delete, pagination, transactions, and FeltKit's consistency guarantees (conflicts, read fences). Use when designing collections, writing queries or mutations that read and write, handling CONFLICT errors, or reasoning about concurrency.
4
+ ---
5
+
6
+ # FeltKit: data on FeltDB
7
+
8
+ FeltDB is the durable source of truth. Each environment has exactly one FeltDB instance; application data, sessions,
9
+ the activity log, AppPort Services, and agent state all live in it. Never open another one.
10
+
11
+ ## Model
12
+
13
+ ```ts
14
+ import { feltkit, s } from "@feltdb/feltkit";
15
+ export const app = feltkit({ name: "crm" });
16
+ export const contacts = app.collection("contacts", {
17
+ name: s.string(),
18
+ email: s.string(),
19
+ stage: s.enum(["lead", "customer"]),
20
+ ownerId: s.string(),
21
+ });
22
+ ```
23
+
24
+ Records carry `id` and `__version` (FeltDB's). Do not declare either. Writes are validated against the shape.
25
+
26
+ ## Read
27
+
28
+ ```ts
29
+ await ctx.db.get(contacts, id); // or null
30
+ await ctx.db.find(contacts, { stage: "lead" }, { orderBy: [{ field: "name", direction: "asc" }], limit: 50 });
31
+ await ctx.db.count(contacts, { ownerId });
32
+ const page = await ctx.db.query(contacts, { where: [{ field: "stage", eq: "lead" }], orderBy: [{ field: "name", direction: "asc" }], limit: 25, cursor });
33
+ // page.records, page.nextCursor, page.exhausted
34
+ ```
35
+
36
+ `where` clauses support `eq`, `neq`, `lt`, `lte`, `gt`, `gte`. Queries are read-only and live in the client
37
+ (`useQuery` re-runs when their data changes).
38
+
39
+ ## Write
40
+
41
+ ```ts
42
+ const id = await ctx.db.insert(contacts, { name, email, stage: "lead", ownerId });
43
+ await ctx.db.patch(contacts, id, { stage: "customer" });
44
+ await ctx.db.replace(contacts, id, { name, email, stage: "customer", ownerId });
45
+ await ctx.db.delete(contacts, id);
46
+ ```
47
+
48
+ A mutation's writes are buffered and commit as **one FeltDB transaction** when the handler returns; if it throws,
49
+ nothing is written.
50
+
51
+ ## Consistency: what is guaranteed
52
+
53
+ - **Atomic**: all of a mutation's writes, or none.
54
+ - **Checked reads**: everything a mutation read — by id, by equality filter (including records that would newly
55
+ match: phantoms), by range (conservatively), and whole collections — is checked at commit. If any of it changed,
56
+ the commit fails with `CONFLICT` and nothing is written. Retry the mutation; do not retry blindly in a loop
57
+ without a bound.
58
+ - **Not guaranteed**: a consistent snapshot *while* a handler runs; checks for read-only mutations; fences against
59
+ writes made through `ctx.unsafe.feltdb`.
60
+ - Service effects (`ctx.services.*`) commit separately from the mutation.
61
+
62
+ ## Patterns
63
+
64
+ - Uniqueness: read with `find` by the unique field, then insert; a concurrent duplicate makes one commit `CONFLICT`.
65
+ - Counters and balances: read then `patch` in the same mutation; concurrent updates conflict instead of losing one.
66
+ - Large scans: page with `query` + `cursor`; `find` is capped.
67
+
68
+ ## Inspect data
69
+
70
+ Studio → Data (application collections and read-only platform collections). From a coding agent, read through the
71
+ application's capabilities (feltkit-agent skill); there is no direct database access for agents, by design.
72
+
73
+ ## Requires approval
74
+
75
+ Deleting records, bulk changes, schema changes that drop fields, or anything in production.
76
+
77
+ ## Compatibility
78
+
79
+ `@feltdb/feltkit` 0.1.x on `@feltdb/core` 0.13.0. Details: the project's `docs/GUARANTEES.md`. Verified in Claude Code only.
@@ -0,0 +1,72 @@
1
+ ---
2
+ name: feltkit-operations
3
+ description: Diagnose, build, test, deploy, and recover FeltKit applications — feltkit doctor, inspect, build, test, deploy, start, sessions, environments, state locations, production configuration (FELTDB_URL, FELTDB_TOKEN, FELTKIT_STATE_DIR), and release. Use when something will not start, a port or instance is already in use, the user wants to ship or deploy, rotate access, or recover state.
4
+ ---
5
+
6
+ # FeltKit: operations
7
+
8
+ ## Diagnose first
9
+
10
+ ```sh
11
+ npx feltkit doctor --json # Node, project, dependencies, one FeltDB copy, frontend tooling, dev server
12
+ npx feltkit inspect --json # application, environment, instance, functions, services, recent activity
13
+ ```
14
+
15
+ `inspect` reads the running server when there is one, otherwise opens the environment directly. It never prints the
16
+ admin token. Share findings, not tokens.
17
+
18
+ | Problem | Meaning | Fix |
19
+ |---|---|---|
20
+ | `DUPLICATE_INSTANCE` / "already running" | Another process owns this environment's FeltDB instance | Stop it, or use that server; never point two processes at the same state |
21
+ | `Port … is already in use` | — | `--port <n>` |
22
+ | "Two copies of @feltdb/core" (doctor) | Mismatched dependency versions | Reinstall; pins must agree (doctor prints the fix) |
23
+ | `CONFIGURATION: FELTDB_URL is set for production but FELTDB_TOKEN is not` | — | Set the token from the secret manager |
24
+ | A function fails only in production | Production hides internal error messages | Read the server logs and Studio's Activity for the request id |
25
+
26
+ ## Environments and state
27
+
28
+ | Environment | State |
29
+ |---|---|
30
+ | development | `.feltkit/development/state` (local FeltDB) |
31
+ | test | a fresh temporary directory per test runtime |
32
+ | production | `FELTDB_URL` + `FELTDB_TOKEN` (a FeltDB server), else `FELTKIT_STATE_DIR`, else `.feltkit/production/state` |
33
+
34
+ `.feltkit/` holds state and the admin token (mode 0600). Never commit it, never paste the token. Back up state by
35
+ copying the stopped state directory; restore by putting it back before starting.
36
+
37
+ ## Build, test, deploy
38
+
39
+ ```sh
40
+ npx feltkit test # node --test on tests/**/*.test.ts, isolated FeltDB per runtime
41
+ npx feltkit build # bundles feltkit/, builds the frontend, loads the bundle to verify it
42
+ npx feltkit deploy --out dist-deploy # verified, self-contained directory with a Dockerfile and DEPLOY.md
43
+ npx feltkit start --port 8080 --host 0.0.0.0 # production runtime (the dashboard is not served)
44
+ ```
45
+
46
+ `build` refuses to ship a frontend that contains secrets (FELTDB_TOKEN, FeltKit tokens, server code).
47
+
48
+ ## Access
49
+
50
+ ```sh
51
+ npx feltkit session create --id ci-bot --role <role> --type agent --ttl 24
52
+ npx feltkit session list
53
+ npx feltkit session revoke <ref>
54
+ ```
55
+
56
+ Revoking a session stops its durable work too (jobs and deliveries it created are refused). API keys are managed on
57
+ the API keys page (Studio → Services → Manage). Production API keys need `FELTKIT_API_KEY_VERIFIER_KEY`.
58
+
59
+ ## Recover
60
+
61
+ - A failed job or delivery: see the feltkit-services skill; retry or replay after fixing the cause.
62
+ - A `CONFLICT` storm: two writers contend; retry with a bound, or narrow what the mutation reads.
63
+ - The agent cannot act for a task: its owner has no active session or key; create one or reassign the work.
64
+
65
+ ## Requires approval
66
+
67
+ Anything in production; deleting or restoring state; revoking sessions or keys; rotating
68
+ `FELTKIT_API_KEY_VERIFIER_KEY`; publishing packages (`npm run publish:packages` in the FeltKit repository).
69
+
70
+ ## Compatibility
71
+
72
+ `@feltdb/feltkit` 0.1.x. Verified in Claude Code only.
@@ -0,0 +1,102 @@
1
+ ---
2
+ name: feltkit-services
3
+ description: Configure, use, and troubleshoot AppPort Services in a FeltKit application — files, notifications, configuration and secrets, API keys, webhooks, jobs, schedules, intelligence. Use when the user wants to enable a service, send a notification, enqueue background work, emit or debug a webhook, issue or revoke an API key, set a configuration variable or secret, or asks why a job or delivery failed.
4
+ ---
5
+
6
+ # FeltKit: services
7
+
8
+ Services are AppPort Services running on the application's own FeltDB instance. Every service effect is
9
+ authorized by AppPort Services' gateway with the application's roles, as the caller. **This skill grants no
10
+ permission and stores no secret.**
11
+
12
+ ## Enable a service
13
+
14
+ ```ts
15
+ // feltkit/app.ts
16
+ export const app = feltkit({
17
+ name: "shop",
18
+ roles: { admin: ["*"], ops: ["jobs.*", "webhooks.*", "orders.*"] },
19
+ services: {
20
+ files: true,
21
+ notifications: true,
22
+ configuration: true,
23
+ apiKeys: { roles: ["machine"] }, // requests with an API key hold these roles
24
+ webhooks: true,
25
+ jobs: { handlers: { "invoice.send": "billing:sendInvoice" } }, // job type → "<module>:<function>"
26
+ schedules: true, // needs jobs
27
+ intelligence: true, // the environment's model; agent decisions use it (feltkit model set)
28
+ },
29
+ });
30
+ ```
31
+
32
+ The permission for each operation is its AppPort Services capability name (`jobs.create`, `webhooks.register`,
33
+ `apikeys.create`, `configuration.write`, `credential.attach`, …). Grant them to roles like any permission.
34
+
35
+ ## Use a service from a function
36
+
37
+ ```ts
38
+ export const checkout = app.mutation({
39
+ access: "orders.write",
40
+ args: { orderId: s.string() },
41
+ handler: async (ctx, { orderId }) => {
42
+ await ctx.services.jobs.enqueue("invoice.send", { orderId }); // runs later, as this caller
43
+ await ctx.services.webhooks.emit("order.paid", { orderId }); // to subscribed endpoints
44
+ await ctx.services.notifications.send({ recipient: "ada", type: "order", title: "Paid" });
45
+ const region = await ctx.services.configuration.get("REGION");
46
+ return { region };
47
+ },
48
+ });
49
+ ```
50
+
51
+ Service effects commit on their own: they are not part of the mutation's transaction.
52
+
53
+ ## Configure a service
54
+
55
+ Configuration happens in AppPort Services' own pages, opened from FeltKit Studio: **Services → Manage**, acting as a
56
+ declared dev identity (development only). Those pages are the package's; FeltKit only signs you in. Do not write a
57
+ second configuration form or store settings elsewhere.
58
+
59
+ **Secrets.** Services store only references: `credential-ref:<id>`. FeltKit resolves a reference from the
60
+ environment variable `FELTKIT_CREDENTIAL_<ID>` (non-alphanumerics → `_`, upper-cased), inside the one effect that
61
+ needs it. Example: a webhook endpoint with `credential-ref:stripe-signing` signs with `FELTKIT_CREDENTIAL_STRIPE_SIGNING`.
62
+ Never put a secret value in code, configuration variables, a commit, a log, or a reply. Ask the user to set the
63
+ variable themselves. Studio's Services screen shows each reference as set or missing — never its value.
64
+
65
+ **API keys** are shown once when created (or rotated). FeltKit accepts them on `/appport` and `/mcp` as an identity
66
+ holding `services.apiKeys.roles`. In production `FELTKIT_API_KEY_VERIFIER_KEY` (≥ 32 bytes) must be set; changing it
67
+ invalidates every key.
68
+
69
+ **Moving configuration to production.** `feltkit config export --out config.json` writes development's variables,
70
+ credential binding names and references, active webhook endpoints, and enabled schedules (never a secret value).
71
+ `feltkit config import config.json --env production --dry-run` shows the plan; run it again without `--dry-run`,
72
+ on the host with the server stopped, to apply it. Imports never create credential bindings: attach each one it
73
+ lists and have the user set its `FELTKIT_CREDENTIAL_<ID>`. Schedules are listed, not imported.
74
+
75
+ ## Troubleshoot
76
+
77
+ Service states in Studio and `npx feltkit inspect --json`: `available` (not enabled), `unconfigured`, `configured`,
78
+ `unhealthy` (store check failed, a required secret is missing, or recent work failed), `unavailable`.
79
+
80
+ | Symptom | Look at | Usual cause |
81
+ |---|---|---|
82
+ | Job `failed` | Services → Job runs (`lastError`), Activity filtered to `via: job` | The handler function threw; or `DENIED` — the enqueuer no longer has an active session or key |
83
+ | Job never runs | `services.jobs.handlers` | No handler for the type (enqueue refuses unknown types) |
84
+ | Delivery `failed` | Services → Webhook deliveries (`lastStatusCode`, `lastError`), Credentials | Signing credential not set; receiver returned 4xx (not retried); destination did not resolve |
85
+ | Endpoint rejected on registration | the error | Private/loopback URLs are refused outside development |
86
+ | Variable set in the page is missing in code | the environment | The page edits the running environment's scope; check `ctx.environment.name` |
87
+
88
+ Durable work (jobs, schedules, deliveries) re-authorizes every attempt **as the principal that created it**. If
89
+ that principal signs out everywhere or its key is revoked, its pending work is refused — by design.
90
+
91
+ Retry or replay from Studio (Job runs → Retry, Deliveries → Replay), or ask the FeltKit agent to diagnose it
92
+ (see the feltkit-agent skill). In tests, drive due work explicitly: `await app.runtime.runServices()`.
93
+
94
+ ## Requires approval
95
+
96
+ Revoking or rotating API keys, disabling endpoints, deleting configuration or secrets, and replaying deliveries
97
+ affect other systems. Confirm with the user before doing any of them.
98
+
99
+ ## Compatibility
100
+
101
+ `@feltdb/feltkit` 0.1.x with `@appport/services` 0.7.0 (shared instance). The console is development-only.
102
+ Verified in Claude Code only.