@cotal-ai/seat 0.0.0-bootstrap.0 → 0.47.1

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,42 @@
1
- # @cotal-ai/seat bootstrap
1
+ # @cotal-ai/seat
2
2
 
3
- This placeholder reserves the package so its owner can configure npm trusted publishing. It provides no runtime implementation. Version 0.47.0 and later official releases are published separately through the repository release workflow.
3
+ Local PTY seat custody: a one-shot launcher, one detached custodian process per seat, and the
4
+ authenticated local protocol a manager worker uses to adopt that handle.
5
+
6
+ **Tier:** `packages/` (leaf). Depends on PTY and terminal-mirror libraries, not on
7
+ `@cotal-ai/core`, workspace, implementations, connectors, or NATS. The manager's `pty` runtime
8
+ is the first production caller.
9
+
10
+ Linux is the production transport in this cut. `create`/`spawn`/`adopt` in this package throw a
11
+ named `custody transport unsupported on <platform>` error on darwin and win32. There is no
12
+ in-process node-pty fallback here. The manager's `pty` runtime still spawns in-process off
13
+ Linux and only `adopt` throws that named error.
14
+
15
+ The Linux `SO_PEERCRED` helper is compiled for the host arch by `pnpm build`. That is a
16
+ developer tree, not a publishable one: it prints a host-dev-build banner and writes
17
+ `build/Release/linux-<arch>/peercred.node`. Pack and publish require both `linux-x64`
18
+ (ELF e_machine 62) and `linux-arm64` (ELF e_machine 183), copied in by
19
+ `scripts/seat-assemble-natives.mjs` from native builder jobs. `prepack` asserts
20
+ those two files and does not compile. `prepublishOnly` runs the same assert on
21
+ publish. The ARM load job installs the same packed tarball
22
+ with no rebuild. The compile uses the `include/node` directory next to the running
23
+ Node binary, not a hardcoded `/usr/include/node`. Off Linux the compile script is a no-op, so
24
+ Windows `pnpm build` does not need headers or a C compiler. There is no `binding.gyp`, so
25
+ `pnpm install` does not infer `node-gyp rebuild`. Customer `npm i` does not compile it. A host
26
+ without a C compiler installs the prebuilt helpers; a missing helper, an unsupported
27
+ `linux-<arch>`, or a load failure throws rather than compiling in place.
28
+
29
+ The package.json has no `os` / `cpu` / libc fields. Manager depends on this package on every
30
+ platform: off Linux it still loads, and only `adopt` throws the named custody-transport error.
31
+ Gating install would skip the package on darwin and win32 and break that path. A musl or
32
+ non-Linux host that reaches `peerCredentials` throws; there is no compile fallback and no
33
+ silent degrade. First use of the helper is the right place for that refusal.
34
+
35
+ The launcher owns no PTY and exits after writing a permissioned per-seat record. Each custodian
36
+ owns exactly one `node-pty` object, its child relationship, its screen mirror, and exit
37
+ observation. A manager worker connects to that custodian over a 0600 filesystem Unix socket
38
+ authenticated by `SO_PEERCRED` uid match plus a per-seat capability token. Path possession is
39
+ not enough. Child exit is pushed to every authenticated controller socket.
40
+
41
+ Generation CAS, the crash journal, N/N-1 protocol compatibility, and manager-worker activation
42
+ are later milestones. This package currently speaks a single implicit controller.
@@ -0,0 +1,55 @@
1
+ import { type StopMode } from "./protocol.js";
2
+ import type { SeatRecord } from "./record.js";
3
+ export interface HelloInfo {
4
+ name: string;
5
+ pid: number;
6
+ cols: number;
7
+ rows: number;
8
+ status: "running" | "exited";
9
+ exit?: {
10
+ code?: number;
11
+ signal?: number;
12
+ };
13
+ }
14
+ export declare class SeatClient {
15
+ private readonly record;
16
+ private sock;
17
+ private connecting;
18
+ private reader;
19
+ private nextId;
20
+ private pending;
21
+ private output;
22
+ private pendingSubscribe;
23
+ private exits;
24
+ private helloInfo;
25
+ private pendingExit;
26
+ private closed;
27
+ constructor(record: SeatRecord);
28
+ connect(): Promise<HelloInfo>;
29
+ info(): HelloInfo;
30
+ snapshot(): Promise<{
31
+ data: string;
32
+ cols: number;
33
+ rows: number;
34
+ }>;
35
+ subscribeOutput(fn: (data: Buffer) => void): Promise<() => void>;
36
+ onExit(fn: () => void): () => void;
37
+ write(data: string): Promise<void>;
38
+ resize(cols: number, rows: number): Promise<void>;
39
+ interrupt(): Promise<void>;
40
+ stop(mode: StopMode): Promise<void>;
41
+ waitExit(): Promise<{
42
+ code?: number;
43
+ signal?: number;
44
+ } | undefined>;
45
+ health(): Promise<{
46
+ pid: number;
47
+ status: "running" | "exited";
48
+ protocol: number;
49
+ }>;
50
+ close(): void;
51
+ private request;
52
+ private dispatch;
53
+ private failAll;
54
+ }
55
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,QAAQ,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C;AAQD,qBAAa,UAAU;IAaT,OAAO,CAAC,QAAQ,CAAC,MAAM;IAZnC,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,MAAM,CAA6C;IAC3D,OAAO,CAAC,gBAAgB,CAAuC;IAC/D,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAAS;gBAEM,MAAM,EAAE,UAAU;IAEzC,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC;IAyCnC,IAAI,IAAI,SAAS;IAKX,QAAQ,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAMjE,eAAe,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;IAgBtE,MAAM,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAW5B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASjD,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAK1B,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnC,QAAQ,IAAI,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAOnE,MAAM,IAAI,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAMxF,KAAK,IAAI,IAAI;IASb,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,QAAQ;IAsBhB,OAAO,CAAC,OAAO;CAchB"}
package/dist/client.js ADDED
@@ -0,0 +1,202 @@
1
+ import { connect } from "node:net";
2
+ import { FrameReader, encodeFrame, } from "./protocol.js";
3
+ export class SeatClient {
4
+ record;
5
+ sock;
6
+ connecting;
7
+ reader = new FrameReader();
8
+ nextId = 1;
9
+ pending = new Map();
10
+ output = new Map();
11
+ pendingSubscribe;
12
+ exits = new Set();
13
+ helloInfo;
14
+ pendingExit = false;
15
+ closed = false;
16
+ constructor(record) {
17
+ this.record = record;
18
+ }
19
+ async connect() {
20
+ if (this.helloInfo)
21
+ return this.helloInfo;
22
+ if (this.closed)
23
+ throw new Error("seat client is closed");
24
+ const sock = await new Promise((resolve, reject) => {
25
+ const s = connect(this.record.socket);
26
+ this.connecting = s;
27
+ s.once("connect", () => {
28
+ this.connecting = undefined;
29
+ resolve(s);
30
+ });
31
+ s.once("error", (err) => {
32
+ this.connecting = undefined;
33
+ reject(err);
34
+ });
35
+ });
36
+ if (this.closed) {
37
+ sock.destroy();
38
+ throw new Error("seat client is closed");
39
+ }
40
+ this.sock = sock;
41
+ sock.on("data", (chunk) => {
42
+ for (const raw of this.reader.push(chunk))
43
+ this.dispatch(raw);
44
+ });
45
+ sock.on("close", () => this.failAll(new Error("custodian socket closed")));
46
+ sock.on("error", (err) => {
47
+ if (this.closed && err.code === "ECONNRESET")
48
+ return;
49
+ this.failAll(err);
50
+ });
51
+ const reply = await this.request({ op: "hello", token: this.record.token });
52
+ if (!reply.ok || reply.op !== "hello")
53
+ throw new Error(reply.ok ? "unexpected hello reply" : reply.error);
54
+ this.helloInfo = {
55
+ name: reply.name,
56
+ pid: reply.pid,
57
+ cols: reply.cols,
58
+ rows: reply.rows,
59
+ status: this.pendingExit ? "exited" : reply.status,
60
+ ...(reply.exit ? { exit: reply.exit } : {}),
61
+ };
62
+ return this.helloInfo;
63
+ }
64
+ info() {
65
+ if (!this.helloInfo)
66
+ throw new Error("seat client is not connected");
67
+ return this.helloInfo;
68
+ }
69
+ async snapshot() {
70
+ const reply = await this.request({ op: "snapshot" });
71
+ if (!reply.ok || reply.op !== "snapshot")
72
+ throw new Error(reply.ok ? "unexpected snapshot reply" : reply.error);
73
+ return { data: reply.data, cols: reply.cols, rows: reply.rows };
74
+ }
75
+ async subscribeOutput(fn) {
76
+ this.pendingSubscribe = fn;
77
+ try {
78
+ const reply = await this.request({ op: "subscribe-output" });
79
+ if (!reply.ok || reply.op !== "subscribe-output")
80
+ throw new Error(reply.ok ? "unexpected subscribe reply" : reply.error);
81
+ this.output.set(reply.sub, fn);
82
+ const sub = reply.sub;
83
+ return () => {
84
+ this.output.delete(sub);
85
+ void this.request({ op: "unsubscribe-output", sub }).catch(() => undefined);
86
+ };
87
+ }
88
+ finally {
89
+ if (this.pendingSubscribe === fn)
90
+ this.pendingSubscribe = undefined;
91
+ }
92
+ }
93
+ onExit(fn) {
94
+ if (this.helloInfo?.status === "exited" || this.pendingExit) {
95
+ queueMicrotask(fn);
96
+ return () => { };
97
+ }
98
+ this.exits.add(fn);
99
+ return () => {
100
+ this.exits.delete(fn);
101
+ };
102
+ }
103
+ async write(data) {
104
+ const reply = await this.request({ op: "write", data });
105
+ if (!reply.ok)
106
+ throw new Error(reply.error);
107
+ }
108
+ async resize(cols, rows) {
109
+ const reply = await this.request({ op: "resize", cols, rows });
110
+ if (!reply.ok)
111
+ throw new Error(reply.error);
112
+ if (this.helloInfo && cols > 0 && rows > 0) {
113
+ this.helloInfo.cols = cols;
114
+ this.helloInfo.rows = rows;
115
+ }
116
+ }
117
+ async interrupt() {
118
+ const reply = await this.request({ op: "interrupt" });
119
+ if (!reply.ok)
120
+ throw new Error(reply.error);
121
+ }
122
+ async stop(mode) {
123
+ const reply = await this.request({ op: "stop", mode });
124
+ if (!reply.ok)
125
+ throw new Error(reply.error);
126
+ }
127
+ async waitExit() {
128
+ const reply = await this.request({ op: "wait-exit" });
129
+ if (!reply.ok || reply.op !== "wait-exit")
130
+ throw new Error(reply.ok ? "unexpected wait-exit reply" : reply.error);
131
+ if (this.helloInfo)
132
+ this.helloInfo.status = "exited";
133
+ return reply.exit;
134
+ }
135
+ async health() {
136
+ const reply = await this.request({ op: "health" });
137
+ if (!reply.ok || reply.op !== "health")
138
+ throw new Error(reply.ok ? "unexpected health reply" : reply.error);
139
+ return { pid: reply.pid, status: reply.status, protocol: reply.protocol };
140
+ }
141
+ close() {
142
+ this.closed = true;
143
+ this.connecting?.destroy();
144
+ this.connecting = undefined;
145
+ this.sock?.destroy();
146
+ this.sock = undefined;
147
+ this.failAll(new Error("seat client is closed"));
148
+ }
149
+ request(body) {
150
+ if (!this.sock || this.closed)
151
+ return Promise.reject(new Error("seat client is closed"));
152
+ const id = this.nextId++;
153
+ const req = { ...body, id };
154
+ return new Promise((resolve, reject) => {
155
+ this.pending.set(id, { op: body.op, resolve, reject });
156
+ this.sock.write(encodeFrame(req));
157
+ });
158
+ }
159
+ dispatch(raw) {
160
+ const msg = raw;
161
+ if ("event" in msg) {
162
+ if (msg.event === "output") {
163
+ const fn = this.output.get(msg.sub) ?? this.pendingSubscribe;
164
+ if (fn)
165
+ fn(Buffer.from(msg.data, "base64"));
166
+ return;
167
+ }
168
+ if (msg.event === "exit") {
169
+ if (this.helloInfo)
170
+ this.helloInfo.status = "exited";
171
+ else
172
+ this.pendingExit = true;
173
+ for (const fn of this.exits)
174
+ fn();
175
+ this.exits.clear();
176
+ }
177
+ return;
178
+ }
179
+ const pending = this.pending.get(msg.id);
180
+ if (!pending)
181
+ return;
182
+ this.pending.delete(msg.id);
183
+ pending.resolve(msg);
184
+ }
185
+ failAll(err) {
186
+ for (const [id, pending] of this.pending) {
187
+ if (pending.op === "wait-exit" && (this.helloInfo?.status === "exited" || this.pendingExit)) {
188
+ pending.resolve({ id, ok: true, op: "wait-exit", exit: this.helloInfo?.exit });
189
+ }
190
+ else {
191
+ pending.reject(err);
192
+ }
193
+ }
194
+ this.pending.clear();
195
+ if (this.helloInfo?.status !== "exited") {
196
+ for (const fn of this.exits)
197
+ fn();
198
+ this.exits.clear();
199
+ }
200
+ }
201
+ }
202
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,UAAU,CAAC;AAChD,OAAO,EACL,WAAW,EACX,WAAW,GAKZ,MAAM,eAAe,CAAC;AAkBvB,MAAM,OAAO,UAAU;IAaQ;IAZrB,IAAI,CAAqB;I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AC,CAAC;IACvB,CAAC;IAEO,OAAO,CAAC,GAAU;QACxB,KAAK,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACzC,IAAI,OAAO,CAAC,EAAE,KAAK,WAAW,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC5F,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACjF,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,IAAI,CAAC,SAAS,EAAE,MAAM,KAAK,QAAQ,EAAE,CAAC;YACxC,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,KAAK;gBAAE,EAAE,EAAE,CAAC;YAClC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ export interface CustodianLaunch {
2
+ id: string;
3
+ name: string;
4
+ command: string;
5
+ args: string[] | string;
6
+ env: Record<string, string>;
7
+ cwd: string;
8
+ socket: string;
9
+ token: string;
10
+ recordPath: string;
11
+ logPath?: string;
12
+ confirm?: boolean;
13
+ }
14
+ export declare function runCustodian(launch: CustodianLaunch): Promise<void>;
15
+ //# sourceMappingURL=custodian.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custodian.d.ts","sourceRoot":"","sources":["../src/custodian.ts"],"names":[],"mappings":"AAuBA,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAOD,wBAAsB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAuTzE"}