@fungi.computer/oyster 0.31.2 → 0.33.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 (63) hide show
  1. package/README.md +59 -0
  2. package/dist/agent-computer-source.d.ts +1 -0
  3. package/dist/agent-computer-source.js +1 -0
  4. package/dist/app-test-copies.d.ts +87 -0
  5. package/dist/app-test-copies.js +170 -0
  6. package/dist/app-test-copy-page.d.ts +4 -0
  7. package/dist/app-test-copy-page.js +89 -0
  8. package/dist/apps/installation.js +19 -14
  9. package/dist/browser/operations.d.ts +1 -1
  10. package/dist/cloudflare.d.ts +68 -3
  11. package/dist/cloudflare.js +214 -3
  12. package/dist/embed-metafiles.js +2 -2
  13. package/dist/embed-scripts.js +2 -2
  14. package/dist/host.d.ts +16 -0
  15. package/dist/host.js +309 -1
  16. package/dist/installation-operations.d.ts +247 -8
  17. package/dist/installation-operations.js +145 -7
  18. package/dist/installation-recovery-page.d.ts +24 -0
  19. package/dist/installation-recovery-page.js +168 -0
  20. package/dist/older-oyster-store.d.ts +1 -1
  21. package/dist/older-oyster-store.js +2 -4
  22. package/dist/page/mount.d.ts +2 -101
  23. package/dist/page/mount.js +1 -22
  24. package/dist/page-config.d.ts +102 -0
  25. package/dist/page-config.js +24 -0
  26. package/dist/page-script.js +1 -1
  27. package/dist/platform-skills.generated.d.ts +11 -0
  28. package/dist/platform-skills.generated.js +16 -0
  29. package/dist/recovery-style.d.ts +5 -0
  30. package/dist/recovery-style.js +32 -0
  31. package/dist/standalone/agents.d.ts +1 -1
  32. package/dist/standalone/agents.js +1 -0
  33. package/dist/standalone/computer-skill-source.d.ts +13 -2
  34. package/dist/standalone/computer-skill-source.js +80 -6
  35. package/dist/standalone/workflow-host.d.ts +4 -4
  36. package/dist/standalone/workflows.d.ts +9 -9
  37. package/dist/storage-frame.d.ts +3 -3
  38. package/dist/upgrade/old-worker-http.d.ts +2 -0
  39. package/dist/upgrade/old-worker-http.js +22 -0
  40. package/dist/upgrade/old-worker-readonly.d.ts +14 -0
  41. package/dist/upgrade/old-worker-readonly.js +22 -0
  42. package/dist/upgrade/old-worker-sql.d.ts +10 -0
  43. package/dist/upgrade/old-worker-sql.js +68 -0
  44. package/dist/upgrade/old-worker-stream.d.ts +12 -0
  45. package/dist/upgrade/old-worker-stream.js +54 -0
  46. package/dist/upgrade/private-stage.d.ts +23 -0
  47. package/dist/upgrade/private-stage.js +109 -0
  48. package/dist/upgrade/standalone-001.d.ts +16 -0
  49. package/dist/upgrade/standalone-001.js +31 -0
  50. package/dist/upgrade/standalone-01.d.ts +37 -0
  51. package/dist/upgrade/standalone-01.js +55 -0
  52. package/dist/upgrade/standalone-02.d.ts +37 -0
  53. package/dist/upgrade/standalone-02.js +55 -0
  54. package/dist/workers.d.ts +16 -2
  55. package/dist/workers.js +117 -7
  56. package/docs/api/README.md +8 -3
  57. package/docs/api/apps.md +33 -33
  58. package/docs/api/cloudflare.md +57 -0
  59. package/docs/api/host.md +223 -14
  60. package/docs/api/page/mount.md +10 -78
  61. package/docs/api/workers-git.md +246 -1
  62. package/docs/api/workers.md +352 -14
  63. package/package.json +23 -10
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Stage supplied sources in a separate, private R2 binding. Even a complete
3
+ * stage is unverified: there is no proven no-writes window or DO/Git inventory.
4
+ * The real manifest belongs to the later certification step, not this module.
5
+ */
6
+ export declare function stageUpgradeSources(input: Readonly<{
7
+ releases: R2Bucket;
8
+ privateBucket: R2Bucket;
9
+ snapshots: () => AsyncIterable<Readonly<{
10
+ kind: "part";
11
+ name: string;
12
+ bytes: Uint8Array;
13
+ }> | Readonly<{
14
+ kind: "complete";
15
+ partCount: number;
16
+ unreachable: readonly string[];
17
+ }>>;
18
+ oldWorkerName: string;
19
+ oldVersion: "0.0.1" | "0.1.0" | "0.2.0";
20
+ }>): Promise<Readonly<{
21
+ stageKey: string;
22
+ sha256: string;
23
+ }>>;
@@ -0,0 +1,109 @@
1
+ import { nanoid } from "@fungi.computer/cairn";
2
+ /** Private safety ceilings; exceeding one refuses a stage rather than omitting data. */
3
+ const partBytes = 8 * 1024 * 1024;
4
+ const maxParts = 10_000;
5
+ async function digest(bytes) {
6
+ return Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes)))
7
+ .map((byte) => byte.toString(16).padStart(2, "0"))
8
+ .join("");
9
+ }
10
+ /**
11
+ * Stage supplied sources in a separate, private R2 binding. Even a complete
12
+ * stage is unverified: there is no proven no-writes window or DO/Git inventory.
13
+ * The real manifest belongs to the later certification step, not this module.
14
+ */
15
+ export async function stageUpgradeSources(input) {
16
+ if (input.releases === input.privateBucket)
17
+ throw new Error("The archive must have a separate private R2 binding");
18
+ // A retry gets a fresh namespace: an old unsealed attempt can never be
19
+ // completed by a later invocation.
20
+ const prefix = `oyster-upgrade/${nanoid()}`;
21
+ const parts = [];
22
+ const store = async (name, bytes) => {
23
+ if (parts.length >= maxParts || bytes.byteLength > partBytes)
24
+ throw new Error("Archive safety ceiling reached; nothing was certified");
25
+ const key = `${prefix}/part-${String(parts.length)}`;
26
+ if ((await input.privateBucket.put(key, bytes)) === null)
27
+ throw new Error("Private archive write refused");
28
+ const saved = await input.privateBucket.get(key);
29
+ if (saved === null)
30
+ throw new Error("Private archive readback failed");
31
+ const readback = await saved.arrayBuffer();
32
+ const sha256 = await digest(bytes);
33
+ if (readback.byteLength !== bytes.byteLength ||
34
+ (await digest(readback)) !== sha256)
35
+ throw new Error("Private archive checksum mismatch");
36
+ parts.push({ name, key, size: bytes.byteLength, sha256 });
37
+ };
38
+ let cursor;
39
+ let pages = 0;
40
+ let truncated = true;
41
+ while (truncated) {
42
+ if (++pages > maxParts)
43
+ throw new Error("R2 listing safety ceiling reached");
44
+ const page = await input.releases.list({ cursor });
45
+ for (const object of page.objects) {
46
+ if (!Number.isSafeInteger(object.size) || object.size < 0)
47
+ throw new Error("Invalid R2 object size");
48
+ for (let offset = 0; offset < object.size || offset === 0; offset += partBytes) {
49
+ const length = Math.min(partBytes, object.size - offset);
50
+ const source = await input.releases.get(object.key, length === 0 ? undefined : { range: { offset, length } });
51
+ if (source?.etag !== object.etag)
52
+ throw new Error("R2 object changed during archive");
53
+ const bytes = await source.arrayBuffer();
54
+ if (bytes.byteLength !== length)
55
+ throw new Error("Incomplete R2 object read");
56
+ await store(`R2:${object.key}:${String(offset)}`, bytes);
57
+ }
58
+ }
59
+ if (page.truncated) {
60
+ const next = page.cursor;
61
+ if (next.length === 0 || next === cursor)
62
+ throw new Error("Incomplete R2 listing");
63
+ cursor = next;
64
+ }
65
+ else {
66
+ truncated = false;
67
+ }
68
+ }
69
+ let completed;
70
+ let snapshotCount = 0;
71
+ let registryPresent = false;
72
+ for await (const record of input.snapshots()) {
73
+ if (completed !== undefined)
74
+ throw new Error("Incomplete DO snapshot");
75
+ if (record.kind === "part") {
76
+ const bytes = record.bytes;
77
+ if (!(bytes instanceof Uint8Array))
78
+ throw new Error("Invalid DO snapshot bytes");
79
+ await store(`DO:${record.name}`, Uint8Array.from(bytes).buffer);
80
+ if (record.name === "registry" || record.name.startsWith("registry/"))
81
+ registryPresent = true;
82
+ snapshotCount += 1;
83
+ }
84
+ else {
85
+ completed = record;
86
+ }
87
+ }
88
+ const unreachable = completed?.unreachable;
89
+ if (unreachable === undefined || completed?.partCount !== snapshotCount)
90
+ throw new Error("Incomplete DO snapshot");
91
+ if (!registryPresent)
92
+ throw new Error("Old Oyster registry snapshot missing");
93
+ const stage = {
94
+ kind: "oyster-unverified-stage-v1",
95
+ oldWorkerName: input.oldWorkerName,
96
+ oldVersion: input.oldVersion,
97
+ parts,
98
+ unreachable,
99
+ };
100
+ const stageKey = `${prefix}/stage.json`;
101
+ const bytes = new TextEncoder().encode(JSON.stringify(stage));
102
+ const sha256 = await digest(Uint8Array.from(bytes).buffer);
103
+ if ((await input.privateBucket.put(stageKey, bytes)) === null)
104
+ throw new Error("Private archive stage write refused");
105
+ const saved = await input.privateBucket.get(stageKey);
106
+ if (saved === null || (await digest(await saved.arrayBuffer())) !== sha256)
107
+ throw new Error("Private archive stage checksum mismatch");
108
+ return { stageKey, sha256 };
109
+ }
@@ -0,0 +1,16 @@
1
+ import type { OysterWorkerEnv } from "@fungi.computer/oyster-old-001/workers";
2
+ import { WorkerEntrypoint } from "cloudflare:workers";
3
+ import { ReadOnlyOldOysterDO } from "./old-worker-readonly.js";
4
+ export declare class OysterBinding extends WorkerEntrypoint {
5
+ }
6
+ export declare class OysterInstance extends ReadOnlyOldOysterDO {
7
+ }
8
+ export declare class OysterMcp extends ReadOnlyOldOysterDO {
9
+ }
10
+ export declare class OysterRegistry extends ReadOnlyOldOysterDO {
11
+ fetch(): Promise<Response>;
12
+ }
13
+ declare const _default: {
14
+ fetch(request: Request, env: OysterWorkerEnv): Promise<Response>;
15
+ };
16
+ export default _default;
@@ -0,0 +1,31 @@
1
+ import { WorkerEntrypoint } from "cloudflare:workers";
2
+ import { defaultTenant, tenantScope, } from "@fungi.computer/oyster-old-001/tenant";
3
+ import { oldRegistrySqlRequest } from "./old-worker-http.js";
4
+ import { ReadOnlyOldOysterDO } from "./old-worker-readonly.js";
5
+ import { streamOldSql } from "./old-worker-stream.js";
6
+ // The packaged 0.0.1 standalone has v1 and mcp-session-owner-v1, not oyster-v1.
7
+ export class OysterBinding extends WorkerEntrypoint {
8
+ }
9
+ export class OysterInstance extends ReadOnlyOldOysterDO {
10
+ }
11
+ export class OysterMcp extends ReadOnlyOldOysterDO {
12
+ }
13
+ export class OysterRegistry extends ReadOnlyOldOysterDO {
14
+ async fetch() {
15
+ const pendingAt = await this.readPendingAlarm();
16
+ return streamOldSql(this.ctx.storage.sql, {
17
+ pendingAt,
18
+ observedAt: Date.now(),
19
+ });
20
+ }
21
+ }
22
+ export default {
23
+ fetch(request, env) {
24
+ return oldRegistrySqlRequest(request, env.OYSTER_OWNER_KEY, () => {
25
+ const scope = tenantScope(defaultTenant, env.OYSTER_ORIGIN);
26
+ // The release-matched bridge binds REGISTRY to the OysterRegistry
27
+ // subclass exported here, whose fetch streams the export.
28
+ return env.REGISTRY.getByName(scope.durableName("registry")).fetch(new Request(request.url));
29
+ });
30
+ },
31
+ };
@@ -0,0 +1,37 @@
1
+ import type { StandaloneEnv } from "@fungi.computer/oyster-old-01/standalone";
2
+ import { WorkerEntrypoint, WorkflowEntrypoint } from "cloudflare:workers";
3
+ import { ReadOnlyOldOysterDO } from "./old-worker-readonly.js";
4
+ export declare class StandaloneTenants extends ReadOnlyOldOysterDO {
5
+ }
6
+ export declare class OysterMcp extends ReadOnlyOldOysterDO {
7
+ }
8
+ export declare class StandaloneWorkflowRuns extends ReadOnlyOldOysterDO {
9
+ }
10
+ export declare class StandaloneInstance extends ReadOnlyOldOysterDO {
11
+ }
12
+ export declare class ComputerDO extends ReadOnlyOldOysterDO {
13
+ }
14
+ export declare class OysterKeys extends ReadOnlyOldOysterDO {
15
+ }
16
+ export declare class OysterWebhooks extends ReadOnlyOldOysterDO {
17
+ }
18
+ export declare class StandaloneAgent extends ReadOnlyOldOysterDO {
19
+ }
20
+ export declare class AgentDirectory extends ReadOnlyOldOysterDO {
21
+ }
22
+ export declare class MediaOperationDO extends ReadOnlyOldOysterDO {
23
+ }
24
+ export declare class OysterBinding extends WorkerEntrypoint {
25
+ }
26
+ export declare class OysterComputerEgress extends WorkerEntrypoint {
27
+ }
28
+ export declare class OysterRegistry extends ReadOnlyOldOysterDO {
29
+ fetch(): Promise<Response>;
30
+ }
31
+ export declare class StandaloneGraphWorkflow extends WorkflowEntrypoint {
32
+ run(): Promise<never>;
33
+ }
34
+ declare const _default: {
35
+ fetch(request: Request, env: StandaloneEnv): Promise<Response>;
36
+ };
37
+ export default _default;
@@ -0,0 +1,55 @@
1
+ import { WorkerEntrypoint, WorkflowEntrypoint } from "cloudflare:workers";
2
+ import { defaultTenant, tenantScope, } from "@fungi.computer/oyster-old-01/tenant";
3
+ import { oldRegistrySqlRequest } from "./old-worker-http.js";
4
+ import { OysterArchivingError, ReadOnlyOldOysterDO, } from "./old-worker-readonly.js";
5
+ import { streamOldSql } from "./old-worker-stream.js";
6
+ // These are the published class identities, with no published constructors or
7
+ // callback bodies. Keep the published oyster-v1 migration tag unchanged.
8
+ export class StandaloneTenants extends ReadOnlyOldOysterDO {
9
+ }
10
+ export class OysterMcp extends ReadOnlyOldOysterDO {
11
+ }
12
+ export class StandaloneWorkflowRuns extends ReadOnlyOldOysterDO {
13
+ }
14
+ export class StandaloneInstance extends ReadOnlyOldOysterDO {
15
+ }
16
+ export class ComputerDO extends ReadOnlyOldOysterDO {
17
+ }
18
+ export class OysterKeys extends ReadOnlyOldOysterDO {
19
+ }
20
+ export class OysterWebhooks extends ReadOnlyOldOysterDO {
21
+ }
22
+ export class StandaloneAgent extends ReadOnlyOldOysterDO {
23
+ }
24
+ export class AgentDirectory extends ReadOnlyOldOysterDO {
25
+ }
26
+ export class MediaOperationDO extends ReadOnlyOldOysterDO {
27
+ }
28
+ export class OysterBinding extends WorkerEntrypoint {
29
+ }
30
+ export class OysterComputerEgress extends WorkerEntrypoint {
31
+ }
32
+ export class OysterRegistry extends ReadOnlyOldOysterDO {
33
+ async fetch() {
34
+ const pendingAt = await this.readPendingAlarm();
35
+ return streamOldSql(this.ctx.storage.sql, {
36
+ pendingAt,
37
+ observedAt: Date.now(),
38
+ });
39
+ }
40
+ }
41
+ export class StandaloneGraphWorkflow extends WorkflowEntrypoint {
42
+ run() {
43
+ return Promise.reject(new OysterArchivingError());
44
+ }
45
+ }
46
+ export default {
47
+ fetch(request, env) {
48
+ return oldRegistrySqlRequest(request, env.OYSTER_OWNER_KEY, () => {
49
+ const scope = tenantScope(defaultTenant, env.OYSTER_ORIGIN);
50
+ // The release-matched bridge binds REGISTRY to the OysterRegistry
51
+ // subclass exported here, whose fetch streams the export.
52
+ return env.REGISTRY.getByName(scope.durableName("registry")).fetch(new Request(request.url));
53
+ });
54
+ },
55
+ };
@@ -0,0 +1,37 @@
1
+ import type { StandaloneEnv } from "@fungi.computer/oyster-old-02/standalone";
2
+ import { WorkerEntrypoint, WorkflowEntrypoint } from "cloudflare:workers";
3
+ import { ReadOnlyOldOysterDO } from "./old-worker-readonly.js";
4
+ export declare class StandaloneTenants extends ReadOnlyOldOysterDO {
5
+ }
6
+ export declare class OysterMcp extends ReadOnlyOldOysterDO {
7
+ }
8
+ export declare class StandaloneWorkflowRuns extends ReadOnlyOldOysterDO {
9
+ }
10
+ export declare class StandaloneInstance extends ReadOnlyOldOysterDO {
11
+ }
12
+ export declare class ComputerDO extends ReadOnlyOldOysterDO {
13
+ }
14
+ export declare class OysterKeys extends ReadOnlyOldOysterDO {
15
+ }
16
+ export declare class OysterWebhooks extends ReadOnlyOldOysterDO {
17
+ }
18
+ export declare class StandaloneAgent extends ReadOnlyOldOysterDO {
19
+ }
20
+ export declare class AgentDirectory extends ReadOnlyOldOysterDO {
21
+ }
22
+ export declare class MediaOperationDO extends ReadOnlyOldOysterDO {
23
+ }
24
+ export declare class OysterBinding extends WorkerEntrypoint {
25
+ }
26
+ export declare class OysterComputerEgress extends WorkerEntrypoint {
27
+ }
28
+ export declare class OysterRegistry extends ReadOnlyOldOysterDO {
29
+ fetch(): Promise<Response>;
30
+ }
31
+ export declare class StandaloneGraphWorkflow extends WorkflowEntrypoint {
32
+ run(): Promise<never>;
33
+ }
34
+ declare const _default: {
35
+ fetch(request: Request, env: StandaloneEnv): Promise<Response>;
36
+ };
37
+ export default _default;
@@ -0,0 +1,55 @@
1
+ import { WorkerEntrypoint, WorkflowEntrypoint } from "cloudflare:workers";
2
+ import { defaultTenant, tenantScope, } from "@fungi.computer/oyster-old-02/tenant";
3
+ import { oldRegistrySqlRequest } from "./old-worker-http.js";
4
+ import { OysterArchivingError, ReadOnlyOldOysterDO, } from "./old-worker-readonly.js";
5
+ import { streamOldSql } from "./old-worker-stream.js";
6
+ // These are the published class identities, with no published constructors or
7
+ // callback bodies. Keep the published oyster-v1 migration tag unchanged.
8
+ export class StandaloneTenants extends ReadOnlyOldOysterDO {
9
+ }
10
+ export class OysterMcp extends ReadOnlyOldOysterDO {
11
+ }
12
+ export class StandaloneWorkflowRuns extends ReadOnlyOldOysterDO {
13
+ }
14
+ export class StandaloneInstance extends ReadOnlyOldOysterDO {
15
+ }
16
+ export class ComputerDO extends ReadOnlyOldOysterDO {
17
+ }
18
+ export class OysterKeys extends ReadOnlyOldOysterDO {
19
+ }
20
+ export class OysterWebhooks extends ReadOnlyOldOysterDO {
21
+ }
22
+ export class StandaloneAgent extends ReadOnlyOldOysterDO {
23
+ }
24
+ export class AgentDirectory extends ReadOnlyOldOysterDO {
25
+ }
26
+ export class MediaOperationDO extends ReadOnlyOldOysterDO {
27
+ }
28
+ export class OysterBinding extends WorkerEntrypoint {
29
+ }
30
+ export class OysterComputerEgress extends WorkerEntrypoint {
31
+ }
32
+ export class OysterRegistry extends ReadOnlyOldOysterDO {
33
+ async fetch() {
34
+ const pendingAt = await this.readPendingAlarm();
35
+ return streamOldSql(this.ctx.storage.sql, {
36
+ pendingAt,
37
+ observedAt: Date.now(),
38
+ });
39
+ }
40
+ }
41
+ export class StandaloneGraphWorkflow extends WorkflowEntrypoint {
42
+ run() {
43
+ return Promise.reject(new OysterArchivingError());
44
+ }
45
+ }
46
+ export default {
47
+ fetch(request, env) {
48
+ return oldRegistrySqlRequest(request, env.OYSTER_OWNER_KEY, () => {
49
+ const scope = tenantScope(defaultTenant, env.OYSTER_ORIGIN);
50
+ // The release-matched bridge binds REGISTRY to the OysterRegistry
51
+ // subclass exported here, whose fetch streams the export.
52
+ return env.REGISTRY.getByName(scope.durableName("registry")).fetch(new Request(request.url));
53
+ });
54
+ },
55
+ };
package/dist/workers.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ApprovalListInput, ApprovalAnswerInput, AutoApproveInput } from "@fungi.computer/approvals";
2
- import type { HostActor } from "@fungi.computer/puffball/app";
2
+ import type { HostActor, AppMethodCallContext } from "@fungi.computer/puffball/app";
3
3
  import { type OysterApprovalCall } from "./approval-home.js";
