@companyhelm/cli 0.0.9 → 0.0.12
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 +21 -201
- package/README.md +1 -1
- package/dist/commands/root.js +131 -3
- package/dist/commands/startup.js +3 -20
- package/dist/service/thread_lifecycle.js +15 -10
- package/dist/utils/process.js +61 -0
- package/dist/utils/terminal.js +34 -0
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,201 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright [yyyy] [name of copyright owner]
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CompanyHelm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
package/dist/commands/root.js
CHANGED
|
@@ -43,6 +43,7 @@ exports.isNoRunningTurnInterruptError = isNoRunningTurnInterruptError;
|
|
|
43
43
|
exports.normalizeThreadAgentApiUrlForRuntime = normalizeThreadAgentApiUrlForRuntime;
|
|
44
44
|
exports.extractThreadNameUpdateFromNotification = extractThreadNameUpdateFromNotification;
|
|
45
45
|
exports.extractServerMessageRequestId = extractServerMessageRequestId;
|
|
46
|
+
exports.runCommandLoop = runCommandLoop;
|
|
46
47
|
exports.isInternalDaemonChildProcess = isInternalDaemonChildProcess;
|
|
47
48
|
exports.runDetachedDaemonProcess = runDetachedDaemonProcess;
|
|
48
49
|
exports.sendDaemonParentMessage = sendDaemonParentMessage;
|
|
@@ -74,6 +75,7 @@ const schema_js_1 = require("../state/schema.js");
|
|
|
74
75
|
const daemon_js_1 = require("../utils/daemon.js");
|
|
75
76
|
const logger_js_1 = require("../utils/logger.js");
|
|
76
77
|
const path_js_1 = require("../utils/path.js");
|
|
78
|
+
const terminal_js_1 = require("../utils/terminal.js");
|
|
77
79
|
const workspace_agents_js_1 = require("../service/workspace_agents.js");
|
|
78
80
|
const COMMAND_CHANNEL_CONNECT_RETRY_DELAY_MS = 1000;
|
|
79
81
|
const COMMAND_CHANNEL_OPEN_TIMEOUT_MS = 5000;
|
|
@@ -95,6 +97,12 @@ const YOLO_SANDBOX_POLICY = { type: "dangerFullAccess" };
|
|
|
95
97
|
const DOCKER_INTERNAL_HOSTNAME = "host.docker.internal";
|
|
96
98
|
const LOCALHOST_HOSTNAMES = new Set(["localhost", "127.0.0.1", "0.0.0.0", "::1"]);
|
|
97
99
|
const DAEMON_STARTUP_TIMEOUT_MS = 15000;
|
|
100
|
+
class RootCommandInterruptedError extends Error {
|
|
101
|
+
constructor(message = "Root command interrupted.") {
|
|
102
|
+
super(message);
|
|
103
|
+
this.name = "RootCommandInterruptedError";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
98
106
|
const threadAppServerSessions = new Map();
|
|
99
107
|
const threadRolloutPaths = new Map();
|
|
100
108
|
function rememberThreadRolloutPath(threadId, rolloutPath) {
|
|
@@ -1370,6 +1378,16 @@ async function sendRequestError(commandChannel, errorMessage, requestId) {
|
|
|
1370
1378
|
});
|
|
1371
1379
|
await commandChannel.send(message);
|
|
1372
1380
|
}
|
|
1381
|
+
async function sendHeartbeatResponse(commandChannel, requestId) {
|
|
1382
|
+
const message = (0, protobuf_1.create)(protos_1.ClientMessageSchema, {
|
|
1383
|
+
requestId,
|
|
1384
|
+
payload: {
|
|
1385
|
+
case: "heartbeatResponse",
|
|
1386
|
+
value: {},
|
|
1387
|
+
},
|
|
1388
|
+
});
|
|
1389
|
+
await commandChannel.send(message);
|
|
1390
|
+
}
|
|
1373
1391
|
async function sendThreadUpdate(commandChannel, threadId, status, requestId) {
|
|
1374
1392
|
const message = (0, protobuf_1.create)(protos_1.ClientMessageSchema, {
|
|
1375
1393
|
requestId,
|
|
@@ -2167,6 +2185,9 @@ async function runCommandLoop(cfg, commandChannel, commandMessageSink, apiClient
|
|
|
2167
2185
|
case "interruptTurnRequest":
|
|
2168
2186
|
await handleInterruptTurnRequest(cfg, commandMessageSink, serverMessage.request.value, logger);
|
|
2169
2187
|
break;
|
|
2188
|
+
case "heartbeatRequest":
|
|
2189
|
+
await sendHeartbeatResponse(commandMessageSink, requestId);
|
|
2190
|
+
break;
|
|
2170
2191
|
default:
|
|
2171
2192
|
break;
|
|
2172
2193
|
}
|
|
@@ -2183,6 +2204,92 @@ function buildGrpcAuthCallOptions(secret) {
|
|
|
2183
2204
|
function isInternalDaemonChildProcess() {
|
|
2184
2205
|
return process.env[daemon_js_1.DAEMON_CHILD_ENV] === "1";
|
|
2185
2206
|
}
|
|
2207
|
+
function abortErrorFromSignal(signal) {
|
|
2208
|
+
return signal.reason instanceof Error ? signal.reason : new RootCommandInterruptedError();
|
|
2209
|
+
}
|
|
2210
|
+
function throwIfAborted(signal) {
|
|
2211
|
+
if (signal.aborted) {
|
|
2212
|
+
throw abortErrorFromSignal(signal);
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
function raceWithAbort(promise, signal) {
|
|
2216
|
+
if (signal.aborted) {
|
|
2217
|
+
return Promise.reject(abortErrorFromSignal(signal));
|
|
2218
|
+
}
|
|
2219
|
+
return Promise.race([
|
|
2220
|
+
promise,
|
|
2221
|
+
new Promise((_, reject) => {
|
|
2222
|
+
const onAbort = () => {
|
|
2223
|
+
signal.removeEventListener("abort", onAbort);
|
|
2224
|
+
reject(abortErrorFromSignal(signal));
|
|
2225
|
+
};
|
|
2226
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2227
|
+
}),
|
|
2228
|
+
]);
|
|
2229
|
+
}
|
|
2230
|
+
function delayWithAbort(delayMs, signal) {
|
|
2231
|
+
if (signal.aborted) {
|
|
2232
|
+
return Promise.reject(abortErrorFromSignal(signal));
|
|
2233
|
+
}
|
|
2234
|
+
return new Promise((resolve, reject) => {
|
|
2235
|
+
const timeout = setTimeout(() => {
|
|
2236
|
+
signal.removeEventListener("abort", onAbort);
|
|
2237
|
+
resolve();
|
|
2238
|
+
}, delayMs);
|
|
2239
|
+
const onAbort = () => {
|
|
2240
|
+
clearTimeout(timeout);
|
|
2241
|
+
signal.removeEventListener("abort", onAbort);
|
|
2242
|
+
reject(abortErrorFromSignal(signal));
|
|
2243
|
+
};
|
|
2244
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
function installRootInterruptHandlers(logger, onInterrupt) {
|
|
2248
|
+
const controller = new AbortController();
|
|
2249
|
+
const requestInterrupt = (reason) => {
|
|
2250
|
+
if (controller.signal.aborted) {
|
|
2251
|
+
return;
|
|
2252
|
+
}
|
|
2253
|
+
(0, terminal_js_1.restoreInteractiveTerminalState)();
|
|
2254
|
+
process.exitCode = 130;
|
|
2255
|
+
logger.info(`${reason} received. Shutting down root command.`);
|
|
2256
|
+
try {
|
|
2257
|
+
onInterrupt();
|
|
2258
|
+
}
|
|
2259
|
+
catch {
|
|
2260
|
+
// Best-effort shutdown hook.
|
|
2261
|
+
}
|
|
2262
|
+
controller.abort(new RootCommandInterruptedError(reason));
|
|
2263
|
+
};
|
|
2264
|
+
const handleSigint = () => {
|
|
2265
|
+
requestInterrupt("SIGINT");
|
|
2266
|
+
};
|
|
2267
|
+
const handleSigterm = () => {
|
|
2268
|
+
requestInterrupt("SIGTERM");
|
|
2269
|
+
};
|
|
2270
|
+
const handleStdinData = (chunk) => {
|
|
2271
|
+
const input = typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
2272
|
+
if ((0, terminal_js_1.containsCtrlCInterruptInput)(input)) {
|
|
2273
|
+
requestInterrupt("Ctrl-C");
|
|
2274
|
+
}
|
|
2275
|
+
};
|
|
2276
|
+
process.on("SIGINT", handleSigint);
|
|
2277
|
+
process.on("SIGTERM", handleSigterm);
|
|
2278
|
+
if (process.stdin.isTTY) {
|
|
2279
|
+
process.stdin.on("data", handleStdinData);
|
|
2280
|
+
process.stdin.resume();
|
|
2281
|
+
}
|
|
2282
|
+
return {
|
|
2283
|
+
signal: controller.signal,
|
|
2284
|
+
dispose: () => {
|
|
2285
|
+
process.off("SIGINT", handleSigint);
|
|
2286
|
+
process.off("SIGTERM", handleSigterm);
|
|
2287
|
+
if (process.stdin.isTTY) {
|
|
2288
|
+
process.stdin.off("data", handleStdinData);
|
|
2289
|
+
}
|
|
2290
|
+
},
|
|
2291
|
+
};
|
|
2292
|
+
}
|
|
2186
2293
|
function resolveEffectiveDaemonLogPath(cfg) {
|
|
2187
2294
|
const envPath = process.env[daemon_js_1.DAEMON_LOG_PATH_ENV];
|
|
2188
2295
|
if (envPath && envPath.trim().length > 0) {
|
|
@@ -2277,6 +2384,7 @@ async function runRootCommand(options, runtimeOptions) {
|
|
|
2277
2384
|
}
|
|
2278
2385
|
if (!configuredSdks) {
|
|
2279
2386
|
await (0, startup_js_1.startup)(cfg);
|
|
2387
|
+
(0, terminal_js_1.restoreInteractiveTerminalState)();
|
|
2280
2388
|
}
|
|
2281
2389
|
await refreshCodexModelsForRegistration(cfg, logger);
|
|
2282
2390
|
const registerRequest = await buildRegisterRunnerRequest(cfg);
|
|
@@ -2290,16 +2398,25 @@ async function runRootCommand(options, runtimeOptions) {
|
|
|
2290
2398
|
logger,
|
|
2291
2399
|
});
|
|
2292
2400
|
let reconnectAttempt = 0;
|
|
2401
|
+
let activeApiClient = null;
|
|
2402
|
+
let activeCommandChannel = null;
|
|
2403
|
+
const interruptState = installRootInterruptHandlers(logger, () => {
|
|
2404
|
+
activeCommandChannel?.cancel();
|
|
2405
|
+
activeApiClient?.close();
|
|
2406
|
+
});
|
|
2293
2407
|
try {
|
|
2294
2408
|
while (true) {
|
|
2409
|
+
throwIfAborted(interruptState.signal);
|
|
2295
2410
|
const apiClient = new companyhelm_api_client_js_1.CompanyhelmApiClient({ apiUrl: cfg.companyhelm_api_url, logger });
|
|
2411
|
+
activeApiClient = apiClient;
|
|
2296
2412
|
let commandChannel = null;
|
|
2297
2413
|
let githubInstallationsSyncAbortController = null;
|
|
2298
2414
|
let githubInstallationsSyncTask = null;
|
|
2299
2415
|
try {
|
|
2300
2416
|
reconnectAttempt += 1;
|
|
2301
2417
|
commandChannel = await apiClient.connect(registerRequest, apiCallOptions);
|
|
2302
|
-
|
|
2418
|
+
activeCommandChannel = commandChannel;
|
|
2419
|
+
await raceWithAbort(commandChannel.waitForOpen(COMMAND_CHANNEL_OPEN_TIMEOUT_MS), interruptState.signal);
|
|
2303
2420
|
commandMessageSink.bind(commandChannel);
|
|
2304
2421
|
const bufferedMessages = commandMessageSink.getBufferedMessageCount();
|
|
2305
2422
|
if (bufferedMessages > 0) {
|
|
@@ -2315,10 +2432,13 @@ async function runRootCommand(options, runtimeOptions) {
|
|
|
2315
2432
|
logger.warn(`GitHub installation sync loop exited unexpectedly: ${toErrorMessage(error)}`);
|
|
2316
2433
|
}
|
|
2317
2434
|
});
|
|
2318
|
-
await runCommandLoop(cfg, commandChannel, commandMessageSink, apiClient, apiCallOptions, logger);
|
|
2435
|
+
await raceWithAbort(runCommandLoop(cfg, commandChannel, commandMessageSink, apiClient, apiCallOptions, logger), interruptState.signal);
|
|
2319
2436
|
logger.warn("CompanyHelm API command channel closed. Reconnecting...");
|
|
2320
2437
|
}
|
|
2321
2438
|
catch (error) {
|
|
2439
|
+
if (error instanceof RootCommandInterruptedError) {
|
|
2440
|
+
return;
|
|
2441
|
+
}
|
|
2322
2442
|
const failureMessage = formatApiConnectionFailureMessage(error, cfg.companyhelm_api_url, options.secret);
|
|
2323
2443
|
const diagnostics = formatApiConnectionFailureDiagnostics(error);
|
|
2324
2444
|
if (diagnostics) {
|
|
@@ -2336,17 +2456,25 @@ async function runRootCommand(options, runtimeOptions) {
|
|
|
2336
2456
|
}
|
|
2337
2457
|
void githubInstallationsSyncTask;
|
|
2338
2458
|
if (commandChannel) {
|
|
2459
|
+
commandChannel.cancel();
|
|
2339
2460
|
commandMessageSink.unbind(commandChannel);
|
|
2340
2461
|
}
|
|
2341
2462
|
else {
|
|
2342
2463
|
commandMessageSink.unbind();
|
|
2343
2464
|
}
|
|
2465
|
+
if (activeCommandChannel === commandChannel) {
|
|
2466
|
+
activeCommandChannel = null;
|
|
2467
|
+
}
|
|
2468
|
+
if (activeApiClient === apiClient) {
|
|
2469
|
+
activeApiClient = null;
|
|
2470
|
+
}
|
|
2344
2471
|
apiClient.close();
|
|
2345
2472
|
}
|
|
2346
|
-
await
|
|
2473
|
+
await delayWithAbort(COMMAND_CHANNEL_CONNECT_RETRY_DELAY_MS, interruptState.signal);
|
|
2347
2474
|
}
|
|
2348
2475
|
}
|
|
2349
2476
|
finally {
|
|
2477
|
+
interruptState.dispose();
|
|
2350
2478
|
const droppedMessages = commandMessageSink.getDroppedMessageCount();
|
|
2351
2479
|
if (droppedMessages > 0) {
|
|
2352
2480
|
logger.warn(`Dropped ${droppedMessages} outbound client message(s) while command channel was disconnected.`);
|
package/dist/commands/startup.js
CHANGED
|
@@ -44,6 +44,7 @@ const config_js_1 = require("../config.js");
|
|
|
44
44
|
const db_js_1 = require("../state/db.js");
|
|
45
45
|
const schema_js_1 = require("../state/schema.js");
|
|
46
46
|
const refresh_models_js_1 = require("../service/sdk/refresh_models.js");
|
|
47
|
+
const terminal_js_1 = require("../utils/terminal.js");
|
|
47
48
|
const auth_js_1 = require("./sdk/codex/auth.js");
|
|
48
49
|
function banner() {
|
|
49
50
|
console.log();
|
|
@@ -58,26 +59,8 @@ const defaultStartupDependencies = {
|
|
|
58
59
|
spawnCommand: node_child_process_1.spawn,
|
|
59
60
|
spawnSyncCommand: node_child_process_1.spawnSync,
|
|
60
61
|
};
|
|
61
|
-
function restoreInteractiveTerminalState() {
|
|
62
|
-
try {
|
|
63
|
-
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
64
|
-
process.stdin.setRawMode(false);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
// Best-effort prompt cleanup.
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
if (process.stdout.isTTY) {
|
|
72
|
-
process.stdout.write("\u001B[?25h");
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
// Best-effort prompt cleanup.
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
62
|
function exitStartup(code) {
|
|
80
|
-
restoreInteractiveTerminalState();
|
|
63
|
+
(0, terminal_js_1.restoreInteractiveTerminalState)();
|
|
81
64
|
process.exit(code);
|
|
82
65
|
}
|
|
83
66
|
async function refreshCodexModelsInStartup(deps) {
|
|
@@ -149,6 +132,6 @@ async function startup(cfg = config_js_1.config.parse({}), overrides = {}) {
|
|
|
149
132
|
exitStartup(1);
|
|
150
133
|
}
|
|
151
134
|
finally {
|
|
152
|
-
restoreInteractiveTerminalState();
|
|
135
|
+
(0, terminal_js_1.restoreInteractiveTerminalState)();
|
|
153
136
|
}
|
|
154
137
|
}
|
|
@@ -129,25 +129,30 @@ function buildRuntimeIdentityProvisionScript(user) {
|
|
|
129
129
|
`AGENT_UID=${shellQuote(String(user.uid))}`,
|
|
130
130
|
`AGENT_GID=${shellQuote(String(user.gid))}`,
|
|
131
131
|
"",
|
|
132
|
-
'install -d -m 0755 -o "$AGENT_UID" -g "$AGENT_GID" "$AGENT_HOME"',
|
|
133
|
-
"",
|
|
134
132
|
'AGENT_GROUP="$AGENT_USER"',
|
|
135
|
-
'
|
|
136
|
-
'
|
|
137
|
-
'
|
|
138
|
-
|
|
139
|
-
'
|
|
133
|
+
'EXISTING_GID_GROUP="$(getent group "$AGENT_GID" | cut -d: -f1 || true)"',
|
|
134
|
+
'if [ -n "$EXISTING_GID_GROUP" ] && [ "$EXISTING_GID_GROUP" != "$AGENT_USER" ] && ! getent group "$AGENT_USER" >/dev/null 2>&1; then',
|
|
135
|
+
' groupmod -n "$AGENT_USER" "$EXISTING_GID_GROUP"',
|
|
136
|
+
"fi",
|
|
137
|
+
'if getent group "$AGENT_USER" >/dev/null 2>&1; then',
|
|
138
|
+
' if [ "$(getent group "$AGENT_USER" | cut -d: -f3)" != "$AGENT_GID" ]; then',
|
|
139
|
+
' groupmod -g "$AGENT_GID" "$AGENT_USER"',
|
|
140
|
+
" fi",
|
|
140
141
|
"else",
|
|
141
142
|
' groupadd -g "$AGENT_GID" "$AGENT_USER"',
|
|
142
|
-
' AGENT_GROUP="$AGENT_USER"',
|
|
143
143
|
"fi",
|
|
144
144
|
"",
|
|
145
|
-
'
|
|
146
|
-
'
|
|
145
|
+
'EXISTING_UID_USER="$(getent passwd "$AGENT_UID" | cut -d: -f1 || true)"',
|
|
146
|
+
'if [ -n "$EXISTING_UID_USER" ] && [ "$EXISTING_UID_USER" != "$AGENT_USER" ] && ! id -u "$AGENT_USER" >/dev/null 2>&1; then',
|
|
147
|
+
' usermod -l "$AGENT_USER" -d "$AGENT_HOME" -g "$AGENT_GROUP" -s /bin/bash "$EXISTING_UID_USER"',
|
|
148
|
+
'elif id -u "$AGENT_USER" >/dev/null 2>&1; then',
|
|
149
|
+
' usermod -u "$AGENT_UID" -g "$AGENT_GROUP" -d "$AGENT_HOME" -s /bin/bash "$AGENT_USER"',
|
|
147
150
|
"else",
|
|
148
151
|
' useradd -m -d "$AGENT_HOME" -u "$AGENT_UID" -g "$AGENT_GROUP" -s /bin/bash "$AGENT_USER"',
|
|
149
152
|
"fi",
|
|
150
153
|
"",
|
|
154
|
+
'install -d -m 0755 -o "$AGENT_UID" -g "$AGENT_GID" "$AGENT_HOME"',
|
|
155
|
+
"",
|
|
151
156
|
'SUDOERS_FILE="/etc/sudoers.d/90-companyhelm-agent"',
|
|
152
157
|
'if command -v sudo >/dev/null 2>&1; then',
|
|
153
158
|
' install -d -m 0750 /etc/sudoers.d',
|
package/dist/utils/process.js
CHANGED
|
@@ -1,12 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseProcStatState = parseProcStatState;
|
|
4
|
+
exports.isZombieProcessState = isZombieProcessState;
|
|
3
5
|
exports.isProcessRunning = isProcessRunning;
|
|
6
|
+
const node_child_process_1 = require("node:child_process");
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
function parseProcStatState(statLine) {
|
|
9
|
+
const trimmed = statLine.trim();
|
|
10
|
+
if (trimmed.length === 0) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const closingParenIndex = trimmed.lastIndexOf(")");
|
|
14
|
+
if (closingParenIndex < 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const suffix = trimmed.slice(closingParenIndex + 1).trim();
|
|
18
|
+
if (suffix.length === 0) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const state = suffix[0]?.trim();
|
|
22
|
+
return state && state.length > 0 ? state : null;
|
|
23
|
+
}
|
|
24
|
+
function isZombieProcessState(state) {
|
|
25
|
+
return state === "Z";
|
|
26
|
+
}
|
|
27
|
+
function readProcessState(pid) {
|
|
28
|
+
if (process.platform === "linux") {
|
|
29
|
+
try {
|
|
30
|
+
return parseProcStatState((0, node_fs_1.readFileSync)(`/proc/${pid}/stat`, "utf8"));
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const code = typeof error === "object" && error && "code" in error ? error.code : undefined;
|
|
34
|
+
if (code === "ENOENT") {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (process.platform === "darwin" || process.platform === "freebsd" || process.platform === "openbsd" || process.platform === "sunos") {
|
|
41
|
+
try {
|
|
42
|
+
const status = (0, node_child_process_1.execFileSync)("ps", ["-o", "stat=", "-p", String(pid)], { encoding: "utf8" }).trim();
|
|
43
|
+
if (!status) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return status[0] ?? null;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
const status = typeof error === "object" && error && "status" in error ? error.status : undefined;
|
|
50
|
+
if (status === 1) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
4
58
|
function isProcessRunning(pid) {
|
|
5
59
|
if (!Number.isInteger(pid) || pid <= 0) {
|
|
6
60
|
return false;
|
|
7
61
|
}
|
|
8
62
|
try {
|
|
9
63
|
process.kill(pid, 0);
|
|
64
|
+
const state = readProcessState(pid);
|
|
65
|
+
if (state === null) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (isZombieProcessState(state)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
10
71
|
return true;
|
|
11
72
|
}
|
|
12
73
|
catch (error) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.containsCtrlCInterruptInput = containsCtrlCInterruptInput;
|
|
4
|
+
exports.restoreInteractiveTerminalState = restoreInteractiveTerminalState;
|
|
5
|
+
const CTRL_C_ETX = "\u0003";
|
|
6
|
+
const CTRL_C_CSI_U_PATTERN = /\u001b\[99;5(?::\d+)?u/;
|
|
7
|
+
const CTRL_C_MODIFY_OTHER_KEYS_PATTERN = /\u001b\[27;5;99~/;
|
|
8
|
+
const RESTORE_KEYBOARD_PROTOCOL_SEQUENCE = "\u001b[<u";
|
|
9
|
+
const SHOW_CURSOR_SEQUENCE = "\u001b[?25h";
|
|
10
|
+
function containsCtrlCInterruptInput(input) {
|
|
11
|
+
return input.includes(CTRL_C_ETX) ||
|
|
12
|
+
CTRL_C_CSI_U_PATTERN.test(input) ||
|
|
13
|
+
CTRL_C_MODIFY_OTHER_KEYS_PATTERN.test(input);
|
|
14
|
+
}
|
|
15
|
+
function restoreInteractiveTerminalState(stdin = process.stdin, stdout = process.stdout) {
|
|
16
|
+
try {
|
|
17
|
+
if (stdin.isTTY && typeof stdin.setRawMode === "function") {
|
|
18
|
+
stdin.setRawMode(false);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Best-effort prompt cleanup.
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
if (stdout.isTTY) {
|
|
26
|
+
// Restore normal keyboard reporting if a prompt enabled kitty/xterm CSI-u handling.
|
|
27
|
+
stdout.write(RESTORE_KEYBOARD_PROTOCOL_SEQUENCE);
|
|
28
|
+
stdout.write(SHOW_CURSOR_SEQUENCE);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Best-effort prompt cleanup.
|
|
33
|
+
}
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@companyhelm/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Run coding agents in fully isolated Docker sandboxes, locally.",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/CompanyHelm/companyhelm-cli"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@bufbuild/protobuf": "^2.11.0",
|
|
33
33
|
"@clack/prompts": "^1.0.1",
|
|
34
|
-
"@companyhelm/protos": "0.5.
|
|
34
|
+
"@companyhelm/protos": "0.5.16",
|
|
35
35
|
"@grpc/grpc-js": "^1.14.3",
|
|
36
36
|
"@libsql/client": "^0.17.0",
|
|
37
37
|
"commander": "^14.0.0",
|