@0perator/operator 0.1.347 → 0.1.348

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.
@@ -0,0 +1,8 @@
1
+ // AuthGate's private-beta refusals and the one sentence a person sees for them: at sign-in, in `operator auth status`
2
+ // and on a turn's 403. Node-free on purpose: engine/agent.ts imports it, and the engine ships in the neutral bundle.
3
+ const REFUSAL = /\b(?:not_allowlisted|pending_approval|account_rejected|account_inactive)\b/;
4
+ /** True when an AuthGate error code, or an error message carrying one, says this person isn't let in. */
5
+ export const isBetaRefusal = (text = "") => REFUSAL.test(text);
6
+ export function privateBetaMessage(who) {
7
+ return `Operator is in private beta and ${who} isn't on the access list yet — ask the Operator team for access.`;
8
+ }
@@ -23,6 +23,12 @@ async function post(path, body, timeoutMs = 15_000) {
23
23
  clearTimeout(t);
24
24
  }
25
25
  }
26
+ // A refusal body is flat (`{error}`) or under FastAPI's `detail` (`{detail:{error, message}}` or `{detail:"..."}`).
27
+ // `message` is the server's own sentence for the person, when it sends one.
28
+ function refusal(status, json) {
29
+ const error = json?.error ?? json?.detail?.error ?? (typeof json?.detail === "string" ? json.detail : `http_${status}`);
30
+ return typeof json?.detail?.message === "string" ? { error, message: json.detail.message } : { error };
31
+ }
26
32
  /** Kick off a device-authorization grant: the CLI shows user_code, the human approves in a browser. */
27
33
  export async function requestDeviceCode() {
28
34
  const { status, json } = await post("/operator/device/code", { client_id: CLIENT_ID });
@@ -81,9 +87,9 @@ export async function verifyTokenDetailed(token, timeoutMs = 10_000) {
81
87
  });
82
88
  if (res.status >= 500)
83
89
  return { state: "unreachable" }; // a sick backend is not a verdict on the token
84
- if (res.status !== 200)
85
- return { state: "rejected", status: res.status };
86
90
  const json = (await res.json().catch(() => ({})));
91
+ if (res.status !== 200)
92
+ return { state: "rejected", status: res.status, ...refusal(res.status, json) };
87
93
  return json.account ? { state: "ok", account: json.account, raw: json } : { state: "rejected", status: 200 };
88
94
  }
