@feltdb/feltkit 0.3.6 → 0.3.7

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 (44) hide show
  1. package/appboundry/engine.wasm +0 -0
  2. package/dist/appboundry/build.d.ts +106 -0
  3. package/dist/appboundry/build.js +306 -0
  4. package/dist/appboundry/build.js.map +1 -0
  5. package/dist/appboundry/codec.d.ts +6 -0
  6. package/dist/appboundry/codec.js +98 -0
  7. package/dist/appboundry/codec.js.map +1 -0
  8. package/dist/appboundry/guest-index.d.ts +9 -0
  9. package/dist/appboundry/guest-index.js +10 -0
  10. package/dist/appboundry/guest-index.js.map +1 -0
  11. package/dist/appboundry/guest.d.ts +3 -0
  12. package/dist/appboundry/guest.js +300 -0
  13. package/dist/appboundry/guest.js.map +1 -0
  14. package/dist/appboundry/wasm.d.ts +12 -0
  15. package/dist/appboundry/wasm.js +68 -0
  16. package/dist/appboundry/wasm.js.map +1 -0
  17. package/dist/cli/main.js +15 -1
  18. package/dist/cli/main.js.map +1 -1
  19. package/dist/dashboard/assets/index-OfCJSyfP.js +15 -0
  20. package/dist/dashboard/assets/index-dGaQg6ak.css +1 -0
  21. package/dist/dashboard/index.html +3 -3
  22. package/dist/dashboard/theme.js +9 -4
  23. package/dist/runtime/assemble.d.ts +2 -0
  24. package/dist/runtime/assemble.js +45 -0
  25. package/dist/runtime/assemble.js.map +1 -0
  26. package/dist/runtime/capabilities.d.ts +2 -0
  27. package/dist/runtime/capabilities.js +24 -0
  28. package/dist/runtime/capabilities.js.map +1 -0
  29. package/dist/runtime/collections.d.ts +7 -0
  30. package/dist/runtime/collections.js +18 -0
  31. package/dist/runtime/collections.js.map +1 -0
  32. package/dist/runtime/data.d.ts +2 -6
  33. package/dist/runtime/data.js +2 -16
  34. package/dist/runtime/data.js.map +1 -1
  35. package/dist/runtime/loader.d.ts +2 -1
  36. package/dist/runtime/loader.js +2 -38
  37. package/dist/runtime/loader.js.map +1 -1
  38. package/dist/runtime/runtime.js +16 -28
  39. package/dist/runtime/runtime.js.map +1 -1
  40. package/package.json +6 -2
  41. package/skills/.claude-plugin/marketplace.json +1 -1
  42. package/skills/.claude-plugin/plugin.json +1 -1
  43. package/dist/dashboard/assets/index-B-ra0AY9.css +0 -1
  44. package/dist/dashboard/assets/index-DLFqtVAO.js +0 -15
