agy-cli 0.1.70: say when Google refuses the account (#3501) instead of a fallback list

Three X reports (16 Nov): "You do not have a valid license of this product
(#3501)", "models can't be fetched", and "magpie's agy proxy stopped
working". agy 1.5.9 gets Google's 403 #3501 on its eligibility check and
fails every command with it (agy models, agy -p). The plugin hid it:
models() fell back to the static catalog as if the account had those
models, usage said only "not eligible", and a request got 400 "model ... is
unavailable to this agy account" because the ACP session offers none.

Now:
- usage.mjs: agyRefusal() reads Google's refusal out of agy's output
  (#3501 first, else the eligibility line), never from agy's own log
  lines or a network failure; usage reports the #3501 text with what to
  do (update agy and sign in again, personal Gmail, unset AGY_ADC_AUTH,
  VPN/region).
- index.mjs: a failed `agy models` records the refusal per agy home;
  models() throws it (magpie shows it as the list error) instead of the
  static catalog, and recovers when agy lists again. A request whose
  session offers no model, or whose turn ends on the refusal, answers 403
  permission_error with the reason (stream and JSON), not 400. After a
  sign-in, magpie shows "agy signed in, but" and the refusal.
- README (zh, en): a Troubleshooting entry for #3501.

Run (mote, HOME=$(mktemp -d)):
- bun test ./packages/agy-cli: 35 pass, 0 fail (110s); bun scripts/check.mjs ok.
- test/usage.mjs with cp-hook preload 6 more times: 0 fail. One earlier
  run had "a direct read that fails leaves the region refusal standing"
  red with "agy usage could not start the CLI" at load ~28; the same red
  shows on the base tree (b35d4b35) in the same run, so it is not this
  change.
- Red on the old code (mica, base b35d4b35 with the new tests): catalog's
  two #3501 tests fail, usage.mjs fails to import agyRefusal.
- Real agy 1.5.9 on WSL (magpie-desktop) against a fake Code Assist that
  answers 403 #3501: before, models() gave the fallback list, chat gave 400
  "unavailable"; after, models() throws the #3501 reason, usage carries
  it, chat answers 403 permission_error with it.

Not tried: a real Google account that gets #3501; macOS and Windows with
real agy; a live ACP turn whose agent error carries #3501 (covered by the
fake agy in catalog.mjs only).
This commit is contained in:
yetone
2026-11-16 10:57:34 +08:00
parent b35d4b35b2
commit 175dfd2555
8 changed files with 192 additions and 7 deletions
+33
View File
@@ -45,10 +45,43 @@ function refusedEligibility(output) {
return ELIGIBILITY.test(output)
}
// Google's 403 #3501 at agy's eligibility check: Google turns the account
// itself away, and agy refuses every command with it, `agy models`, print
// mode and a turn alike (agy 1.5.9 against a Code Assist answering it):
// Eligibility check failed: PERMISSION_DENIED (code 403): You do not have
// a valid license of this product. ... (#3501). Please log out (/logout)
// and log back in (/login).
// Three people on X (11-16) got only a list of fallback models, "model …
// is unavailable to this agy account" or "not eligible" from the plugin.
const LICENSE_REFUSAL = /valid license of this product|\(#3501\)/i
export const LICENSE_REFUSED = "Google refuses this Google account for Antigravity " +
"(403 #3501: \"You do not have a valid license of this product\"). agy itself gets the same " +
"answer, so this account can't be used until Google accepts it. Update agy, then sign in to " +
"the account again (in magpie, or run `agy` in a terminal and /logout, then /login); sign in " +
"with a personal Google account (@gmail.com) rather than a Workspace one; unset AGY_ADC_AUTH " +
"if it is set; and turn off a VPN or proxy that puts you in a region Antigravity isn't offered in."
// agyRefusal is what to tell the user when agy's output says Google turned
// the account away at its eligibility check, or "" when it doesn't: the
// license refusal (#3501), or any other refusal of the check that isn't a
// network failure ("Eligibility check failed: EOF"), in agy's own words.
// agy's diagnostic log lines are not read: a background poll it logs can
// fail on its own.
export function agyRefusal(output) {
const said = withoutDiagnostics(String(output ?? ""))
if (LICENSE_REFUSAL.test(said)) return LICENSE_REFUSED
if (!ELIGIBILITY.test(said) || NETWORK.test(said)) return ""
const line = said.split(/\r?\n/).map(l => l.trim().replace(/^error:\s*/i, "")).find(l => ELIGIBILITY.test(l)) || ""
return `Google refuses this account for Antigravity: ${line.slice(0, 400)}. agy itself gets the same answer. ` +
"Antigravity isn't offered in every region: turn off a VPN or proxy that puts you in another one, or use an account Google serves there."
}
function commandFailure(output) {
if (/not (?:logged|signed) in(?:to)?\b|unauthenticated|authentication required|login required|please (?:log|sign) in|sign in again|\binvalid_grant\b/i.test(withoutDiagnostics(output))) {
return new UsageError("agy usage needs authentication. Run `agy` in a terminal to sign in again.", { kind: "auth" })
}
if (LICENSE_REFUSAL.test(withoutDiagnostics(output))) return new UsageError(LICENSE_REFUSED)
const eligibility = ELIGIBILITY.test(output)
const network = NETWORK.test(output)
if (network) return new UsageError(`agy usage ${eligibility ? "eligibility check " : ""}failed on a network request. Check network or proxy settings.`)