@feltdb/feltkit 0.3.14 → 0.3.16

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 (46) hide show
  1. package/dist/app.d.ts +11 -0
  2. package/dist/app.js.map +1 -1
  3. package/dist/appboundry/build.d.ts +8 -1
  4. package/dist/appboundry/build.js +8 -1
  5. package/dist/appboundry/build.js.map +1 -1
  6. package/dist/appboundry/guest.js +16 -0
  7. package/dist/appboundry/guest.js.map +1 -1
  8. package/dist/appboundry/host.js +8 -1
  9. package/dist/appboundry/host.js.map +1 -1
  10. package/dist/appboundry/runtime.d.ts +5 -0
  11. package/dist/appboundry/runtime.js +5 -0
  12. package/dist/appboundry/runtime.js.map +1 -1
  13. package/dist/authorize.d.ts +63 -0
  14. package/dist/authorize.js +45 -0
  15. package/dist/authorize.js.map +1 -0
  16. package/dist/cli/deploy-appboundry-self-hosted.d.ts +16 -0
  17. package/dist/cli/deploy-appboundry-self-hosted.js +200 -0
  18. package/dist/cli/deploy-appboundry-self-hosted.js.map +1 -0
  19. package/dist/cli/deploy-appboundry.d.ts +142 -0
  20. package/dist/cli/deploy-appboundry.js +263 -0
  21. package/dist/cli/deploy-appboundry.js.map +1 -0
  22. package/dist/cli/main.js +106 -5
  23. package/dist/cli/main.js.map +1 -1
  24. package/dist/docs.d.ts +1 -1
  25. package/dist/docs.js +2 -1
  26. package/dist/docs.js.map +1 -1
  27. package/dist/index.d.ts +2 -0
  28. package/dist/runtime/activity.d.ts +5 -0
  29. package/dist/runtime/activity.js.map +1 -1
  30. package/dist/runtime/context.d.ts +5 -0
  31. package/dist/runtime/crypto-token.d.ts +8 -0
  32. package/dist/runtime/crypto-token.js +17 -0
  33. package/dist/runtime/crypto-token.js.map +1 -0
  34. package/dist/runtime/runtime.d.ts +0 -9
  35. package/dist/runtime/runtime.js +35 -1
  36. package/dist/runtime/runtime.js.map +1 -1
  37. package/dist/server/admin.d.ts +1 -1
  38. package/docs/APPBOUNDRY-DEPLOY-CONTRACT.md +49 -0
  39. package/docs/APPBOUNDRY.md +43 -0
  40. package/docs/GUARANTEES.md +22 -0
  41. package/docs/README.md +4 -3
  42. package/docs/UPSTREAM-GAPS.md +2 -0
  43. package/package.json +2 -2
  44. package/skills/.claude-plugin/marketplace.json +1 -1
  45. package/skills/.claude-plugin/plugin.json +1 -1
  46. package/skills/feltkit-build/SKILL.md +3 -2
