@fungi.computer/puffball 0.0.2 → 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.
package/dist/app-api.js CHANGED
@@ -24,6 +24,9 @@ const method = Schema.Struct({
24
24
  pending: Schema.optional(Schema.Literal(true)),
25
25
  hidden: Schema.optional(Schema.Literal(true)),
26
26
  anonymous: Schema.optional(Schema.Literal(true)),
27
+ present: Schema.optional(Schema.Struct({
28
+ verb: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(32)),
29
+ })),
27
30
  effect: Schema.Literals(["read", "write", "external"]),
28
31
  requires: Schema.Array(Schema.Literals(appCapabilityIds)).pipe(Schema.check(Schema.makeFilter((values) => new Set(values).size === values.length))),
29
32
  }).check(Schema.makeFilter((value) => value.anonymous !== true ||
@@ -60,6 +60,19 @@ export declare const appBackendBindingKinds: {
60
60
  readonly APPS: {
61
61
  readonly name: "APPS";
62
62
  readonly operations: {
63
+ /** Register the calling installation's repository as an App from its
64
+ * exact main manifest. No Computer execution or installation is implied. */
65
+ readonly register: {
66
+ readonly cap: "app.register";
67
+ readonly requires: readonly ["git.repository"];
68
+ readonly effect: "write";
69
+ };
70
+ /** Read the captured installation's registered repository identity. */
71
+ readonly repository: {
72
+ readonly cap: "app.catalog.read";
73
+ readonly requires: readonly ["git.repository"];
74
+ readonly effect: "read";
75
+ };
63
76
  readonly build: {
64
77
  readonly cap: "app.build";
65
78
  readonly requires: readonly ["git.repository", "computer.execute"];
@@ -228,11 +241,6 @@ export declare const appBackendBindingKinds: {
228
241
  readonly requires: readonly ["computer.writeFile"];
229
242
  readonly effect: "write";
230
243
  };
231
- readonly workflowGitPass: {
232
- readonly cap: "app.computer.exec";
233
- readonly requires: readonly ["computer.execute"];
234
- readonly effect: "write";
235
- };
236
244
  readonly preview: {
237
245
  readonly cap: "app.computer.exec";
238
246
  readonly requires: readonly ["computer.execute"];
@@ -49,6 +49,19 @@ export const appBackendBindingKinds = {
49
49
  APPS: {
50
50
  name: "APPS",
51
51
  operations: {
52
+ /** Register the calling installation's repository as an App from its
53
+ * exact main manifest. No Computer execution or installation is implied. */
54
+ register: {
55
+ cap: "app.register",
56
+ requires: ["git.repository"],
57
+ effect: "write",
58
+ },
59
+ /** Read the captured installation's registered repository identity. */
60
+ repository: {
61
+ cap: "app.catalog.read",
62
+ requires: ["git.repository"],
63
+ effect: "read",
64
+ },
52
65
  build: {
53
66
  cap: "app.build",
54
67
  requires: ["git.repository", "computer.execute"],
@@ -217,11 +230,6 @@ export const appBackendBindingKinds = {
217
230
  requires: ["computer.writeFile"],
218
231
  effect: "write",
219
232
  },
220
- workflowGitPass: {
221
- cap: "app.computer.exec",
222
- requires: ["computer.execute"],
223
- effect: "write",
224
- },
225
233
  preview: {
226
234
  cap: "app.computer.exec",
227
235
  requires: ["computer.execute"],
@@ -11,7 +11,7 @@ export declare const appBackendShardBindingsSchema: Schema.$Array<Schema.Union<S
11
11
  readonly name: Schema.Literal<"BACKGROUND" | "GIT" | "EVENTS" | "APPS" | "WORKFLOWS" | "APP_STORAGE" | "MEDIA" | "COMPUTER" | "INBOX" | "AGENTS">;
12
12
  readonly operations: Schema.$Array<Schema.Union<Schema.Struct<{
13
13
  readonly name: Schema.Literal<string>;
14
- readonly cap: Schema.Literal<"agent.list" | "agent.send" | "app.events.emit" | "app.background.admit" | "app.git.create" | "app.git.fork" | "app.git.read" | "app.git.write" | "app.git.exchange" | "app.build" | "app.select" | "app.catalog.read" | "app.fork" | "app.workflow.read" | "app.workflow.run" | "app.storage.read" | "app.storage.write" | "app.media.read" | "app.media.generate" | "app.computer.read" | "app.computer.write" | "app.computer.exec" | "inbox.read" | "inbox.visit">;
14
+ readonly cap: Schema.Literal<"agent.list" | "agent.send" | "app.events.emit" | "app.background.admit" | "app.git.create" | "app.git.fork" | "app.git.read" | "app.git.write" | "app.git.exchange" | "app.register" | "app.catalog.read" | "app.build" | "app.select" | "app.fork" | "app.workflow.read" | "app.workflow.run" | "app.storage.read" | "app.storage.write" | "app.media.read" | "app.media.generate" | "app.computer.read" | "app.computer.write" | "app.computer.exec" | "inbox.read" | "inbox.visit">;
15
15
  }>[]>>;
16
16
  }>[]>>;
17
17
  /** Look up an operation within its declared kind; unknown names have no authority. */
@@ -1,7 +1,7 @@
1
1
  import * as Schema from "effect/Schema";
2
2
  import { type AppDeclaration, type AppDeclaredCommand } from "./app-vocabulary.js";
3
3
  export declare const appRoleSchema: Schema.Literals<readonly ["dashboard", "inbox", "files", "media", "sessions", "terminal"]>;
4
- export declare const appCapabilityIdSchema: Schema.Literals<readonly ["agent.list", "agent.manage", "agent.rename", "agent.toolPolicy", "agent.read", "agent.send", "computer.list", "computer.readFile", "computer.writeFile", "computer.execute", "llm.generation", "media.generation", "games:servers", "git.repository", "apps.open", "apps.call", "app.storage", "app.events.emit", "team.workbenchHost", "marketplace.browse", "marketplace.purchase", "workflow.run", "workflow.publish", "workflow.arm", "world", "channels.read", "channels.personal.manage"]>;
4
+ export declare const appCapabilityIdSchema: Schema.Literals<readonly ["approvals", "agent.list", "agent.manage", "agent.rename", "agent.avatar", "agent.toolPolicy", "agent.read", "agent.send", "computer.list", "computer.readFile", "computer.writeFile", "computer.execute", "llm.generation", "media.generation", "games:servers", "git.repository", "apps.open", "apps.call", "app.storage", "app.events.emit", "team.workbenchHost", "marketplace.browse", "marketplace.purchase", "workflow.run", "workflow.publish", "workflow.arm", "world", "channels.read", "channels.personal.manage"]>;
5
5
  export declare const appHandlerSchema: Schema.Literals<readonly ["file.open"]>;
6
6
  /**
7
7
  * One declared command: a Whistle definition's identity and projections.
@@ -26,7 +26,7 @@ export declare const appEventFactSchema: z.ZodObject<{
26
26
  appId: z.ZodString;
27
27
  releaseId: z.ZodString;
28
28
  gitSource: z.ZodOptional<z.ZodObject<{
29
- eventId: z.ZodString;
29
+ eventId: z.ZodLazy<z.ZodString>;
30
30
  repository: z.ZodString;
31
31
  updates: z.ZodArray<z.ZodObject<{
32
32
  ref: z.ZodString;
@@ -52,10 +52,10 @@ export declare const appMethodCallerSchema: z.ZodMiniObject<{
52
52
  keyId: z.ZodMiniString<string>;
53
53
  }, z.core.$strip>], "kind">;
54
54
  backgroundLane: z.ZodMiniOptional<z.ZodMiniString<string>>;
55
- backgroundOrigin: z.ZodMiniOptional<z.ZodMiniObject<{
55
+ backgroundOrigin: z.ZodMiniOptional<z.ZodMiniLazy<z.ZodMiniObject<{
56
56
  method: z.ZodMiniString<string>;
57
57
  seal: z.ZodMiniString<string>;
58
- }, z.core.$strict>>;
58
+ }, z.core.$strict>>>;
59
59
  role: z.ZodMiniOptional<z.ZodMiniEnum<{
60
60
  member: "member";
61
61
  owner: "owner";
@@ -56,10 +56,10 @@ export const workflowAttestationSchema = z.object({
56
56
  });
57
57
  // Keep the single origin grammar in the lightweight caller module. The host-side
58
58
  // background-replay entry exposes this same schema without a runtime import cycle.
59
- const backgroundOrigin = z.strictObject({
59
+ const backgroundOrigin = z.lazy(() => z.strictObject({
60
60
  method: z.string().check(z.refine((name) => isAppApiMethodName(name))),
61
61
  seal: z.string().check(z.regex(/^[A-Za-z0-9_-]{43}$/u)),
62
- });
62
+ }));
63
63
  /** Sole grammar for the host-minted Computer pin and actor attribution. */
64
64
  export const appMethodCallerSchema = z.object({
65
65
  computerId: z.nullable(identity),
@@ -58,7 +58,7 @@ export declare function resolveAppRoles(choices: ReadonlyMap<AppRole, string>, c
58
58
  * Host capabilities an App may request. A request is never authority; the
59
59
  * Team's installation grants decide. Extend this list here.
60
60
  */
61
- export declare const appCapabilityIds: readonly ["agent.list", "agent.manage", "agent.rename", "agent.toolPolicy", "agent.read", "agent.send", "computer.list", "computer.readFile", "computer.writeFile", "computer.execute", "llm.generation", "media.generation", "games:servers", "git.repository", "apps.open", "apps.call", "app.storage", "app.events.emit", "team.workbenchHost", "marketplace.browse", "marketplace.purchase", "workflow.run", "workflow.publish", "workflow.arm", "world", "channels.read", "channels.personal.manage"];
61
+ export declare const appCapabilityIds: readonly ["approvals", "agent.list", "agent.manage", "agent.rename", "agent.avatar", "agent.toolPolicy", "agent.read", "agent.send", "computer.list", "computer.readFile", "computer.writeFile", "computer.execute", "llm.generation", "media.generation", "games:servers", "git.repository", "apps.open", "apps.call", "app.storage", "app.events.emit", "team.workbenchHost", "marketplace.browse", "marketplace.purchase", "workflow.run", "workflow.publish", "workflow.arm", "world", "channels.read", "channels.personal.manage"];
62
62
  /** One requestable host capability id. */
63
63
  export type AppCapabilityId = (typeof appCapabilityIds)[number];
64
64
  /** Backend requests are narrower than the App capabilities a Team approves. */
@@ -78,6 +78,10 @@ export type AppApi = Readonly<{
78
78
  hidden?: true | undefined;
79
79
  /** Request anonymous read admission; declaration alone grants no authority. */
80
80
  anonymous?: true | undefined;
81
+ /** Finished calls read as a person-facing row projected by the App's hidden `present` method. */
82
+ present?: Readonly<{
83
+ verb: string;
84
+ }> | undefined;
81
85
  }>>>;
82
86
  /** A signed dynamic tool namespace; its methods remain subject to ordinary admission. */
83
87
  toolFamily?: Readonly<{
@@ -49,9 +49,11 @@ export function resolveAppRoles(choices, candidates) {
49
49
  * Team's installation grants decide. Extend this list here.
50
50
  */
51
51
  export const appCapabilityIds = [
52
+ "approvals",
52
53
  "agent.list",
53
54
  "agent.manage",
54
55
  "agent.rename",
56
+ "agent.avatar",
55
57
  "agent.toolPolicy",
56
58
  "agent.read",
57
59
  "agent.send",
@@ -4,19 +4,19 @@ import { type HostActor, type AppMethodCallContext } from "./app-method-runtime.
4
4
  import type { AppApi } from "./app-vocabulary.js";
5
5
  export { backgroundSyncAllowed } from "./internal/background-sync.js";
6
6
  /** The caller's single lightweight grammar for a host-sealed enqueue origin. */
7
- export declare const backgroundOriginSchema: import("zod/mini").ZodMiniObject<{
7
+ export declare const backgroundOriginSchema: import("zod/mini").ZodMiniLazy<import("zod/mini").ZodMiniObject<{
8
8
  method: import("zod/mini").ZodMiniString<string>;
9
9
  seal: import("zod/mini").ZodMiniString<string>;
10
- }, z.core.$strict>;
10
+ }, z.core.$strict>>;
11
11
  /** Origin evidence, never a retained grant or credential. */
12
12
  export type BackgroundOrigin = z.output<typeof backgroundOriginSchema>;
13
13
  /** The closed result of checking a claimed job's origin in a fresh replay frame. */
14
- export declare const claimedJobAdmissionSchema: z.ZodUnion<readonly [z.ZodObject<{
14
+ export declare const claimedJobAdmissionSchema: z.ZodLazy<z.ZodUnion<readonly [z.ZodObject<{
15
15
  kind: z.ZodLiteral<"admitted">;
16
16
  }, z.core.$strict>, z.ZodObject<{
17
17
  kind: z.ZodLiteral<"refused">;
18
18
  code: z.ZodLiteral<"access_changed">;
19
- }, z.core.$strict>]>;
19
+ }, z.core.$strict>]>>;
20
20
  /** A claim either passes origin admission or refuses before binding effects. */
21
21
  export type ClaimedJobAdmission = z.output<typeof claimedJobAdmissionSchema>;
22
22
  /** Host-minted replay port; an App cannot declare this binding. */
@@ -50,7 +50,7 @@ export declare function backgroundContext(context: AppMethodCallContext, ancestr
50
50
  /** App-side eligibility reads only the host-attested context; it never invents ancestry. */
51
51
  export declare function mayEnqueueBackground(context: AppMethodCallContext): boolean;
52
52
  /** Identity and observed revisions only. Unknown fields, including bearer material, refuse. */
53
- export declare const backgroundWakeSchema: z.ZodObject<{
53
+ export declare const backgroundWakeSchema: z.ZodLazy<z.ZodObject<{
54
54
  installationId: z.ZodString;
55
55
  actor: z.ZodObject<{
56
56
  kind: import("zod/mini").ZodMiniLiteral<"member">;
@@ -59,12 +59,12 @@ export declare const backgroundWakeSchema: z.ZodObject<{
59
59
  lane: z.ZodString;
60
60
  originMethod: z.ZodString;
61
61
  observed: z.ZodObject<{
62
- authorityVersion: z.ZodNumber;
62
+ authorityVersion: z.ZodLazy<z.ZodNumber>;
63
63
  artifactDigest: z.ZodCustom<Sha256Digest, Sha256Digest>;
64
- membershipVersion: z.ZodOptional<z.ZodNumber>;
64
+ membershipVersion: z.ZodOptional<z.ZodLazy<z.ZodNumber>>;
65
65
  }, z.core.$strict>;
66
- epoch: z.ZodNumber;
67
- }, z.core.$strict>;
66
+ epoch: z.ZodLazy<z.ZodNumber>;
67
+ }, z.core.$strict>>;
68
68
  /** A host wake cannot confer authority without fresh directory and method admission. */
69
69
  export type BackgroundWake = z.output<typeof backgroundWakeSchema>;
70
70
  /** A retained identity eligible for member-only replay. */
@@ -8,13 +8,13 @@ export { backgroundSyncAllowed } from "./internal/background-sync.js";
8
8
  /** The caller's single lightweight grammar for a host-sealed enqueue origin. */
9
9
  export const backgroundOriginSchema = appMethodCallerSchema.shape.backgroundOrigin.def.innerType;
10
10
  /** The closed result of checking a claimed job's origin in a fresh replay frame. */
11
- export const claimedJobAdmissionSchema = z.union([
11
+ export const claimedJobAdmissionSchema = z.lazy(() => z.union([
12
12
  z.strictObject({ kind: z.literal("admitted") }),
13
13
  z.strictObject({
14
14
  kind: z.literal("refused"),
15
15
  code: z.literal("access_changed"),
16
16
  }),
17
- ]);
17
+ ]));
18
18
  const originBytes = (claims) => new TextEncoder().encode(JSON.stringify([
19
19
  "fungi.background-origin/1",
20
20
  claims.instanceId,
@@ -110,9 +110,9 @@ export function mayEnqueueBackground(context) {
110
110
  Schema.is(WatchdogQueuedJobSchema.fields.lane)(context.backgroundLane));
111
111
  }
112
112
  const member = z.strictObject(hostActorSchema.def.options[0].shape);
113
- const revision = z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
113
+ const revision = z.lazy(() => z.number().int().positive().max(Number.MAX_SAFE_INTEGER));
114
114
  /** Identity and observed revisions only. Unknown fields, including bearer material, refuse. */
115
- export const backgroundWakeSchema = z
115
+ export const backgroundWakeSchema = z.lazy(() => z
116
116
  .strictObject({
117
117
  installationId: z.string().min(1).max(256),
118
118
  actor: member,
@@ -130,7 +130,7 @@ export const backgroundWakeSchema = z
130
130
  })
131
131
  .refine((wake) => wake.lane === actorLane(wake.actor), {
132
132
  message: "Wake lane must name its member",
133
- });
133
+ }));
134
134
  /** The App can settle a refused lane without receiving any binding authority. */
135
135
  export const backgroundRefusalCodeSchema = z.enum([
136
136
  "access_changed",
@@ -217,6 +217,67 @@ export declare const appArtifactErasureReadbackSchema: Schema.Struct<{
217
217
  export declare const APP_RELEASE_D1_FRESH_SCHEMA: string;
218
218
  /** Create the native registry that joins a Team publisher to one App/source. */
219
219
  export declare function createD1TeamAppPublisherRegistry(database: AppReleaseD1Database): TeamAppPublisherRegistry;
220
+ /** One boot result's identity: the Release and the version of the check that judged it. */
221
+ export type ReleaseBootResultKey = Readonly<{
222
+ releaseId: string;
223
+ checkVersion: string;
224
+ }>;
225
+ /** A recorded boot result, opaque JSON owned by the boot gate that wrote it. */
226
+ export type ReleaseBootResultRecord = Readonly<{
227
+ kind: "recorded";
228
+ result: Schema.Json;
229
+ checkedAt: number;
230
+ }>;
231
+ /**
232
+ * One boot result per Release and check version, beside the Release in the
233
+ * global catalog. Whoever checks first (the publisher at submission or a
234
+ * Team's first install) records it; everyone reads it; nobody rechecks.
235
+ * The catalog owns identity and write-once storage; the boot gate owns the
236
+ * result's meaning and parses it on read.
237
+ *
238
+ * Writers are host-run checkers only, recording only definitive outcomes
239
+ * (never an inconclusive or "not checked" run) with sanitized diagnostics;
240
+ * the result covers the UI page check alone, not backend construction.
241
+ */
242
+ export type ReleaseBootResults = Readonly<{
243
+ /** The recorded result for this Release and check version, if any. */
244
+ read: (key: ReleaseBootResultKey) => Promise<Readonly<{
245
+ kind: "absent";
246
+ }> | ReleaseBootResultRecord>;
247
+ /** Record a result unless one exists; always answers with the stored one. */
248
+ recordIfAbsent: (input: ReleaseBootResultKey & Readonly<{
249
+ result: Schema.Json;
250
+ checkedAt: number;
251
+ }>) => Promise<ReleaseBootResultRecord>;
252
+ }>;
253
+ /** The catalog's write-once boot results, over the same App Release D1. */
254
+ export declare function createD1ReleaseBootResults(database: AppReleaseD1Database): ReleaseBootResults;
255
+ /** The longest a boot capability lease may live: one boot check plus cleanup. */
256
+ export declare const BOOT_CAPABILITY_MAX_LIFETIME_MS = 60000;
257
+ /**
258
+ * The catalog storage behind a host's boot `BootCapabilityStore`: one
259
+ * short-lived row per issued lease, keyed by the token's digest (never the
260
+ * token). The lease itself is opaque JSON owned by the boot capability
261
+ * contract, which parses it on resolve. Expired rows are deleted on resolve
262
+ * and purged on every issue; revoke deletes.
263
+ */
264
+ export type BootCapabilityRows = Readonly<{
265
+ /** Store one lease; refuses a raw token or a lifetime beyond the maximum. */
266
+ issue: (input: Readonly<{
267
+ tokenDigest: string;
268
+ leaseId: string;
269
+ releaseId: string;
270
+ leaseJson: string;
271
+ expiresAt: number;
272
+ now: number;
273
+ }>) => Promise<void>;
274
+ /** The live lease's JSON for this digest, or `null` when absent or expired. */
275
+ resolve: (tokenDigest: string, now: number) => Promise<string | null>;
276
+ /** Delete one lease once its check is done. */
277
+ revoke: (leaseId: string) => Promise<void>;
278
+ }>;
279
+ /** The catalog's short-lived boot capability rows, over the same App Release D1. */
280
+ export declare function createD1BootCapabilityRows(database: AppReleaseD1Database): BootCapabilityRows;
220
281
  /** Create the D1-backed App Release store with private public-website authority. */
221
282
  export declare function createD1AppReleaseStore(database: AppReleaseD1Database): PromiseAppReleaseStore & {
222
283
  readonly transitionObligations: AppReleaseTransitionObligationStore;
@@ -512,6 +512,11 @@ CREATE INDEX app_release_team_publishers_team_idx ON app_release_team_publishers
512
512
  CREATE TABLE app_release_release_verification_metadata (release_id TEXT PRIMARY KEY REFERENCES app_release_release_verifications(release_id), artifact_digest TEXT NOT NULL, description_json TEXT NOT NULL CHECK(json_valid(description_json))) STRICT;
513
513
  CREATE TABLE publisher_template_seed_receipts (template_repository TEXT NOT NULL, seed_revision TEXT NOT NULL, platform_app_id TEXT NOT NULL, source_revision TEXT NOT NULL, source_tree_digest TEXT NOT NULL, recipe_json TEXT CHECK(recipe_json IS NULL OR json_valid(recipe_json)), build_recipe_digest TEXT CHECK(build_recipe_digest IS NULL OR (length(build_recipe_digest) = 71 AND substr(build_recipe_digest, 1, 7) = 'sha256:' AND substr(build_recipe_digest, 8) NOT GLOB '*[^0-9a-f]*')), CHECK((recipe_json IS NULL) = (build_recipe_digest IS NULL)), PRIMARY KEY (template_repository, seed_revision)) STRICT;
514
514
  CREATE TABLE publisher_artifacts_repositories (repository_name TEXT PRIMARY KEY CHECK(length(repository_name) BETWEEN 1 AND 128), provider_id TEXT NOT NULL CHECK(length(provider_id) > 0), default_branch TEXT NOT NULL CHECK(default_branch = 'main'), remote TEXT NOT NULL CHECK(length(remote) > 0), parent_repository TEXT REFERENCES publisher_artifacts_repositories(repository_name), CHECK(parent_repository IS NULL OR parent_repository <> repository_name)) STRICT;
515
+ CREATE TABLE app_release_boot_results (release_id TEXT NOT NULL REFERENCES app_release_releases(release_id), check_version TEXT NOT NULL CHECK(length(check_version) BETWEEN 1 AND 64), outcome_json TEXT NOT NULL CHECK(json_valid(outcome_json) AND length(outcome_json) <= 65536), checked_at INTEGER NOT NULL, PRIMARY KEY (release_id, check_version)) STRICT;
516
+ CREATE TRIGGER app_release_boot_results_write_once BEFORE UPDATE ON app_release_boot_results BEGIN SELECT RAISE(ABORT, 'App Release boot results are write-once'); END;
517
+ CREATE TABLE app_release_boot_capabilities (token_digest TEXT PRIMARY KEY CHECK(length(token_digest) = 64 AND token_digest NOT GLOB '*[^0-9a-f]*'), lease_id TEXT NOT NULL UNIQUE CHECK(length(lease_id) BETWEEN 1 AND 128), release_id TEXT NOT NULL REFERENCES app_release_releases(release_id), lease_json TEXT NOT NULL CHECK(json_valid(lease_json) AND length(lease_json) <= 262144), expires_at INTEGER NOT NULL) STRICT;
518
+ CREATE INDEX app_release_boot_capabilities_expiry_idx ON app_release_boot_capabilities(expires_at);
519
+ CREATE TRIGGER app_release_boot_capabilities_write_once BEFORE UPDATE ON app_release_boot_capabilities BEGIN SELECT RAISE(ABORT, 'Boot capability leases are write-once'); END;
515
520
  ${publicRouteSchemaSql}
516
521
  ${platformOwnerReplaySchemaSql}
517
522
  ${buyerReferenceSchemaSql}
@@ -647,6 +652,89 @@ export function createD1TeamAppPublisherRegistry(database) {
647
652
  },
648
653
  };
649
654
  }
655
+ const bootResultRowSchema = Schema.Struct({
656
+ outcome_json: Schema.fromJsonString(Schema.Json),
657
+ checked_at: Schema.Number,
658
+ });
659
+ /** The catalog's write-once boot results, over the same App Release D1. */
660
+ export function createD1ReleaseBootResults(database) {
661
+ const read = async (key) => {
662
+ const row = await database
663
+ .prepare(`SELECT outcome_json, checked_at FROM app_release_boot_results
664
+ WHERE release_id = ? AND check_version = ?`)
665
+ .bind(parseReleaseId(key.releaseId), key.checkVersion)
666
+ .first();
667
+ if (row === null)
668
+ return { kind: "absent" };
669
+ const decoded = Schema.decodeUnknownSync(bootResultRowSchema)(row);
670
+ return {
671
+ kind: "recorded",
672
+ result: decoded.outcome_json,
673
+ checkedAt: decoded.checked_at,
674
+ };
675
+ };
676
+ return {
677
+ read,
678
+ recordIfAbsent: async (input) => {
679
+ await database
680
+ .prepare(`INSERT INTO app_release_boot_results
681
+ (release_id, check_version, outcome_json, checked_at)
682
+ VALUES (?, ?, ?, ?)
683
+ ON CONFLICT (release_id, check_version) DO NOTHING`)
684
+ .bind(parseReleaseId(input.releaseId), input.checkVersion, JSON.stringify(input.result), input.checkedAt)
685
+ .run();
686
+ const stored = await read(input);
687
+ if (stored.kind === "absent")
688
+ throw new Error("The boot result was not recorded");
689
+ return stored;
690
+ },
691
+ };
692
+ }
693
+ /** The longest a boot capability lease may live: one boot check plus cleanup. */
694
+ export const BOOT_CAPABILITY_MAX_LIFETIME_MS = 60_000;
695
+ const tokenDigestSchema = Schema.String.pipe(Schema.check(Schema.isPattern(/^[0-9a-f]{64}$/u)));
696
+ const bootCapabilityRowSchema = Schema.Struct({ lease_json: Schema.String });
697
+ /** The catalog's short-lived boot capability rows, over the same App Release D1. */
698
+ export function createD1BootCapabilityRows(database) {
699
+ return {
700
+ issue: async (input) => {
701
+ const tokenDigest = Schema.decodeUnknownSync(tokenDigestSchema)(input.tokenDigest);
702
+ if (input.expiresAt <= input.now ||
703
+ input.expiresAt - input.now > BOOT_CAPABILITY_MAX_LIFETIME_MS)
704
+ throw new RangeError("Boot capability lifetime is out of bounds");
705
+ await database.batch([
706
+ database
707
+ .prepare("DELETE FROM app_release_boot_capabilities WHERE expires_at <= ?")
708
+ .bind(input.now),
709
+ database
710
+ .prepare(`INSERT INTO app_release_boot_capabilities
711
+ (token_digest, lease_id, release_id, lease_json, expires_at)
712
+ VALUES (?, ?, ?, ?, ?)`)
713
+ .bind(tokenDigest, input.leaseId, parseReleaseId(input.releaseId), input.leaseJson, input.expiresAt),
714
+ ]);
715
+ },
716
+ resolve: async (tokenDigest, now) => {
717
+ const digest = Schema.decodeUnknownSync(tokenDigestSchema)(tokenDigest);
718
+ await database
719
+ .prepare("DELETE FROM app_release_boot_capabilities WHERE token_digest = ? AND expires_at <= ?")
720
+ .bind(digest, now)
721
+ .run();
722
+ const row = await database
723
+ .prepare("SELECT lease_json FROM app_release_boot_capabilities WHERE token_digest = ? AND expires_at > ?")
724
+ .bind(digest, now)
725
+ .first();
726
+ return row === null
727
+ ? null
728
+ : Schema.decodeUnknownSync(bootCapabilityRowSchema)(row).lease_json;
729
+ },
730
+ revoke: async (leaseId) => {
731
+ await database
732
+ .prepare("DELETE FROM app_release_boot_capabilities WHERE lease_id = ?")
733
+ .bind(leaseId)
734
+ .run();
735
+ },
736
+ };
737
+ }
650
738
  /** Create the D1-backed App Release store with private public-website authority. */
651
739
  export function createD1AppReleaseStore(database) {
652
740
  const transitionObligations = {
@@ -10,4 +10,4 @@ export declare const gitRefUpdateSchema: z.ZodObject<{
10
10
  after: z.ZodString;
11
11
  }, z.core.$strict>;
12
12
  /** Host push event IDs include the Computer and local event identity. */
13
- export declare const gitPushEventIdSchema: z.ZodString;
13
+ export declare const gitPushEventIdSchema: z.ZodLazy<z.ZodString>;
@@ -13,4 +13,4 @@ export const gitRefUpdateSchema = z.strictObject({
13
13
  after: gitSha1Schema,
14
14
  });
15
15
  /** Host push event IDs include the Computer and local event identity. */
16
- export const gitPushEventIdSchema = z.string().min(1).max(512);
16
+ export const gitPushEventIdSchema = z.lazy(() => z.string().min(1).max(512));
@@ -1468,6 +1468,9 @@ export declare const decodeReleaseLifecycleStoreResult: (input: unknown, options
1468
1468
  pending?: true | undefined;
1469
1469
  hidden?: true | undefined;
1470
1470
  anonymous?: true | undefined;
1471
+ present?: Readonly<{
1472
+ verb: string;
1473
+ }> | undefined;
1471
1474
  }>>>;
1472
1475
  toolFamily?: Readonly<{
1473
1476
  name: string;
@@ -226,6 +226,9 @@ export declare const decodePublicWebsiteAuthorityStoreResult: (input: unknown, o
226
226
  pending?: true | undefined;
227
227
  hidden?: true | undefined;
228
228
  anonymous?: true | undefined;
229
+ present?: Readonly<{
230
+ verb: string;
231
+ }> | undefined;
229
232
  }>>>;
230
233
  toolFamily?: Readonly<{
231
234
  name: string;