@fungi.computer/computer 0.16.6 → 0.18.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/Dockerfile +21 -4
- package/container/computer-init.mjs +28 -0
- package/container/computer-start.sh +8 -1
- package/container/fungi-services +2 -0
- package/container/fungi-services.mjs +190 -0
- package/container/package.json +2 -1
- package/container/pnpm-lock.yaml +8 -0
- package/container/services-render.mjs +126 -0
- package/container/terminal-assets/global-tools.sh +4 -0
- package/container/terminal-server.mjs +55 -16
- package/container/tools/cli.mjs +55 -0
- package/container/tools/fungi-tools +14 -0
- package/container/tools/install.mjs +310 -0
- package/container/tools/manifest.mjs +111 -0
- package/container/tools/pi/package.json +8 -0
- package/container/tools/pi/pnpm-lock.yaml +1174 -0
- package/container/tools/pi/pnpm-workspace.yaml +4 -0
- package/dist/fleet/wire.d.ts +14 -0
- package/dist/fleet/wire.js +7 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +150 -25
- package/dist/port-failure.d.ts +10 -2
- package/dist/port-failure.js +25 -5
- package/dist/port-ownership.d.ts +16 -0
- package/dist/port-ownership.js +36 -0
- package/dist/preview-wait.d.ts +24 -0
- package/dist/preview-wait.js +47 -0
- package/dist/process-inventory.js +7 -21
- package/dist/services-apply.d.ts +54 -0
- package/dist/services-apply.js +66 -0
- package/dist/services-tools.d.ts +30 -0
- package/dist/services-tools.js +91 -0
- package/dist/services.d.ts +38 -0
- package/dist/services.js +123 -0
- package/dist/team-candidate-builder.mjs +29 -12
- package/package.json +17 -8
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ComputerServiceInventory, ComputerServicesApply } from "./services.js";
|
|
3
|
+
/** The command result `applyDeclaredServices` needs from the Computer's exec path. */
|
|
4
|
+
export type ServicesCommandResult = Readonly<{
|
|
5
|
+
status: string;
|
|
6
|
+
exitCode: number | null;
|
|
7
|
+
stdout: string;
|
|
8
|
+
stderr: string;
|
|
9
|
+
}>;
|
|
10
|
+
/** How a `fungi-services` command failed: its kind, and the last line it wrote. */
|
|
11
|
+
declare const servicesFailureSchema: z.ZodObject<{
|
|
12
|
+
failure: z.ZodEnum<{
|
|
13
|
+
refused: "refused";
|
|
14
|
+
missing: "missing";
|
|
15
|
+
timeout: "timeout";
|
|
16
|
+
other: "other";
|
|
17
|
+
}>;
|
|
18
|
+
detail: z.ZodString;
|
|
19
|
+
}, z.core.$strict>;
|
|
20
|
+
export type ComputerServicesFailure = z.output<typeof servicesFailureSchema>;
|
|
21
|
+
/**
|
|
22
|
+
* The failure `fungi-services` reported on stderr. A command that wrote none
|
|
23
|
+
* (a crash, a stopped runtime) is `other`, with the last line it wrote.
|
|
24
|
+
*/
|
|
25
|
+
export declare function servicesFailureOf(result: ServicesCommandResult): ComputerServicesFailure;
|
|
26
|
+
/** `fungi-services apply` did not finish; the Computer's services may be stopped. */
|
|
27
|
+
export declare class ComputerServicesApplyError extends Error {
|
|
28
|
+
readonly result: ServicesCommandResult;
|
|
29
|
+
constructor(result: ServicesCommandResult);
|
|
30
|
+
}
|
|
31
|
+
/** A read or control command of `fungi-services` did not finish. */
|
|
32
|
+
export declare class ComputerServicesCommandError extends Error {
|
|
33
|
+
readonly result: ServicesCommandResult;
|
|
34
|
+
constructor(operation: string, result: ServicesCommandResult);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The shell command that hands `fungi-services apply` the declarations. The
|
|
38
|
+
* JSON travels as base64, which holds only characters a single-quoted word
|
|
39
|
+
* keeps literal, so no declared byte reaches the shell as syntax.
|
|
40
|
+
*/
|
|
41
|
+
export declare function servicesApplyCommand(payload: ComputerServicesApply): string;
|
|
42
|
+
/**
|
|
43
|
+
* Bring a runtime to the declared services: re-admit their ports, then render
|
|
44
|
+
* and start them. On a fresh runtime a Computer with nothing declared runs
|
|
45
|
+
* nothing, because its scan directory is already empty; a live runtime that
|
|
46
|
+
* just lost its last declaration still needs the apply that stops it, so a
|
|
47
|
+
* caller that changed a declaration passes `whenEmpty: "run"`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function applyDeclaredServices(options: {
|
|
50
|
+
inventory: ComputerServiceInventory;
|
|
51
|
+
run: (command: string) => Promise<ServicesCommandResult>;
|
|
52
|
+
whenEmpty?: "run" | "skip";
|
|
53
|
+
}): Promise<"applied" | "none">;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** How a `fungi-services` command failed: its kind, and the last line it wrote. */
|
|
3
|
+
const servicesFailureSchema = z.strictObject({
|
|
4
|
+
failure: z.enum(["refused", "missing", "timeout", "other"]),
|
|
5
|
+
detail: z.string(),
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* The failure `fungi-services` reported on stderr. A command that wrote none
|
|
9
|
+
* (a crash, a stopped runtime) is `other`, with the last line it wrote.
|
|
10
|
+
*/
|
|
11
|
+
export function servicesFailureOf(result) {
|
|
12
|
+
const last = result.stderr.trim().split("\n").at(-1) ?? "";
|
|
13
|
+
try {
|
|
14
|
+
return servicesFailureSchema.parse(JSON.parse(last));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return { failure: "other", detail: last };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** `fungi-services apply` did not finish; the Computer's services may be stopped. */
|
|
21
|
+
export class ComputerServicesApplyError extends Error {
|
|
22
|
+
result;
|
|
23
|
+
constructor(result) {
|
|
24
|
+
super(`Computer services could not be applied (${result.status}, exit ${String(result.exitCode)}): ${result.stderr.slice(0, 500)}`);
|
|
25
|
+
this.name = "ComputerServicesApplyError";
|
|
26
|
+
this.result = result;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** A read or control command of `fungi-services` did not finish. */
|
|
30
|
+
export class ComputerServicesCommandError extends Error {
|
|
31
|
+
result;
|
|
32
|
+
constructor(operation, result) {
|
|
33
|
+
super(`Computer services ${operation} failed (${result.status}, exit ${String(result.exitCode)}): ${result.stderr.slice(0, 500)}`);
|
|
34
|
+
this.name = "ComputerServicesCommandError";
|
|
35
|
+
this.result = result;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The shell command that hands `fungi-services apply` the declarations. The
|
|
40
|
+
* JSON travels as base64, which holds only characters a single-quoted word
|
|
41
|
+
* keeps literal, so no declared byte reaches the shell as syntax.
|
|
42
|
+
*/
|
|
43
|
+
export function servicesApplyCommand(payload) {
|
|
44
|
+
let binary = "";
|
|
45
|
+
for (const byte of new TextEncoder().encode(JSON.stringify(payload)))
|
|
46
|
+
binary += String.fromCharCode(byte);
|
|
47
|
+
const encoded = btoa(binary);
|
|
48
|
+
return `printf %s '${encoded}' | base64 -d | fungi-services apply`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Bring a runtime to the declared services: re-admit their ports, then render
|
|
52
|
+
* and start them. On a fresh runtime a Computer with nothing declared runs
|
|
53
|
+
* nothing, because its scan directory is already empty; a live runtime that
|
|
54
|
+
* just lost its last declaration still needs the apply that stops it, so a
|
|
55
|
+
* caller that changed a declaration passes `whenEmpty: "run"`.
|
|
56
|
+
*/
|
|
57
|
+
export async function applyDeclaredServices(options) {
|
|
58
|
+
options.inventory.ensurePorts();
|
|
59
|
+
const payload = options.inventory.applyPayload();
|
|
60
|
+
if (payload.services.length === 0 && options.whenEmpty !== "run")
|
|
61
|
+
return "none";
|
|
62
|
+
const result = await options.run(servicesApplyCommand(payload));
|
|
63
|
+
if (result.status !== "completed" || result.exitCode !== 0)
|
|
64
|
+
throw new ComputerServicesApplyError(result);
|
|
65
|
+
return "applied";
|
|
66
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { computerServiceViewSchema, serviceLogsOutputSchema, type serviceListOutputSchema } from "@fungi.computer/computer-contract";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { type ServicesCommandResult } from "./services-apply.js";
|
|
4
|
+
import type { ComputerServiceDeclaration, ComputerServiceInventory } from "./services.js";
|
|
5
|
+
/** What the Agent tools need of a Computer: whether it is awake, and a command run on it. */
|
|
6
|
+
export type ServicesRuntime = Readonly<{
|
|
7
|
+
/** True only while a hosted runtime is running; asking never starts one. */
|
|
8
|
+
awake: () => Promise<boolean>;
|
|
9
|
+
run: (command: string) => Promise<ServicesCommandResult>;
|
|
10
|
+
}>;
|
|
11
|
+
export type ComputerServiceView = z.output<typeof computerServiceViewSchema>;
|
|
12
|
+
export type ComputerServiceList = z.output<typeof serviceListOutputSchema>;
|
|
13
|
+
/** `list_services`: every declaration with its live status; reading never wakes the Computer. */
|
|
14
|
+
export declare function listServices(inventory: ComputerServiceInventory, runtime: ServicesRuntime): Promise<ComputerServiceList>;
|
|
15
|
+
/** `declare_service`: save, then start now if the Computer is awake. */
|
|
16
|
+
export declare function declareService(inventory: ComputerServiceInventory, runtime: ServicesRuntime, input: ComputerServiceDeclaration, declaredBy: string): Promise<ComputerServiceView>;
|
|
17
|
+
/** `stop_service` and `start_service`: change whether it is declared as running. */
|
|
18
|
+
export declare function setServiceEnabled(inventory: ComputerServiceInventory, runtime: ServicesRuntime, name: string, enabled: boolean): Promise<ComputerServiceView>;
|
|
19
|
+
/** `restart_service`: apply first, then restart one that was already declared to run. */
|
|
20
|
+
export declare function restartService(inventory: ComputerServiceInventory, runtime: ServicesRuntime, name: string): Promise<ComputerServiceView>;
|
|
21
|
+
/** `remove_service`: forget it, stopping it if the Computer is awake. */
|
|
22
|
+
export declare function removeService(inventory: ComputerServiceInventory, runtime: ServicesRuntime, name: string): Promise<{
|
|
23
|
+
name: string;
|
|
24
|
+
removed: true;
|
|
25
|
+
}>;
|
|
26
|
+
/** `service_logs`: the newest lines, kept only while the Computer is awake. */
|
|
27
|
+
export declare function serviceLogs(inventory: ComputerServiceInventory, runtime: ServicesRuntime, input: {
|
|
28
|
+
name: string;
|
|
29
|
+
lines?: number | undefined;
|
|
30
|
+
}): Promise<z.output<typeof serviceLogsOutputSchema>>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ComputerServiceNotFoundError, computerServiceViewSchema, computerServiceNameSchema, maximumProcessLogLines, serviceLogsOutputSchema, } from "@fungi.computer/computer-contract";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { applyDeclaredServices, ComputerServicesCommandError, } from "./services-apply.js";
|
|
4
|
+
const supervisorStatus = z.strictObject({
|
|
5
|
+
services: z.record(computerServiceNameSchema, z.strictObject({
|
|
6
|
+
state: z.enum(["up", "restarting", "down"]),
|
|
7
|
+
pid: z.number().int().positive().optional(),
|
|
8
|
+
seconds: z.number().int().nonnegative().optional(),
|
|
9
|
+
})),
|
|
10
|
+
});
|
|
11
|
+
const logTail = serviceLogsOutputSchema;
|
|
12
|
+
async function command(runtime, operation, text) {
|
|
13
|
+
const result = await runtime.run(text);
|
|
14
|
+
if (result.status !== "completed" || result.exitCode !== 0)
|
|
15
|
+
throw new ComputerServicesCommandError(operation, result);
|
|
16
|
+
return result.stdout;
|
|
17
|
+
}
|
|
18
|
+
/** Render and start what is declared, now, but only on a runtime that already runs. */
|
|
19
|
+
async function applyWhileAwake(inventory, runtime) {
|
|
20
|
+
if (!(await runtime.awake()))
|
|
21
|
+
return false;
|
|
22
|
+
await applyDeclaredServices({
|
|
23
|
+
inventory,
|
|
24
|
+
run: (text) => runtime.run(text),
|
|
25
|
+
whenEmpty: "run",
|
|
26
|
+
});
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
async function views(inventory, runtime) {
|
|
30
|
+
const declared = inventory.list();
|
|
31
|
+
const awake = await runtime.awake();
|
|
32
|
+
const live = awake
|
|
33
|
+
? supervisorStatus.parse(JSON.parse(await command(runtime, "status", "fungi-services status"))).services
|
|
34
|
+
: {};
|
|
35
|
+
return declared.map((service) => computerServiceViewSchema.parse({
|
|
36
|
+
...service,
|
|
37
|
+
status: !awake
|
|
38
|
+
? { state: "asleep" }
|
|
39
|
+
: (live[service.name] ??
|
|
40
|
+
// Declared and enabled but not rendered yet, or stopped and not rendered.
|
|
41
|
+
{ state: service.enabled ? "restarting" : "down" }),
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
async function viewOf(inventory, runtime, service) {
|
|
45
|
+
const found = (await views(inventory, runtime)).find((view) => view.name === service.name);
|
|
46
|
+
if (found === undefined)
|
|
47
|
+
throw new ComputerServiceNotFoundError(service.name);
|
|
48
|
+
return found;
|
|
49
|
+
}
|
|
50
|
+
/** `list_services`: every declaration with its live status; reading never wakes the Computer. */
|
|
51
|
+
export async function listServices(inventory, runtime) {
|
|
52
|
+
return { services: [...(await views(inventory, runtime))] };
|
|
53
|
+
}
|
|
54
|
+
/** `declare_service`: save, then start now if the Computer is awake. */
|
|
55
|
+
export async function declareService(inventory, runtime, input, declaredBy) {
|
|
56
|
+
const service = inventory.declare(input, declaredBy);
|
|
57
|
+
await applyWhileAwake(inventory, runtime);
|
|
58
|
+
return viewOf(inventory, runtime, service);
|
|
59
|
+
}
|
|
60
|
+
/** `stop_service` and `start_service`: change whether it is declared as running. */
|
|
61
|
+
export async function setServiceEnabled(inventory, runtime, name, enabled) {
|
|
62
|
+
const service = inventory.setEnabled(name, enabled);
|
|
63
|
+
await applyWhileAwake(inventory, runtime);
|
|
64
|
+
return viewOf(inventory, runtime, service);
|
|
65
|
+
}
|
|
66
|
+
/** `restart_service`: apply first, then restart one that was already declared to run. */
|
|
67
|
+
export async function restartService(inventory, runtime, name) {
|
|
68
|
+
const before = inventory.get(name);
|
|
69
|
+
if (before === undefined)
|
|
70
|
+
throw new ComputerServiceNotFoundError(name);
|
|
71
|
+
const service = inventory.setEnabled(name, true);
|
|
72
|
+
if (await applyWhileAwake(inventory, runtime))
|
|
73
|
+
if (before.enabled)
|
|
74
|
+
await command(runtime, "restart", `fungi-services restart ${name}`);
|
|
75
|
+
return viewOf(inventory, runtime, service);
|
|
76
|
+
}
|
|
77
|
+
/** `remove_service`: forget it, stopping it if the Computer is awake. */
|
|
78
|
+
export async function removeService(inventory, runtime, name) {
|
|
79
|
+
inventory.remove(name);
|
|
80
|
+
await applyWhileAwake(inventory, runtime);
|
|
81
|
+
return { name, removed: true };
|
|
82
|
+
}
|
|
83
|
+
/** `service_logs`: the newest lines, kept only while the Computer is awake. */
|
|
84
|
+
export async function serviceLogs(inventory, runtime, input) {
|
|
85
|
+
if (inventory.get(input.name) === undefined)
|
|
86
|
+
throw new ComputerServiceNotFoundError(input.name);
|
|
87
|
+
if (!(await runtime.awake()))
|
|
88
|
+
return { name: input.name, lines: [], truncated: false };
|
|
89
|
+
const lines = input.lines ?? maximumProcessLogLines;
|
|
90
|
+
return logTail.parse(JSON.parse(await command(runtime, "logs", `fungi-services logs ${input.name} ${String(lines)}`)));
|
|
91
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { computerServiceSchema, type computerServiceDeclarationSchema } from "@fungi.computer/computer-contract";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { type ExposedPortStorage } from "./port-ownership.js";
|
|
4
|
+
/** A declared service as stored, the shape the contract names. */
|
|
5
|
+
export type ComputerService = z.output<typeof computerServiceSchema>;
|
|
6
|
+
/** What a person or Agent declares: name, command and optional cwd, port and env. */
|
|
7
|
+
export type ComputerServiceDeclaration = z.output<typeof computerServiceDeclarationSchema>;
|
|
8
|
+
/** The JSON `fungi-services apply` reads on stdin to render the supervisor's directories. */
|
|
9
|
+
export type ApplyService = Pick<ComputerService, "name" | "command" | "cwd" | "env" | "enabled">;
|
|
10
|
+
export type ComputerServicesApply = Readonly<{
|
|
11
|
+
services: readonly Readonly<ApplyService>[];
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* The Computer's declared services: the durable rules, never the live state.
|
|
15
|
+
* Whether one is up is read from the supervisor on demand. A service's port is
|
|
16
|
+
* admitted through the same table as a process's, so a port has one owner.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ComputerServiceInventory {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(storage: ExposedPortStorage, now: () => number);
|
|
21
|
+
/** Declare or replace one service; it is enabled, so the next apply starts it. */
|
|
22
|
+
declare(input: ComputerServiceDeclaration, declaredBy: string): ComputerService;
|
|
23
|
+
/** One service, or `undefined` when none is declared by that name. */
|
|
24
|
+
get(name: string): ComputerService | undefined;
|
|
25
|
+
/** Every declared service by name. */
|
|
26
|
+
list(): readonly ComputerService[];
|
|
27
|
+
/** Start or stop declaring a service as running; a stopped one stays declared. */
|
|
28
|
+
setEnabled(name: string, enabled: boolean): ComputerService;
|
|
29
|
+
/** Remove a declaration and the port it owned. */
|
|
30
|
+
remove(name: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Re-admit every declared service port. The process inventory rebuilds the
|
|
33
|
+
* exposure table when its own schema changes; the declarations outlive that.
|
|
34
|
+
*/
|
|
35
|
+
ensurePorts(): void;
|
|
36
|
+
/** What `fungi-services apply` renders: every declaration and whether it runs. */
|
|
37
|
+
applyPayload(): ComputerServicesApply;
|
|
38
|
+
}
|
package/dist/services.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { ComputerServiceLimitError, ComputerServiceNotFoundError, computerServiceSchema, maximumComputerServices, } from "@fungi.computer/computer-contract";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { claimPort, createExposedPorts, releasePortsOwnedBy, } from "./port-ownership.js";
|
|
4
|
+
const envColumn = z.record(z.string(), z.string());
|
|
5
|
+
function toService(row) {
|
|
6
|
+
const env = envColumn.parse(JSON.parse(row.env));
|
|
7
|
+
const service = {
|
|
8
|
+
name: row.name,
|
|
9
|
+
command: row.command,
|
|
10
|
+
enabled: row.enabled === 1,
|
|
11
|
+
declaredBy: row.declared_by,
|
|
12
|
+
declaredAt: row.declared_at,
|
|
13
|
+
revision: row.revision,
|
|
14
|
+
};
|
|
15
|
+
if (row.cwd !== null)
|
|
16
|
+
service.cwd = row.cwd;
|
|
17
|
+
if (row.port !== null)
|
|
18
|
+
service.port = row.port;
|
|
19
|
+
if (Object.keys(env).length > 0)
|
|
20
|
+
service.env = env;
|
|
21
|
+
return computerServiceSchema.parse(service);
|
|
22
|
+
}
|
|
23
|
+
const ownerOf = (name) => `service:${name}`;
|
|
24
|
+
/**
|
|
25
|
+
* The Computer's declared services: the durable rules, never the live state.
|
|
26
|
+
* Whether one is up is read from the supervisor on demand. A service's port is
|
|
27
|
+
* admitted through the same table as a process's, so a port has one owner.
|
|
28
|
+
*/
|
|
29
|
+
export class ComputerServiceInventory {
|
|
30
|
+
#storage;
|
|
31
|
+
#now;
|
|
32
|
+
constructor(storage, now) {
|
|
33
|
+
this.#storage = storage;
|
|
34
|
+
this.#now = now;
|
|
35
|
+
storage.transactionSync(() => {
|
|
36
|
+
createExposedPorts(storage);
|
|
37
|
+
storage.sql.exec("CREATE TABLE IF NOT EXISTS computer_services (name TEXT PRIMARY KEY, command TEXT NOT NULL, cwd TEXT, port INTEGER, env TEXT NOT NULL DEFAULT '{}', enabled INTEGER NOT NULL CHECK (enabled IN (0,1)), declared_by TEXT NOT NULL, declared_at INTEGER NOT NULL, revision INTEGER NOT NULL CHECK (revision >= 1)) STRICT");
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
#row(name) {
|
|
41
|
+
return this.#storage.sql
|
|
42
|
+
.exec("SELECT * FROM computer_services WHERE name = ?", name)
|
|
43
|
+
.toArray()[0];
|
|
44
|
+
}
|
|
45
|
+
/** Declare or replace one service; it is enabled, so the next apply starts it. */
|
|
46
|
+
declare(input, declaredBy) {
|
|
47
|
+
return this.#storage.transactionSync(() => {
|
|
48
|
+
const existing = this.#row(input.name);
|
|
49
|
+
if (existing === undefined) {
|
|
50
|
+
const count = this.#storage.sql
|
|
51
|
+
.exec("SELECT COUNT(*) AS count FROM computer_services")
|
|
52
|
+
.toArray()[0]?.count ?? maximumComputerServices;
|
|
53
|
+
if (count >= maximumComputerServices)
|
|
54
|
+
throw new ComputerServiceLimitError();
|
|
55
|
+
}
|
|
56
|
+
// Only a port that moves is released: keeping it must not reset its
|
|
57
|
+
// visibility or share links.
|
|
58
|
+
if (existing?.port != null && existing.port !== (input.port ?? null))
|
|
59
|
+
releasePortsOwnedBy(this.#storage, ownerOf(input.name));
|
|
60
|
+
if (input.port !== undefined)
|
|
61
|
+
claimPort(this.#storage, input.port, ownerOf(input.name));
|
|
62
|
+
this.#storage.sql.exec("INSERT INTO computer_services (name, command, cwd, port, env, enabled, declared_by, declared_at, revision) VALUES (?, ?, ?, ?, ?, 1, ?, ?, 1) ON CONFLICT(name) DO UPDATE SET command = excluded.command, cwd = excluded.cwd, port = excluded.port, env = excluded.env, enabled = 1, declared_by = excluded.declared_by, declared_at = excluded.declared_at, revision = revision + 1", input.name, input.command, input.cwd ?? null, input.port ?? null, JSON.stringify(input.env ?? {}), declaredBy, this.#now());
|
|
63
|
+
return this.#require(input.name);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
#require(name) {
|
|
67
|
+
const row = this.#row(name);
|
|
68
|
+
if (row === undefined)
|
|
69
|
+
throw new ComputerServiceNotFoundError(name);
|
|
70
|
+
return toService(row);
|
|
71
|
+
}
|
|
72
|
+
/** One service, or `undefined` when none is declared by that name. */
|
|
73
|
+
get(name) {
|
|
74
|
+
const row = this.#row(name);
|
|
75
|
+
return row === undefined ? undefined : toService(row);
|
|
76
|
+
}
|
|
77
|
+
/** Every declared service by name. */
|
|
78
|
+
list() {
|
|
79
|
+
return this.#storage.sql
|
|
80
|
+
.exec("SELECT * FROM computer_services ORDER BY name")
|
|
81
|
+
.toArray()
|
|
82
|
+
.map(toService);
|
|
83
|
+
}
|
|
84
|
+
/** Start or stop declaring a service as running; a stopped one stays declared. */
|
|
85
|
+
setEnabled(name, enabled) {
|
|
86
|
+
return this.#storage.transactionSync(() => {
|
|
87
|
+
this.#require(name);
|
|
88
|
+
this.#storage.sql.exec("UPDATE computer_services SET enabled = ? WHERE name = ?", enabled ? 1 : 0, name);
|
|
89
|
+
return this.#require(name);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/** Remove a declaration and the port it owned. */
|
|
93
|
+
remove(name) {
|
|
94
|
+
this.#storage.transactionSync(() => {
|
|
95
|
+
this.#require(name);
|
|
96
|
+
releasePortsOwnedBy(this.#storage, ownerOf(name));
|
|
97
|
+
this.#storage.sql.exec("DELETE FROM computer_services WHERE name = ?", name);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Re-admit every declared service port. The process inventory rebuilds the
|
|
102
|
+
* exposure table when its own schema changes; the declarations outlive that.
|
|
103
|
+
*/
|
|
104
|
+
ensurePorts() {
|
|
105
|
+
this.#storage.transactionSync(() => {
|
|
106
|
+
for (const service of this.list())
|
|
107
|
+
if (service.port !== undefined)
|
|
108
|
+
claimPort(this.#storage, service.port, ownerOf(service.name));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** What `fungi-services apply` renders: every declaration and whether it runs. */
|
|
112
|
+
applyPayload() {
|
|
113
|
+
const services = this.list().map(({ name, command, cwd, env, enabled }) => {
|
|
114
|
+
const entry = { name, command, enabled };
|
|
115
|
+
if (cwd !== undefined)
|
|
116
|
+
entry.cwd = cwd;
|
|
117
|
+
if (env !== undefined)
|
|
118
|
+
entry.env = env;
|
|
119
|
+
return entry;
|
|
120
|
+
});
|
|
121
|
+
return { services };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -36084,7 +36084,7 @@ function snapshotBuildEnvironment(sourceSnapshotPath) {
|
|
|
36084
36084
|
};
|
|
36085
36085
|
return env;
|
|
36086
36086
|
}
|
|
36087
|
-
function rebuildViteSnapshot(sourceSnapshotPath, recipe, options) {
|
|
36087
|
+
function rebuildViteSnapshot(sourceSnapshotPath, recipe, options, shared) {
|
|
36088
36088
|
if (recipe.kind === "source-html")
|
|
36089
36089
|
return rebuildNpmSnapshot(sourceSnapshotPath, recipe, options);
|
|
36090
36090
|
return gen2(function* () {
|
|
@@ -36110,15 +36110,23 @@ function rebuildViteSnapshot(sourceSnapshotPath, recipe, options) {
|
|
|
36110
36110
|
)
|
|
36111
36111
|
);
|
|
36112
36112
|
const installStarted = performance.now();
|
|
36113
|
-
|
|
36114
|
-
|
|
36115
|
-
|
|
36116
|
-
|
|
36117
|
-
|
|
36118
|
-
|
|
36119
|
-
|
|
36113
|
+
if (shared === null)
|
|
36114
|
+
yield* run2([
|
|
36115
|
+
...productionWorkspaceSelectors(html),
|
|
36116
|
+
...frozenSnapshotInstallArguments(
|
|
36117
|
+
options.packageStoreDirectory,
|
|
36118
|
+
options.packageCacheDirectory
|
|
36119
|
+
)
|
|
36120
|
+
]);
|
|
36121
|
+
else if (shared.snapshotPath !== sourceSnapshotPath || !productionWorkspaceSelectors(html).every(
|
|
36122
|
+
(selector) => shared.selectors.has(selector)
|
|
36123
|
+
))
|
|
36124
|
+
return yield* fail5(
|
|
36125
|
+
new Error("The shared install did not hydrate this App's workspace")
|
|
36126
|
+
);
|
|
36120
36127
|
const buildStarted = performance.now();
|
|
36121
|
-
|
|
36128
|
+
if (shared === null)
|
|
36129
|
+
options.onPhase?.("install", buildStarted - installStarted);
|
|
36122
36130
|
const appDirectory = join5(sourceSnapshotPath, html.directory);
|
|
36123
36131
|
const dependencies = join5(appDirectory, ".publisher-dependencies.mjs");
|
|
36124
36132
|
const program = join5(appDirectory, ".publisher-build.mjs");
|
|
@@ -36132,8 +36140,11 @@ function rebuildViteSnapshot(sourceSnapshotPath, recipe, options) {
|
|
|
36132
36140
|
catch: (error2) => error2
|
|
36133
36141
|
})
|
|
36134
36142
|
);
|
|
36143
|
+
const steps = html.steps.filter(
|
|
36144
|
+
(step) => step.kind !== "typescript" || !shared?.compiled.has(step.config)
|
|
36145
|
+
);
|
|
36135
36146
|
const groups = [];
|
|
36136
|
-
for (const step of
|
|
36147
|
+
for (const step of steps) {
|
|
36137
36148
|
const last = groups.at(-1);
|
|
36138
36149
|
if (step.kind === "typescript" && last?.every((member) => member.kind === "typescript"))
|
|
36139
36150
|
last.push(step);
|
|
@@ -36166,6 +36177,9 @@ function rebuildViteSnapshot(sourceSnapshotPath, recipe, options) {
|
|
|
36166
36177
|
],
|
|
36167
36178
|
appDirectory
|
|
36168
36179
|
);
|
|
36180
|
+
for (const compiled of group)
|
|
36181
|
+
if (compiled.kind === "typescript")
|
|
36182
|
+
shared?.compiled.add(compiled.config);
|
|
36169
36183
|
}
|
|
36170
36184
|
yield* run2(
|
|
36171
36185
|
[
|
|
@@ -36460,6 +36474,9 @@ function localSnapshotBuildOptions(source, recipe, emission) {
|
|
|
36460
36474
|
return options;
|
|
36461
36475
|
}
|
|
36462
36476
|
function createLocalBuildExecutor(options = {}) {
|
|
36477
|
+
return createWorkspaceBuildExecutor(options, null);
|
|
36478
|
+
}
|
|
36479
|
+
function createWorkspaceBuildExecutor(options, shared) {
|
|
36463
36480
|
const emissions = /* @__PURE__ */ new WeakMap();
|
|
36464
36481
|
const compiler2 = {
|
|
36465
36482
|
build: (source, recipe) => {
|
|
@@ -36526,7 +36543,7 @@ function createLocalBuildExecutor(options = {}) {
|
|
|
36526
36543
|
const ui = yield* recipe.kind === "bundled-html" ? tryPromise2({
|
|
36527
36544
|
try: () => readBundledHtml(source.snapshotPath, recipe),
|
|
36528
36545
|
catch: () => new Error("Captured HTML bundle failed validation")
|
|
36529
|
-
}) : rebuildViteSnapshot(source.snapshotPath, recipe, options);
|
|
36546
|
+
}) : rebuildViteSnapshot(source.snapshotPath, recipe, options, shared);
|
|
36530
36547
|
const code = yield* compiler2.build(source, {
|
|
36531
36548
|
bundle: true,
|
|
36532
36549
|
entry,
|
|
@@ -36552,7 +36569,7 @@ function createLocalBuildExecutor(options = {}) {
|
|
|
36552
36569
|
};
|
|
36553
36570
|
});
|
|
36554
36571
|
}
|
|
36555
|
-
return recipe.format !== "esm" ? rebuildViteSnapshot(source.snapshotPath, recipe, options) : acquireUseRelease2(
|
|
36572
|
+
return recipe.format !== "esm" ? rebuildViteSnapshot(source.snapshotPath, recipe, options, shared) : acquireUseRelease2(
|
|
36556
36573
|
tryPromise2({
|
|
36557
36574
|
try: () => {
|
|
36558
36575
|
const emission = emissions.get(source);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/computer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"description": "Cloudflare Computer host for one durable Fungi Computer",
|
|
6
6
|
"type": "module",
|
|
@@ -50,6 +50,14 @@
|
|
|
50
50
|
"./port-access": {
|
|
51
51
|
"types": "./dist/port-access.d.ts",
|
|
52
52
|
"import": "./dist/port-access.js"
|
|
53
|
+
},
|
|
54
|
+
"./services": {
|
|
55
|
+
"types": "./dist/services.d.ts",
|
|
56
|
+
"import": "./dist/services.js"
|
|
57
|
+
},
|
|
58
|
+
"./services-apply": {
|
|
59
|
+
"types": "./dist/services-apply.d.ts",
|
|
60
|
+
"import": "./dist/services-apply.js"
|
|
53
61
|
}
|
|
54
62
|
},
|
|
55
63
|
"files": [
|
|
@@ -62,12 +70,12 @@
|
|
|
62
70
|
"dependencies": {
|
|
63
71
|
"@fungi.computer/cairn": "0.1.0",
|
|
64
72
|
"@fungi.computer/capnweb": "0.12.0-fungi.0",
|
|
65
|
-
"@fungi.computer/cloudflare-computer": "0.2.1-fungi.
|
|
73
|
+
"@fungi.computer/cloudflare-computer": "0.2.1-fungi.3",
|
|
66
74
|
"@fungi.computer/cordyceps": "0.4.3",
|
|
67
|
-
"@fungi.computer/knapsack": "0.4.
|
|
68
|
-
"@fungi.computer/seam": "0.2.
|
|
69
|
-
"@fungi.computer/watchdog": "0.1.
|
|
70
|
-
"@fungi.computer/computer-contract": "0.
|
|
75
|
+
"@fungi.computer/knapsack": "0.4.24",
|
|
76
|
+
"@fungi.computer/seam": "0.2.7",
|
|
77
|
+
"@fungi.computer/watchdog": "0.1.5",
|
|
78
|
+
"@fungi.computer/computer-contract": "0.6.0",
|
|
71
79
|
"effect": "4.0.2",
|
|
72
80
|
"just-bash": "3.4.2",
|
|
73
81
|
"zod": "4.4.3",
|
|
@@ -119,7 +127,7 @@
|
|
|
119
127
|
"build:container": "bash ../../tooling/proof-runner/run-proof.sh docker build --load --platform linux/amd64 --provenance=false .",
|
|
120
128
|
"build:native": "fungi-apply-patch-build --out native/bin",
|
|
121
129
|
"clean": "node --input-type=module --eval \"import { rm } from 'node:fs/promises'; await rm('dist', { recursive: true, force: true });\"",
|
|
122
|
-
"test": "pnpm run test:unit && pnpm run test:fleet-native && node test/files-rpc.native.mjs && node test/shell-groups.native.mjs && node test/port-proof.mjs && node test/terminal-container-proof.mjs && node test/ssh-container-proof.mjs && node test/fuse-startup-proof.mjs && node test/container-resource-proof.mjs && node test/runtime-proof.mjs && node test/process-schema-proof.mjs && node test/process-proof.mjs && node test/terminal-proof.mjs && pnpm run test:app-method-execution && pnpm run test:execution-lifecycle && pnpm run test:home-patch",
|
|
130
|
+
"test": "pnpm run test:unit && pnpm run test:fleet-native && node test/files-rpc.native.mjs && node test/shell-groups.native.mjs && node test/port-proof.mjs && node test/services-proof.mjs && node test/services-wake-proof.mjs && node test/terminal-container-proof.mjs && node test/ssh-container-proof.mjs && node test/fuse-startup-proof.mjs && node test/container-resource-proof.mjs && node test/runtime-proof.mjs && node test/process-schema-proof.mjs && node test/process-proof.mjs && node test/terminal-proof.mjs && pnpm run test:app-method-execution && pnpm run test:execution-lifecycle && pnpm run test:home-patch",
|
|
123
131
|
"format:check": "node ../../tooling/repository/scripts/format-package-check.mjs",
|
|
124
132
|
"lint:anti-slop": "node ../../tooling/repository/scripts/lint-package-anti-slop.mjs",
|
|
125
133
|
"test:merge": "pnpm run test",
|
|
@@ -129,7 +137,8 @@
|
|
|
129
137
|
"test:ssh-container": "node test/ssh-container-proof.mjs",
|
|
130
138
|
"test:preview-failure:browser": "node test/preview-failure.browser.mjs",
|
|
131
139
|
"test:execution-lifecycle": "node test/execution-lifecycle-proof.mjs",
|
|
132
|
-
"test:unit": "bash ../../tooling/proof-runner/hermetic-host.sh -- sh -c \"node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/egress-policy.test.mjs test/preview.test.mjs test/port-failure.test.mjs test/port-access.test.mjs test/process-wait.test.mjs test/fleet.test.mjs test/proof-worker.test.mjs test/proof-client.test.mjs test/native-readiness.test.mjs test/workspace-sync.test.mjs test/runtime-observer.test.mjs test/files-patch.test.mjs test/exec-output.test.mjs && node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/seam-signature.test.mjs test/local-backend-replay.test.mjs test/machine-link-reopen-replay.test.mjs test/computer-backends.test.mjs test/terminal-welcome.test.mjs test/on-box-vm.test.mjs && node test/terminal-protocol.test.mjs && node test/container-policy.test.mjs && node test/files-adapter-proof.mjs && node test/operation-record-proof.mjs && node test/process-inventory-proof.mjs\"",
|
|
140
|
+
"test:unit": "bash ../../tooling/proof-runner/hermetic-host.sh -- sh -c \"node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/egress-policy.test.mjs test/preview.test.mjs test/port-failure.test.mjs test/port-access.test.mjs test/process-wait.test.mjs test/fleet.test.mjs test/proof-worker.test.mjs test/proof-client.test.mjs test/native-readiness.test.mjs test/workspace-sync.test.mjs test/runtime-observer.test.mjs test/files-patch.test.mjs test/exec-output.test.mjs test/tools-install.test.mjs test/services.test.mjs test/services-apply.test.mjs test/services-tools.test.mjs test/services-render.test.mjs && node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/seam-signature.test.mjs test/local-backend-replay.test.mjs test/machine-link-reopen-replay.test.mjs test/computer-backends.test.mjs test/terminal-welcome.test.mjs test/on-box-vm.test.mjs && node test/terminal-protocol.test.mjs && node test/container-policy.test.mjs && node test/files-adapter-proof.mjs && node test/operation-record-proof.mjs && node test/process-inventory-proof.mjs\"",
|
|
141
|
+
"test:services": "node test/services-proof.mjs && node test/services-wake-proof.mjs",
|
|
133
142
|
"test:fleet-native": "node test/fleet.native.mjs",
|
|
134
143
|
"assemble:image": "node scripts/assemble-image.mjs"
|
|
135
144
|
}
|