@devries-cameron20 / t3code Mirror · read-only / commits / a73cdc4df1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

fix(provider-acp-registry): a failed terminal sign-in shows what the login command printed (#39238)

Julius Marminge committed Nov 19, 2026 at 09:45 UTC a73cdc4df17486b0b2e365a6312c4080652134bf
2 files changed +56 -13
packages/provider-acp-registry/src/server/auth.test.ts
+16
@@ -363,6 +363,22 @@ it.effect("does not report authentication when post-login verification fails", (
363 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
364 );
365
366 +it.effect("surfaces what the login command printed when it exits non-zero", () =>
367 + Effect.gen(function* () {
368 + const h = yield* makeHarness(terminalMethod);
369 + yield* h.controller.start("owner", Effect.void, "terminal");
370 + yield* h.phase("waiting");
371 + h.data("Connect to the VPN, then sign in again.\r\n");
372 + h.exit(1);
373 + const failed = yield* h.phase("failed");
374 + assert.strictEqual(
375 + failed.message,
376 + "The provider login command did not finish successfully. Connect to the VPN, then sign in again.",
377 + );
378 + assert.deepEqual(h.changed, []);
379 + }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
380 +);
381 +
382 it.effect("surfaces the agent error message when authenticate fails with AcpRequestError", () =>
383 Effect.gen(function* () {
384 const error = new AcpRequestError({
packages/provider-acp-registry/src/server/auth.ts
+40 -13
@@ -5,6 +5,7 @@ import {
5 } from "@t3tools/contracts";
6 import type { AcpRegistrySettings } from "../settings.ts";
7 import * as SecureRandom from "effect/crypto/SecureRandom";
8 +import * as NodeUtil from "node:util";
9 import * as Cause from "effect/Cause";
10 import * as Deferred from "effect/Deferred";
11 import * as Effect from "effect/Effect";
@@ -29,20 +30,36 @@ const isAcpRequestError = Schema.is(EffectAcpErrors.AcpRequestError);
30
31 const MAX_ERROR_MESSAGE_LENGTH = 500;
32
33 +const appendDetail = (detail: string, reason: string): string => {
34 + let message = reason.trim();
35 + if (message.length > MAX_ERROR_MESSAGE_LENGTH) {
36 + message = `${message.slice(0, MAX_ERROR_MESSAGE_LENGTH).trimEnd()}…`;
37 + }
38 + if (message.length === 0) return detail;
39 + const trimmed = detail.trimEnd();
40 + const prefix = trimmed.endsWith(".") ? `${trimmed} ` : `${trimmed}. `;
41 + return `${prefix}${message}`;
42 +};
43 +
44 export const formatFailureDetail = (detail: string, cause?: unknown): string => {
45 const unwrapped = Cause.isCause(cause) ? Cause.squash(cause) : cause;
34 - if (isAcpRequestError(unwrapped)) {
35 - let message = unwrapped.errorMessage.trim();
36 - if (message.length > MAX_ERROR_MESSAGE_LENGTH) {
37 - message = `${message.slice(0, MAX_ERROR_MESSAGE_LENGTH).trimEnd()}…`;
38 - }
39 - if (message.length > 0) {
40 - const trimmed = detail.trimEnd();
41 - const prefix = trimmed.endsWith(".") ? `${trimmed} ` : `${trimmed}. `;
42 - return `${prefix}${message}`;
43 - }
44 - }
45 - return detail;
46 + return isAcpRequestError(unwrapped) ? appendDetail(detail, unwrapped.errorMessage) : detail;
47 +};
48 +
49 +const MAX_LOGIN_OUTPUT_LINES = 5;
50 +
51 +const lastPrintedLines = (output: string): string => {
52 + const lines = NodeUtil.stripVTControlCharacters(output)
53 + .split("\n")
54 + .map((line) => line.trimEnd())
55 + // A carriage return inside a line redraws it, so only the text after the last one is visible.
56 + .map((line) => line.slice(line.lastIndexOf("\r") + 1).trim())
57 + .filter((line) => line.length > 0)
58 + .slice(-MAX_LOGIN_OUTPUT_LINES)
59 + .join(" ");
60 + return lines.length > MAX_ERROR_MESSAGE_LENGTH
61 + ? `…${lines.slice(-MAX_ERROR_MESSAGE_LENGTH).trimStart()}`
62 + : lines;
63 };
64
65 type Runtime = Pick<
@@ -206,7 +223,10 @@ export const makeAcpRegistryAuth = Effect.fn("makeAcpRegistryAuth")(function* (o
223 failure("start", "Could not open the provider sign-in terminal.", cause),
224 ),
225 );
226 + // Kept in the callback so output that arrives just before exit is not lost to the reader.
227 + let printed = "";
228 const detachData = process.onData((data) => {
229 + printed = (printed + data).slice(-4_096);
230 Queue.offerUnsafe(output, data.slice(-16_384));
231 });
232 const detachExit = process.onExit(({ exitCode }) => {
@@ -250,7 +270,14 @@ export const makeAcpRegistryAuth = Effect.fn("makeAcpRegistryAuth")(function* (o
270 Effect.forkScoped,
271 );
272 if ((yield* Deferred.await(exited)) !== 0)
253 - return yield* failure("start", "The provider login command did not finish successfully.");
273 + return yield* new ProviderSetupError({
274 + instanceId: options.instanceId,
275 + operation: "start",
276 + detail: appendDetail(
277 + "The provider login command did not finish successfully.",
278 + lastPrintedLines(printed),
279 + ),
280 + });
281 });
282
283 const authenticate = Effect.fn("AcpRegistryAuth.authenticate")(function* (