@@ -0,0 +1,263 @@
1
+ /**
2
+ * `feltkit deploy --target appboundry`: hand the application's artifact to the AppBoundry control plane.
3
+ *
4
+ * FeltKit builds the application and its immutable artifact. AppBoundry registers, deploys, executes and
5
+ * operates it. FeltKit never generates or manages the execution environment: whether an AppBoundry host
6
+ * runs the artifact in Docker, Podman, a microVM or something else is AppBoundry's business, and nothing
7
+ * here depends on it. (For running the AppBoundry runtime yourself, see deploy-appboundry-self-hosted.ts.)
8
+ *
9
+ * Three outputs, three owners:
10
+ * application artifact FeltKit build .feltkit/appboundry/<name>.app (immutable)
11
+ * deployment request FeltKit -> AppBoundry upload + deployment intent, over the portal API
12
+ * execution environment AppBoundry never visible here
13
+ *
14
+ * The contract is AppBoundry's managed-hosting API (rkendel1/appboundry apps/cloud-portal), authenticated with an AppBoundry
15
+ * deploy token (`Authorization: Bearer abd_…`):
16
+ * GET /api/applications/{id}/hosting registered? artifacts, deployments
17
+ * POST /api/applications/{id}/artifacts the artifact as .tar.gz, x-archive-sha256; verified there, stored
18
+ * immutably; registers the application from it when the token may
19
+ * POST /api/applications/{id}/deployments { artifactId, hostId? }, Idempotency-Key; AppBoundry places it
20
+ * GET /api/applications/{id}/deployments/{deployment} state, the runtime's own evidence, and routing
21
+ * The contract: docs/APPBOUNDRY-DEPLOY-CONTRACT.md; the fixtures both sides test against: test/fixtures/appboundry-contract.json.
22
+ *
23
+ * A deployment is reported Running only when AppBoundry says so AND the evidence it holds names the module
24
+ * this build produced (the runtime reports its module SHA-256; the portal only records it). Nothing is
25
+ * inferred from an upload or a request being accepted.
26
+ */
27
+ import { createHash, randomBytes } from "node:crypto";
28
+ import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
29
+ import { join, relative, resolve } from "node:path";
30
+ import { gzipSync } from "node:zlib";
31
+ import { FeltKitError } from "../errors.js";
32
+ import { SDK_VERSION, build } from "../server/project.js";
33
+ import { buildAppBoundry } from "../appboundry/build.js";
34
+ export const APPBOUNDRY_TARGET_TITLE = "AppBoundry: send the verified artifact to AppBoundry, which deploys and operates it";
35
+ /** Where the deployment request's result is recorded, for `feltkit status`. */
36
+ export const APPBOUNDRY_RECORD = join(".feltkit", "appboundry", "deployment.json");
37
+ /** Read the connection from options, then the environment. Refuses http except to loopback. */
38
+ export function appboundryConnection(options = {}) {
39
+ const env = options.env ?? process.env;
40
+ const portal = (options.portal ?? env.APPBOUNDRY_URL ?? "").replace(/\/+$/, "");
41
+ const token = env.APPBOUNDRY_TOKEN ?? "";
42
+ const hostId = options.hostId ?? env.APPBOUNDRY_HOST ?? "";
43
+ const missing = [!portal && "APPBOUNDRY_URL (the AppBoundry portal)", !token && "APPBOUNDRY_TOKEN (an AppBoundry deploy token)"].filter(Boolean);
44
+ if (missing.length)
45
+ throw new FeltKitError("CONFIGURATION", `Deploying to AppBoundry needs ${missing.join(", ")}.`, { hint: "Set them in the environment (or pass --portal and --host). The token is read from the environment only and is never printed or stored." });
46
+ let url;
47
+ try {
48
+ url = new URL(portal);
49
+ }
50
+ catch {
51
+ throw new FeltKitError("CONFIGURATION", `APPBOUNDRY_URL is not a URL: ${portal}`);
52
+ }
53
+ const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
54
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback))
55
+ throw new FeltKitError("CONFIGURATION", "APPBOUNDRY_URL must be https (http only for a portal on this machine).");
56
+ return { portal: url.origin, token, ...(hostId ? { hostId } : {}) };
57
+ }
58
+ /**
59
+ * The artifact folder as a deterministic ustar .tar.gz: files at the root, sorted, fixed modes and times,
60
+ * so the same artifact always has the same archive digest. This is the format the portal ingests.
61
+ */
62
+ export function artifactArchive(dir) {
63
+ const files = [];
64
+ const walk = (current) => {
65
+ for (const name of readdirSync(current).sort()) {
66
+ const path = join(current, name);
67
+ if (statSync(path).isDirectory())
68
+ walk(path);
69
+ else
70
+ files.push(path);
71
+ }
72
+ };
73
+ walk(dir);
74
+ const parts = [];
75
+ for (const file of files) {
76
+ const name = relative(dir, file).split("\\").join("/");
77
+ const content = readFileSync(file);
78
+ const block = Buffer.alloc(512);
79
+ const encoded = Buffer.from(name);
80
+ if (encoded.length <= 100)
81
+ encoded.copy(block, 0);
82
+ else {
83
+ const cut = name.lastIndexOf("/");
84
+ const prefix = name.slice(0, cut), base = name.slice(cut + 1);
85
+ if (Buffer.byteLength(base) > 100 || Buffer.byteLength(prefix) > 155)
86
+ throw new FeltKitError("CONFIGURATION", `An artifact path is too long to archive: ${name}`);
87
+ block.write(base, 0);
88
+ block.write(prefix, 345);
89
+ }
90
+ block.write("0000644\0", 100);
91
+ block.write("0000000\0", 108);
92
+ block.write("0000000\0", 116);
93
+ block.write(`${content.length.toString(8).padStart(11, "0")}\0`, 124);
94
+ block.write("00000000000\0", 136);
95
+ block.write(" ", 148);
96
+ block.write("0", 156);
97
+ block.write("ustar\0", 257);
98
+ block.write("00", 263);
99
+ let sum = 0;
100
+ for (const byte of block)
101
+ sum += byte;
102
+ block.write(`${sum.toString(8).padStart(6, "0")}\0 `, 148);
103
+ parts.push(block, content);
104
+ const pad = (512 - (content.length % 512)) % 512;
105
+ if (pad)
106
+ parts.push(Buffer.alloc(pad));
107
+ }
108
+ parts.push(Buffer.alloc(1024));
109
+ return gzipSync(Buffer.concat(parts), { level: 9 });
110
+ }
111
+ /** One portal call, with the portal's own error codes surfaced as FeltKit errors that say what to do. */
112
+ async function call(conn, fetchImpl, path, init = {}) {
113
+ let response;
114
+ try {
115
+ response = await fetchImpl(`${conn.portal}${path}`, {
116
+ method: init.method ?? "GET",
117
+ headers: { authorization: `Bearer ${conn.token}`, accept: "application/json", "user-agent": `feltkit/${SDK_VERSION}`, ...(init.headers ?? {}) },
118
+ ...(init.body !== undefined ? { body: typeof init.body === "string" ? init.body : new Uint8Array(init.body) } : {}),
119
+ redirect: "error",
120
+ });
121
+ }
122
+ catch (error) {
123
+ throw new FeltKitError("UNAVAILABLE", `The AppBoundry portal at ${conn.portal} could not be reached: ${error.message}`);
124
+ }
125
+ const text = await response.text();
126
+ let body = {};
127
+ try {
128
+ body = text ? JSON.parse(text) : {};
129
+ }
130
+ catch {
131
+ body = { error: text.slice(0, 300) };
132
+ }
133
+ if (response.ok)
134
+ return { status: response.status, body: body };
135
+ const code = String(body?.code ?? "");
136
+ const message = String(body?.error ?? `HTTP ${response.status}`);
137
+ if (response.status === 401) {
138
+ throw new FeltKitError("UNAUTHORIZED", `AppBoundry did not accept APPBOUNDRY_TOKEN (${code || 401}): it is missing, malformed, unknown, revoked or expired.`, {
139
+ hint: "Ask the AppBoundry platform owner for a deploy token (portal: POST /api/deploy-tokens) and set it in APPBOUNDRY_TOKEN. FeltKit never prints or stores it.",
140
+ });
141
+ }
142
+ if (response.status === 403) {
143
+ throw new FeltKitError("FORBIDDEN", `AppBoundry: ${message}${code ? ` (${code})` : ""}`, {
144
+ hint: "The token is valid but its scope does not include this application. Use a token scoped to this application, or to the organization that holds it.",
145
+ });
146
+ }
147
+ if (code === "APPLICATION_NOT_REGISTERED") {
148
+ throw new FeltKitError("NOT_FOUND", message, { hint: "This token may not register applications. Register it once in the AppBoundry portal, or use a token whose scope allows registration (docs/APPBOUNDRY-DEPLOY-CONTRACT.md §3.2)." });
149
+ }
150
+ if (code === "NO_EXECUTION_CAPACITY") {
151
+ const reason = String(body?.details?.reason ?? "");
152
+ throw new FeltKitError("UNAVAILABLE", `AppBoundry has no execution capacity for this deployment${reason ? ` (${reason})` : ""}: ${message}`, {
153
+ details: { reason }, retryable: reason !== "untrusted_execution_disabled",
154
+ hint: reason === "untrusted_execution_disabled" ? "This AppBoundry does not run deploy-token deployments yet (its isolation release gate is closed). The artifact is stored; nothing was deployed." : "The artifact is stored; nothing was deployed. Try again later, or ask the platform owner about capacity.",
155
+ });
156
+ }
157
+ if (code === "ARCHIVE_DIGEST_MISMATCH")
158
+ throw new FeltKitError("UNAVAILABLE", `AppBoundry received a damaged upload (${code}); nothing was stored. Run the deploy again.`, { retryable: true });
159
+ throw new FeltKitError(response.status >= 500 ? "UNAVAILABLE" : "FAILED_PRECONDITION", `AppBoundry: ${message}${code ? ` (${code})` : ""}`);
160
+ }
161
+ const sleep = (ms) => new Promise((ok) => setTimeout(ok, ms));
162
+ const terminal = (state) => state === "Running" || state === "Failed" || state === "Stopped" || state === "Superseded";
163
+ /**
164
+ * Running counts only with evidence that names the module this build produced, observed on the deployment's current attempt
165
+ * (AppBoundry enforces both; FeltKit checks again rather than trusting the state word alone).
166
+ */
167
+ export function verifiedRunning(deployment, moduleSha256) {
168
+ const e = deployment.evidence;
169
+ return deployment.state === "Running" && deployment.moduleSha256 === moduleSha256 && e?.health === "ready" && e.observedModuleSha256 === moduleSha256
170
+ && e.attempt === (deployment.attempt ?? 1) && Boolean(e.instanceId) && Boolean(e.runtime);
171
+ }
172
+ /** The outcome FeltKit reports for what AppBoundry says now. */
173
+ export function outcomeOf(deployment, moduleSha256) {
174
+ return verifiedRunning(deployment, moduleSha256) ? "running" : terminal(deployment.state) ? "failed" : "pending";
175
+ }
176
+ export async function deployToAppBoundry(options) {
177
+ const fetchImpl = options.fetch ?? fetch;
178
+ const conn = options.connection;
179
+ const projectDir = resolve(options.projectDir);
180
+ const progress = options.onProgress ?? (() => { });
181
+ // 1. The artifact: the same build and checks as `feltkit build --target appboundry`.
182
+ const outDir = join(projectDir, ".feltkit", "appboundry");
183
+ mkdirSync(outDir, { recursive: true });
184
+ const built = await build(projectDir);
185
+ const artifact = await buildAppBoundry(projectDir, { bundle: built.bundle, client: built.client, producerVersion: SDK_VERSION, outDir });
186
+ const m = artifact.manifest;
187
+ const applicationId = m.application.id;
188
+ const archive = artifactArchive(artifact.path);
189
+ // The artifact's identity is the SHA-256 of its manifest; AppBoundry derives it the same way from what it received.
190
+ const artifactIdLocal = createHash("sha256").update(readFileSync(join(artifact.path, "manifest.json"))).digest("hex");
191
+ const archiveSha256 = createHash("sha256").update(archive).digest("hex");
192
+ progress({ step: "built", detail: `${relative(projectDir, artifact.path)} module sha256:${m.module.sha256}` });
193
+ // 2. Checks the credential before uploading, and whether AppBoundry already knows the application.
194
+ const hosting = await call(conn, fetchImpl, `/api/applications/${encodeURIComponent(applicationId)}/hosting`);
195
+ // 3. Upload: AppBoundry verifies the artifact itself, stores it immutably, and registers the application from
196
+ // it when it is new and the token's scope allows (contract §3.2). Same bytes, same artifact.
197
+ const uploaded = await call(conn, fetchImpl, `/api/applications/${encodeURIComponent(applicationId)}/artifacts`, {
198
+ method: "POST", body: archive, headers: { "content-type": "application/gzip", "x-archive-sha256": archiveSha256 },
199
+ });
200
+ const artifactId = uploaded.body.artifact.artifactId;
201
+ if (uploaded.body.artifact.module.sha256 !== m.module.sha256 || artifactId !== artifactIdLocal) {
202
+ throw new FeltKitError("FAILED_PRECONDITION", `AppBoundry recorded artifact ${artifactId} (module sha256:${uploaded.body.artifact.module.sha256}) for the upload, but this build is artifact ${artifactIdLocal} (module sha256:${m.module.sha256}). Nothing was deployed.`);
203
+ }
204
+ progress({ step: "uploaded", detail: `artifact ${artifactId}${uploaded.body.created ? "" : " (already stored)"}${uploaded.body.registeredNow || !hosting.body.registered ? "; application registered" : ""}` });
205
+ // 4. The deployment request. One idempotency key per run: a retried request cannot create a second deployment.
206
+ const idempotencyKey = `feltkit.${artifactId.slice(0, 16)}.${randomBytes(8).toString("hex")}`;
207
+ const requested = await call(conn, fetchImpl, `/api/applications/${encodeURIComponent(applicationId)}/deployments`, {
208
+ method: "POST", body: JSON.stringify({ artifactId, ...(conn.hostId ? { hostId: conn.hostId } : {}) }), headers: { "content-type": "application/json", "idempotency-key": idempotencyKey },
209
+ });
210
+ let deployment = requested.body.deployment;
211
+ progress({ step: "requested", detail: `deployment ${deployment.deploymentId}${deployment.hostId ? ` on ${deployment.hostId}` : ""}` });
212
+ record(projectDir, conn, { applicationId, artifactId, archiveSha256, moduleSha256: m.module.sha256, deploymentId: deployment.deploymentId });
213
+ // 5. Wait for AppBoundry's answer: Running with the runtime's evidence, or a failure.
214
+ const deadline = Date.now() + (options.waitMs ?? 5 * 60_000);
215
+ let last = deployment.state;
216
+ while (!terminal(deployment.state) && Date.now() < deadline) {
217
+ await sleep(options.pollMs ?? 2000);
218
+ deployment = (await call(conn, fetchImpl, `/api/applications/${encodeURIComponent(applicationId)}/deployments/${encodeURIComponent(deployment.deploymentId)}`)).body.deployment;
219
+ if (deployment.state !== last)
220
+ progress({ step: "state", detail: deployment.state });
221
+ last = deployment.state;
222
+ }
223
+ const outcome = outcomeOf(deployment, m.module.sha256);
224
+ observe(projectDir, deployment, outcome);
225
+ return { portal: conn.portal, applicationId, artifact: { path: artifact.path, artifactId, moduleSha256: m.module.sha256, archiveSha256, created: uploaded.body.created }, deployment, outcome, manifest: m };
226
+ }
227
+ function record(projectDir, conn, fields) {
228
+ const note = { portal: conn.portal, ...(conn.hostId ? { hostId: conn.hostId } : {}), ...fields, requestedAt: new Date().toISOString(), feltkit: SDK_VERSION };
229
+ mkdirSync(join(projectDir, ".feltkit", "appboundry"), { recursive: true });
230
+ // What was requested, never the credential. AppBoundry stays the authority on what is running.
231
+ writeFileSync(join(projectDir, APPBOUNDRY_RECORD), JSON.stringify(note, null, 2) + "\n");
232
+ }
233
+ /** Records what AppBoundry said, with when. */
234
+ function observe(projectDir, deployment, outcome) {
235
+ const note = readAppBoundryRecord(projectDir);
236
+ if (!note || note.deploymentId !== deployment.deploymentId)
237
+ return;
238
+ const next = { ...note, ...(deployment.hostId ? { hostId: deployment.hostId } : {}), lastStatus: { state: deployment.state, outcome, ...(deployment.hostId ? { hostId: deployment.hostId } : {}), address: deployment.address ?? null }, lastObservedAt: new Date().toISOString() };
239
+ writeFileSync(join(resolve(projectDir), APPBOUNDRY_RECORD), JSON.stringify(next, null, 2) + "\n");
240
+ }
241
+ export function readAppBoundryRecord(projectDir) {
242
+ const path = join(resolve(projectDir), APPBOUNDRY_RECORD);
243
+ if (!existsSync(path))
244
+ return null;
245
+ return JSON.parse(readFileSync(path, "utf8"));
246
+ }
247
+ /** `feltkit status`: what AppBoundry says about the last deployment requested from this project. */
248
+ export async function appboundryStatus(options) {
249
+ const note = readAppBoundryRecord(options.projectDir);
250
+ if (!note)
251
+ return null;
252
+ const env = options.env ?? process.env;
253
+ const token = options.connection?.token ?? env.APPBOUNDRY_TOKEN ?? "";
254
+ if (!token)
255
+ throw new FeltKitError("CONFIGURATION", "APPBOUNDRY_TOKEN is needed to ask AppBoundry for the deployment's status.");
256
+ const conn = { portal: options.connection?.portal ?? note.portal, token, ...(note.hostId ? { hostId: note.hostId } : {}) };
257
+ const fetchImpl = options.fetch ?? fetch;
258
+ const { body } = await call(conn, fetchImpl, `/api/applications/${encodeURIComponent(note.applicationId)}/deployments/${encodeURIComponent(note.deploymentId)}`);
259
+ const outcome = outcomeOf(body.deployment, note.moduleSha256);
260
+ observe(options.projectDir, body.deployment, outcome);
261
+ return { note, deployment: body.deployment, verified: outcome === "running", outcome };
262
+ }
263
+ //# sourceMappingURL=deploy-appboundry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy-appboundry.js","sourceRoot":"","sources":["../../src/cli/deploy-appboundry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,QAA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AE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACjJ,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;IACzC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAmC,IAAI,EAAE,SAAS,EAAE,qBAAqB,kBAAkB,CAAC,IAAI,CAAC,aAAa,CAAC,gBAAgB,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IACnM,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9D,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACtD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,KAAK,SAAS,EAAE,OAAO,EAAE,CAAC;AACzF,CAAC"}
package/dist/cli/main.js CHANGED
@@ -83,7 +83,8 @@ ${c.bold("Commands")}
83
83
  start Run the production build (environment: production)