89
95
  catch {
@@ -106,8 +112,7 @@ export async function signupStart(email) {
106
112
  const { status, json } = await post("/operator/signup/start", { email });
107
113
  if (status === 200)
108
114
  return { ok: true };
109
- const error = json?.error ?? json?.detail?.error ?? (typeof json?.detail === "string" ? json.detail : `http_${status}`);
110
- return { ok: false, error, status };
115
+ return { ok: false, status, ...refusal(status, json) };
111
116
  }
112
117
  /** Exchange (email, 6-digit code) for an operator token. Burns the code on success. */
113
118
  export async function signupVerify(email, code) {
@@ -115,6 +120,5 @@ export async function signupVerify(email, code) {
115
120
  if (status === 200 && json?.token) {
116
121
  return { ok: true, token: json.token, account: (json.account ?? { external_id: email }) };
117
122
  }
118
- const error = json?.error ?? json?.detail?.error ?? (typeof json?.detail === "string" ? json.detail : `http_${status}`);
119
- return { ok: false, error, status };
123
+ return { ok: false, status, ...refusal(status, json) };
120
124
  }
@@ -14,7 +14,8 @@
14
14
  import { spawn } from "node:child_process";
15
15
  import { platform } from "node:os";
16
16
  import { createInterface } from "node:readline/promises";
17
- import { requestDeviceCode, awaitApproval, verifyToken, authBase, signupStart, signupVerify, } from "./client.js";
17
+ import { requestDeviceCode, awaitApproval, verifyToken, verifyTokenDetailed, authBase, signupStart, signupVerify, } from "./client.js";
18
+ import { isBetaRefusal, privateBetaMessage } from "./beta.js";
18
19
  import { saveCredentials, loadCredentials, clearCredentials } from "./store.js";
19
20
  import { listByoAccounts, hasByoToken, deleteByoToken, setByoTokenInteractive } from "./byo.js";
20
21
  import { auditControl } from "../telemetry/lifecycle.js";
@@ -73,6 +74,8 @@ async function loginEmail(emailArg) {
73
74
  console.error(`✗ "${email}" doesn't look like a valid email address`);
74
75
  else if (started.error === "too_many_requests")
75
76
  console.error("✗ too many codes requested for that address — wait a few minutes, then try again");
77
+ else if (isBetaRefusal(started.error))
78
+ console.error(`✗ ${started.message ?? privateBetaMessage(email)}`);
76
79
  else
77
80
  console.error(`✗ couldn't start sign-in via ${authBase()} (${started.error})`);
78
81
  await audit("auth_failed", `method=email stage=start reason=${started.error}`);
@@ -107,6 +110,10 @@ async function loginEmail(emailArg) {
107
110
  console.error("✗ too many wrong tries — run `operator auth login` again for a fresh code");
108
111
  return 1;
109
112
  }
113
+ if (isBetaRefusal(v.error)) {
114
+ console.error(`✗ ${v.message ?? privateBetaMessage(email)}`);
115
+ return 1;
116
+ }
110
117
  console.error(`✗ sign-in failed (${v.error})`);
111
118
  return 1;
112
119
  }
@@ -151,7 +158,9 @@ async function loginDevice() {
151
158
  const r = await awaitApproval(dc, { signal: ctrl.signal, onTick: () => process.stdout.write(".") });
152
159
  process.stdout.write("\n");
153
160
  if (r.state !== "approved") {
154
- console.error(`✗ sign-in ${r.state === "expired" ? "timed out" : r.state}`);
161
+ // AuthGate denies the grant for someone off the access list; a Ctrl-C also ends the wait as "denied".
162
+ const refused = r.state === "denied" && !ctrl.signal.aborted;
163
+ console.error(refused ? `✗ sign-in not approved — ${privateBetaMessage("your account")}` : `✗ sign-in ${r.state === "expired" ? "timed out" : r.state}`);
155
164
  await audit("auth_failed", `method=browser reason=${r.state}`);
156
165
  return 1;
157
166
  }
@@ -185,12 +194,17 @@ async function status() {
185
194
  console.log("not signed in — run `operator auth login`");
186
195
  return 0;
187
196
  }
188
- const account = await verifyToken(creds.token);
189
- if (!account) {
197
+ const r = await verifyTokenDetailed(creds.token);
198
+ if (r.state === "rejected" && isBetaRefusal(r.error)) {
199
+ const who = creds.user?.replace(/^phone:/, "") ?? "your account"; // a phone identity's external_id is "phone:+E164"
200
+ console.log(`signed in, but access isn't active: ${r.message ?? privateBetaMessage(who)}`);
201
+ return 0;
202
+ }
203
+ if (r.state !== "ok") {
190
204
  console.log(`stored credentials for ${creds.user ?? "?"} are no longer valid — run \`operator auth login\``);
191
205
  return 0;
192
206
  }
193
- console.log(`signed in as ${account.email ?? account.external_id} · ${creds.host ?? authBase()}`);
207
+ console.log(`signed in as ${r.account.email ?? r.account.external_id} · ${creds.host ?? authBase()}`);
194
208
  return 0;
195
209
  }
196
210
  function flagValue(rest, flag) {
package/dist/cli.js CHANGED
@@ -1943,6 +1943,7 @@ function Root() {
1943
1943
  // /login --browser the explicit device-grant fallback (unchanged behaviour)
1944
1944
  const a = (arg ?? "").trim();
1945
1945
  const { signupStart, signupVerify, verifyToken, authBase } = await import("./auth/client.js");
1946
+ const { isBetaRefusal, privateBetaMessage } = await import("./auth/beta.js");
1946
1947
  const { classifyLoginArg } = await import("./auth/login-intent.js");
1947
1948
  const { saveCredentials } = await import("./auth/store.js");
1948
1949
  const { setOperatorToken } = await import("./engine/aurora.js");
@@ -1963,6 +1964,8 @@ function Root() {
1963
1964
  setAuthUser(r.account.email ?? r.account.external_id);
1964
1965
  sys(`✓ Authenticated as ${r.account.email ?? r.account.external_id}`);
1965
1966
  }
1967
+ else if (r.state === "denied")
1968
+ sys(`sign-in not approved — ${privateBetaMessage("your account")}`);
1966
1969
  else
1967
1970
  sys(`sign-in ${r.state} — try /login <email> to sign in by code instead`);
1968
1971
  }
@@ -2007,6 +2010,10 @@ function Root() {
2007
2010
  pendingLoginEmailRef.current = null;
2008
2011
  sys("too many wrong tries — /login <email> for a fresh code");
2009
2012
  }
2013
+ else if (isBetaRefusal(v.error)) {
2014
+ pendingLoginEmailRef.current = null;
2015
+ sys(v.message ?? privateBetaMessage(email));
2016
+ }
2010
2017
  else
2011
2018
  sys(`sign-in failed (${v.error}) — /login <email> to retry`);
2012
2019
  break;
@@ -2021,6 +2028,8 @@ function Root() {
2021
2028
  sys(`"${a}" doesn't look like a valid email`);
2022
2029
  else if (started.error === "too_many_requests")
2023
2030
  sys("too many codes requested — wait a few minutes, then /login <email> again");
2031
+ else if (isBetaRefusal(started.error))
2032
+ sys(started.message ?? privateBetaMessage(a));
2024
2033
  else
2025
2034
  sys(`couldn't start sign-in (${started.error})`);
2026
2035
  break;
@@ -14,6 +14,7 @@ import { detectRefusal, buildAffirmativeRetry, UNRESTRICTED_MAX_RETRIES } from "
14
14
  import { ComputerEventStream, ComputerEventTracker } from "./computer-event.js";
15
15
  import { LoopRecovery, IDEMPOTENT_TOOLS, LoopGuard, PollSpinGuard, NoWriteProgressGuard, YieldAfterDispatchGuard, loopStopNote, resolveLoopGuardConfig } from "./loop-guard.js";
16
16
  import { RunawayStreamWatch, ReasoningBudgetWatch, isDegenerateReply, REPETITION_INTERRUPTED, REASONING_BUDGET_INTERRUPTED } from "./repetition-guard.js";
17
+ import { isBetaRefusal, privateBetaMessage } from "../auth/beta.js";
17
18
  const MAX_SELF_HEAL_PER_TURN = 3;
18
19
  // A "loading" 503 (endpoint restarting/warming) is a KNOWN-recoverable WAIT, not a failure — a model reload
19
20
  // is ~30-90s, far longer than the ≤8s exponential self-heal backoff, so it gets its own patient budget that
@@ -547,11 +548,14 @@ function watchRepetition(opts, on) {
547
548
  }
548
549
  /** Runs one user turn to completion: compacts, loops model↔tools ≤maxRounds, self-heals, finalizes. */
549
550
  /** A gateway 401/403 with the reason a person can act on: no token was loaded at all (signed out, or the keychain
550
- * is locked — every SSH session on macOS), versus a token the gateway rejected. */
551
+ * is locked — every SSH session on macOS), versus a token the gateway rejected, versus an account the private beta
552
+ * hasn't let in (pending or removed), which no new sign-in can fix. */
551
553
  export function authError(err, base) {
552
554
  const msg = err instanceof Error ? err.message : String(err);
553
555
  if (!requiresOperatorToken(base))
554
556
  return err instanceof Error ? err : new Error(msg);
557
+ if (isBetaRefusal(msg))
558
+ return new Error(`${msg}\n${privateBetaMessage("your account")} Signing in again won't change this.`);
555
559
  const why = getOperatorToken()
556
560
  ? "the gateway rejected this Operator's sign-in token — run `operator auth login` to renew it"
557
561
  : "no sign-in token was loaded — run `operator auth login`; over SSH the macOS keychain is locked, so unlock it " +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.347",
3
+ "version": "0.1.348",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "operator": "dist/cli.js",