@@ -0,0 +1,300 @@
1
+ /**
2
+ * The FeltKit runtime inside an AppBoundry artifact (guest ABI appboundry-guest/1).
3
+ *
4
+ * This file is bundled, with the application's own `feltkit/` modules, into the program
5
+ * that the guest engine (appboundry/engine) evaluates. It runs handlers with the same
6
+ * `ctx` an application gets from `feltkit dev`, but it owns nothing: every read, write,
7
+ * and service effect is an operation it asks the host for, and the host (AppBoundry)
8
+ * validates each one against the artifact's manifest before performing it.
9
+ *
10
+ * __abg.describe() what this program implements (checked by the host on load)
11
+ * __abg.invoke(json) start one function call
12
+ * __abg.resume(json) results of the operations the call was waiting for
13
+ * __abg.poll() { state: "suspended", calls } | { state: "returned", value } | { state: "failed", error }
14
+ *
15
+ * Suspend and resume: an operation is a promise that stays pending until the host
16
+ * answers it. When the engine has run every job it can, poll() hands the host the
17
+ * operations still outstanding (several, when a handler awaits them together).
18
+ *
19
+ * Kept from FeltKit: argument, record, and `returns` validation with the application's
20
+ * own schemas, FeltKit's error shapes and messages, and `ctx.auth`. The host checks the
21
+ * same schemas and permissions again, independently: the guest is never trusted to
22
+ * enforce them. Writes are buffered by the host, which commits them atomically when the
23
+ * handler returns and discards them if it throws.
24
+ */
25
+ import { grantsPermission } from "@appport/authorization";
26
+ import { FeltKitError, isFeltKitError } from "../errors.js";
27
+ import { validate } from "../schema.js";
28
+ import { assemble } from "../runtime/assemble.js";
29
+ import { CollectionResolver } from "../runtime/collections.js";
30
+ import { fromBase64, toBase64, utf8Decode, utf8Encode, installTextCodecs } from "./codec.js";
31
+ export const GUEST_ABI = "appboundry-guest/1";
32
+ const UNSUPPORTED = (what) => new FeltKitError("CONFIGURATION", `${what} is not available in an AppBoundry artifact.`, {
33
+ hint: "`feltkit build --target appboundry` refuses applications that use it; this call should not have been reachable.",
34
+ });
35
+ /** Install `globalThis.__abg` for the modules of one application. */
36
+ export function installGuest(namespaces, producer) {
37
+ installTextCodecs();
38
+ const project = assemble(namespaces);
39
+ const resolver = new CollectionResolver(project.app.collections);
40
+ let pending = new Map();
41
+ let outbox = [];
42
+ let logs = [];
43
+ let settled = null;
44
+ let active = false;
45
+ let nextId = 1;
46
+ const host = (op, payload) => new Promise((resolve, reject) => {
47
+ const id = nextId++;
48
+ pending.set(id, { resolve: resolve, reject });
49
+ outbox.push({ id, op, ...payload });
50
+ });
51
+ const log = (level) => (message, fields) => {
52
+ logs.push({ level, message: String(message), ...(fields ? { fields: plain(fields) } : {}) });
53
+ };
54
+ const errorJSON = (error, production) => {
55
+ if (isFeltKitError(error))
56
+ return error.toJSON();
57
+ const message = error?.message ?? String(error);
58
+ log("error")(`Unhandled error: ${message}`, error?.stack ? { stack: error.stack } : undefined);
59
+ if (production)
60
+ return { code: "INTERNAL", message: "Internal error." };
61
+ return { code: "INTERNAL", message, hint: "This error was thrown by application code. Throw FeltKitError (or use fail()) to return a structured error." };
62
+ };
63
+ const run = async (fn, invocation) => {
64
+ const parsed = validate(fn.argsSchema, invocation.args ?? {});
65
+ if (!parsed.ok) {
66
+ throw new FeltKitError("INVALID_ARGUMENT", `Invalid arguments for ${invocation.function}: ${parsed.issues.map((i) => `${i.path}: ${i.message}`).join("; ")}`, {
67
+ details: { issues: parsed.issues },
68
+ });
69
+ }
70
+ const writable = fn.kind === "mutation";
71
+ const ctx = {
72
+ db: database(resolver, host, writable),
73
+ auth: authContext(invocation.principal, invocation.permissions),
74
+ services: services(host, writable),
75
+ environment: invocation.environment,
76
+ requestId: invocation.requestId,
77
+ log: { info: log("info"), warn: log("warn"), error: log("error") },
78
+ };
79
+ if (writable) {
80
+ Object.defineProperty(ctx, "agent", { enumerable: true, get: () => { throw UNSUPPORTED("ctx.agent"); } });
81
+ Object.defineProperty(ctx, "unsafe", { enumerable: true, get: () => { throw UNSUPPORTED("ctx.unsafe.feltdb"); } });
82
+ }
83
+ const value = await fn.handler(ctx, parsed.value);
84
+ if (fn.returns) {
85
+ const output = validate(fn.returns, value);
86
+ if (!output.ok) {
87
+ throw new FeltKitError("INTERNAL", `${invocation.function} returned a value that does not match its \`returns\` schema: ${output.issues.map((i) => `${i.path}: ${i.message}`).join("; ")}`);
88
+ }
89
+ }
90
+ return value === undefined ? null : value;
91
+ };
92
+ const status = () => {
93
+ const drained = logs;
94
+ logs = [];
95
+ if (settled) {
96
+ const done = { ...settled, logs: [...settled.logs, ...drained] };
97
+ active = false;
98
+ settled = null;
99
+ pending = new Map();
100
+ outbox = [];
101
+ return done;
102
+ }
103
+ const calls = outbox;
104
+ outbox = [];
105
+ return { state: "suspended", calls, logs: drained };
106
+ };
107
+ globalThis.__abg = {
108
+ describe() {
109
+ return JSON.stringify({
110
+ ok: true,
111
+ abi: GUEST_ABI,
112
+ producer,
113
+ application: project.app.name,
114
+ functions: [...project.functions.entries()].map(([name, fn]) => ({ name, kind: fn.kind })).sort((a, b) => a.name.localeCompare(b.name)),
115
+ });
116
+ },
117
+ invoke(json) {
118
+ if (active)
119
+ throw new Error("A call is already running in this instance.");
120
+ active = true;
121
+ settled = null;
122
+ const invocation = JSON.parse(json);
123
+ const production = invocation.environment?.production === true;
124
+ const fn = project.functions.get(invocation.function);
125
+ if (!fn) {
126
+ settled = { state: "failed", error: new FeltKitError("FUNCTION_NOT_FOUND", `No query or mutation named "${invocation.function}".`).toJSON(), logs: [] };
127
+ return;
128
+ }
129
+ run(fn, invocation).then((value) => { settled = { state: "returned", value: plain(value), logs: [] }; }, (error) => { settled = { state: "failed", error: errorJSON(error, production), logs: [] }; });
130
+ },
131
+ resume(json) {
132
+ for (const result of JSON.parse(json)) {
133
+ const waiting = pending.get(result.id);
134
+ if (!waiting)
135
+ continue;
136
+ pending.delete(result.id);
137
+ if (result.ok)
138
+ waiting.resolve(result.value);
139
+ else {
140
+ const error = result.error ?? { code: "INTERNAL", message: "The host refused the operation." };
141
+ waiting.reject(new FeltKitError(error.code, error.message, { ...(error.details !== undefined ? { details: error.details } : {}), ...(error.hint ? { hint: error.hint } : {}) }));
142
+ }
143
+ }
144
+ },
145
+ poll() {
146
+ return JSON.stringify(status());
147
+ },
148
+ };
149
+ }
150
+ /** A JSON-safe copy: what crosses the boundary is data, never live objects. */
151
+ function plain(value) {
152
+ if (value === undefined)
153
+ return null;
154
+ return JSON.parse(JSON.stringify(value, (_key, v) => (v instanceof Uint8Array ? { $bytes: toBase64(v) } : v)));
155
+ }
156
+ function authContext(principal, granted) {
157
+ const permissions = Object.freeze([...granted]);
158
+ return Object.freeze({
159
+ principal,
160
+ permissions,
161
+ has: (permission) => grantsPermission([...permissions], permission),
162
+ require(permission) {
163
+ if (!principal)
164
+ throw new FeltKitError("UNAUTHORIZED", "Authentication is required");
165
+ if (!grantsPermission([...permissions], permission))
166
+ throw new FeltKitError("FORBIDDEN", `Missing permission: ${permission}`);
167
+ },
168
+ requirePrincipal() {
169
+ if (!principal)
170
+ throw new FeltKitError("UNAUTHORIZED", "Authentication is required");
171
+ return principal;
172
+ },
173
+ });
174
+ }
175
+ function stripSystem(value) {
176
+ const { id: _id, __version: _v, ...rest } = value;
177
+ return rest;
178
+ }
179
+ function validateRecord(resolver, name, value) {
180
+ const definition = resolver.resolve(name);
181
+ const result = validate(definition.schema, value);
182
+ if (!result.ok) {
183
+ throw new FeltKitError("VALIDATION_FAILED", `Invalid "${definition.name}" record: ${result.issues.map((i) => `${i.path}: ${i.message}`).join("; ")}`, {
184
+ details: { collection: definition.name, issues: result.issues },
185
+ });
186
+ }
187
+ }
188
+ /** `ctx.db`. Reads and writes are host operations; the host keeps the mutation's pending writes. */
189
+ function database(resolver, host, writable) {
190
+ const name = (ref) => resolver.resolve(ref).name;
191
+ const reader = {
192
+ get: (ref, id) => {
193
+ const collection = name(ref);
194
+ if (typeof id !== "string" || !id)
195
+ throw new FeltKitError("INVALID_ARGUMENT", "get() needs a record id.");
196
+ return host("db.get", { collection, key: id });
197
+ },
198
+ find: (ref, filter, options = {}) => host("db.find", { collection: name(ref), filter: definedOnly(filter), options: plain(options) }),
199
+ query: (ref, request) => host("db.query", { collection: name(ref), request: plain(request ?? {}) }),
200
+ count: (ref, filter) => host("db.count", { collection: name(ref), filter: definedOnly(filter) }),
201
+ };
202
+ if (!writable)
203
+ return reader;
204
+ return {
205
+ ...reader,
206
+ insert: async (ref, value) => {
207
+ const collection = name(ref);
208
+ if (!value || typeof value !== "object")
209
+ throw new FeltKitError("INVALID_ARGUMENT", "insert() needs a record object.");
210
+ const fields = stripSystem(value);
211
+ validateRecord(resolver, collection, fields);
212
+ return host("db.insert", { collection, value: plain(fields) });
213
+ },
214
+ patch: (ref, id, fields) => {
215
+ const collection = name(ref);
216
+ const set = stripSystem(fields ?? {});
217
+ // JSON has no undefined: a field patched to undefined is removed, as in FeltKit.
218
+ const unset = Object.entries(set).filter(([, v]) => v === undefined).map(([k]) => k);
219
+ return host("db.patch", { collection, key: id, fields: plain(set), unset });
220
+ },
221
+ replace: (ref, id, value) => {
222
+ const collection = name(ref);
223
+ const fields = stripSystem(value ?? {});
224
+ validateRecord(resolver, collection, fields);
225
+ return host("db.replace", { collection, key: id, value: plain(fields) });
226
+ },
227
+ delete: async (ref, id) => {
228
+ await host("db.delete", { collection: name(ref), key: id });
229
+ },
230
+ };
231
+ }
232
+ function definedOnly(filter) {
233
+ return plain(Object.fromEntries(Object.entries(filter ?? {}).filter(([, v]) => v !== undefined)));
234
+ }
235
+ /** `ctx.services`, as FeltKit binds them. Every method is one host operation on AppPort Services. */
236
+ function services(host, writable) {
237
+ const call = (service, method, input = {}) => host("service", { service, method, input: plain(input) });
238
+ const withBytes = (read) => {
239
+ const bytes = fromBase64(read.content);
240
+ return { file: read.file, bytes, text: () => utf8Decode(bytes) };
241
+ };
242
+ const filesReader = {
243
+ list: (filter = {}) => call("files", "list", { filter }),
244
+ get: (id) => call("files", "get", { id }),
245
+ read: async (id) => withBytes(await call("files", "read", { id })),
246
+ };
247
+ const notificationsReader = {
248
+ list: (filter = {}) => call("notifications", "list", { filter }),
249
+ get: (id) => call("notifications", "get", { id }),
250
+ };
251
+ const configurationReader = {
252
+ list: () => call("configuration", "list"),
253
+ get: async (name) => (await call("configuration", "list"))[name] ?? null,
254
+ };
255
+ if (!writable)
256
+ return { files: filesReader, notifications: notificationsReader, configuration: configurationReader };
257
+ return {
258
+ files: {
259
+ ...filesReader,
260
+ upload: (input) => {
261
+ if (!input || typeof input.name !== "string" || !input.name.trim())
262
+ throw new FeltKitError("INVALID_ARGUMENT", "upload() needs a file name.");
263
+ const bytes = typeof input.content === "string" ? utf8Encode(input.content) : input.content;
264
+ if (!(bytes instanceof Uint8Array))
265
+ throw new FeltKitError("INVALID_ARGUMENT", "upload() content must be a string or Uint8Array.");
266
+ return call("files", "upload", {
267
+ name: input.name,
268
+ ...(input.contentType ? { contentType: input.contentType } : {}),
269
+ content: toBase64(bytes),
270
+ ...(input.metadata ? { metadata: input.metadata } : {}),
271
+ });
272
+ },
273
+ remove: async (id) => {
274
+ await call("files", "remove", { id });
275
+ },
276
+ },
277
+ notifications: {
278
+ ...notificationsReader,
279
+ send: (input) => call("notifications", "send", input),
280
+ markRead: (id) => call("notifications", "markRead", { id }),
281
+ dismiss: (id) => call("notifications", "dismiss", { id }),
282
+ },
283
+ configuration: {
284
+ ...configurationReader,
285
+ set: async (name, value) => {
286
+ await call("configuration", "set", { name, value });
287
+ },
288
+ remove: async (name) => {
289
+ await call("configuration", "remove", { name });
290
+ },
291
+ },
292
+ jobs: {
293
+ enqueue: (type, payload = {}, options = {}) => call("jobs", "enqueue", { type, payload, options }),
294
+ },
295
+ webhooks: {
296
+ emit: (type, payload) => call("webhooks", "emit", { type, payload }),
297
+ },
298
+ };
299
+ }
300
+ //# sourceMappingURL=guest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guest.js","sourceRo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AAM,IAAI,CAAC,eAAe,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YACtD,CAAC;YACD,MAAM,EAAE,KAAK,EAAE,IAAY,EAAE,EAAE;gBAC7B,MAAM,IAAI,CAAC,eAAe,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,CAAC;SACF;QACD,IAAI,EAAE;YACJ,OAAO,EAAE,CAAC,IAAY,EAAE,UAAmC,EAAE,EAAE,UAAmC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;SAC7J;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,CAAC,IAAY,EAAE,OAAgC,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;SACtG;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The few WebAssembly binary operations the AppBoundry target needs: append a custom
3
+ * section, read one back. A custom section is covered by the module's hash and ignored
4
+ * by the engine's code, so the program travels inside module.wasm itself.
5
+ */
6
+ /** The custom section holding the application program (UTF-8 JavaScript). */
7
+ export declare const PROGRAM_SECTION = "appboundry.program";
8
+ export declare function appendCustomSection(module: Uint8Array, name: string, payload: Uint8Array): Uint8Array;
9
+ export declare function customSections(module: Uint8Array): Array<{
10
+ name: string;
11
+ payload: Uint8Array;
12
+ }>;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The few WebAssembly binary operations the AppBoundry target needs: append a custom
3
+ * section, read one back. A custom section is covered by the module's hash and ignored
4
+ * by the engine's code, so the program travels inside module.wasm itself.
5
+ */
6
+ /** The custom section holding the application program (UTF-8 JavaScript). */
7
+ export const PROGRAM_SECTION = "appboundry.program";
8
+ function uleb(value) {
9
+ const out = [];
10
+ do {
11
+ let byte = value & 0x7f;
12
+ value >>>= 7;
13
+ if (value !== 0)
14
+ byte |= 0x80;
15
+ out.push(byte);
16
+ } while (value !== 0);
17
+ return out;
18
+ }
19
+ function readUleb(bytes, offset) {
20
+ let result = 0;
21
+ let shift = 0;
22
+ for (;;) {
23
+ const byte = bytes[offset++];
24
+ result += (byte & 0x7f) * 2 ** shift;
25
+ if ((byte & 0x80) === 0)
26
+ return [result, offset];
27
+ shift += 7;
28
+ }
29
+ }
30
+ const MAGIC = [0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];
31
+ function assertModule(bytes) {
32
+ if (bytes.length < 8 || MAGIC.some((b, i) => bytes[i] !== b))
33
+ throw new Error("not a WebAssembly 1.0 module");
34
+ }
35
+ export function appendCustomSection(module, name, payload) {
36
+ assertModule(module);
37
+ if (customSections(module).some((section) => section.name === name))
38
+ throw new Error(`the module already has a "${name}" section`);
39
+ const encodedName = new TextEncoder().encode(name);
40
+ const content = [...uleb(encodedName.length), ...encodedName];
41
+ const size = content.length + payload.length;
42
+ const header = new Uint8Array([0x00, ...uleb(size), ...content]);
43
+ const out = new Uint8Array(module.length + header.length + payload.length);
44
+ out.set(module, 0);
45
+ out.set(header, module.length);
46
+ out.set(payload, module.length + header.length);
47
+ return out;
48
+ }
49
+ export function customSections(module) {
50
+ assertModule(module);
51
+ const found = [];
52
+ let offset = 8;
53
+ while (offset < module.length) {
54
+ const id = module[offset++];
55
+ const [size, start] = readUleb(module, offset);
56
+ const end = start + size;
57
+ if (end > module.length)
58
+ throw new Error("truncated section");
59
+ if (id === 0) {
60
+ const [nameLength, nameStart] = readUleb(module, start);
61
+ const name = new TextDecoder().decode(module.subarray(nameStart, nameStart + nameLength));
62
+ found.push({ name, payload: module.subarray(nameStart + nameLength, end) });
63
+ }
64
+ offset = end;
65
+ }
66
+ return found;
67
+ }
68
+ //# sourceMappingURL=wasm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm.js","sourceRoot":"","sources":["../../src/appboundry/wasm.ts"],"names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AAG,MAAM,CAAC,MAAM,EAAE,CAAC;QAC9B,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,CAAE,CAAC;QAC7B,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/C,MAAM,GAAG,GAAG,KAAK,GAAG,IAAI,CAAC;QACzB,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC9D,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;YACb,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACxD,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC;YAC1F,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS,GAAG,UAAU,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAC9E,CAAC;QACD,MAAM,GAAG,GAAG,CAAC;IACf,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/dist/cli/main.js CHANGED
@@ -87,7 +87,7 @@ Docs: https://github.com/rkendel1/concave#readme`;
87
87
  const COMMAND_HELP = {
88
88
  create: "feltkit create <dir> [--name <app-name>] [--template tasks|managed]\n Copies a starter into <dir>: tasks (default; local FeltDB) or managed (Managed FeltDB, --managed).\n Refuses to write into a non-empty directory.",
89
89
  dev: "feltkit dev [--port 3000] [--host 127.0.0.1] [--no-frontend]\n Development environment: state in .feltkit/development/state.",
90
- build: "feltkit build\n Writes .feltkit/build/functions.mjs and dist/client, then loads the bundle to verify it.",
90
+ build: "feltkit build [--target appboundry] [--out <dir>]\n Writes .feltkit/build/functions.mjs and dist/client, then loads the bundle to verify it.\n --target appboundry also compiles <name>.app: manifest.json, module.wasm (imports nothing) and the\n frontend, which `appboundry run <name>.app` runs without this project, Node tooling, or FeltKit.",
91
91
  start: "feltkit start [--port $PORT] [--host 0.0.0.0] [--env production]\n Uses FELTDB_URL + FELTDB_TOKEN when set, else FELTKIT_STATE_DIR or .feltkit/production/state.",
92
92
  test: "feltkit test [files…]\n Runs node --test on tests/**/*.test.ts with FELTKIT_ENV=test.",
93
93
  inspect: "feltkit inspect [--json] [--env development]\n Reads from the running server when there is one; otherwise opens the environment directly.",
@@ -348,6 +348,20 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
348
348
  const result = await build(projectDir);
349
349
  line(`${symbols.ok} Backend ${result.bundle.replace(projectDir + "/", "")} ${c.dim(`(${result.functions} functions, ${result.capabilities} capabilities, verified by loading the bundle)`)}`);
350
350
  line(result.client ? `${symbols.ok} Frontend ${result.client.replace(projectDir + "/", "")} ${c.dim("(scanned: no server-only values)")}` : `${symbols.info} No frontend (no index.html)`);
351
+ if (flags.target !== undefined) {
352
+ if (String(flags.target) !== "appboundry")
353
+ throw new FeltKitError("INVALID_ARGUMENT", `Unknown build target "${String(flags.target)}".`, { hint: "feltkit build --target appboundry" });
354
+ const { buildAppBoundry } = await import("../appboundry/build.js");
355
+ const artifact = await buildAppBoundry(projectDir, { bundle: result.bundle, client: result.client, producerVersion: SDK_VERSION, ...(flags.out ? { outDir: resolve(projectDir, String(flags.out)) } : {}) });
356
+ const m = artifact.manifest;
357
+ line(`${symbols.ok} Artifact ${artifact.path.replace(projectDir + "/", "")} ${c.dim(`(${m.functions.length} functions, ${m.functions.filter((f) => f.capability).length} capabilities, ${m.collections.length} collections, ${m.frontend ? `${m.frontend.files.length} frontend files` : "no frontend"})`)}`);
358
+ line(` ${c.bold("module.wasm")} sha256:${m.module.sha256.slice(0, 16)}… ${c.dim(`${(m.module.size / 1024 / 1024).toFixed(1)} MB, imports nothing; loaded in the guest engine to verify`)}`);
359
+ line(` ${c.bold("Host access")} collections ${m.permissions.collections.read.join(", ") || "none"}; services ${m.permissions.services.join(", ") || "none"}; network none; filesystem none`);
360
+ for (const note of artifact.omitted)
361
+ line(` ${symbols.info} ${c.dim(`Not in the artifact: ${note}`)}`);
362
+ line(c.dim(`\nRun it with AppBoundry: appboundry run ${artifact.path.replace(projectDir + "/", "")}`));
363
+ return 0;
364
+ }
351
365
  line(c.dim("\nRun it with `feltkit start`, or package it with `feltkit deploy`."));
352
366
  return 0;
353
367
  }