@fungi.computer/computer 0.6.2 → 0.7.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 +97 -83
- package/dist/apply-patch/cache.mjs +3 -1
- package/dist/fleet/inventory.d.ts +2 -0
- package/dist/fleet/inventory.js +47 -2
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,93 +1,21 @@
|
|
|
1
|
-
# Computer
|
|
1
|
+
# Computer (`@fungi.computer/computer`)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
A Fungi Computer is a durable workspace for Agents: files in SQLite inside a
|
|
4
|
+
Durable Object, with a Linux container or an in-Worker shell behind it to run
|
|
5
|
+
commands, processes and ports. Oyster's standalone host runs one; the Fungi Hub
|
|
6
|
+
composes it with Team authorization, capacity and billing.
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Install
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
from
|
|
12
|
-
`@fungi.computer/computer/backing`. These entries do not load Worker runtime
|
|
13
|
-
declarations. The `./fleet` lifecycle and main Computer entry require the host
|
|
14
|
-
runtime's Cloudflare Workers types.
|
|
15
|
-
|
|
16
|
-
The packed stranger check exercises these Node-safe entries and the egress
|
|
17
|
-
helpers after a cold install of the runtime closure. The fork's companion check
|
|
18
|
-
parses the published shell-module groups used by the Computer image with Acorn
|
|
19
|
-
and checks their declarations. Neither check starts a Computer, executes a
|
|
20
|
-
Worker shell, or qualifies the Worker/Workspace/Git SDK in a Node type
|
|
21
|
-
environment.
|
|
22
|
-
|
|
23
|
-
`@fungi.computer/computer/fleet` owns the host-neutral grant check, backing
|
|
24
|
-
records and fact contracts. A host authenticates its caller and supplies a
|
|
25
|
-
`ComputerGrant`: one Computer, explicit actions, an expiry, optional host-owned
|
|
26
|
-
egress data, plus opaque actor/invocation provenance. `checkComputerGrant`
|
|
27
|
-
returns `admitted` or `Refused`; grants impose no paid-usage budget. A caller's
|
|
28
|
-
per-command timeout remains a command parameter enforced by the operation
|
|
29
|
-
executor. Hub credit enforcement remains on its existing funded/unfunded
|
|
30
|
-
admission and `creditChanged` → credit-publication restate/stop path.
|
|
31
|
-
|
|
32
|
-
`createFleetBacking` accepts the maintained SQLite owner. Creation records a
|
|
33
|
-
plain backing decision once. Explicit fleet-default and Computer overrides
|
|
34
|
-
remain possible; local attachment keeps replay identity, actor ownership and
|
|
35
|
-
detach cancellation. Mutations return complete backend projections rather than
|
|
36
|
-
calling a host or delivering messages. The composing host can include the call
|
|
37
|
-
and durable outbox staging in its SQLite transaction. Its deployment chooses the
|
|
38
|
-
offered backing kinds; the fleet never rereads deployment configuration.
|
|
39
|
-
|
|
40
|
-
`ComputerFact` describes process exit, file writes, egress, lifecycle and
|
|
41
|
-
runtime interval observations with provenance. CPU time is nullable when
|
|
42
|
-
unmeasured. The host reads these records and owns settlement and delivery.
|
|
43
|
-
Host-specific egress data is decoded by its host; the fleet contract carries
|
|
44
|
-
JSON data without importing the host's policy.
|
|
45
|
-
|
|
46
|
-
The fleet also owns inventory/replay receipts, running-slot storage, runtime
|
|
47
|
-
intervals, and native lifecycle activity/recycling. Inventory admission stays at
|
|
48
|
-
the host: an existing create receipt is checked before funding a new create.
|
|
49
|
-
Slot capacity is explicit infrastructure input; grants carry no usage cap.
|
|
50
|
-
`FleetLifecycle.run` checks a host-issued start grant before native execution.
|
|
51
|
-
The host consumes returned reservation/diagnostic facts and
|
|
52
|
-
`ComputerRuntimeUsage.pendingFacts` interval facts; it owns credit changes,
|
|
53
|
-
usage delivery, logging, and Team Git. Acknowledgment retains the existing
|
|
54
|
-
runtime checkpoint identity and occurs only after delivery. Transport activity,
|
|
55
|
-
idle sleep, and VM recycle sequencing retain the existing runtime behavior. The
|
|
56
|
-
Hub records creation backing facts for its declared known Computers at
|
|
57
|
-
initialization; the fleet never derives missing records on reads.
|
|
58
|
-
|
|
59
|
-
The Hub projects each current resource decision into a grant for the requested
|
|
60
|
-
Files or execution permission. It carries the stored decision's expiry and
|
|
61
|
-
actor/attachment identity. Native acceptance still rechecks the current Hub
|
|
62
|
-
decision before fleet admission; a grant is never cached across that check. The
|
|
63
|
-
Hub projects interval facts into its existing usage Post payload without
|
|
64
|
-
changing billing or credit-stop behavior.
|
|
65
|
-
|
|
66
|
-
The repository architecture test rejects upward imports from this runtime into
|
|
67
|
-
Apps, Billing, Broker or Team/plan modules, including type and dynamic imports.
|
|
68
|
-
|
|
69
|
-
## Source setup
|
|
70
|
-
|
|
71
|
-
Use a configured repository checkout with the pinned Node and pnpm tools. Run
|
|
72
|
-
from the repository root:
|
|
10
|
+
Install it beside Oyster, whose example `wrangler.jsonc` builds the Computer's
|
|
11
|
+
container from this package's `Dockerfile`:
|
|
73
12
|
|
|
74
13
|
```sh
|
|
75
|
-
|
|
76
|
-
pnpm --filter @fungi.computer/computer typecheck
|
|
77
|
-
pnpm --filter @fungi.computer/computer lint
|
|
78
|
-
pnpm turbo:run run test --filter=@fungi.computer/computer
|
|
14
|
+
npm install @fungi.computer/oyster @fungi.computer/computer
|
|
79
15
|
```
|
|
80
16
|
|
|
81
|
-
The
|
|
82
|
-
|
|
83
|
-
checks. Docker owns its layer cache; the image build has a separate bounded
|
|
84
|
-
proof lifetime, so cold compilation does not consume the Worker response
|
|
85
|
-
deadline. Before invoking a native test file directly, run
|
|
86
|
-
`pnpm turbo:run run build:container --filter=@fungi.computer/computer`.
|
|
87
|
-
|
|
88
|
-
The test suite uses disposable Workers and proof containers, so container proofs
|
|
89
|
-
require a working local Docker/Workers environment. These commands do not deploy
|
|
90
|
-
a Hub, publish an App or replace a production Computer image.
|
|
17
|
+
The [Oyster README](https://github.com/fungi-computer/oyster) deploys both. The
|
|
18
|
+
runtime itself does not own Team roles or billing.
|
|
91
19
|
|
|
92
20
|
## Files and operation results
|
|
93
21
|
|
|
@@ -212,6 +140,67 @@ Computer control endpoints to the browser.
|
|
|
212
140
|
the host's admitted egress composition; a native container binding and the
|
|
213
141
|
on-box host adapter are separate configuration paths.
|
|
214
142
|
|
|
143
|
+
## Fleet contracts
|
|
144
|
+
|
|
145
|
+
Node tooling and browser consumers can import the grant/fact schemas and types
|
|
146
|
+
from `@fungi.computer/computer/fleet/wire`, and backing descriptions from
|
|
147
|
+
`@fungi.computer/computer/backing`. These entries do not load Worker runtime
|
|
148
|
+
declarations. The `./fleet` lifecycle and main Computer entry require the host
|
|
149
|
+
runtime's Cloudflare Workers types.
|
|
150
|
+
|
|
151
|
+
The packed stranger check exercises these Node-safe entries and the egress
|
|
152
|
+
helpers after a cold install of the runtime closure. The fork's companion check
|
|
153
|
+
parses the published shell-module groups used by the Computer image with Acorn
|
|
154
|
+
and checks their declarations. Neither check starts a Computer, executes a
|
|
155
|
+
Worker shell, or qualifies the Worker/Workspace/Git SDK in a Node type
|
|
156
|
+
environment.
|
|
157
|
+
|
|
158
|
+
`@fungi.computer/computer/fleet` owns the host-neutral grant check, backing
|
|
159
|
+
records and fact contracts. A host authenticates its caller and supplies a
|
|
160
|
+
`ComputerGrant`: one Computer, explicit actions, an expiry, optional host-owned
|
|
161
|
+
egress data, plus opaque actor/invocation provenance. `checkComputerGrant`
|
|
162
|
+
returns `admitted` or `Refused`; grants impose no paid-usage budget. A caller's
|
|
163
|
+
per-command timeout remains a command parameter enforced by the operation
|
|
164
|
+
executor. Hub credit enforcement remains on its existing funded/unfunded
|
|
165
|
+
admission and `creditChanged` → credit-publication restate/stop path.
|
|
166
|
+
|
|
167
|
+
`createFleetBacking` accepts the maintained SQLite owner. Creation records a
|
|
168
|
+
plain backing decision once. Explicit fleet-default and Computer overrides
|
|
169
|
+
remain possible; local attachment keeps replay identity, actor ownership and
|
|
170
|
+
detach cancellation. Mutations return complete backend projections rather than
|
|
171
|
+
calling a host or delivering messages. The composing host can include the call
|
|
172
|
+
and durable outbox staging in its SQLite transaction. Its deployment chooses the
|
|
173
|
+
offered backing kinds; the fleet never rereads deployment configuration.
|
|
174
|
+
|
|
175
|
+
`ComputerFact` describes process exit, file writes, egress, lifecycle and
|
|
176
|
+
runtime interval observations with provenance. CPU time is nullable when
|
|
177
|
+
unmeasured. The host reads these records and owns settlement and delivery.
|
|
178
|
+
Host-specific egress data is decoded by its host; the fleet contract carries
|
|
179
|
+
JSON data without importing the host's policy.
|
|
180
|
+
|
|
181
|
+
The fleet also owns inventory/replay receipts, running-slot storage, runtime
|
|
182
|
+
intervals, and native lifecycle activity/recycling. Inventory admission stays at
|
|
183
|
+
the host: an existing create receipt is checked before funding a new create.
|
|
184
|
+
Slot capacity is explicit infrastructure input; grants carry no usage cap.
|
|
185
|
+
`FleetLifecycle.run` checks a host-issued start grant before native execution.
|
|
186
|
+
The host consumes returned reservation/diagnostic facts and
|
|
187
|
+
`ComputerRuntimeUsage.pendingFacts` interval facts; it owns credit changes,
|
|
188
|
+
usage delivery, logging, and Team Git. Acknowledgment retains the existing
|
|
189
|
+
runtime checkpoint identity and occurs only after delivery. Transport activity,
|
|
190
|
+
idle sleep, and VM recycle sequencing retain the existing runtime behavior. The
|
|
191
|
+
Hub records creation backing facts for its declared known Computers at
|
|
192
|
+
initialization; the fleet never derives missing records on reads.
|
|
193
|
+
|
|
194
|
+
The Hub projects each current resource decision into a grant for the requested
|
|
195
|
+
Files or execution permission. It carries the stored decision's expiry and
|
|
196
|
+
actor/attachment identity. Native acceptance still rechecks the current Hub
|
|
197
|
+
decision before fleet admission; a grant is never cached across that check. The
|
|
198
|
+
Hub projects interval facts into its existing usage Post payload without
|
|
199
|
+
changing billing or credit-stop behavior.
|
|
200
|
+
|
|
201
|
+
The repository architecture test rejects upward imports from this runtime into
|
|
202
|
+
Apps, Billing, Broker or Team/plan modules, including type and dynamic imports.
|
|
203
|
+
|
|
215
204
|
## Image and build inputs
|
|
216
205
|
|
|
217
206
|
The [Dockerfile](Dockerfile) builds the Linux environment with pinned Node,
|
|
@@ -261,3 +250,28 @@ service-relative routing. The host supplies its selector decoder, hostname
|
|
|
261
250
|
policy and live admission callback. Admission runs at the exposed-port listing
|
|
262
251
|
and forwarding acceptance points; a ticket is never a grant. Hub retains its
|
|
263
252
|
local App projection and signed-ticket hostname configuration.
|
|
253
|
+
|
|
254
|
+
## Contribute
|
|
255
|
+
|
|
256
|
+
Use a configured repository checkout with the pinned Node and pnpm tools. Run
|
|
257
|
+
from the repository root:
|
|
258
|
+
|
|
259
|
+
```sh
|
|
260
|
+
pnpm turbo:run run build --filter=@fungi.computer/computer
|
|
261
|
+
pnpm --filter @fungi.computer/computer typecheck
|
|
262
|
+
pnpm --filter @fungi.computer/computer lint
|
|
263
|
+
pnpm turbo:run run test --filter=@fungi.computer/computer
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
The build emits the runtime and copies its daemon/build assets. The test graph
|
|
267
|
+
assembles and builds the local container image before starting native Worker
|
|
268
|
+
checks. Docker owns its layer cache; the image build has a separate bounded
|
|
269
|
+
proof lifetime, so cold compilation does not consume the Worker response
|
|
270
|
+
deadline. Before invoking a native test file directly, run
|
|
271
|
+
`pnpm turbo:run run build:container --filter=@fungi.computer/computer`.
|
|
272
|
+
|
|
273
|
+
The test suite uses disposable Workers and proof containers, so container proofs
|
|
274
|
+
require a working local Docker/Workers environment. These commands do not deploy
|
|
275
|
+
a Hub, publish an App or replace a production Computer image.
|
|
276
|
+
|
|
277
|
+
MIT. See [`LICENSE`](LICENSE).
|
|
@@ -114,10 +114,12 @@ export async function ensureNativePatchArtifact({
|
|
|
114
114
|
}
|
|
115
115
|
if (await published()) return restore("hit");
|
|
116
116
|
// Compilation runs in an asynchronous child, so the maintained lock heartbeat stays live.
|
|
117
|
+
// Wait as long as the holder heartbeats: a contended box can compile for
|
|
118
|
+
// longer than any fixed retry budget, and a dead holder's lock goes stale.
|
|
117
119
|
const release = await lockfile.lock(key, {
|
|
118
120
|
stale: 120_000,
|
|
119
121
|
update: 20_000,
|
|
120
|
-
retries: {
|
|
122
|
+
retries: { forever: true, factor: 1.5, minTimeout: 50, maxTimeout: 1_000 },
|
|
121
123
|
});
|
|
122
124
|
let staging;
|
|
123
125
|
try {
|
|
@@ -10,6 +10,8 @@ export declare function createFleetInventory(options: Readonly<{
|
|
|
10
10
|
replay: (actor: FleetActor, request: ComputerCreateRequest) => FleetComputer | null;
|
|
11
11
|
create: (actor: FleetActor, request: ComputerCreateRequest) => FleetComputer;
|
|
12
12
|
read: (computerId: string) => FleetComputer | null;
|
|
13
|
+
creator: (computerId: string) => FleetActor | null;
|
|
14
|
+
retire: (computerId: string) => "retired" | "already_retired" | null;
|
|
13
15
|
list: (input: ComputerPage) => {
|
|
14
16
|
readonly computers: Readonly<{
|
|
15
17
|
computerId: string;
|
package/dist/fleet/inventory.js
CHANGED
|
@@ -120,8 +120,9 @@ export function createFleetInventory(options) {
|
|
|
120
120
|
const stored = rowSchema.safeParse(sql
|
|
121
121
|
.exec(`${selectRow} WHERE computer_id=?`, receipt.data.computer_id)
|
|
122
122
|
.toArray()[0]);
|
|
123
|
+
if (stored.success && stored.data.active === 0)
|
|
124
|
+
throw new ComputerInventoryError("request_conflict");
|
|
123
125
|
if (!stored.success ||
|
|
124
|
-
stored.data.active === 0 ||
|
|
125
126
|
stored.data.name !== receipt.data.name ||
|
|
126
127
|
stored.data.actor_kind !== receipt.data.actor_kind ||
|
|
127
128
|
stored.data.actor_id !== receipt.data.actor_id)
|
|
@@ -148,5 +149,49 @@ export function createFleetInventory(options) {
|
|
|
148
149
|
throw new ComputerInventoryError("partial_init");
|
|
149
150
|
return created;
|
|
150
151
|
});
|
|
151
|
-
|
|
152
|
+
/** Who created an active Computer; authorization belongs to the host. */
|
|
153
|
+
const creator = (computerId) => {
|
|
154
|
+
const raw = sql
|
|
155
|
+
.exec(`${selectRow} WHERE computer_id=?`, computerId)
|
|
156
|
+
.toArray()[0];
|
|
157
|
+
if (raw === undefined)
|
|
158
|
+
return null;
|
|
159
|
+
const row = rowSchema.safeParse(raw);
|
|
160
|
+
if (!row.success)
|
|
161
|
+
throw new ComputerInventoryError("partial_init");
|
|
162
|
+
return row.data.active === 0
|
|
163
|
+
? null
|
|
164
|
+
: { kind: row.data.actor_kind, id: row.data.actor_id };
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Retire a Computer: it leaves the inventory, its name becomes free, and a
|
|
168
|
+
* replayed create refuses. The row stays as the retirement record so a
|
|
169
|
+
* retried teardown still knows the Computer was this Team's.
|
|
170
|
+
*/
|
|
171
|
+
const retire = (computerId) => options.transactionSync(() => {
|
|
172
|
+
const raw = sql
|
|
173
|
+
.exec(`${selectRow} WHERE computer_id=?`, computerId)
|
|
174
|
+
.toArray()[0];
|
|
175
|
+
if (raw === undefined)
|
|
176
|
+
return null;
|
|
177
|
+
const row = rowSchema.safeParse(raw);
|
|
178
|
+
if (!row.success)
|
|
179
|
+
throw new ComputerInventoryError("partial_init");
|
|
180
|
+
if (row.data.active === 0)
|
|
181
|
+
return "already_retired";
|
|
182
|
+
// The Computer ID is unique, so it frees the name without a collision.
|
|
183
|
+
sql.exec("UPDATE hub_team_computers SET active=0,name=computer_id,updated_at=? WHERE computer_id=?", Date.now(), computerId);
|
|
184
|
+
return "retired";
|
|
185
|
+
});
|
|
186
|
+
return {
|
|
187
|
+
ensure,
|
|
188
|
+
replay,
|
|
189
|
+
create,
|
|
190
|
+
read,
|
|
191
|
+
creator,
|
|
192
|
+
retire,
|
|
193
|
+
list,
|
|
194
|
+
ids,
|
|
195
|
+
count,
|
|
196
|
+
};
|
|
152
197
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/computer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"description": "Cloudflare Computer host for one durable Fungi Computer",
|
|
6
6
|
"type": "module",
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
"@fungi.computer/cairn": "0.1.0",
|
|
60
60
|
"@fungi.computer/capnweb": "0.12.0-fungi.0",
|
|
61
61
|
"@fungi.computer/cloudflare-computer": "0.2.1-fungi.2",
|
|
62
|
-
"@fungi.computer/cordyceps": "0.4.
|
|
63
|
-
"@fungi.computer/knapsack": "0.4.
|
|
64
|
-
"@fungi.computer/seam": "0.2.
|
|
65
|
-
"@fungi.computer/watchdog": "0.1.
|
|
66
|
-
"@fungi.computer/computer-contract": "0.0.
|
|
62
|
+
"@fungi.computer/cordyceps": "0.4.1",
|
|
63
|
+
"@fungi.computer/knapsack": "0.4.8",
|
|
64
|
+
"@fungi.computer/seam": "0.2.5",
|
|
65
|
+
"@fungi.computer/watchdog": "0.1.3",
|
|
66
|
+
"@fungi.computer/computer-contract": "0.0.13",
|
|
67
67
|
"effect": "4.0.2",
|
|
68
68
|
"just-bash": "3.4.2",
|
|
69
69
|
"zod": "4.4.3"
|