4
4
  import { type BootCapabilityGrant, type BootCapabilityLease } from "./boot-capability.js";
5
5
  import { type Installation } from "./apps/installation.js";
@@ -22,6 +22,7 @@ import * as Schema from "effect/Schema";
22
22
  import type { Release } from "@fungi.computer/puffball";
23
23
  import { type Backend, type Instance, type OwnerState } from "./index.js";
24
24
  import { r2ArtifactStore, type FrameBindingReply, type FrameBindingMethod, type FrameBindingProps } from "./cloudflare.js";
25
+ import type { AppTestCopy, AppTestCopyAuthority } from "./app-test-copies.js";
25
26
  import { type BackgroundFrameState, type InvocationFacts, type InvocationFrame } from "./invocation.js";
26
27
  import { type InstallationCommit, type InstanceResult, type OysterAuth, type OysterHost, type OysterJson } from "./host.js";
27
28
  import { type AppStorageResult, type AppStorageWrite, type AppStorageReset, type ResolvedAppStorage } from "@fungi.computer/agar/storage";
@@ -117,6 +118,7 @@ export declare class OysterRegistry<Env extends OysterWorkerEnv = OysterWorkerEn
117
118
  readonly revision: number;
118
119
  readonly expiresAt: number;
119
120
  readonly operation: string;
