@companyhelm/cli 0.0.5 → 0.0.6

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.
@@ -34,6 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.isRetryableApiConnectionError = isRetryableApiConnectionError;
37
+ exports.formatApiConnectionFailureMessage = formatApiConnectionFailureMessage;
38
+ exports.formatApiConnectionFailureDiagnostics = formatApiConnectionFailureDiagnostics;
37
39
  exports.shouldUseTurnSteer = shouldUseTurnSteer;
38
40
  exports.isNoActiveTurnSteerError = isNoActiveTurnSteerError;
39
41
  exports.isNoRunningTurnInterruptError = isNoRunningTurnInterruptError;
@@ -206,19 +208,74 @@ function getGrpcStatusCode(error) {
206
208
  const { code } = error;
207
209
  return typeof code === "number" ? code : undefined;
208
210
  }
211
+ function getGrpcStatusName(error) {
212
+ const code = getGrpcStatusCode(error);
213
+ if (code === undefined) {
214
+ return undefined;
215
+ }
216
+ const statusName = grpc.status[code];
217
+ return typeof statusName === "string" ? statusName : undefined;
218
+ }
209
219
  function isRetryableApiConnectionError(error) {
210
220
  return getGrpcStatusCode(error) !== grpc.status.UNAUTHENTICATED;
211
221
  }
212
- function toApiConnectionFailureMessage(error, secret) {
213
- const message = toErrorMessage(error);
214
- if (getGrpcStatusCode(error) !== grpc.status.UNAUTHENTICATED) {
215
- return message;
222
+ function formatGrpcMetadataForLog(metadata) {
223
+ if (!metadata) {
224
+ return undefined;
216
225
  }
217
- if (!secret || secret.trim().length === 0) {
218
- return `${message} Provide --secret <secret> to authenticate.`;
226
+ const rawEntries = metadata.getMap();
227
+ const entries = Object.entries(rawEntries);
228
+ if (entries.length === 0) {
229
+ return undefined;
230
+ }
231
+ const normalizedEntries = Object.fromEntries(entries.map(([key, value]) => [
232
+ key,
233
+ Buffer.isBuffer(value) ? value.toString("base64") : String(value),
234
+ ]));
235
+ return JSON.stringify(normalizedEntries);
236
+ }
237
+ function formatApiConnectionFailureMessage(error, apiUrl, secret) {
238
+ const statusCode = getGrpcStatusCode(error);
239
+ const statusName = getGrpcStatusName(error);
240
+ const serviceError = isGrpcServiceError(error) ? error : undefined;
241
+ const baseMessage = serviceError && typeof serviceError.details === "string" && serviceError.details.trim().length > 0
242
+ ? serviceError.details.trim()
243
+ : toErrorMessage(error);
244
+ let message = baseMessage;
245
+ if (statusCode !== undefined) {
246
+ message = `gRPC ${statusName ?? "UNKNOWN"} (${statusCode}): ${baseMessage}`;
247
+ }
248
+ message += ` [endpoint=${apiUrl}]`;
249
+ if (statusCode === grpc.status.UNAUTHENTICATED && (!secret || secret.trim().length === 0)) {
250
+ message += " Provide --secret <secret> to authenticate.";
219
251
  }
220
252
  return message;
221
253
  }
254
+ function formatApiConnectionFailureDiagnostics(error) {
255
+ if (!isGrpcServiceError(error)) {
256
+ return error instanceof Error && typeof error.stack === "string" ? error.stack : undefined;
257
+ }
258
+ const diagnostics = [];
259
+ const statusCode = getGrpcStatusCode(error);
260
+ const statusName = getGrpcStatusName(error);
261
+ if (statusCode !== undefined) {
262
+ diagnostics.push(`code=${statusCode}`);
263
+ }
264
+ if (statusName) {
265
+ diagnostics.push(`status=${statusName}`);
266
+ }
267
+ if (typeof error.details === "string" && error.details.trim().length > 0) {
268
+ diagnostics.push(`details=${JSON.stringify(error.details.trim())}`);
269
+ }
270
+ const metadata = formatGrpcMetadataForLog(error.metadata);
271
+ if (metadata) {
272
+ diagnostics.push(`metadata=${metadata}`);
273
+ }
274
+ if (typeof error.stack === "string" && error.stack.trim().length > 0) {
275
+ diagnostics.push(`stack=${JSON.stringify(error.stack)}`);
276
+ }
277
+ return diagnostics.length > 0 ? diagnostics.join(" ") : undefined;
278
+ }
222
279
  function shouldUseTurnSteer(allowSteer, startedFromIdle) {
223
280
  return allowSteer && !startedFromIdle;
224
281
  }
@@ -2252,7 +2309,11 @@ async function runRootCommand(options, runtimeOptions) {
2252
2309
  logger.warn("CompanyHelm API command channel closed. Reconnecting...");
2253
2310
  }
2254
2311
  catch (error) {
2255
- const failureMessage = toApiConnectionFailureMessage(error, options.secret);
2312
+ const failureMessage = formatApiConnectionFailureMessage(error, cfg.companyhelm_api_url, options.secret);
2313
+ const diagnostics = formatApiConnectionFailureDiagnostics(error);
2314
+ if (diagnostics) {
2315
+ logger.debug(`CompanyHelm API failure diagnostics: ${diagnostics}`);
2316
+ }
2256
2317
  if (!isRetryableApiConnectionError(error)) {
2257
2318
  throw new Error(failureMessage);
2258
2319
  }
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@companyhelm/cli",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Run coding agents in fully isolated Docker sandboxes, locally.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/CompanyHelm/companyhelm-cli"
9
- }, "engines": {
9
+ },
10
+ "engines": {
10
11
  "node": ">=24"
11
12
  },
12
13
  "bin": {
13
- "companyhelm-runner": "dist/cli.js"
14
+ "companyhelm": "dist/cli.js"
14
15
  },
15
16
  "files": [
16
17
  "dist",