@powerhousedao/host-core 6.4.0-next.3 → 6.4.0-next.5

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 (44) hide show
  1. package/dist/{compound-L62ALvYc.d.mts → compound-BLhEewO6.d.mts} +8 -2
  2. package/dist/compound-BLhEewO6.d.mts.map +1 -0
  3. package/dist/{compound-Q9sZSEZF.mjs → compound-g6x_KkWp.mjs} +133 -1208
  4. package/dist/compound-g6x_KkWp.mjs.map +1 -0
  5. package/dist/control-channel-DVn4dvfQ.d.mts +206 -0
  6. package/dist/control-channel-DVn4dvfQ.d.mts.map +1 -0
  7. package/dist/control-channel.d.mts +2 -2
  8. package/dist/control-channel.mjs +358 -47
  9. package/dist/control-channel.mjs.map +1 -1
  10. package/dist/host-entry-B8n_590_.mjs +188 -0
  11. package/dist/host-entry-B8n_590_.mjs.map +1 -0
  12. package/dist/index.d.mts +68 -102
  13. package/dist/index.d.mts.map +1 -1
  14. package/dist/index.mjs +6 -3
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/instance-C6uugZ32.d.mts +165 -0
  17. package/dist/instance-C6uugZ32.d.mts.map +1 -0
  18. package/dist/instance.d.mts +3 -0
  19. package/dist/instance.mjs +145 -0
  20. package/dist/instance.mjs.map +1 -0
  21. package/dist/kill-tree.d.mts +2 -0
  22. package/dist/kill-tree.d.mts.map +1 -1
  23. package/dist/kill-tree.mjs +1 -1
  24. package/dist/kill-tree.mjs.map +1 -1
  25. package/dist/run-record-C6oTZF_C.mjs +1077 -0
  26. package/dist/run-record-C6oTZF_C.mjs.map +1 -0
  27. package/dist/runners/compound.d.mts +1 -1
  28. package/dist/runners/compound.mjs +2 -1
  29. package/dist/runners/compound.mjs.map +1 -1
  30. package/dist/spawn-host-DWroRe1S.d.mts +107 -0
  31. package/dist/spawn-host-DWroRe1S.d.mts.map +1 -0
  32. package/dist/supervisor-record.d.mts +88 -0
  33. package/dist/supervisor-record.d.mts.map +1 -0
  34. package/dist/supervisor-record.mjs +127 -0
  35. package/dist/supervisor-record.mjs.map +1 -0
  36. package/dist/supervisor.d.mts +205 -0
  37. package/dist/supervisor.d.mts.map +1 -0
  38. package/dist/supervisor.mjs +905 -0
  39. package/dist/supervisor.mjs.map +1 -0
  40. package/package.json +21 -3
  41. package/dist/compound-L62ALvYc.d.mts.map +0 -1
  42. package/dist/compound-Q9sZSEZF.mjs.map +0 -1
  43. package/dist/control-channel-eqvyUF03.d.mts +0 -123
  44. package/dist/control-channel-eqvyUF03.d.mts.map +0 -1
