@fungi.computer/oyster 0.32.0 → 0.34.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/README.md +59 -0
- package/dist/app-sandbox.d.ts +2 -2
- package/dist/app-sandbox.js +2 -2
- package/dist/app-test-copies.d.ts +87 -0
- package/dist/app-test-copies.js +170 -0
- package/dist/app-test-copy-page.d.ts +4 -0
- package/dist/app-test-copy-page.js +89 -0
- package/dist/approval-deadline.d.ts +2 -0
- package/dist/approval-deadline.js +7 -0
- package/dist/approval-home.d.ts +26 -3
- package/dist/approval-home.js +148 -18
- package/dist/apps/index.d.ts +1 -1
- package/dist/apps/index.js +1 -1
- package/dist/browser/operations.d.ts +1 -1
- package/dist/cloudflare.d.ts +68 -3
- package/dist/cloudflare.js +214 -3
- package/dist/embed-metafiles.js +2 -2
- package/dist/embed-scripts.js +1 -1
- package/dist/host.d.ts +20 -4
- package/dist/host.js +314 -3
- package/dist/installation-operations.d.ts +247 -8
- package/dist/installation-operations.js +145 -7
- package/dist/installation-recovery-page.d.ts +24 -0
- package/dist/installation-recovery-page.js +168 -0
- package/dist/mcp.js +42 -13
- package/dist/older-oyster-store.d.ts +1 -1
- package/dist/older-oyster-store.js +2 -4
- package/dist/page/app-permissions.js +8 -7
- package/dist/page/computer-handles.d.ts +0 -1
- package/dist/page/mount.d.ts +2 -101
- package/dist/page/mount.js +1 -22
- package/dist/page-config.d.ts +102 -0
- package/dist/page-config.js +24 -0
- package/dist/page-script.js +2 -2
- package/dist/platform-skills.generated.d.ts +5 -2
- package/dist/platform-skills.generated.js +6 -2
- package/dist/recovery-style.d.ts +5 -0
- package/dist/recovery-style.js +32 -0
- package/dist/standalone/agents.d.ts +1 -1
- package/dist/standalone/agents.js +43 -7
- package/dist/standalone/computer-fleet.js +3 -0
- package/dist/standalone/computer.d.ts +6 -2
- package/dist/standalone/computer.js +27 -14
- package/dist/standalone/media.js +7 -2
- package/dist/standalone/preview.d.ts +21 -20
- package/dist/standalone/preview.js +147 -151
- package/dist/standalone/registry.d.ts +14 -21
- package/dist/standalone/registry.js +74 -28
- package/dist/standalone/worker.js +6 -3
- package/dist/starter-agent.d.ts +6 -2
- package/dist/starter-agent.js +25 -4
- package/dist/upgrade/old-worker-http.d.ts +2 -0
- package/dist/upgrade/old-worker-http.js +22 -0
- package/dist/upgrade/old-worker-readonly.d.ts +14 -0
- package/dist/upgrade/old-worker-readonly.js +22 -0
- package/dist/upgrade/old-worker-sql.d.ts +10 -0
- package/dist/upgrade/old-worker-sql.js +68 -0
- package/dist/upgrade/old-worker-stream.d.ts +12 -0
- package/dist/upgrade/old-worker-stream.js +54 -0
- package/dist/upgrade/private-stage.d.ts +23 -0
- package/dist/upgrade/private-stage.js +109 -0
- package/dist/upgrade/standalone-001.d.ts +16 -0
- package/dist/upgrade/standalone-001.js +31 -0
- package/dist/upgrade/standalone-01.d.ts +37 -0
- package/dist/upgrade/standalone-01.js +55 -0
- package/dist/upgrade/standalone-02.d.ts +37 -0
- package/dist/upgrade/standalone-02.js +55 -0
- package/dist/workers.d.ts +45 -14
- package/dist/workers.js +198 -21
- package/docs/api/README.md +8 -3
- package/docs/api/apps.md +21 -0
- package/docs/api/cloudflare.md +57 -0
- package/docs/api/host.md +263 -25
- package/docs/api/page/mount.md +13 -81
- package/docs/api/workers-git.md +246 -1
- package/docs/api/workers.md +518 -95
- package/package.json +38 -24
package/README.md
CHANGED
|
@@ -283,6 +283,65 @@ the low-level Instance, invocation and git ports. Most of the package's other
|
|
|
283
283
|
entry points are parts that the standalone host and the Fungi Hub assemble; you
|
|
284
284
|
do not need them to run Oyster.
|
|
285
285
|
|
|
286
|
+
## Recover an App
|
|
287
|
+
|
|
288
|
+
Open `/recovery` on your Oyster and sign in as its owner. This host-owned page
|
|
289
|
+
and its forms load no App, Shell or page assets, so they remain usable when the
|
|
290
|
+
selected App or home Shell cannot load. The page shows the current Release and
|
|
291
|
+
the prior confirmed activation, including its recorded UI-check outcome.
|
|
292
|
+
`not_checked` is not a passing UI check.
|
|
293
|
+
|
|
294
|
+
Rollback becomes available once an App has had a new version confirmed after an
|
|
295
|
+
Oyster upgrade: the first such version records the starting point, and the next
|
|
296
|
+
one gives you a version to return to. Until then the page says there is no
|
|
297
|
+
earlier version.
|
|
298
|
+
|
|
299
|
+
The installation owner retains its latest two distinct confirmed activations,
|
|
300
|
+
independently of expiring request receipts. Rollback chooses the prior
|
|
301
|
+
activation; if a newer selection never completed, it chooses the latest
|
|
302
|
+
confirmed one. The target must still belong to this App, Instance, host scope
|
|
303
|
+
and store incarnation. The owner selects the Release, not the browser.
|
|
304
|
+
|
|
305
|
+
**Roll back** submits a fresh, idempotent installation command fenced by the
|
|
306
|
+
displayed authority version and store generation. Admission is not completion:
|
|
307
|
+
the redirected observation reports the retained request state; refresh it to see
|
|
308
|
+
settlement. Normal artifact verification, permissions and Instance schema checks
|
|
309
|
+
still apply. Nothing rolls back automatically.
|
|
310
|
+
|
|
311
|
+
Rollback preserves the Instance and uses **current App data**. It does not
|
|
312
|
+
restore old data, undo completed external effects or provide a state-schema
|
|
313
|
+
migration. The owner API is `GET /api/installations/:installationId/recovery`
|
|
314
|
+
and `POST /api/installations/:installationId/rollback`; the POST takes only
|
|
315
|
+
`authorityVersion` and `storeGeneration`, with an `Idempotency-Key` header.
|
|
316
|
+
These routes reject App-mediated and cross-origin browser requests.
|
|
317
|
+
|
|
318
|
+
### Try disposable App data
|
|
319
|
+
|
|
320
|
+
On a native host with App-facet cloning, **Open test copy** snapshots the
|
|
321
|
+
enabled App's current data into one disposable sibling. It is not another
|
|
322
|
+
Installation or product Instance. Its page uses the selected Release's ordinary
|
|
323
|
+
sandboxed App UI and backend/method transports, without loading the editable
|
|
324
|
+
Shell. Creating and discarding the copy still work when App and Shell assets
|
|
325
|
+
cannot load; interacting with its App UI naturally needs that UI's assets.
|
|
326
|
+
|
|
327
|
+
The copy has no live bindings, Computer, capabilities or outbound network. Its
|
|
328
|
+
SQLite changes never promote into the live App. It expires after five minutes,
|
|
329
|
+
without renewal on retry, and **Discard test copy** retires it sooner. Selection
|
|
330
|
+
or store changes, installation revocation and deletion also retire it. This is
|
|
331
|
+
not a backup, data restoration, schema migration or reversal of external
|
|
332
|
+
effects. Hosts without the native copy service report it unavailable; rollback
|
|
333
|
+
does not depend on that service.
|
|
334
|
+
|
|
335
|
+
Owner-direct, same-origin forms use `POST /recovery/:installationId/test-copy`
|
|
336
|
+
and `POST /recovery/:installationId/test-copy/:copyId/discard`, fenced by
|
|
337
|
+
`authorityVersion` and `storeGeneration`. Creation takes a `requestId`; discard
|
|
338
|
+
names the host-minted `copyId`. Those identities are separate: replaying an old
|
|
339
|
+
creation request cannot revive a retired resource or let its delayed discard
|
|
340
|
+
retire a later copy. The latest request receipt is retained, not an unbounded
|
|
341
|
+
request history. The copy page is `GET` at that copy's path; its sibling
|
|
342
|
+
`PUT .../backend` and `POST .../methods/:name` doors retain current owner and
|
|
343
|
+
selection admission. No Release or lifetime is caller-selectable.
|
|
344
|
+
|
|
286
345
|
## Limits and errors
|
|
287
346
|
|
|
288
347
|
An App's backend gets 1,000 ms of CPU and 50 subrequests per call unless the
|
package/dist/app-sandbox.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export declare const appSandbox = "allow-scripts allow-modals allow-popups allow-forms";
|
|
1
|
+
/** Apps stay opaque; external tabs need their own origin for preview cookies. */
|
|
2
|
+
export declare const appSandbox = "allow-scripts allow-modals allow-popups allow-popups-to-escape-sandbox allow-forms";
|
package/dist/app-sandbox.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export const appSandbox = "allow-scripts allow-modals allow-popups allow-forms";
|
|
1
|
+
/** Apps stay opaque; external tabs need their own origin for preview cookies. */
|
|
2
|
+
export const appSandbox = "allow-scripts allow-modals allow-popups allow-popups-to-escape-sandbox allow-forms";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import type { WatchdogSqliteOwner } from "@fungi.computer/watchdog";
|
|
4
|
+
import { AppInstanceError, type Instance } from "./index.js";
|
|
5
|
+
/** A test copy is fenced to the same store and owner selection as its source. */
|
|
6
|
+
export declare const appTestCopyAuthoritySchema: z.ZodObject<{
|
|
7
|
+
selection: z.ZodPipe<z.ZodUnknown, z.ZodTransform<{
|
|
8
|
+
readonly instanceId: import("./instance-id.js").InstanceId;
|
|
9
|
+
readonly owner: {
|
|
10
|
+
readonly kind: "installation" | "deployment";
|
|
11
|
+
readonly id: string;
|
|
12
|
+
};
|
|
13
|
+
readonly appId: import("@fungi.computer/puffball").AppId;
|
|
14
|
+
readonly releaseId: import("@fungi.computer/puffball").ReleaseId;
|
|
15
|
+
readonly authorityVersion: number;
|
|
16
|
+
}, unknown>>;
|
|
17
|
+
storeGeneration: z.ZodString;
|
|
18
|
+
}, z.core.$strict>;
|
|
19
|
+
/** Exact source selection and store incarnation observed by the owner. */
|
|
20
|
+
export type AppTestCopyAuthority = z.output<typeof appTestCopyAuthoritySchema>;
|
|
21
|
+
/** Host-owned identity and fixed deadline of one disposable App-data sibling. */
|
|
22
|
+
export declare const appTestCopySchema: z.ZodObject<{
|
|
23
|
+
selection: z.ZodPipe<z.ZodUnknown, z.ZodTransform<{
|
|
24
|
+
readonly instanceId: import("./instance-id.js").InstanceId;
|
|
25
|
+
readonly owner: {
|
|
26
|
+
readonly kind: "installation" | "deployment";
|
|
27
|
+
readonly id: string;
|
|
28
|
+
};
|
|
29
|
+
readonly appId: import("@fungi.computer/puffball").AppId;
|
|
30
|
+
readonly releaseId: import("@fungi.computer/puffball").ReleaseId;
|
|
31
|
+
readonly authorityVersion: number;
|
|
32
|
+
}, unknown>>;
|
|
33
|
+
storeGeneration: z.ZodString;
|
|
34
|
+
copyId: z.ZodString;
|
|
35
|
+
expiresAt: z.ZodNumber;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
/** Observed sibling identity and nonrenewing deadline, never live host grants. */
|
|
38
|
+
export type AppTestCopy = z.output<typeof appTestCopySchema>;
|
|
39
|
+
/** Native operations stay with the Instance; only the App facet is cloned. */
|
|
40
|
+
export type AppTestCopyPorts = Readonly<{
|
|
41
|
+
owner: WatchdogSqliteOwner;
|
|
42
|
+
now: () => number;
|
|
43
|
+
source: () => Effect.Effect<Readonly<{
|
|
44
|
+
instance: Instance;
|
|
45
|
+
storeGeneration: string;
|
|
46
|
+
}> | null, Error>;
|
|
47
|
+
clone: () => Effect.Effect<void, Error>;
|
|
48
|
+
purge: () => Effect.Effect<void, Error>;
|
|
49
|
+
wake: (at: number) => Effect.Effect<void, Error>;
|
|
50
|
+
}>;
|
|
51
|
+
/** One bounded durable lifecycle, independent of App and editable Shell code. */
|
|
52
|
+
export declare function createAppTestCopies(ports: AppTestCopyPorts): {
|
|
53
|
+
open: (authority: AppTestCopyAuthority, requestId: string) => Effect.Effect<{
|
|
54
|
+
selection: {
|
|
55
|
+
readonly instanceId: import("./instance-id.js").InstanceId;
|
|
56
|
+
readonly owner: {
|
|
57
|
+
readonly kind: "installation" | "deployment";
|
|
58
|
+
readonly id: string;
|
|
59
|
+
};
|
|
60
|
+
readonly appId: import("@fungi.computer/puffball").AppId;
|
|
61
|
+
readonly releaseId: import("@fungi.computer/puffball").ReleaseId;
|
|
62
|
+
readonly authorityVersion: number;
|
|
63
|
+
};
|
|
64
|
+
storeGeneration: string;
|
|
65
|
+
copyId: string;
|
|
66
|
+
expiresAt: number;
|
|
67
|
+
}, Error | AppInstanceError, never>;
|
|
68
|
+
inspect: (authority: AppTestCopyAuthority) => Effect.Effect<{
|
|
69
|
+
selection: {
|
|
70
|
+
readonly instanceId: import("./instance-id.js").InstanceId;
|
|
71
|
+
readonly owner: {
|
|
72
|
+
readonly kind: "installation" | "deployment";
|
|
73
|
+
readonly id: string;
|
|
74
|
+
};
|
|
75
|
+
readonly appId: import("@fungi.computer/puffball").AppId;
|
|
76
|
+
readonly releaseId: import("@fungi.computer/puffball").ReleaseId;
|
|
77
|
+
readonly authorityVersion: number;
|
|
78
|
+
};
|
|
79
|
+
storeGeneration: string;
|
|
80
|
+
copyId: string;
|
|
81
|
+
expiresAt: number;
|
|
82
|
+
} | null, Error, never>;
|
|
83
|
+
withCopy: <A>(authority: AppTestCopyAuthority, copyId: string, work: (copy: AppTestCopy) => Effect.Effect<A, Error>) => Effect.Effect<A, Error | AppInstanceError, never>;
|
|
84
|
+
discard: (authority: AppTestCopyAuthority, copyId: string) => Effect.Effect<boolean, Error, never>;
|
|
85
|
+
expire: () => Effect.Effect<void, Error, never>;
|
|
86
|
+
revoke: () => Effect.Effect<void, Error, never>;
|
|
87
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Exit from "effect/Exit";
|
|
4
|
+
import * as Semaphore from "effect/Semaphore";
|
|
5
|
+
import { defineIdFamily } from "@fungi.computer/cairn/id";
|
|
6
|
+
import { ownerCodec } from "./apps/installation.js";
|
|
7
|
+
import { installationRequestIdSchema } from "./installation-operations.js";
|
|
8
|
+
import { AppInstanceError, selectionSchema } from "./index.js";
|
|
9
|
+
/** A test copy is fenced to the same store and owner selection as its source. */
|
|
10
|
+
export const appTestCopyAuthoritySchema = z.strictObject({
|
|
11
|
+
selection: ownerCodec(selectionSchema),
|
|
12
|
+
storeGeneration: z.string().min(1).max(256),
|
|
13
|
+
});
|
|
14
|
+
/** Resource identity is host-minted, never an idempotency key or an Instance. */
|
|
15
|
+
const appTestCopyIds = defineIdFamily({
|
|
16
|
+
family: "app-test-copy",
|
|
17
|
+
version: 1,
|
|
18
|
+
kinds: { copy: { prefix: "appcopy" } },
|
|
19
|
+
});
|
|
20
|
+
/** Host-owned identity and fixed deadline of one disposable App-data sibling. */
|
|
21
|
+
export const appTestCopySchema = appTestCopyAuthoritySchema.extend({
|
|
22
|
+
copyId: z.string().refine((value) => appTestCopyIds.copy.is(value)),
|
|
23
|
+
expiresAt: z.number().int().nonnegative(),
|
|
24
|
+
});
|
|
25
|
+
const recordSchema = appTestCopySchema.extend({
|
|
26
|
+
requestId: installationRequestIdSchema,
|
|
27
|
+
phase: z.enum(["creating", "active", "closing", "closed"]),
|
|
28
|
+
});
|
|
29
|
+
// Private resource ceiling, not caller-selectable policy or a renewable lease.
|
|
30
|
+
const lifetimeMs = 5 * 60 * 1000;
|
|
31
|
+
function matches(a, b) {
|
|
32
|
+
const left = a.selection;
|
|
33
|
+
const right = b.selection;
|
|
34
|
+
return (a.storeGeneration === b.storeGeneration &&
|
|
35
|
+
left.instanceId === right.instanceId &&
|
|
36
|
+
left.owner.kind === right.owner.kind &&
|
|
37
|
+
left.owner.id === right.owner.id &&
|
|
38
|
+
left.appId === right.appId &&
|
|
39
|
+
left.releaseId === right.releaseId &&
|
|
40
|
+
left.authorityVersion === right.authorityVersion);
|
|
41
|
+
}
|
|
42
|
+
function metadata(record) {
|
|
43
|
+
return {
|
|
44
|
+
selection: record.selection,
|
|
45
|
+
storeGeneration: record.storeGeneration,
|
|
46
|
+
copyId: record.copyId,
|
|
47
|
+
expiresAt: record.expiresAt,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** One bounded durable lifecycle, independent of App and editable Shell code. */
|
|
51
|
+
export function createAppTestCopies(ports) {
|
|
52
|
+
const sql = ports.owner.sql;
|
|
53
|
+
sql.exec("CREATE TABLE IF NOT EXISTS app_test_copy (id INTEGER PRIMARY KEY CHECK(id=1), record TEXT NOT NULL) STRICT");
|
|
54
|
+
const lock = Semaphore.makeUnsafe(1);
|
|
55
|
+
const attempt = (work) => Effect.try({
|
|
56
|
+
try: work,
|
|
57
|
+
catch: (cause) => cause instanceof Error ? cause : new Error("Test copy storage failed"),
|
|
58
|
+
});
|
|
59
|
+
const read = attempt(() => {
|
|
60
|
+
const row = sql
|
|
61
|
+
.exec("SELECT record FROM app_test_copy WHERE id=1")
|
|
62
|
+
.toArray()[0];
|
|
63
|
+
if (row === undefined)
|
|
64
|
+
return null;
|
|
65
|
+
const stored = z.strictObject({ record: z.string() }).parse(row);
|
|
66
|
+
return recordSchema.parse(JSON.parse(stored.record));
|
|
67
|
+
});
|
|
68
|
+
const write = (record) => attempt(() => {
|
|
69
|
+
sql.exec("INSERT INTO app_test_copy(id,record) VALUES(1,?) ON CONFLICT(id) DO UPDATE SET record=excluded.record", JSON.stringify(record));
|
|
70
|
+
});
|
|
71
|
+
const close = (record) => Effect.gen(function* () {
|
|
72
|
+
yield* write({ ...record, phase: "closing" });
|
|
73
|
+
// The expiry wake preceded clone. Purging must not depend on another
|
|
74
|
+
// scheduler write; a failed purge remains closing for that wake/replay.
|
|
75
|
+
yield* ports.purge();
|
|
76
|
+
yield* write({ ...record, phase: "closed" });
|
|
77
|
+
});
|
|
78
|
+
const currentSource = (authority) => ports.source().pipe(Effect.map((source) => source !== null &&
|
|
79
|
+
source.instance.status === "active" &&
|
|
80
|
+
source.instance.stateSchema !== null &&
|
|
81
|
+
matches(authority, {
|
|
82
|
+
selection: source.instance,
|
|
83
|
+
storeGeneration: source.storeGeneration,
|
|
84
|
+
})));
|
|
85
|
+
const live = Effect.gen(function* () {
|
|
86
|
+
const record = yield* read;
|
|
87
|
+
if (record === null || record.phase === "closed")
|
|
88
|
+
return null;
|
|
89
|
+
if (record.phase !== "active" ||
|
|
90
|
+
record.expiresAt <= ports.now() ||
|
|
91
|
+
!(yield* currentSource(record))) {
|
|
92
|
+
yield* close(record);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return record;
|
|
96
|
+
});
|
|
97
|
+
const inspect = (authority) => lock.withPermits(1)(live.pipe(Effect.map((record) => record !== null && matches(record, authority)
|
|
98
|
+
? metadata(record)
|
|
99
|
+
: null)));
|
|
100
|
+
// The native adapter bounds work. Keep its allocation and invocation under
|
|
101
|
+
// the same permit as retirement, not merely its initial metadata read.
|
|
102
|
+
const withCopy = (authority, copyId, work) => lock.withPermits(1)(Effect.gen(function* () {
|
|
103
|
+
const record = yield* live;
|
|
104
|
+
if (record?.copyId !== copyId || !matches(record, authority))
|
|
105
|
+
return yield* Effect.fail(new AppInstanceError("expired"));
|
|
106
|
+
const result = yield* work(metadata(record));
|
|
107
|
+
const current = yield* live;
|
|
108
|
+
if (current?.copyId !== copyId || !matches(current, authority))
|
|
109
|
+
return yield* Effect.fail(new AppInstanceError("revoked"));
|
|
110
|
+
return result;
|
|
111
|
+
}));
|
|
112
|
+
const open = (authority, requestId) => lock.withPermits(1)(Effect.gen(function* () {
|
|
113
|
+
const input = yield* attempt(() => appTestCopyAuthoritySchema.parse(authority));
|
|
114
|
+
const id = yield* attempt(() => installationRequestIdSchema.parse(requestId));
|
|
115
|
+
if (!(yield* currentSource(input)))
|
|
116
|
+
return yield* Effect.fail(new AppInstanceError("instance_inactive"));
|
|
117
|
+
yield* live;
|
|
118
|
+
const current = yield* read;
|
|
119
|
+
if (current?.phase === "closed" && current.requestId === id)
|
|
120
|
+
return yield* Effect.fail(new AppInstanceError("expired"));
|
|
121
|
+
if (current !== null && current.phase !== "closed") {
|
|
122
|
+
if (current.phase === "active" &&
|
|
123
|
+
current.requestId === id &&
|
|
124
|
+
matches(current, input))
|
|
125
|
+
return metadata(current);
|
|
126
|
+
return yield* Effect.fail(new AppInstanceError("conflicting_owner_state"));
|
|
127
|
+
}
|
|
128
|
+
const record = {
|
|
129
|
+
...input,
|
|
130
|
+
copyId: appTestCopyIds.copy.generate(),
|
|
131
|
+
requestId: id,
|
|
132
|
+
expiresAt: ports.now() + lifetimeMs,
|
|
133
|
+
phase: "creating",
|
|
134
|
+
};
|
|
135
|
+
yield* write(record);
|
|
136
|
+
return yield* Effect.gen(function* () {
|
|
137
|
+
// Retain cleanup before clone, including a crash before publication.
|
|
138
|
+
yield* ports.wake(record.expiresAt);
|
|
139
|
+
yield* ports.clone();
|
|
140
|
+
const active = { ...record, phase: "active" };
|
|
141
|
+
yield* write(active);
|
|
142
|
+
return metadata(active);
|
|
143
|
+
}).pipe(Effect.onExit((exit) => Exit.isFailure(exit) ? close(record) : Effect.void));
|
|
144
|
+
}));
|
|
145
|
+
const discard = (authority, copyId) => lock.withPermits(1)(Effect.gen(function* () {
|
|
146
|
+
const record = yield* read;
|
|
147
|
+
if (record === null ||
|
|
148
|
+
record.phase === "closed" ||
|
|
149
|
+
record.copyId !== copyId ||
|
|
150
|
+
!matches(record, authority))
|
|
151
|
+
return false;
|
|
152
|
+
yield* close(record);
|
|
153
|
+
return true;
|
|
154
|
+
}));
|
|
155
|
+
const expire = () => lock.withPermits(1)(Effect.gen(function* () {
|
|
156
|
+
const record = yield* read;
|
|
157
|
+
if (record === null || record.phase === "closed")
|
|
158
|
+
return;
|
|
159
|
+
if (record.phase !== "active" || record.expiresAt <= ports.now())
|
|
160
|
+
yield* close(record);
|
|
161
|
+
else
|
|
162
|
+
yield* ports.wake(record.expiresAt);
|
|
163
|
+
}));
|
|
164
|
+
const revoke = () => lock.withPermits(1)(Effect.gen(function* () {
|
|
165
|
+
const record = yield* read;
|
|
166
|
+
if (record !== null && record.phase !== "closed")
|
|
167
|
+
yield* close(record);
|
|
168
|
+
}));
|
|
169
|
+
return { open, inspect, withCopy, discard, expire, revoke };
|
|
170
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AppTestCopy } from "./app-test-copies.js";
|
|
2
|
+
import type { AppDeclaration } from "@fungi.computer/puffball/app";
|
|
3
|
+
/** Ordinary App mounting, but only the sibling backend/method doors are supplied. */
|
|
4
|
+
export declare function appTestCopyPage(installationId: string, copy: AppTestCopy, declaration: AppDeclaration | null, pageModule: string): Promise<Response>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { recoveryStyle } from "./recovery-style.js";
|
|
2
|
+
import { html, raw } from "hono/html";
|
|
3
|
+
import { appSandbox } from "./app-sandbox.js";
|
|
4
|
+
/** Ordinary App mounting, but only the sibling backend/method doors are supplied. */
|
|
5
|
+
export async function appTestCopyPage(installationId, copy, declaration, pageModule) {
|
|
6
|
+
const base = `/recovery/${encodeURIComponent(installationId)}/test-copy/${encodeURIComponent(copy.copyId)}`;
|
|
7
|
+
const config = {
|
|
8
|
+
workbench: false,
|
|
9
|
+
shellModuleUrl: null,
|
|
10
|
+
storage: false,
|
|
11
|
+
appsOpen: false,
|
|
12
|
+
computerId: null,
|
|
13
|
+
authorityVersion: copy.selection.authorityVersion,
|
|
14
|
+
commands: declaration?.commands ?? [],
|
|
15
|
+
icon: declaration?.icon ?? null,
|
|
16
|
+
roles: declaration?.roles ?? [],
|
|
17
|
+
capabilities: [],
|
|
18
|
+
installationId,
|
|
19
|
+
appId: copy.selection.appId,
|
|
20
|
+
releaseId: copy.selection.releaseId,
|
|
21
|
+
uiUrl: `/ui/${installationId}/${copy.selection.releaseId}/`,
|
|
22
|
+
backendUrl: `${base}/backend`,
|
|
23
|
+
methodsUrl: `${base}/methods/`,
|
|
24
|
+
};
|
|
25
|
+
return new Response(await html `<!doctype html>
|
|
26
|
+
<html lang="en">
|
|
27
|
+
<meta charset="utf-8" />
|
|
28
|
+
<meta name="viewport" content="width=device-width" />
|
|
29
|
+
<title>Test copy · ${installationId}</title>
|
|
30
|
+
${recoveryStyle}
|
|
31
|
+
<style>
|
|
32
|
+
html,
|
|
33
|
+
body {
|
|
34
|
+
margin: 0;
|
|
35
|
+
height: 100%;
|
|
36
|
+
}
|
|
37
|
+
body {
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-direction: column;
|
|
40
|
+
}
|
|
41
|
+
iframe {
|
|
42
|
+
border: 0;
|
|
43
|
+
width: 100%;
|
|
44
|
+
flex: 1;
|
|
45
|
+
min-height: 0;
|
|
46
|
+
}
|
|
47
|
+
</style>
|
|
48
|
+
<header class="bar">
|
|
49
|
+
<strong>Disposable test copy: ${installationId}</strong>
|
|
50
|
+
<p class="muted">
|
|
51
|
+
Changes stay in this copy, not the live App. Live capabilities and
|
|
52
|
+
network access are unavailable. Expires at
|
|
53
|
+
${new Date(copy.expiresAt).toISOString()}.
|
|
54
|
+
</p>
|
|
55
|
+
<form method="post" action="${base}/discard">
|
|
56
|
+
<input
|
|
57
|
+
type="hidden"
|
|
58
|
+
name="authorityVersion"
|
|
59
|
+
value="${copy.selection.authorityVersion}"
|
|
60
|
+
/>
|
|
61
|
+
<input
|
|
62
|
+
type="hidden"
|
|
63
|
+
name="storeGeneration"
|
|
64
|
+
value="${copy.storeGeneration}"
|
|
65
|
+
/>
|
|
66
|
+
<input type="hidden" name="copyId" value="${copy.copyId}" />
|
|
67
|
+
<button type="submit">Discard test copy</button>
|
|
68
|
+
</form>
|
|
69
|
+
<a href="/recovery">App recovery</a>
|
|
70
|
+
</header>
|
|
71
|
+
<iframe
|
|
72
|
+
id="oyster-app"
|
|
73
|
+
sandbox="${appSandbox}"
|
|
74
|
+
src="${config.uiUrl}"
|
|
75
|
+
title="${installationId} test copy"
|
|
76
|
+
></iframe>
|
|
77
|
+
<script type="application/json" id="oyster-config">
|
|
78
|
+
${raw(JSON.stringify(config).replaceAll("<", "\\u003c"))}
|
|
79
|
+
</script>
|
|
80
|
+
<script type="module" src="${pageModule}"></script>
|
|
81
|
+
</html>`, {
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
84
|
+
"Cache-Control": "no-store",
|
|
85
|
+
"X-Content-Type-Options": "nosniff",
|
|
86
|
+
"Content-Security-Policy": "default-src 'none'; script-src 'self'; worker-src 'none'; style-src 'unsafe-inline'; frame-src 'self'; connect-src 'self'; img-src 'self' data:; base-uri 'none'; form-action 'self'; frame-ancestors 'none'",
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Mycelium's execute admission caps the live invocation at fifteen minutes.
|
|
2
|
+
const maximumCallMs = 900_000;
|
|
3
|
+
/** Pin a finite deadline before RPC so delayed delivery cannot renew a call. */
|
|
4
|
+
export function oysterApprovalDeadlineAt(deadlineAt) {
|
|
5
|
+
const maximum = Date.now() + maximumCallMs;
|
|
6
|
+
return Math.min(deadlineAt ?? maximum, maximum);
|
|
7
|
+
}
|
package/dist/approval-home.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { ApprovalLedger, type Approvals, type
|
|
2
|
+
import { ApprovalLedger, type Approvals, type ApprovalApplyResult } from "@fungi.computer/approvals";
|
|
3
3
|
import type { WatchdogSqliteOwner } from "@fungi.computer/watchdog";
|
|
4
4
|
import type { OysterHost } from "./host.js";
|
|
5
5
|
import type { HostActor } from "@fungi.computer/puffball/app";
|
|
@@ -25,13 +25,31 @@ declare const callSchema: z.ZodObject<{
|
|
|
25
25
|
authorityFence: z.ZodString;
|
|
26
26
|
idempotencyKey: z.ZodString;
|
|
27
27
|
input: z.ZodJSONSchema;
|
|
28
|
+
deadlineAt: z.ZodNumber;
|
|
28
29
|
}, z.core.$strict>;
|
|
29
30
|
/** Host-generated App call metadata; the operation's input contains no actor or approval choice. */
|
|
30
31
|
export type OysterApprovalCall = z.output<typeof callSchema>;
|
|
32
|
+
/** The originating call receives the output or this terminal decision, never a pending notice. */
|
|
33
|
+
export type OysterApprovalResult = Exclude<ApprovalApplyResult, {
|
|
34
|
+
kind: "refused";
|
|
35
|
+
}> | Readonly<{
|
|
36
|
+
kind: "denied";
|
|
37
|
+
by: string;
|
|
38
|
+
note?: string;
|
|
39
|
+
message: string;
|
|
40
|
+
}> | Readonly<{
|
|
41
|
+
kind: "refused";
|
|
42
|
+
reason: Exclude<Extract<ApprovalApplyResult, {
|
|
43
|
+
kind: "refused";
|
|
44
|
+
}>["reason"], "expired"> | "approval_expired" | "cancelled";
|
|
45
|
+
denialNote?: string;
|
|
46
|
+
}>;
|
|
31
47
|
/** The registry's durable App effect home. Mycelium still owns operation/schema invocation. */
|
|
32
48
|
export declare class OysterApprovalHome {
|
|
33
49
|
private readonly host;
|
|
34
50
|
readonly ledger: ApprovalLedger;
|
|
51
|
+
private readonly active;
|
|
52
|
+
private readonly waiting;
|
|
35
53
|
private surfaces;
|
|
36
54
|
constructor(host: Readonly<{
|
|
37
55
|
owner: WatchdogSqliteOwner;
|
|
@@ -41,10 +59,15 @@ export declare class OysterApprovalHome {
|
|
|
41
59
|
commit: <T>(write: () => Promise<T>, nextWakeAt: () => number | null) => Promise<T>;
|
|
42
60
|
}>);
|
|
43
61
|
private createLedger;
|
|
44
|
-
submit(raw: OysterApprovalCall): Promise<
|
|
62
|
+
submit(raw: OysterApprovalCall): Promise<OysterApprovalResult>;
|
|
63
|
+
/** Trusted host cancellation, pinned to the same caller and operation identity. */
|
|
64
|
+
cancel(raw: OysterApprovalCall): Promise<void>;
|
|
65
|
+
private pruneCancellations;
|
|
66
|
+
private nextWakeAt;
|
|
67
|
+
private run;
|
|
45
68
|
/** Bind each read/decision to current membership, not the renderer's actor bytes. */
|
|
46
69
|
capability(rawActor: HostActor): Approvals;
|
|
47
|
-
/**
|
|
70
|
+
/** Alarms expire records only. They never execute a former call's effect. */
|
|
48
71
|
reconcile(): Promise<number | null>;
|
|
49
72
|
private resolve;
|
|
50
73
|
private execution;
|