121
+ readonly reason: "pending" | "expired" | "not-found" | "not-eligible" | "already-answered" | "stale-revision" | "declined" | "fenced" | "not-granted" | "read-only" | "in-flight" | "outcome-unknown" | "identity-conflict" | null;
120
122
  readonly description: {
121
123
  readonly title: string;
122
124
  readonly inputBytes: number;
@@ -130,7 +132,6 @@ export declare class OysterRegistry<Env extends OysterWorkerEnv = OysterWorkerEn
130
132
  } | null;
131
133
  readonly access: "write" | "external";
132
134
  readonly state: "pending" | "expired" | "denied" | "applied" | "requested" | "approved" | "claimed" | "outcome_unknown";
133
- readonly reason: "pending" | "expired" | "not-found" | "not-eligible" | "already-answered" | "stale-revision" | "declined" | "fenced" | "not-granted" | "read-only" | "in-flight" | "outcome-unknown" | "identity-conflict" | null;
134
135
  readonly updatedAt: number;
135
136
  readonly module: string;
136
137
  readonly recordId: string;
@@ -377,10 +378,23 @@ export declare class OysterInstance<Env extends OysterWorkerEnv = OysterWorkerEn
377
378
  private runtime;
378
379
  private limits;
379
380
  private readonly frames;
