@testsprite/testsprite-cli 0.12.0 → 0.14.0

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 (113) hide show
  1. package/README.md +59 -49
  2. package/dist/commands/agent.js +16 -13
  3. package/dist/commands/auth.d.ts +19 -0
  4. package/dist/commands/auth.js +60 -24
  5. package/dist/commands/ci.d.ts +86 -1
  6. package/dist/commands/ci.js +436 -5
  7. package/dist/commands/doctor.d.ts +2 -0
  8. package/dist/commands/doctor.js +34 -20
  9. package/dist/commands/init.js +14 -11
  10. package/dist/commands/project-env.d.ts +11 -1
  11. package/dist/commands/project-env.js +408 -70
  12. package/dist/commands/project-sign-in.d.ts +60 -0
  13. package/dist/commands/project-sign-in.js +289 -0
  14. package/dist/commands/project.d.ts +14 -5
  15. package/dist/commands/project.js +110 -70
  16. package/dist/commands/schedule.d.ts +14 -0
  17. package/dist/commands/schedule.js +193 -15
  18. package/dist/commands/test.d.ts +123 -44
  19. package/dist/commands/test.js +2993 -636
  20. package/dist/commands/testlist.d.ts +10 -5
  21. package/dist/commands/testlist.js +217 -47
  22. package/dist/commands/tunnel.d.ts +26 -3
  23. package/dist/commands/tunnel.js +221 -18
  24. package/dist/commands/usage.d.ts +3 -0
  25. package/dist/commands/usage.js +12 -5
  26. package/dist/index.js +39 -50
  27. package/dist/lib/agent-targets.d.ts +3 -3
  28. package/dist/lib/agent-targets.js +2 -2
  29. package/dist/lib/billing-refusal.d.ts +43 -0
  30. package/dist/lib/billing-refusal.js +171 -0
  31. package/dist/lib/bundle.d.ts +5 -0
  32. package/dist/lib/bundle.js +43 -13
  33. package/dist/lib/ci-linkage.d.ts +90 -0
  34. package/dist/lib/ci-linkage.js +181 -0
  35. package/dist/lib/client-factory.d.ts +16 -2
  36. package/dist/lib/client-factory.js +37 -6
  37. package/dist/lib/config.d.ts +17 -0
  38. package/dist/lib/config.js +20 -1
  39. package/dist/lib/conflict-reason.d.ts +27 -3
  40. package/dist/lib/conflict-reason.js +53 -4
  41. package/dist/lib/credentials.js +56 -14
  42. package/dist/lib/dry-run/samples.d.ts +13 -1
  43. package/dist/lib/dry-run/samples.js +104 -7
  44. package/dist/lib/environment-tunnel.d.ts +109 -0
  45. package/dist/lib/environment-tunnel.js +465 -0
  46. package/dist/lib/errors.d.ts +18 -11
  47. package/dist/lib/errors.js +123 -14
  48. package/dist/lib/failing-fe-resolver.d.ts +1 -1
  49. package/dist/lib/failing-fe-resolver.js +3 -3
  50. package/dist/lib/gh-output.d.ts +1 -0
  51. package/dist/lib/gh-output.js +16 -4
  52. package/dist/lib/history-retention.d.ts +8 -0
  53. package/dist/lib/history-retention.js +24 -0
  54. package/dist/lib/http.d.ts +39 -19
  55. package/dist/lib/http.js +46 -24
  56. package/dist/lib/interrupt.d.ts +21 -13
  57. package/dist/lib/interrupt.js +32 -21
  58. package/dist/lib/junit-report.d.ts +18 -4
  59. package/dist/lib/junit-report.js +23 -5
  60. package/dist/lib/local-target.d.ts +14 -4
  61. package/dist/lib/local-target.js +48 -13
  62. package/dist/lib/output.js +15 -1
  63. package/dist/lib/plan-poll.d.ts +11 -11
  64. package/dist/lib/plan-poll.js +15 -16
  65. package/dist/lib/plans.types.d.ts +9 -9
  66. package/dist/lib/plans.types.js +3 -3
  67. package/dist/lib/poll.d.ts +2 -2
  68. package/dist/lib/poll.js +9 -3
  69. package/dist/lib/redact.d.ts +38 -0
  70. package/dist/lib/redact.js +140 -0
  71. package/dist/lib/render-error.d.ts +21 -5
  72. package/dist/lib/render-error.js +44 -0
  73. package/dist/lib/response-schemas.d.ts +54 -12
  74. package/dist/lib/response-schemas.js +88 -7
  75. package/dist/lib/runs.types.d.ts +68 -11
  76. package/dist/lib/secret-file.js +72 -14
  77. package/dist/lib/skill-nudge.d.ts +6 -1
  78. package/dist/lib/skill-nudge.js +32 -5
  79. package/dist/lib/target-url-preflight.d.ts +6 -4
  80. package/dist/lib/target-url-preflight.js +64 -51
  81. package/dist/lib/target-url.js +11 -11
  82. package/dist/lib/telemetry.d.ts +10 -8
  83. package/dist/lib/telemetry.js +24 -17
  84. package/dist/lib/testlist.types.d.ts +1 -0
  85. package/dist/lib/ticker.d.ts +9 -0
  86. package/dist/lib/ticker.js +111 -4
  87. package/dist/lib/tunnel-session.d.ts +16 -4
  88. package/dist/lib/tunnel-session.js +7 -5
  89. package/dist/lib/tunnel.types.d.ts +12 -2
  90. package/dist/lib/tunnel.types.js +2 -2
  91. package/dist/lib/v3-advisory.js +0 -1
  92. package/dist/lib/wait-exit.d.ts +8 -0
  93. package/dist/lib/wait-exit.js +76 -4
  94. package/dist/lib/workspace-status.d.ts +23 -0
  95. package/dist/lib/workspace-status.js +15 -0
  96. package/dist/vendor/tunnel-client/client.d.ts +15 -8
  97. package/dist/vendor/tunnel-client/client.js +477 -407
  98. package/dist/vendor/tunnel-client/config.d.ts +5 -5
  99. package/dist/vendor/tunnel-client/config.js +5 -5
  100. package/dist/vendor/tunnel-client/index.d.ts +4 -4
  101. package/dist/vendor/tunnel-client/index.js +4 -4
  102. package/dist/vendor/tunnel-client/types.d.ts +19 -34
  103. package/dist/vendor/tunnel-client/types.js +1 -0
  104. package/dist/vendor/tunnel-client/ws-compat.d.ts +13 -3
  105. package/dist/vendor/tunnel-client/ws-compat.js +70 -12
  106. package/dist/version-guard.d.ts +7 -1
  107. package/dist/version-guard.js +19 -1
  108. package/dist/version.d.ts +1 -1
  109. package/dist/version.js +1 -1
  110. package/package.json +4 -4
  111. package/skills/testsprite-onboard.skill.md +8 -8
  112. package/skills/testsprite-verify.codex.md +59 -57
  113. package/skills/testsprite-verify.skill.md +53 -38