@@ -0,0 +1,205 @@
1
+ import { l as ControlRecord, r as CallControlOptions, w as RunRecord } from "./control-channel-DVn4dvfQ.mjs";
2
+ import { o as RestartState } from "./instance-C6uugZ32.mjs";
3
+ import { o as SpawnedHost } from "./spawn-host-DWroRe1S.mjs";
4
+ import { FoundSupervisor, SUPERVISOR_HOME_ENV, SupervisorHello, SupervisorMode, SupervisorRecord, findSupervisor, readSupervisorRecord, silentSupervisorMessage, supervisorHome, supervisorLockHolder, supervisorLockPath, supervisorRecordPath, supervisorRecordSchema, supervisorRecorded } from "./supervisor-record.mjs";
5
+ import { z } from "zod";
6
+ //#region src/supervisor-client.d.ts
7
+ /**
8
+ * A tool's side of the supervisor: the requests of supervisor.ts as calls.
9
+ * It opens a connection per request and loads nothing of the supervisor.
10
+ */
11
+ /** A lease: the supervisor stops what was started with the caller under it
12
+ * when its connection ends, which it does with this process. */
13
+ export interface SupervisorLease {
14
+ id: string;
15
+ /** Ends it now: what lives with this caller is stopped. */
16
+ release(): Promise<void>;
17
+ /** Resolves when the supervisor no longer holds it (released, or the
18
+ * supervisor went away). */
19
+ readonly ended: Promise<void>;
20
+ }
21
+ /** Takes a lease. The connection does not keep this process running. */
22
+ export declare function holdSupervisorLease(control: ControlRecord): Promise<SupervisorLease>;
23
+ export interface SupervisedList {
24
+ supervisor: {
25
+ pid: number;
26
+ mode: string;
27
+ version: string;
28
+ home: string;
29
+ };
30
+ instances: SupervisedInstance[];
31
+ }
32
+ /** What the supervisor holds, and what else runs on `dataDir`. */
33
+ export declare function listSupervised(control: ControlRecord, dataDir?: string, options?: CallControlOptions): Promise<SupervisedList>;
34
+ export declare function startSupervised(control: ControlRecord, params: SupervisorStartParams, options?: CallControlOptions): Promise<{
35
+ instance: SupervisedInstance;
36
+ started: boolean;
37
+ }>;
38
+ export declare function stopSupervised(control: ControlRecord, handle: string): Promise<SupervisedInstance>;
39
+ export declare function restartSupervised(control: ControlRecord, handle: string, options?: CallControlOptions): Promise<SupervisedInstance>;
40
+ export declare function supervisedLogs(control: ControlRecord, handle: string, lines?: number): Promise<{
41
+ text: string;
42
+ logFile: string;
43
+ }>;
44
+ /** Stops the supervisor, and with it what it holds. */
45
+ export declare function shutdownSupervisor(control: ControlRecord): Promise<{
46
+ pid: number;
47
+ held: number;
48
+ }>;
49
+ /** A host the supervisor holds, in the shape `spawnHost` returns. */
50
+ export interface SupervisedHost extends SpawnedHost {
51
+ handle: string;
52
+ lifetime: InstanceLifetime | undefined;
53
+ /** What the supervisor said of it when it was started. */
54
+ instance: SupervisedInstance;
55
+ }
56
+ /**
57
+ * `spawnHost` through the supervisor: the instance is the supervisor's
58
+ * child, not this process's. `existing` is set when the key ran already;
59
+ * its `stop()` then leaves it running, as `spawnHost`'s does. Aborting
60
+ * `signal` while it starts stops it.
61
+ */
62
+ export declare function startSupervisedHost(control: ControlRecord, params: SupervisorStartParams, options?: {
63
+ signal?: AbortSignal;
64
+ }): Promise<SupervisedHost>;
65
+ //#endregion
66
+ //#region src/supervisor.d.ts
67
+ /**
68
+ * The supervisor of an OS user: one process that starts, stops and lists
69
+ * instances for every tool of that user, and holds no application itself.
70
+ *
71
+ * An instance is the project's own `ph run <host>` as a child process: the
72
+ * project's installed ph-cli (else ph-run) is found through its
73
+ * `package.json` and started; nothing of the project is loaded here. After
74
+ * that the supervisor knows an instance through its run record and its
75
+ * process only, so projects on different versions run side by side. A host
76
+ * that writes an older record, or none, is still started, listed and stopped
77
+ * (by its process tree); what cannot be done with it is said in
78
+ * {@link SupervisedInstance.missing}.
79
+ *
80
+ * Requests arrive on a control channel (control-channel.ts): `start`, `stop`,
81
+ * `restart`, `list`, `logs`, `lease` and `shutdown`. An instance lives `with
82
+ * the caller` (the default) or `with the supervisor`. A caller's lease is a
83
+ * `lease` request it keeps open: when its connection ends, however the
84
+ * caller ended, every instance started with the caller under that lease is
85
+ * stopped with its process tree.
86
+ *
87
+ * A `start` may carry a restart policy. The supervisor then applies it, and
88
+ * is the one party that does: an instance that was ready and ends on its own
89
+ * is started again under its handle after the policy's delay, until it has
90
+ * been restarted `maxRetries` times in a row without getting ready. A stop
91
+ * that was asked for, a caller that left, or the supervisor stopping, never
92
+ * restarts.
93
+ */
94
+ type Env = Readonly<Record<string, string | undefined>>;
95
+ export type InstanceLifetime = "caller" | "supervisor";
96
+ /** An instance as `list` shows it. */
97
+ export interface SupervisedInstance {
98
+ /** Short, for commands: `stop 3`. */
99
+ handle: string;
100
+ /** The host as `ph run` takes it. */
101
+ host: string;
102
+ verb?: string;
103
+ projectDir: string;
104
+ dataDir: string;
105
+ /** Of its last run, while it waits for a restart or after it ended. */
106
+ pid: number;
107
+ /** `restarting`: it ended on its own and its restart policy starts it
108
+ * again after the delay. `failed`: that policy gave up; `restart.failed`
109
+ * says why. */
110
+ status: "starting" | "running" | "stopping" | "exited" | "restarting" | "failed";
111
+ /** False: it runs on a data folder this supervisor knows and was started
112
+ * by something else. Listed from its run record, never stopped here. */
113
+ mine: boolean;
114
+ lifetime?: InstanceLifetime;
115
+ startedAt: string;
116
+ /** Where its output goes. */
117
+ logFile?: string;
118
+ /** The version of the project's ph-cli (or ph-run) that runs it. */
119
+ runnerVersion?: string;
120
+ /** Its run record, when it wrote one this version reads. */
121
+ record?: RunRecord;
122
+ /** The ports it bound and the URLs it published, from its record. */
123
+ ports?: Record<string, number>;
124
+ endpoints?: Record<string, string>;
125
+ /** The protocol of its control channel, when its record names one. */
126
+ controlProtocol?: number;
127
+ /** What cannot be done with it, each with the reason. */
128
+ missing: string[];
129
+ /** How it ended. */
130
+ exit?: {
131
+ code: number | null;
132
+ signal: string | null;
133
+ forced: boolean;
134
+ };
135
+ /** Where its restart policy stands, when it was started with one. */
136
+ restart?: RestartState;
137
+ }
138
+ declare const startParamsSchema: z.ZodObject<{
139
+ host: z.ZodString;
140
+ projectDir: z.ZodString;
141
+ dataDir: z.ZodOptional<z.ZodString>;
142
+ verb: z.ZodOptional<z.ZodString>;
143
+ argv: z.ZodOptional<z.ZodArray<z.ZodString>>;
144
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
145
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
146
+ baseEnv: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
147
+ lifetime: z.ZodOptional<z.ZodEnum<{
148
+ caller: "caller";
149
+ supervisor: "supervisor";
150
+ }>>;
151
+ lease: z.ZodOptional<z.ZodString>;
152
+ readyTimeoutMs: z.ZodOptional<z.ZodNumber>;
153
+ stopTimeoutMs: z.ZodOptional<z.ZodNumber>;
154
+ logFile: z.ZodOptional<z.ZodString>;
155
+ record: z.ZodOptional<z.ZodEnum<{
156
+ optional: "optional";
157
+ required: "required";
158
+ }>>;
159
+ restart: z.ZodOptional<z.ZodObject<{
160
+ enabled: z.ZodOptional<z.ZodBoolean>;
161
+ maxRetries: z.ZodNumber;
162
+ delay: z.ZodNumber;
163
+ }, z.core.$strip>>;
164
+ }, z.core.$strip>;
165
+ export type SupervisorStartParams = z.infer<typeof startParamsSchema>;
166
+ export interface SupervisorOptions {
167
+ /** Where `PH_SUPERVISOR_HOME` is read from (default: this process). */
168
+ env?: Env;
169
+ /** The version of the package this runs from, for `hello`. */
170
+ version?: string;
171
+ mode?: SupervisorMode;
172
+ /** One line per event, for the terminal it runs in. */
173
+ log?: (line: string) => void;
174
+ }
175
+ export interface Supervisor {
176
+ readonly record: SupervisorRecord;
177
+ readonly home: string;
178
+ /** Whether the system lets this user alone open its channel. */
179
+ readonly ownerOnly: boolean;
180
+ instances(): SupervisedInstance[];
181
+ /** Stops what it holds, each with its process tree, removes its record
182
+ * and closes its channel. */
183
+ stop(): Promise<void>;
184
+ /** Resolves once it has stopped, on `stop()` or a `shutdown` request. */
185
+ readonly stopped: Promise<void>;
186
+ }
187
+ export type SupervisorStart = {
188
+ supervisor: Supervisor;
189
+ } |
190
+ /** Another process is this user's supervisor: nothing was started. */
191
+ {
192
+ existing: Exclude<FoundSupervisor, {
193
+ status: "none";
194
+ }>;
195
+ };
196
+ /**
197
+ * Makes this process the supervisor of its OS user. With one running
198
+ * already (or recorded and silent) nothing is started and it is returned as
199
+ * `existing`.
200
+ */
201
+ export declare function startSupervisor(options?: SupervisorOptions): Promise<SupervisorStart>;
202
+ //#endregion
203
+ export { FoundSupervisor, SUPERVISOR_HOME_ENV, SupervisorHello, SupervisorMode, SupervisorRecord, findSupervisor, readSupervisorRecord, silentSupervisorMessage, supervisorHome, supervisorLockHolder, supervisorLockPath, supervisorRecordPath, supervisorRecordSchema, supervisorRecorded };
204
+ export {};
205
+ //# sourceMappingURL=supervisor.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supervisor.d.mts","names":[],"sources":["../src/supervisor-client.ts","../src/supervisor.ts"],"mappings":";;;;;;;;;;;;iBAuBiB;EACf;;EAEA,WAAW;;;WAGF,OAAO;;;wBAIF,oBACd,SAAS,gBACR,QAAQ;iBA2CM;EACf;IAAc;IAAa;IAAc;IAAiB;;EAC1D,WAAW;;;wBAIS,eACpB,SAAS,eACT,kBACA,UAAS,qBACR,QAAQ;wBASW,gBACpB,SAAS,eACT,QAAQ,uBACR,UAAS,qBACR;EAAU,UAAU;EAAoB;;wBAOrB,eACpB,SAAS,eACT,iBACC,QAAQ;wBAOW,kBACpB,SAAS,eACT,gBACA,UAAS,qBACR,QAAQ;wBAUW,eACpB,SAAS,eACT,gBACA,iBACC;EAAU;EAAc;;;wBAQL,mBACpB,SAAS,gBACR;EAAU;EAAa;;;iBAQT,uBAAuB;EACtC;EACA,UAAU;;EAEV,UAAU;;;;;;;;wBAWU,oBACpB,SAAS,eACT,QAAQ,uBACR;EAAW,SAAS;IACnB,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KCnGN,MAAM,SAAS;YAER;;iBAGK;;EAEf;;EAEA;EACA;EACA;EACA;;EAEA;;;;EAIA;;;EASA;EACA,WAAW;EACX;;EAEA;;EAEA;;EAEA,SAAS;;EAET,QAAQ;EACR,YAAY;;EAEZ;;EAEA;;EAEA;IAAS;IAAqB;IAAuB;;;EAErD,UAAU;;cAGN,mBAAiB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCrB,EAAA,KAAA;YACU,wBAAwB,EAAE,aAAa;iBAwKlC;;EAEf,MAAM;;EAEN;EACA,OAAO;;EAEP,OAAO;;iBAGQ;WACN,QAAQ;WACR;;WAEA;EACT,aAAa;;;EAGb,QAAQ;;WAEC,SAAS;;YAGR;EACN,YAAY;;;;EAEZ,UAAU,QAAQ;IAAmB;;;;;;;;wBAkCrB,gBACpB,UAAS,oBACR,QAAQ"}