84
84
  test Run the project's tests against an isolated test environment
85
85
  inspect Show what the application is, where its state lives, and what it's doing
86
- deploy Build a verified deployment: one container, an app container + FeltDB, Vercel, Cloudflare, or Fly.io
86
+ deploy Deploy to AppBoundry, or build a verified deployment: one container, an app container + FeltDB, Vercel, Cloudflare, Fly.io
87
+ status What AppBoundry says about the last deployment from this project
87
88
  vercel <action> Set a Vercel project's environment from FeltDB's values, deploy, and sign you in
88
89
  cloudflare <action> Set a Cloudflare Worker's secrets from FeltDB's values, deploy, and sign you in
89
90
  fly <action> Create the Fly.io app (and volume), set its secrets, deploy, and sign you in
@@ -161,7 +162,7 @@ const COMMAND_HELP = {
161
162
  " Writes the FeltDB application contract: this application's collections, FeltKit's own records, and FeltDB's\n" +
162
163
  " agent state. Managed FeltDB stores only what the promoted contract declares; publish it with\n" +
163
164
  " `feltdb publish --contract feltdb.contract.json`. --check exits 1 when the file is out of date.",
164
- deploy: "feltkit deploy [--target container|hosted|self-hosted|vercel|cloudflare|fly] [--data volume|managed|self-hosted] [--instances <n>] [--out <dir>] [--yes]\n" +
165
+ deploy: "feltkit deploy [--target appboundry|container|hosted|self-hosted|vercel|cloudflare|fly|appboundry-self-hosted] [--portal <url>] [--host <id>] [--data volume|managed|self-hosted] [--instances <n>] [--out <dir>] [--yes]\n" +
165
166
  " Builds, verifies the build boots, and writes .feltkit/deploy for how you run it:\n" +
166
167
  " container everything in one container: the app and its FeltDB state on a volume (default)\n" +
167
168
  " hosted a separate app container; data in Managed FeltDB (with feltdb.contract.json)\n" +
@@ -171,7 +172,12 @@ const COMMAND_HELP = {
171
172
  " --instances <n> spreads requests over n containers (default 1)\n" +
172
173
  " fly Fly.io Machines; data on a Fly volume beside the app, one machine (default; --data managed:\n" +
173
174
  " Managed FeltDB, --data self-hosted: your FeltDB server; any number of machines)\n" +
174
- " Each has a Dockerfile, docker-compose.yml, fly.toml, .env.example and DEPLOY.md. Asks which in a terminal.",
175
+ " appboundry sends the verified artifact to AppBoundry, which deploys and operates it: uploads it (AppBoundry\n" +
176
+ " verifies and stores it), requests a deployment, waits for the runtime's evidence. Needs\n" +
177
+ " APPBOUNDRY_URL and APPBOUNDRY_TOKEN (a deploy token), optionally APPBOUNDRY_HOST (or --portal/--host;\n" +
178
+ " AppBoundry places it when no host is named). Then: feltkit status\n" +
179
+ " appboundry-self-hosted the artifact with the AppBoundry runtime in one Docker container you operate\n" +
180
+ " Each has a Dockerfile, docker-compose.yml and DEPLOY.md. Asks which in a terminal.",
175
181
  vercel: "feltkit vercel env [--from <file>[,<file>]] [--environment production|preview|development] [--dry-run]\n" +
176
182
  " For an artifact built with `feltkit deploy --target vercel`: uploads the variables it needs to the linked\n" +
177
183
  " Vercel project, from .env.local (what `feltdb init-managed` wrote), the environment, or --from files.\n" +
@@ -891,11 +897,41 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
891
897
  printInspect(value, source);
892
898
  return 0;
893
899
  }
900
+ case "status": {
901
+ const { appboundryStatus } = await import("./deploy-appboundry.js");
902
+ const s = await appboundryStatus({ projectDir, ...(flags.portal ? { connection: { portal: String(flags.portal) } } : {}) });
903
+ if (!s) {
904
+ line(`${symbols.info} No AppBoundry deployment has been requested from this project.`);
905
+ line(c.dim("Deploy with: npx feltkit deploy --target appboundry"));
906
+ return json ? (line(JSON.stringify({ ok: false, deployment: null })), 0) : 0;
907
+ }
908
+ const d = s.deployment;
909
+ if (json) {
910
+ line(JSON.stringify({ ok: s.verified, outcome: s.outcome, portal: s.note.portal, application: s.note.applicationId, artifactId: s.note.artifactId, module: `sha256:${s.note.moduleSha256}`, deployment: d, verified: s.verified, address: d.address ?? null }, null, 2));
911
+ return 0;
912
+ }
913
+ line(`${c.bold(s.note.applicationId)} on AppBoundry ${c.dim(s.note.portal)}`);
914
+ line(` Deployment ${d.deploymentId} ${s.verified ? c.green(d.state) : d.state === "Failed" ? c.red(d.state) : d.state} ${c.dim(`host ${d.hostId}, attempt ${d.attempt ?? 1}`)}`);
915
+ line(` Artifact ${s.note.artifactId.slice(0, 16)}… module sha256:${s.note.moduleSha256.slice(0, 16)}…`);
916
+ line(` Runtime ${d.runtime ? `${d.runtime.package} ${d.runtime.version}` : "unknown"}`);
917
+ if (d.evidence)
918
+ line(` Evidence the runtime reported module sha256:${d.evidence.observedModuleSha256.slice(0, 16)}… ${d.evidence.health} at ${d.evidence.observedAt}${s.verified ? c.dim(" (matches this build)") : c.red(" (does not match this build)")}`);
919
+ else
920
+ line(` Evidence ${c.dim("none yet: AppBoundry reports Running only when the runtime itself names the module")}`);
921
+ if (d.failure)
922
+ line(` Failure ${d.failure.code}: ${d.failure.message}`);
923
+ line(` Address ${d.address ?? c.dim(`none${d.routing?.reason ? `: ${d.routing.reason}` : ""}`)}`);
924
+ if (!s.verified && s.outcome === "pending")
925
+ line(c.dim(" Pending: AppBoundry has not observed a ready runtime for this build yet."));
926
+ return s.outcome === "failed" ? 1 : 0;
927
+ }
894
928
  case "deploy": {
895
929
  // How it will run: --target, else asked in a terminal, else one container.
896
930
  let target = flags.target ? String(flags.target) : undefined;
897
931
  if (!target && process.stdin.isTTY && process.stdout.isTTY && !flags.yes) {
898
- const choices = Object.entries(DEPLOY_TARGETS);
932
+ const { APPBOUNDRY_TARGET_TITLE } = await import("./deploy-appboundry.js");
933
+ const { APPBOUNDRY_SELF_HOSTED_TITLE } = await import("./deploy-appboundry-self-hosted.js");
934
+ const choices = [["appboundry", APPBOUNDRY_TARGET_TITLE], ...Object.entries(DEPLOY_TARGETS), ["appboundry-self-hosted", APPBOUNDRY_SELF_HOSTED_TITLE]];
899
935
  line(c.bold("How do you want to run it?"));
900
936
  choices.forEach(([name, text], i) => line(` ${i + 1}) ${text} ${c.dim(`(--target ${name})`)}`));
901
937
  const rl = createInterface({ input: process.stdin, output: process.stdout });
@@ -905,6 +941,71 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
905
941
  if (!target)
906
942
  throw new FeltKitError("INVALID_ARGUMENT", `Answer 1-${choices.length}.`);
907
943
  }
944
+ if (target === "appboundry") {
945
+ if (flags.data !== undefined || flags.instances !== undefined || flags.out !== undefined)
946
+ throw new FeltKitError("INVALID_ARGUMENT", "--data, --instances and --out do not apply to --target appboundry: AppBoundry deploys and operates the artifact.");
947
+ const { appboundryConnection, deployToAppBoundry } = await import("./deploy-appboundry.js");
948
+ const connection = appboundryConnection({ ...(flags.portal ? { portal: String(flags.portal) } : {}), ...(flags.host ? { hostId: String(flags.host) } : {}) });
949
+ if (!json)
950
+ line(`${c.bold("feltkit deploy")} ${c.dim(`→ AppBoundry at ${connection.portal}`)}`);
951
+ const r = await deployToAppBoundry({ projectDir, connection, onProgress: json ? undefined : (e) => {
952
+ if (e.step === "built")
953
+ line(`${symbols.ok} Built the application and its artifact ${c.dim(e.detail)}`);
954
+ else if (e.step === "uploaded")
955
+ line(`${symbols.ok} Uploaded AppBoundry verified the artifact and stored it immutably ${c.dim(e.detail)}`);
956
+ else if (e.step === "requested")
957
+ line(`${symbols.ok} Requested ${c.dim(e.detail)}`);
958
+ else
959
+ line(` ${c.dim("→")} ${e.detail}`);
960
+ } });
961
+ if (json) {
962
+ line(JSON.stringify({ ok: r.outcome === "running", outcome: r.outcome, target: "appboundry", portal: r.portal, application: r.applicationId, artifactId: r.artifact.artifactId, module: `sha256:${r.artifact.moduleSha256}`, deployment: r.deployment, sdk: SDK_VERSION }, null, 2));
963
+ return r.outcome === "failed" ? 1 : 0;
964
+ }
965
+ if (r.outcome === "running") {
966
+ line(`${symbols.ok} Running on ${r.deployment.hostId}; the runtime reports module sha256:${r.deployment.evidence.observedModuleSha256.slice(0, 16)}…, the module this build produced`);
967
+ line(` Address ${r.deployment.address ?? c.dim(`none yet${r.deployment.routing?.reason ? `: ${r.deployment.routing.reason}` : ""}`)}`);
968
+ line(c.dim(`\nAppBoundry operates it from here. Check it any time: npx feltkit status`));
969
+ return 0;
970
+ }
971
+ if (r.outcome === "pending") {
972
+ line(`${symbols.info} ${r.deployment.state}: AppBoundry has the deployment; its runtime has not reported ready yet.`);
973
+ line(c.dim("Check it with: npx feltkit status"));
974
+ return 0;
975
+ }
976
+ if (r.deployment.state === "Running")
977
+ line(`${symbols.fail} AppBoundry reports Running, but its evidence does not name this build's module on the current attempt; not reported as running.`);
978
+ else
979
+ line(`${symbols.fail} ${r.deployment.state}${r.deployment.failure ? `: ${r.deployment.failure.message} (${r.deployment.failure.code})` : ""}`);
980
+ return 1;
981
+ }
982
+ if (target === "appboundry-self-hosted") {
983
+ if (flags.data !== undefined || flags.instances !== undefined)
984
+ throw new FeltKitError("INVALID_ARGUMENT", "--data and --instances do not apply to --target appboundry-self-hosted: the runtime keeps the state on the container's volume.");
985
+ const { accessCommands, deployAppBoundrySelfHosted } = await import("./deploy-appboundry-self-hosted.js");
986
+ const ab = await deployAppBoundrySelfHosted({ projectDir, ...(flags.out ? { out: String(flags.out) } : {}) });
987
+ const m = ab.manifest;
988
+ if (json) {
989
+ line(JSON.stringify({ ok: true, dir: relative(projectDir, ab.dir) || ".", target: "appboundry-self-hosted", application: ab.application, artifact: relative(projectDir, ab.artifact), module: `sha256:${m.module.sha256}`, runtime: { package: "@appport/appboundry", version: ab.runtime }, verified: { check: "guest-load", functions: m.functions.length }, sdk: SDK_VERSION }, null, 2));
990
+ return 0;
991
+ }
992
+ const at = relative(process.cwd(), ab.dir) || ".";
993
+ line(`${symbols.ok} Built and verified: the artifact's module loaded in the guest engine and defines exactly its manifest's ${m.functions.length} functions.`);
994
+ line(`${symbols.ok} Artifact ${c.bold(relative(process.cwd(), ab.artifact))} ${c.dim(`(module sha256:${m.module.sha256.slice(0, 16)}…, imports nothing; ${m.collections.length} collections, ${m.functions.filter((f) => f.capability).length} capabilities)`)}`);
995
+ line(`${symbols.ok} Runtime @appport/appboundry ${ab.runtime} ${c.dim("(installed in the image; no FeltKit code runs in the deployment)")}`);
996
+ line(`${symbols.ok} Self-hosted deployment (the AppBoundry runtime in one container you operate; data on a volume): ${c.bold(ab.dir)}${flags.out ? "" : c.dim(" (replaced on every deploy; the state is on the container's volume)")}`);
997
+ for (const note of ab.omitted)
998
+ line(` ${symbols.info} ${c.dim(`Not in the artifact: ${note}`)}`);
999
+ const composeFile = join(at, "docker-compose.yml");
1000
+ line(`\n${c.bold("Run it yourself")} ${c.dim("(refuses any other module, verifies the artifact, creates the operator on first start)")}`);
1001
+ line(` docker compose -f ${composeFile} up --build`);
1002
+ line(`\n${c.bold("Give someone access")} ${c.dim("(an operator adds a user with one of the app's roles and issues their session)")}`);
1003
+ for (const command of accessCommands(composeFile))
1004
+ line(` ${command}`);
1005
+ line(c.dim(`\nThen open http://localhost:3000 and paste the session. The contract (identity, upgrades, limits): ${join(at, "DEPLOY.md")}.`));
1006
+ line(c.dim("To have AppBoundry deploy and operate it instead, with no container to run: npx feltkit deploy --target appboundry"));
1007
+ return 0;
1008
+ }
908
1009
  const result = await deploy({ projectDir, ...(flags.out ? { out: String(flags.out) } : {}), ...(target ? { target: target } : {}), ...(flags.data ? { data: String(flags.data) } : {}), ...(flags.instances !== undefined ? { instances: Number(flags.instances) } : {}) });
909
1010
  if (json) {
910
1011
  // What a caller (the platform's change.apply) can rely on: deploy() returns only after the
@@ -980,7 +1081,7 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
980
1081
  line(c.dim(result.target === "vercel" || result.target === "cloudflare" || result.target === "fly"
981
1082
  ? `\nLater: \`npx feltkit manage\` opens production Studio again. The whole setup, the target's contract (state, recovery, upgrades), and its limits: ${join(at, "DEPLOY.md")}.`
982
1083
  : `\nThen open http://localhost:3000. The target's contract (state, recovery, upgrades), Fly.io and other hosts: ${join(at, "DEPLOY.md")}.`));
983
- line(c.dim(`Other ways to run it: ${Object.keys(DEPLOY_TARGETS).filter((id) => id !== result.target).map((id) => `npx feltkit deploy --target ${id}`).join(" | ")}`));
1084
+ line(c.dim(`Other ways to run it: ${["appboundry", ...Object.keys(DEPLOY_TARGETS).filter((id) => id !== result.target)].map((id) => `npx feltkit deploy --target ${id}`).join(" | ")}`));
984
1085
  if (result.target === "vercel")
985
1086
  line(c.dim("Vercel's container runtime is in beta. Its limits (stream length, body size, scale to zero): DEPLOY.md."));
986
1087
  if (result.target === "cloudflare")