@powerhousedao/host-core 6.4.0-next.2 → 6.4.0-next.4

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,206 @@
1
+ import { z } from "zod";
2
+ //#region src/run-record-schema.d.ts
3
+ declare const runRecordMemberSchema: z.ZodObject<{
4
+ host: z.ZodString;
5
+ runnerModule: z.ZodString;
6
+ kind: z.ZodEnum<{
7
+ compound: "compound";
8
+ reactor: "reactor";
9
+ }>;
10
+ verb: z.ZodString;
11
+ outputs: z.ZodRecord<z.ZodString, z.ZodUnknown>;
12
+ }, z.core.$strict>;
13
+ declare const runRecordSchema: z.ZodObject<{
14
+ version: z.ZodLiteral<2>;
15
+ host: z.ZodString;
16
+ package: z.ZodOptional<z.ZodString>;
17
+ projectName: z.ZodString;
18
+ kind: z.ZodEnum<{
19
+ compound: "compound";
20
+ reactor: "reactor";
21
+ }>;
22
+ verb: z.ZodString;
23
+ pid: z.ZodNumber;
24
+ startedAt: z.ZodString;
25
+ outputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
26
+ members: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
27
+ host: z.ZodString;
28
+ runnerModule: z.ZodString;
29
+ kind: z.ZodEnum<{
30
+ compound: "compound";
31
+ reactor: "reactor";
32
+ }>;
33
+ verb: z.ZodString;
34
+ outputs: z.ZodRecord<z.ZodString, z.ZodUnknown>;
35
+ }, z.core.$strict>>>;
36
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
37
+ }, z.core.$strict>;
38
+ type RunRecord = z.infer<typeof runRecordSchema>;
39
+ type RunRecordMember = z.infer<typeof runRecordMemberSchema>;
40
+ //#endregion
41
+ //#region src/control-channel.d.ts
42
+ /**
43
+ * The control channel of a process that keeps running (a serving Cli, a
44
+ * compound with one): a local stream other processes of the same OS user
45
+ * send requests to, so a command typed in a second terminal acts on what
46
+ * runs in the first. A named pipe on Windows, a socket file elsewhere. Its
47
+ * address and token are in the process's run record (`extra.control`).
48
+ *
49
+ * Same user only. Elsewhere the socket is mode 0600 in a 0700 folder of the
50
+ * user. On Windows the pipe's access list is replaced once it listens: the
51
+ * user alone, and no caller from the network ({@link ControlChannel.ownerOnly}
52
+ * says whether that took). Until then, and when it did not take, the pipe has
53
+ * the system's default list: only its creator, administrators and the system
54
+ * write to it, everyone may open it to read. So the server sends nothing
55
+ * before a request that carries the token, and drops a caller that sends
56
+ * none in time.
57
+ *
58
+ * One JSON value per line. A request is
59
+ * `{ protocol, id, token, method, params }`. Its answer ends with
60
+ * `{ id, ok: true, result }` or `{ id, ok: false, error: { code, message } }`;
61
+ * before that a handler may send output as it is produced:
62
+ * `{ id, stream: "stdout" | "stderr", data }`, in the order it was written.
63
+ * `{ protocol, id, token, cancel: true }` cancels the request `id` of the
64
+ * same connection, and so does the end of the connection.
65
+ *
66
+ * A caller that can answer questions while its request runs lists their
67
+ * kinds in the request, `asks: [kind, ...]`. The handler may then ask one:
68
+ * `{ id, ask: { seq, kind, payload } }`, and the caller answers on the same
69
+ * connection with `{ protocol, id, token, answer: { seq, ok: true, result } }`
70
+ * or `{ ..., answer: { seq, ok: false, error: { code, message } } }`. An
71
+ * answer is taken at once, not behind the request it answers.
72
+ */
73
+ /** 2: output frames, `cancel`, and asks for the kinds a request lists. A
74
+ * caller and a process of different protocols refuse each other, each naming
75
+ * both. */
76
+ declare const CONTROL_PROTOCOL = 2;
77
+ /** How long an ask waits for its answer unless told otherwise. */
78
+ declare const ASK_TIMEOUT_MS: number;
79
+ /** A run record's `extra.control`. */
80
+ declare const controlRecordSchema: z.ZodObject<{
81
+ protocol: z.ZodNumber;
82
+ address: z.ZodString;
83
+ token: z.ZodString;
84
+ }, z.core.$strip>;
85
+ type ControlRecord = z.infer<typeof controlRecordSchema>;
86
+ type ControlErrorCode = "unauthorized" | "protocol" | "bad-request" | "unknown-method" | "failed" | "cancelled" | "unreachable" |
87
+ /** The caller does not answer asks of this kind. */
88
+ "unsupported" |
89
+ /** The caller would not answer: what it said is the message. */
90
+ "refused" |
91
+ /** The caller did not answer in time. */
92
+ "timeout";
93
+ declare class ControlError extends Error {
94
+ readonly code: ControlErrorCode;
95
+ constructor(code: ControlErrorCode, message: string);
96
+ }
97
+ type ControlStream = "stdout" | "stderr";
98
+ /** One request, as its handler sees it. */
99
+ interface ControlCall {
100
+ /** Aborted when the caller cancels, or goes away. */
101
+ readonly signal: AbortSignal;
102
+ /** Sends output to the caller now. Nothing is sent once the request is
103
+ * cancelled. */
104
+ write(stream: ControlStream, data: string): void;
105
+ /** The kinds of ask the caller answers (its request's `asks`). */
106
+ readonly asks: ReadonlySet<string>;
107
+ /**
108
+ * Asks the caller and resolves with its answer. Rejects with a
109
+ * {@link ControlError}: `unsupported` for a kind the caller did not list,
110
+ * the code the caller refused with, `cancelled` when the request ends
111
+ * first, `timeout` after `timeoutMs` (default {@link ASK_TIMEOUT_MS}).
112
+ */
113
+ ask(kind: string, payload?: unknown, options?: {
114
+ timeoutMs?: number;
115
+ }): Promise<unknown>;
116
+ }
117
+ type ControlHandler = (params: unknown, call: ControlCall) => unknown;
118
+ interface ControlChannel {
119
+ /** What the run record holds. */
120
+ readonly record: ControlRecord;
121
+ /** Whether the system lets this user alone open the channel: the socket
122
+ * file's mode, or on Windows the pipe's access list once it was replaced.
123
+ * False: the token is what keeps other users out. */
124
+ readonly ownerOnly: boolean;
125
+ /** Answers `method` from now on (replacing an earlier handler). */
126
+ handle(method: string, handler: ControlHandler): void;
127
+ /** Added to the answer to `hello`. */
128
+ describe(info: Record<string, unknown>): void;
129
+ close(): Promise<void>;
130
+ }
131
+ interface OpenControlChannelOptions {
132
+ /** The folder of the socket file (not on Windows). Default: a folder of
133
+ * the user under the system's temporary folder. */
134
+ socketDir?: string;
135
+ /** How long a caller may take to send its first request (default 5 s). */
136
+ handshakeTimeoutMs?: number;
137
+ /** What `hello` answers as `mode` (default "ad hoc": the process
138
+ * supervises what it started itself). A supervisor names its own. */
139
+ mode?: string;
140
+ }
141
+ /** The longest request line, and the longest line of output. */
142
+ declare const MAX_LINE_BYTES: number;
143
+ /** The control channel a live run of this record answers on, when it has
144
+ * one of a protocol this version speaks. */
145
+ declare function controlRecordOf(record: Pick<RunRecord, "extra"> | undefined): ControlRecord | undefined;
146
+ /** The protocol of the control channel a record names, whichever it is. */
147
+ declare function controlProtocolOf(record: Pick<RunRecord, "extra"> | undefined): number | undefined;
148
+ /** What a caller of one protocol is told about a process of another. */
149
+ declare function protocolMismatch(theirs: unknown): string;
150
+ /**
151
+ * The access list (SDDL) of the pipe `name` (as in `\\.\pipe\<name>`);
152
+ * undefined when it cannot be read. Windows only.
153
+ */
154
+ declare function pipeAccessList(name: string): Promise<string | undefined>;
155
+ /** The access list a control pipe gets: no caller from the network, and the
156
+ * user `sid` alone. */
157
+ declare const ownerOnlyPipeAccess: (sid: string) => string;
158
+ /**
159
+ * Opens a control channel for this process and resolves once it listens.
160
+ * The server holds no process open. `hello` is answered by the channel
161
+ * itself: `{ protocol, pid, mode, methods }` and what `describe` added.
162
+ */
163
+ declare function openControlChannel(options?: OpenControlChannelOptions): Promise<ControlChannel>;
164
+ /**
165
+ * This process's control channel, opened on the first call. Undefined when
166
+ * it cannot be opened: the process then runs without one, as before.
167
+ */
168
+ declare function ensureProcessControlChannel(options?: OpenControlChannelOptions): Promise<ControlChannel | undefined>;
169
+ /** This process's control channel, when it has opened one. */
170
+ declare function processControlChannel(): ControlChannel | undefined;
171
+ /** Closes this process's control channel, if it has one. */
172
+ declare function closeProcessControlChannel(): Promise<void>;
173
+ interface CallControlOptions {
174
+ /** How long the answer may take (default: no limit; the request ends when
175
+ * the other process does). */
176
+ timeoutMs?: number;
177
+ /** How long connecting may take (default 2 s). */
178
+ connectTimeoutMs?: number;
179
+ /** Do not hold this process open for the answer. */
180
+ unref?: boolean;
181
+ /** Output the other process sends while it works on the request. */
182
+ onOutput?: (stream: ControlStream, data: string) => void;
183
+ /** Cancels the request there; the call then rejects with `cancelled`. */
184
+ signal?: AbortSignal;
185
+ /**
186
+ * Answers what the other process asks while it works on the request, for
187
+ * the kinds in `asks`. Its result is the answer; what it throws is a
188
+ * refusal, with the error's `code` when that is a {@link ControlErrorCode}.
189
+ * `signal` aborts when the request ends.
190
+ */
191
+ onAsk?: (kind: string, payload: unknown, signal: AbortSignal) => unknown;
192
+ /** The kinds `onAsk` answers; sent with the request. */
193
+ asks?: readonly string[];
194
+ }
195
+ /**
196
+ * One request to the control channel a run record names. Resolves with the
197
+ * result; rejects with a {@link ControlError}: `unreachable` when nothing
198
+ * answers there, `protocol` when it speaks another protocol, else the code
199
+ * the other process refused with. A request that is cancelled, or whose
200
+ * caller ends, is cancelled in the other process.
201
+ */
202
+ declare function callControl(control: ControlRecord, method: string, params?: unknown, options?: CallControlOptions): Promise<unknown>;
203
+ //#endregion
204
+ export { protocolMismatch as C, runRecordSchema as D, runRecordMemberSchema as E, processControlChannel as S, RunRecordMember as T, controlRecordSchema as _, ControlChannel as a, ownerOnlyPipeAccess as b, ControlHandler as c, MAX_LINE_BYTES as d, OpenControlChannelOptions as f, controlRecordOf as g, controlProtocolOf as h, ControlCall as i, ControlRecord as l, closeProcessControlChannel as m, CONTROL_PROTOCOL as n, ControlError as o, callControl as p, CallControlOptions as r, ControlErrorCode as s, ASK_TIMEOUT_MS as t, ControlStream as u, ensureProcessControlChannel as v, RunRecord as w, pipeAccessList as x, openControlChannel as y };
205
+ export {};
206
+ //# sourceMappingURL=control-channel-DVn4dvfQ.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-channel-DVn4dvfQ.d.mts","names":[],"sources":["../src/run-record-schema.ts","../src/control-channel.ts"],"mappings":";;cAmBa,uBAAqB,EAAA;;;;;;;;;GAQhC,EAAA,KAAA;cAEW,iBAAe,EAAA;;;;;;;;;;;;;;;;;;;;;;;;GAiB1B,EAAA,KAAA;KAEU,YAAY,EAAE,aAAa;KAC3B,kBAAkB,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCLhC;;cAGA;;cAGA,qBAAmB,EAAA;;;;GAI9B,EAAA,KAAA;KACU,gBAAgB,EAAE,aAAa;KAE/B;;;;;;;cAmCC,qBAAqB;WAErB,MAAM;EADjB,YACW,MAAM,kBACf;;KAOQ;;UAGK;;WAEN,QAAQ;;;EAGjB,MAAM,QAAQ,eAAe;;WAEpB,MAAM;;;;;;;EAOf,IACE,cACA,mBACA;IAAY;MACX;;KAeO,kBAAkB,iBAAiB,MAAM;UAEpC;;WAEN,QAAQ;;;;WAIR;;EAET,OAAO,gBAAgB,SAAS;;EAEhC,SAAS,MAAM;EACf,SAAS;;UAGM;;;EAGf;;EAEA;;;EAGA;;;cAIW;;;iBAOG,gBACd,QAAQ,KAAK,kCACZ;;iBASa,kBACd,QAAQ,KAAK;;iBAOC,iBAAiB;;;;;iBAiFjB,eAAe,eAAe;;;cAUjC,sBAAmB;;;;;;iBA2BV,mBACpB,UAAS,4BACR,QAAQ;;;;;iBA6WW,4BACpB,UAAS,4BACR,QAAQ;;iBAeK,yBAAyB;;iBAKnB,8BAA8B;UAOnC;;;EAGf;;EAEA;;EAEA;;EAEA,YAAY,QAAQ,eAAe;;EAEnC,SAAS;;;;;;;EAOT,SAAS,cAAc,kBAAkB,QAAQ;;EAEjD;;;;;;;;;iBAYc,YACd,SAAS,eACT,gBACA,kBACA,UAAS,qBACR"}
@@ -1,3 +1,3 @@
1
- import { a as ControlErrorCode, c as OpenControlChannelOptions, d as controlRecordOf, f as controlRecordSchema, h as processControlChannel, i as ControlError, l as callControl, m as openControlChannel, n as CallControlOptions, o as ControlHandler, p as ensureProcessControlChannel, r as ControlChannel, s as ControlRecord, t as CONTROL_PROTOCOL, u as closeProcessControlChannel } from "./control-channel-eqvyUF03.mjs";
2
- export { CONTROL_PROTOCOL, CallControlOptions, ControlChannel, ControlError, ControlErrorCode, ControlHandler, ControlRecord, OpenControlChannelOptions, callControl, closeProcessControlChannel, controlRecordOf, controlRecordSchema, ensureProcessControlChannel, openControlChannel, processControlChannel };
1
+ import { C as protocolMismatch, S as processControlChannel, _ as controlRecordSchema, a as ControlChannel, b as ownerOnlyPipeAccess, c as ControlHandler, d as MAX_LINE_BYTES, f as OpenControlChannelOptions, g as controlRecordOf, h as controlProtocolOf, i as ControlCall, l as ControlRecord, m as closeProcessControlChannel, n as CONTROL_PROTOCOL, o as ControlError, p as callControl, r as CallControlOptions, s as ControlErrorCode, t as ASK_TIMEOUT_MS, u as ControlStream, v as ensureProcessControlChannel, x as pipeAccessList, y as openControlChannel } from "./control-channel-DVn4dvfQ.mjs";
2
+ export { ASK_TIMEOUT_MS, CONTROL_PROTOCOL, CallControlOptions, ControlCall, ControlChannel, ControlError, ControlErrorCode, ControlHandler, ControlRecord, ControlStream, MAX_LINE_BYTES, OpenControlChannelOptions, callControl, closeProcessControlChannel, controlProtocolOf, controlRecordOf, controlRecordSchema, ensureProcessControlChannel, openControlChannel, ownerOnlyPipeAccess, pipeAccessList, processControlChannel, protocolMismatch };
3
3
  export {};