381
+ private readonly testCopies;
380
382
  /** Content-addressed backends are verified once per Instance, not per call. */
381
383
  private readonly backends;
382
384
  private readonly gitJournal;
383
385
  constructor(ctx: DurableObjectState, env: Env);
386
+ /** Every wake owner shares the native alarm; none may postpone another. */
387
+ private scheduleWake;
388
+ /** Open only under the existing Instance serialization and pinned tenant. */
389
+ openTestCopy(authority: AppTestCopyAuthority, requestId: string, tenantId?: TenantId): Promise<InstanceResult<AppTestCopy>>;
390
+ /** Observation rechecks both applied selection and current registry incarnation. */
391
+ inspectTestCopy(authority: AppTestCopyAuthority, tenantId?: TenantId): Promise<InstanceResult<AppTestCopy | null>>;
392
+ /** A delayed discard cannot target a later sibling. */
393
+ discardTestCopy(authority: AppTestCopyAuthority, copyId: string, tenantId?: TenantId): Promise<InstanceResult<boolean>>;
394
+ /** Uses the ordinary invocation facade, without live bindings or host context. */
395
+ testCopyBackend(authority: AppTestCopyAuthority, copyId: string, request: Request, limits?: GuestLimits, tenantId?: TenantId): Promise<Response>;
396
+ /** Declared methods share copy isolation, never a live invocation frame or binding env. */
397
+ callTestCopy(authority: AppTestCopyAuthority, copyId: string, name: string, input: Schema.Json, caller: AppMethodCallContext, limits?: GuestLimits, tenantId?: TenantId): Promise<InstanceResult<unknown>>;
384
398
  /** The deployable root's host for one pinned tenant; this plain root is the single owner key. */