@@ -25,6 +25,95 @@ export function isNoColor(env = process.env) {
25
25
  const value = env.NO_COLOR;
26
26
  return typeof value === 'string' && value.length > 0;
27
27
  }
28
+ const DEFAULT_TERMINAL_COLUMNS = 80;
29
+ const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
30
+ const markPattern = /^\p{Mark}$/u;
31
+ const emojiPattern = /\p{Extended_Pictographic}|\p{Regional_Indicator}|\u20e3/u;
32
+ /**
33
+ * Return whether a Unicode code point normally occupies two terminal columns.
34
+ *
35
+ * @param codePoint - Unicode scalar value to classify.
36
+ * @returns Whether the code point is full-width in a terminal.
37
+ */
38
+ function isFullwidthCodePoint(codePoint) {
39
+ return (codePoint >= 0x1100 &&
40
+ (codePoint <= 0x115f ||
41
+ codePoint === 0x2329 ||
42
+ codePoint === 0x232a ||
43
+ (codePoint >= 0x2e80 && codePoint <= 0xa4cf && codePoint !== 0x303f) ||
44
+ (codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
45
+ (codePoint >= 0xf900 && codePoint <= 0xfaff) ||
46
+ (codePoint >= 0xfe10 && codePoint <= 0xfe19) ||
47
+ (codePoint >= 0xfe30 && codePoint <= 0xfe6f) ||
48
+ (codePoint >= 0xff00 && codePoint <= 0xff60) ||
49
+ (codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
50
+ (codePoint >= 0x1b000 && codePoint <= 0x1b001) ||
51
+ (codePoint >= 0x1f200 && codePoint <= 0x1f251) ||
52
+ (codePoint >= 0x20000 && codePoint <= 0x3fffd)));
53
+ }
54
+ /**
55
+ * Measure one grapheme cluster in terminal display columns.
56
+ *
57
+ * @param grapheme - User-perceived character produced by the segmenter.
58
+ * @returns The number of terminal columns occupied by the grapheme.
59
+ */
60
+ function graphemeWidth(grapheme) {
61
+ if (emojiPattern.test(grapheme))
62
+ return 2;
63
+ let width = 0;
64
+ for (const character of grapheme) {
65
+ const codePoint = character.codePointAt(0);
66
+ if (codePoint === 0x200d ||
67
+ (codePoint >= 0xfe00 && codePoint <= 0xfe0f) ||
68
+ (codePoint >= 0xe0100 && codePoint <= 0xe01ef) ||
69
+ codePoint <= 0x1f ||
70
+ (codePoint >= 0x7f && codePoint <= 0x9f) ||
71
+ markPattern.test(character)) {
72
+ continue;
73
+ }
74
+ width += isFullwidthCodePoint(codePoint) ? 2 : 1;
75
+ }
76
+ return width;
77
+ }
78
+ /**
79
+ * Measure a complete string in terminal display columns.
80
+ *
81
+ * @param text - Text to measure.
82
+ * @returns The number of terminal columns occupied by the text.
83
+ */
84
+ function terminalWidth(text) {
85
+ let width = 0;
86
+ for (const { segment } of graphemeSegmenter.segment(text)) {
87
+ width += graphemeWidth(segment);
88
+ }
89
+ return width;
90
+ }
91
+ /**
92
+ * Keep a ticker frame inside the terminal's last safe column. Terminal width is
93
+ * read for every frame so an in-progress ticker follows live resizes.
94
+ */
95
+ function fitToTerminal(line) {
96
+ const reportedColumns = typeof process !== 'undefined' ? process.stderr.columns : undefined;
97
+ const columns = typeof reportedColumns === 'number' && Number.isFinite(reportedColumns) && reportedColumns > 0
98
+ ? Math.floor(reportedColumns)
99
+ : DEFAULT_TERMINAL_COLUMNS;
100
+ const maxWidth = Math.max(0, columns - 1);
101
+ if (terminalWidth(line) <= maxWidth)
102
+ return line;
103
+ if (maxWidth === 0)
104
+ return '';
105
+ const contentWidth = maxWidth - 1;
106
+ let fitted = '';
107
+ let fittedWidth = 0;
108
+ for (const { segment } of graphemeSegmenter.segment(line)) {
109
+ const width = graphemeWidth(segment);
110
+ if (fittedWidth + width > contentWidth)
111
+ break;
112
+ fitted += segment;
113
+ fittedWidth += width;
114
+ }
115
+ return `${fitted}…`;
116
+ }
28
117
  /**
29
118
  * Create a ticker bound to the given stderr writer. Respects
30
119
  * `isTTY` to silently no-op in CI environments.
@@ -52,6 +141,7 @@ export function createTicker(stderrWrite, isTTY, stderrRaw, noColor) {
52
141
  redrawsInPlace: false,
53
142
  update: () => undefined,
54
143
  finalize: () => undefined,
144
+ note: (line) => stderrWrite(line),
55
145
  };
56
146
  }
57
147
  if (suppressAnsi) {
@@ -59,40 +149,57 @@ export function createTicker(stderrWrite, isTTY, stderrRaw, noColor) {
59
149
  return {
60
150
  redrawsInPlace: false,
61
151
  update(line) {
62
- const stamped = `${new Date().toISOString()} ${line}`;
152
+ const stamped = fitToTerminal(`${new Date().toISOString()} ${line}`);
63
153
  stderrWrite(stamped);
64
154
  lastLength = stamped.length;
65
155
  },
66
156
  finalize(line) {
67
157
  if (line !== undefined) {
68
- const stamped = `${new Date().toISOString()} ${line}`;
158
+ const stamped = fitToTerminal(`${new Date().toISOString()} ${line}`);
69
159
  stderrWrite(stamped);
70
160
  lastLength = stamped.length;
71
161
  }
72
162
  void stderrWrite;
73
163
  },
164
+ note(line) {
165
+ // Every update is already its own line here; nothing to clear.
166
+ stderrWrite(line);
167
+ lastLength = 0;
168
+ },
74
169
  };
75
170
  }
76
171
  return {
77
172
  redrawsInPlace: true,
78
173
  update(line) {
79
174
  // ANSI ESC[2K clears the entire line; \r moves to column 0.
80
- const stamped = `${new Date().toISOString()} ${line}`;
175
+ const stamped = fitToTerminal(`${new Date().toISOString()} ${line}`);
81
176
  rawWrite(`\x1b[2K\r${stamped}`);
82
177
  lastLength = stamped.length;
83
178
  },
84
179
  finalize(line) {
85
180
  if (line !== undefined) {
86
- const stamped = `${new Date().toISOString()} ${line}`;
181
+ const stamped = fitToTerminal(`${new Date().toISOString()} ${line}`);
87
182
  rawWrite(`\x1b[2K\r${stamped}`);
88
183
  lastLength = stamped.length;
89
184
  }
90
185
  if (lastLength > 0) {
91
186
  // Move to a fresh line so the result block doesn't run into the ticker.
92
187
  rawWrite('\n');
188
+ // The live line is gone: a second finalize() (e.g. the failed-stage
189
+ // branch, then the catch-all) must not emit a stray blank line.
190
+ lastLength = 0;
93
191
  }
94
192
  void stderrWrite; // reference to suppress unused warning
95
193
  },
194
+ note(line) {
195
+ // Clear the live progress line (same ESC[2K + \r as update), then
196
+ // print the note with its own newline through the SAME raw writer so
197
+ // ordering is preserved. The next update() redraws below it.
198
+ if (lastLength > 0)
199
+ rawWrite('\x1b[2K\r');
200
+ rawWrite(`${line}\n`);
201
+ lastLength = 0;
202
+ },
96
203
  };
97
204
  }
98
205
  //# sourceMappingURL=ticker.js.map
@@ -45,10 +45,9 @@ import type { TunnelMintResponse } from './tunnel.types.js';
45
45
  * How long to wait for the control plane's first successful connection.
46
46
  *
47
47
  * The vendored client resolves `start()` only on the first
48
- * `control-connected` event, and its control loop retries every non-auth
49
- * failure forever. Without a deadline, `--local` against an unreachable
50
- * control plane hangs with no output at all — the worst possible shape for a
51
- * command an agent might be driving unattended.
48
+ * `control-authenticated` event. The client also bounds authentication at
49
+ * 10 seconds; this outer deadline bounds the complete connection attempt so an
50
+ * unreachable control plane cannot leave an unattended command hanging.
52
51
  */
53
52
  export declare const DEFAULT_TUNNEL_CONNECT_TIMEOUT_MS = 20000;
54
53
  /** Maximum time teardown lets a wedged client delay credential deletion. */
@@ -101,6 +100,19 @@ export interface OpenTunnelSessionOptions {
101
100
  connectTimeoutMs?: number;
102
101
  /** Called once, the first time the tunnel becomes unusable for this run. */
103
102
  onFatal?: (reason: TunnelFatalReason, message?: string) => void;
103
+ /**
104
+ * Called once, right after the mint succeeds and BEFORE the connect attempt,
105
+ * with the binding's non-secret handle. A process killed while connecting
106
+ * never reaches the line a caller prints after connect, and the binding it
107
+ * leaves behind holds a slot of the per-account cap until it expires; this
108
+ * is what lets the caller name that binding while it still can. Not called
109
+ * for an adopted client. A throw is treated like a failed connect: the
110
+ * binding is deleted and the error propagates.
111
+ */
112
+ onMinted?: (minted: {
113
+ clientId: string;
114
+ expiresAt: string;
115
+ }) => void;
104
116
  /**
105
117
  * Attach to a client someone else minted (`testsprite tunnel start` in
106
118
  * another terminal) instead of minting one. No secret is available, so
@@ -38,17 +38,16 @@
38
38
  * does instead is honest failure: record the loss, let the caller stop the run
39
39
  * and say why. See `openTunnelSession`'s `onFatal`.
40
40
  */
41
- import { ApiError } from './errors.js';
41
+ import { ApiError, InterruptError } from './errors.js';
42
42
  import { ErrCode, TunnelClient } from '../vendor/tunnel-client/index.js';
43
43
  import { DEFAULT_DATA_PLANE_RETRY_DEADLINE_MS } from '../vendor/tunnel-client/config.js';
44
44
  /**
45
45
  * How long to wait for the control plane's first successful connection.
46
46
  *
47
47
  * The vendored client resolves `start()` only on the first
48
- * `control-connected` event, and its control loop retries every non-auth
49
- * failure forever. Without a deadline, `--local` against an unreachable
50
- * control plane hangs with no output at all — the worst possible shape for a
51
- * command an agent might be driving unattended.
48
+ * `control-authenticated` event. The client also bounds authentication at
49
+ * 10 seconds; this outer deadline bounds the complete connection attempt so an
50
+ * unreachable control plane cannot leave an unattended command hanging.
52
51
  */
53
52
  export const DEFAULT_TUNNEL_CONNECT_TIMEOUT_MS = 20_000;
54
53
  /** Maximum time teardown lets a wedged client delay credential deletion. */
@@ -218,6 +217,7 @@ export async function openTunnelSession(options, deps) {
218
217
  }
219
218
  };
220
219
  try {
220
+ options.onMinted?.({ clientId: minted.clientId, expiresAt: minted.expiresAt });
221
221
  client = createClient({
222
222
  clientId: minted.clientId,
223
223
  secret: minted.secret,
@@ -280,6 +280,8 @@ export async function openTunnelSession(options, deps) {
280
280
  }
281
281
  catch (err) {
282
282
  await stopAndDestroy();
283
+ if (err instanceof InterruptError)
284
+ throw err;
283
285
  if (err instanceof ApiError)
284
286
  throw err;
285
287
  throw ApiError.fromEnvelope({
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Wire types for the `/api/cli/v1/tunnel` facade (DEV-747 piece 1).
2
+ * Wire types for the `/api/cli/v1/tunnel` facade.
3
3
  *
4
- * Three routes and deliberately no fourth — there is no resume/adopt route to
4
+ * The list and status reads are secret-free. There is no resume/adopt route to
5
5
  * hand a `{clientId, secret}` back to, so the CLI mints fresh per invocation.
6
6
  */
7
7
  /** Body of `POST /api/cli/v1/tunnel`. */
@@ -54,3 +54,13 @@ export interface TunnelStatusResponse {
54
54
  status: 'online' | 'offline' | (string & {});
55
55
  expiresAt: string;
56
56
  }
57
+ /** One secret-free binding returned by `GET /api/cli/v1/tunnel`. */
58
+ export interface TunnelListItem {
59
+ clientId: string;
60
+ status: 'online' | 'offline' | 'unknown' | (string & {});
61
+ expiresAt: string;
62
+ createdAt?: string | null;
63
+ }
64
+ export interface TunnelListResponse {
65
+ tunnels: TunnelListItem[];
66
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Wire types for the `/api/cli/v1/tunnel` facade (DEV-747 piece 1).
2
+ * Wire types for the `/api/cli/v1/tunnel` facade.
3
3
  *
4
- * Three routes and deliberately no fourth — there is no resume/adopt route to
4
+ * The list and status reads are secret-free. There is no resume/adopt route to
5
5
  * hand a `{clientId, secret}` back to, so the CLI mints fresh per invocation.
6
6
  */
7
7
  export {};
@@ -28,7 +28,6 @@ export function routingLabel(v3Enabled) {
28
28
  */
29
29
  export const V3_ROUTING_ADVISORY = [
30
30
  '[advisory] V3 routing is on for this account. While these gaps are open:',
31
- ' - `--target-url` is ignored on frontend runs (the run uses the project environment)',
32
31
  ' - a frontend rerun replays the run it was pointed at, not necessarily the latest saved code',
33
32
  ];
34
33
  /** Write the advisory to a stderr sink, one line per call. */
@@ -14,8 +14,16 @@ export interface WaitMemberResult {
14
14
  code: string;
15
15
  message: string;
16
16
  exitCode?: number;
17
+ nextAction?: string;
18
+ serverNextAction?: string;
19
+ requestId?: string;
20
+ details?: Record<string, unknown>;
21
+ apiUrl?: string;
17
22
  };
18
23
  }
24
+ export declare function waitMemberError(err: ApiError): NonNullable<WaitMemberResult['error']> & {
25
+ exitCode: number;
26
+ };
19
27
  /**
20
28
  * Resolve the process-level failure for a completed `--wait` fan-out, or `null`
21
29
  * when every member passed. Shared by `test run --all` / `test rerun` and
@@ -1,4 +1,47 @@
1
- import { ApiError, CLIError, isAuthCode } from './errors.js';
1
+ import { ApiError, CLIError, isAuthCode, isErrorCode } from './errors.js';
2
+ import { classifyBillingRefusal, isPausedReason } from './billing-refusal.js';
3
+ /**
4
+ * Envelope metadata for a billing/feature-gate member error, keyed by the
5
+ * IDENTITY of the object `waitMemberError` returns. The enumerable shape of
6
+ * that object must stay exactly `{ code, message, exitCode }` — it lands
7
+ * verbatim in `--output json` stdout (`accepted[]` / `results[]`), and a
8
+ * `nextAction` / `details` / `apiUrl` riding along there would both leak
9
+ * internal fields to every consumer AND (since the guard below fires for
10
+ * every FEATURE_GATED, including `rollout`) attach billing-looking data to a
11
+ * refusal that isn't one. The extra fields `resolveWaitFailure` needs to
12
+ * reconstruct a faithful ApiError travel here instead, out of band.
13
+ */
14
+ const memberEnvelopeMeta = new WeakMap();
15
+ export function waitMemberError(err) {
16
+ const memberError = { code: err.code, message: err.message, exitCode: err.exitCode };
17
+ if (err.code === 'FEATURE_GATED' || classifyBillingRefusal(err)) {
18
+ memberEnvelopeMeta.set(memberError, {
19
+ nextAction: err.nextAction,
20
+ serverNextAction: err.serverNextAction,
21
+ requestId: err.requestId,
22
+ details: err.details,
23
+ apiUrl: err.apiUrl,
24
+ });
25
+ }
26
+ return memberError;
27
+ }
28
+ /**
29
+ * Read a member error's out-of-band envelope metadata, falling back to
30
+ * whatever the object carries as OWN enumerable properties. The fallback
31
+ * exists for callers that build a `WaitMemberResult['error']` by hand (a
32
+ * legacy/shared JUnit result shape, or a test fixture) rather than through
33
+ * `waitMemberError` — those never got a `memberEnvelopeMeta` entry, so their
34
+ * fields must still be read the old way.
35
+ */
36
+ function memberMeta(error) {
37
+ return (memberEnvelopeMeta.get(error) ?? {
38
+ nextAction: error.nextAction,
39
+ serverNextAction: error.serverNextAction,
40
+ requestId: error.requestId,
41
+ details: error.details,
42
+ apiUrl: error.apiUrl,
43
+ });
44
+ }
2
45
  /**
3
46
  * Exit-code precedence for a `--wait` fan-out, highest first. Ordered
4
47
  * batch-wide-non-retriable → per-run → transient → timeout → generic:
@@ -61,10 +104,39 @@ export function resolveWaitFailure(results, opts) {
61
104
  // non-1 exit like 0/99). Routed through the ENVELOPE so `--output json`
62
105
  // carries `error.code` — the machine-readable field this fix exists for;
63
106
  // `ApiError.fromEnvelope` derives the exit via `exitCodeFor(code)`.
64
- const operational = errored
65
- .filter(r => isOperationalCode(r.error.exitCode ?? 1))
66
- .sort((a, b) => priorityOf(a.error.exitCode) - priorityOf(b.error.exitCode))[0];
107
+ const operationalCandidates = errored.filter(r => isOperationalCode(r.error.exitCode ?? 1));
108
+ // Narrow exception to the table above (mirrors the identical rule in
109
+ // conflict-reason.ts's `isPausedRefusal`): when EVERY operational
110
+ // member is a billing refusal and at least one is a paused workspace, paused
111
+ // wins over a plain credits shortfall — topping up credits cannot resume a
112
+ // paused workspace. This does not reorder WAIT_EXIT_PRIORITY for any other
113
+ // code combination.
114
+ const isPausedMember = (r) => r.error.code === 'FEATURE_GATED' && isPausedReason(memberMeta(r.error).details?.reason);
115
+ const isBillingRefusalMember = (r) => r.error.code === 'INSUFFICIENT_CREDITS' || isPausedMember(r);
116
+ const operational = operationalCandidates.length > 0 &&
117
+ operationalCandidates.every(isBillingRefusalMember) &&
118
+ operationalCandidates.some(isPausedMember)
119
+ ? operationalCandidates.find(isPausedMember)
120
+ : operationalCandidates.sort((a, b) => priorityOf(a.error.exitCode) - priorityOf(b.error.exitCode))[0];
67
121
  if (operational) {
122
+ const meta = memberMeta(operational.error);
123
+ if (meta.details && isErrorCode(operational.error.code)) {
124
+ // Merge the server's own details with the local runId/testId (never the
125
+ // reverse) so automation reading `error.details.runId`/`testId` keeps
126
+ // working for a billing refusal exactly as it does for any other typed
127
+ // error, while `reason` (billing_hold / rollout / …) survives untouched.
128
+ return new ApiError({
129
+ code: operational.error.code,
130
+ message: operational.error.message,
131
+ nextAction: meta.nextAction ?? '',
132
+ requestId: meta.requestId ?? 'local',
133
+ details: {
134
+ ...meta.details,
135
+ runId: operational.runId ?? null,
136
+ testId: operational.testId ?? null,
137
+ },
138
+ }, undefined, undefined, meta.apiUrl, meta.serverNextAction);
139
+ }
68
140
  return ApiError.fromEnvelope({
69
141
  error: {
70
142
  code: operational.error.code,
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The workspace's billing standing, as `GET /me` reports it under
3
+ * `activeOrg.workspace` (backend `WorkspaceGateService.status`). `state` is
4
+ * what the FE banners key on; `notice` is the refusal every write will get
5
+ * while the workspace is paused, already worded — it is null while the
6
+ * workspace can be written to.
7
+ */
8
+ export interface WorkspaceStatus {
9
+ state: 'ok' | 'pending' | 'paused';
10
+ tier: string;
11
+ notice: {
12
+ title: string;
13
+ message: string;
14
+ cta: string;
15
+ billingUrl: string;
16
+ } | null;
17
+ }
18
+ /**
19
+ * One line for the text renderers (`auth status`, `usage`) — undefined when
20
+ * the workspace is simply on its plan, so the callers print nothing then.
21
+ * `--output json` carries the whole object; this is the human reading of it.
22
+ */
23
+ export declare function formatWorkspaceStatus(ws: WorkspaceStatus | undefined): string | undefined;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * One line for the text renderers (`auth status`, `usage`) — undefined when
3
+ * the workspace is simply on its plan, so the callers print nothing then.
4
+ * `--output json` carries the whole object; this is the human reading of it.
5
+ */
6
+ export function formatWorkspaceStatus(ws) {
7
+ if (!ws || ws.state === 'ok')
8
+ return undefined;
9
+ if (ws.notice)
10
+ return `${ws.state} — ${ws.notice.message} ${ws.notice.cta}: ${ws.notice.billingUrl}`;
11
+ if (ws.state === 'pending')
12
+ return 'pending — a scheduled plan change or a payment retry is in progress; the workspace keeps working meanwhile';
13
+ return ws.state;
14
+ }
15
+ //# sourceMappingURL=workspace-status.js.map
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from "node:events";
2
- import { TunnelClientOptions } from "./types.js";
2
+ import { ErrCode, TunnelClientOptions, TunnelTransport } from "./types.js";
3
3
  export declare class TunnelClient extends EventEmitter {
4
4
  #private;
5
5
  private readonly options;
@@ -11,28 +11,31 @@ export declare class TunnelClient extends EventEmitter {
11
11
  private controlConnectionGeneration;
12
12
  private allowTunnelReconnect;
13
13
  private dataPlaneTerminalErrorReported;
14
+ private clientUnknownEpisodeStartedAt?;
15
+ private clientUnknownDeadline?;
14
16
  private readonly tunnelRuntimes;
15
- private reconnectDelayController;
17
+ private lifecycleController;
18
+ private targetDialController;
16
19
  private readonly activeTargetSockets;
17
20
  constructor(options: TunnelClientOptions);
18
- get transport(): "tls" | "plaintext";
21
+ get transport(): TunnelTransport;
19
22
  start(): Promise<void>;
20
23
  stop(): Promise<void>;
21
24
  private runControlLoop;
25
+ private openClientUnknownEpisode;
26
+ private clearClientUnknownEpisode;
22
27
  private runTunnelLoop;
23
28
  private connectControl;
24
29
  private sendControlMessage;
25
30
  private parseControlMessage;
26
31
  private ensureTunnelRuntime;
27
32
  private connectTunnel;
28
- private recordDataPlaneFailure;
29
- private armDataPlaneFailureDeadline;
33
+ private connectDataPlane;
34
+ private openDataPlaneFailureEpisode;
30
35
  private expireDataPlaneFailureEpisode;
31
- private markDataPlaneEstablished;
32
- private clearDataPlaneAttemptTimers;
33
36
  private clearDataPlaneFailureEpisode;
37
+ private clearAttemptTimers;
34
38
  private stopAllTunnelRuntimes;
35
- private beginStop;
36
39
  private handleIncomingStream;
37
40
  private proxyStreams;
38
41
  private copyOneWay;
@@ -84,6 +87,10 @@ export declare function ensureTargetAllowed(host: string, port: number, candidat
84
87
  host: string;
85
88
  port: number;
86
89
  }>, allowPrivateNetwork: boolean): void;
90
+ export declare class ClientUnknownError extends Error {
91
+ readonly code = ErrCode.ClientUnknown;
92
+ constructor(deadlineMs: number);
93
+ }
87
94
  /**
88
95
  * Thrown by {@link ensureTargetAllowed} when a proxied target resolves into a blocked
89
96
  * (private/internal) range. Mirrors the Rust client's `ensure_candidates_allowed` error.