385
399
  protected hostFor(scope: TenantScope): Promise<OysterHost>;
386
400
  /** Reconstruct current host admission for each wake; non-default tenants get no wakes. */
package/dist/workers.js CHANGED
@@ -36,7 +36,7 @@ import * as Schema from "effect/Schema";
36
36
  import * as Stream from "effect/Stream";
37
37
  import { releaseSchema } from "@fungi.computer/puffball/effect";
38
38
  import { AppInstanceError, } from "./index.js";
39
- import { createCloudflareAppInstance, r2ArtifactStore, createCloudflareInvocationGate, edgeVerifiedObjectCache, decodeFrameBindingProps, captureFrameBindingReply, frameBindingEntrypoint, backgroundFrameMethods, } from "./cloudflare.js";
39
+ import { createCloudflareAppInstance, createCloudflareAppTestCopies, r2ArtifactStore, createCloudflareInvocationGate, edgeVerifiedObjectCache, decodeFrameBindingProps, captureFrameBindingReply, frameBindingEntrypoint, backgroundFrameMethods, } from "./cloudflare.js";
40
40
  import { invocationFactsSchema, assertBackgroundBinding, admitBackgroundFrame, } from "./invocation.js";
41
41
  import { deliverBackground, deliverGitPush } from "./internal/delivery.js";
42
42
  import { reportSlowInvocation } from "./internal/invocation-timing.js";
@@ -568,6 +568,18 @@ export class OysterBinding extends oysterBindingEntrypoint(oysterBindings) {
568
568
  function instanceHandle(target, scope, budget) {
569
569
  const { tenantId, origin } = scope;
570
570
  return {
571
+ testCopies: {
572
+ open: (authority, requestId) => target.openTestCopy(authority, requestId, tenantId),
573
+ inspect: (authority) => target.inspectTestCopy(authority, tenantId),
574
+ discard: (authority, copyId) => target.discardTestCopy(authority, copyId, tenantId),
575
+ fetch: (authority, copyId, request) => target.testCopyBackend(authority, copyId, request, budget, tenantId),
576
+ call: async (authority, copyId, name, input, caller) => {
577
+ const reply = await target.callTestCopy(authority, copyId, name, input, caller, budget, tenantId);
578
+ return reply.ok
579
+ ? { ok: true, value: appMethodReplySchema.parse(reply.value) }
580
+ : reply;
581
+ },
582
+ },
571
583
  prepare: (state, release) => target.prepare(state, release, budget, { tenantId, origin }),
572
584
  apply: (state, release) => target.apply(state, release, budget, { tenantId, origin }),
573
585
  fetch: (facts, request) => target.backend(facts, request, budget, tenantId),
@@ -600,6 +612,7 @@ export class OysterInstance extends DurableObject {
600
612
  runtime;
601
613
  limits = guestLimits();
602
614
  frames;
615
+ testCopies;
603
616
  /** Content-addressed backends are verified once per Instance, not per call. */
604
617
  backends;
605
618
  gitJournal;
@@ -616,6 +629,44 @@ export class OysterInstance extends DurableObject {
616
629
  this.backends = backendCache(r2ArtifactStore(env.RELEASES));
617
630
  this.runtime = this.createRuntime(this.limits);
618
631
  this.frames = createCloudflareInvocationGate(ctx, (frame) => this.closeBackground(frame));
632
+ this.testCopies = createCloudflareAppTestCopies(ctx, env.LOADER, {
633
+ limits: () => this.limits,
634
+ source: () => Effect.tryPromise({
635
+ try: async () => {
636
+ const instance = await Effect.runPromise(this.runtime.inspect());
637
+ if (instance?.owner.id !== this.installationId())
638
+ return null;
639
+ const store = registryInstallations(env, this.scope());
640
+ const installation = await store.get(instance.owner.id);
641
+ if (!isCommittedInstallation(installation, { ...instance, status: "enabled" }, this.release(instance.releaseId)))
642
+ return null;
643
+ return { instance, storeGeneration: await store.generation() };
644
+ },
645
+ catch: (cause) => cause instanceof Error
646
+ ? cause
647
+ : new Error("Copy source unavailable"),
648
+ }),
649
+ resolve: (releaseId) => Effect.tryPromise({
650
+ try: async () => {
651
+ const release = this.release(releaseId);
652
+ const backend = await this.backends(release);
653
+ if (backend === null)
654
+ throw new Error("Release has no backend");
655
+ return {
656
+ release,
657
+ ...backend,
658
+ api: backend.declaration?.api ?? null,
659
+ };
660
+ },
661
+ catch: (cause) => cause instanceof Error
662
+ ? cause
663
+ : new Error("Copy Release unavailable"),
664
+ }),
665
+ wake: (at) => Effect.tryPromise({
666
+ try: () => this.scheduleWake(at),
667
+ catch: (cause) => cause instanceof Error ? cause : new Error("Copy wake unavailable"),
668
+ }),
669
+ });
619
670
  // Local delivery avoids calling this Instance's own RPC stub from its alarm.
620
671
  const instances = {
621
672
  get: (instanceId) => this.localInstance(instanceId),
@@ -648,13 +699,53 @@ export class OysterInstance extends DurableObject {
648
699
  receipt: { lane: wake.lane, epoch: wake.epoch },
649
700
  };
650
701
  },
651
- scheduleWake: (at) => ctx.storage.transaction(async (transaction) => {
652
- const current = await transaction.getAlarm();
653
- if (current === null || at < current)
654
- await transaction.setAlarm(at);
655
- }),
702
+ scheduleWake: (at) => this.scheduleWake(at),
656
703
  }));
657
704
  }
705
+ /** Every wake owner shares the native alarm; none may postpone another. */
706
+ scheduleWake(at) {
707
+ return this.ctx.storage.transaction(async (transaction) => {
708
+ const current = await transaction.getAlarm();
709
+ if (current === null || at < current)
710
+ await transaction.setAlarm(at);
711
+ });
712
+ }
713
+ /** Open only under the existing Instance serialization and pinned tenant. */
714
+ openTestCopy(authority, requestId, tenantId = defaultTenant) {
715
+ this.requireTenant(tenantId);
716
+ return this.frames.exclusive(() => result(this.testCopies.open(authority, requestId)));
717
+ }
718
+ /** Observation rechecks both applied selection and current registry incarnation. */
719
+ inspectTestCopy(authority, tenantId = defaultTenant) {
720
+ this.requireTenant(tenantId);
721
+ return this.frames.exclusive(() => result(this.testCopies.inspect(authority)));
722
+ }
723
+ /** A delayed discard cannot target a later sibling. */
724
+ discardTestCopy(authority, copyId, tenantId = defaultTenant) {
725
+ this.requireTenant(tenantId);
726
+ return this.frames.exclusive(() => result(this.testCopies.discard(authority, copyId)));
727
+ }
728
+ /** Uses the ordinary invocation facade, without live bindings or host context. */
729
+ async testCopyBackend(authority, copyId, request, limits, tenantId = defaultTenant) {
730
+ this.requireTenant(tenantId);
731
+ try {
732
+ return await this.frames.exclusive(() => {
733
+ this.runtimeFor(limits);
734
+ return Effect.runPromise(this.testCopies.fetch(authority, copyId, request));
735
+ });
736
+ }
737
+ catch (cause) {
738
+ return Response.json({ error: cause instanceof AppInstanceError ? cause.code : "failed" }, { status: cause instanceof AppInstanceError ? 403 : 502 });
739
+ }
740
+ }
741
+ /** Declared methods share copy isolation, never a live invocation frame or binding env. */
742
+ callTestCopy(authority, copyId, name, input, caller, limits, tenantId = defaultTenant) {
743
+ this.requireTenant(tenantId);
744
+ return this.frames.exclusive(() => {
745
+ this.runtimeFor(limits);
746
+ return result(this.testCopies.call(authority, copyId, name, input, caller));
747
+ });
748
+ }
658
749
  /** The deployable root's host for one pinned tenant; this plain root is the single owner key. */
659
750
  hostFor(scope) {
660
751
  return Promise.resolve(ownerKeyRootHost(this.env, { scope }));
@@ -831,7 +922,14 @@ export class OysterInstance extends DurableObject {
831
922
  }
832
923
  /** Carrier owns retries, dead letters and retained delivery receipts. */
833
924
  async alarm() {
834
- await (await this.gitJournal).alarm();
925
+ // Neither duty may mask the other; the first failure still surfaces.
926
+ const settled = await Promise.allSettled([
927
+ this.gitJournal.then((journal) => journal.alarm()),
928
+ Effect.runPromise(this.testCopies.expire()),
929
+ ]);
930
+ const failed = settled.find((outcome) => outcome.status === "rejected");
931
+ if (failed !== undefined)
932
+ throw failed.reason;
835
933
  }
836
934
  /** Installation changes end guest work; a Workflow cancel targets only its run. */
837
935
  async revoke(installationId, runId, tenantId = defaultTenant) {
@@ -847,6 +945,8 @@ export class OysterInstance extends DurableObject {
847
945
  if (installationId !== this.installationId())
848
946
  throw new AppInstanceError("instance_owner_mismatch");
849
947
  await this.frames.revoke(new AppInstanceError("revoked"), runId === undefined ? undefined : { runId });
948
+ if (runId === undefined)
949
+ await Effect.runPromise(this.testCopies.revoke());
850
950
  }
851
951
  /** One registry read re-admits a guest binding packet against its frame. */
852
952
  async assertCurrent(frame) {
@@ -1006,6 +1106,16 @@ export class OysterInstance extends DurableObject {
1006
1106
  checkTenant();
1007
1107
  if (!(await committed()))
1008
1108
  return { ok: false, code: "stale_authority" };
1109
+ try {
1110
+ await Effect.runPromise(this.testCopies.revoke());
1111
+ }
1112
+ catch (cause) {
1113
+ // A stuck test copy must not block the selection that retires it:
1114
+ // it stays closing and the alarm's expiry retries the purge.
1115
+ console.error("Oyster: test copy revoke failed during activation", {
1116
+ causeClass: causeClass(cause),
1117
+ });
1118
+ }
1009
1119
  // These pins attest the committed owner, not successful activation.
1010
1120
  // Persist before boot so a failed first activation can be retried or
1011
1121
  // revoked/deleted without ever claiming an active lifecycle receipt.
@@ -148,9 +148,14 @@ installed Apps are cleared once: Oyster Home asks you to reinstall them with
148
148
  `npx @fungi.computer/oyster install-apps`, which restores the Apps and their App
149
149
  settings, while each App's own backend database starts empty. Agents, Sessions,
150
150
  files and keys are kept. From 0.2 or earlier, Oyster answers every request with
151
- `409` and `store_from_older_oyster`; deploy under new resource names or tear the
152
- old one down first. The changelog entry for each release says when it resets
153
- data.
151
+ `409` and `store_from_older_oyster` and leaves the store untouched. Do not tear
152
+ the old Worker down or deploy over it: verify its release first (0.0.1 needs a
153
+ release-matched bridge; 0.1 and 0.2 are archived through their own Worker before
154
+ a fresh setup under new names). A bridge at the old Worker's name accepts only
155
+ the owner's export request and answers everything else `503 oyster_archiving`.
156
+ The archive workflow is still being built and its registry SQL export is not a
157
+ certified archive, so keep the old Worker and its stores until you have one. The
158
+ changelog entry for each release says when it resets data.
154
159
 
155
160
  ### Run on celld
156
161