gogcli-mcp-slides 2.21.0 → 2.22.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.
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "metadata": {
9
9
  "description": "Extended Google Slides for Claude via gogcli — auth + full Slides support (create, edit, export, templates, markdown)",
10
- "version": "2.21.0"
10
+ "version": "2.22.0"
11
11
  },
12
12
  "plugins": [
13
13
  {
@@ -15,7 +15,7 @@
15
15
  "displayName": "gogcli (Slides)",
16
16
  "source": "./",
17
17
  "description": "Extended Google Slides for Claude via gogcli — auth + full Slides support (create, edit, export, templates, markdown)",
18
- "version": "2.21.0",
18
+ "version": "2.22.0",
19
19
  "author": {
20
20
  "name": "Chris Hall"
21
21
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gogcli-mcp-slides",
3
3
  "displayName": "gogcli (Slides)",
4
- "version": "2.21.0",
4
+ "version": "2.22.0",
5
5
  "description": "Extended Google Slides for Claude via gogcli — auth + full Slides support (create, edit, export, templates, markdown)",
6
6
  "author": {
7
7
  "name": "Chris Hall",
package/dist/index.js CHANGED
@@ -31140,6 +31140,21 @@ import { delimiter, join } from "node:path";
31140
31140
  function isGogFileArg(arg) {
31141
31141
  return typeof arg !== "string";
31142
31142
  }
31143
+ var RUNNER_TRANSPORT_BRAND = /* @__PURE__ */ Symbol.for("gogcli.RunnerTransportError");
31144
+ var RunnerTransportError = class extends Error {
31145
+ kind;
31146
+ status;
31147
+ constructor(message, kind, status) {
31148
+ super(message);
31149
+ this.name = "RunnerTransportError";
31150
+ this.kind = kind;
31151
+ this.status = status;
31152
+ Object.defineProperty(this, RUNNER_TRANSPORT_BRAND, { value: true });
31153
+ }
31154
+ };
31155
+ function isRunnerTransportError(err) {
31156
+ return err instanceof Error && err[RUNNER_TRANSPORT_BRAND] === true;
31157
+ }
31143
31158
  var runExecutor = new AsyncLocalStorage();
31144
31159
  var defaultExecutor;
31145
31160
  function setDefaultGogExecutor(executor) {
@@ -31320,7 +31335,11 @@ async function run(args, options = {}) {
31320
31335
  }
31321
31336
  return redact(output);
31322
31337
  } catch (err) {
31323
- throw new Error(redact(err instanceof Error ? err.message : String(err)));
31338
+ const message = redact(err instanceof Error ? err.message : String(err));
31339
+ if (isRunnerTransportError(err)) {
31340
+ throw new RunnerTransportError(message, err.kind, err.status);
31341
+ }
31342
+ throw new Error(message);
31324
31343
  }
31325
31344
  }
31326
31345
 
@@ -31411,6 +31430,13 @@ var TIMESTAMP_KEYS = /* @__PURE__ */ new Set([
31411
31430
  // Calendar event start/end
31412
31431
  "internalDate",
31413
31432
  // Gmail, epoch milliseconds (authoritative)
31433
+ // gog >= 0.35.0 Gmail message AND thread listings. Already offset-bearing
31434
+ // (RFC3339 from internalDate), so it needs no offset repair — it is
31435
+ // allowlisted purely to gain a Display sibling, and to be re-rendered in
31436
+ // DISPLAY_TZ like every other instant. Separately sourced from the sibling
31437
+ // `date`, which is a naive re-format of the sender's Date header; the two may
31438
+ // legitimately disagree. See docs/timestamps.md.
31439
+ "internalDateIso",
31414
31440
  "modifiedTime",
31415
31441
  // Drive
31416
31442
  "createdTime",
@@ -31579,7 +31605,7 @@ function registerRunTool(server, options) {
31579
31605
  function errorText(err) {
31580
31606
  return err instanceof Error ? `Error: ${err.message}` : String(err);
31581
31607
  }
31582
- var DEFINITE_AUTH_PATTERN = /\b(401|unauthorized|invalid_grant)\b/i;
31608
+ var DEFINITE_AUTH_PATTERN = /\b(?:unauthorized|invalid_grant)\b|\b(?:error|status|code|http|responded|response)["']?[\s:=(,]{0,4}401\b/i;
31583
31609
  var STALE_TOKEN_PATTERN = /\b(?:access[ _-]?)?token\b[^.;\n]{0,40}\b(?:has\s+)?(?:been\s+)?(?:expired|revoked)\b|\b(?:expired|revoked)\s+(?:access[ _-]?)?token\b/i;
31584
31610
  var AUTH_ERROR_PATTERN = new RegExp(`${DEFINITE_AUTH_PATTERN.source}|${STALE_TOKEN_PATTERN.source}`, "i");
31585
31611
  var INVALID_GRANT_PATTERN = /invalid_grant|token has been expired or revoked/i;
@@ -31589,6 +31615,14 @@ var AUTH_HINT = "\n\nAuthentication may have expired. Use gog_auth_add to re-aut
31589
31615
  var INVALID_GRANT_HINT = '\n\nThe stored refresh token was rejected (invalid_grant): it has expired or been revoked, so the whole account is signed out and re-authorization is required. The most common cause is the 7-day refresh-token limit Google applies to OAuth apps whose consent screen is still in "Testing" mode. Re-authorize with gog_auth_add (opens a browser) or gog_auth_add_url + gog_auth_add_complete (remote/headless). To stop this recurring, publish the OAuth consent screen to "In production" in the Google Cloud project that owns the OAuth client. Ask the user if they would like to re-authenticate.';
31590
31616
  var TRANSIENT_HINT = "\n\nThis error is often transient. Retry the same call before trying a different approach (do not fall back to smaller writes or row-by-row operations).";
31591
31617
  var GRID_LIMIT_HINT = "\n\nThe target range is outside the sheet's current grid. Add the missing rows or columns first with gog_sheets_insert (dimension: rows or cols), then retry the write.";
31618
+ var RUNNER_TRANSPORT_AUTH_HINT = "\n\nThis is the CONNECTOR's own transport auth failing, not your Google sign-in. The gog-runner backend rejected the bearer token this server sent, so the request never reached gog and no Google credential was checked \u2014 the Google account is not the problem and re-authorizing it cannot fix this. An operator must make the Worker secret GOG_RUNNER_KEY equal RUNNER_KEY on the Fly app (wrangler secret put GOG_RUNNER_KEY / fly secrets set RUNNER_KEY), then retry.";
31619
+ var RUNNER_TRANSPORT_HINTS = {
31620
+ "transport-auth": RUNNER_TRANSPORT_AUTH_HINT,
31621
+ // The request itself was malformed, so the runner will refuse it identically
31622
+ // every time. Nothing to advise beyond the message the runner already gave.
31623
+ "transport-request": "",
31624
+ "transport-retryable": TRANSIENT_HINT
31625
+ };
31592
31626
  function formatAccountList(raw) {
31593
31627
  try {
31594
31628
  const parsed = JSON.parse(raw);
@@ -31601,11 +31635,12 @@ function formatAccountList(raw) {
31601
31635
  }
31602
31636
  async function diagnose(err) {
31603
31637
  const errText = errorText(err);
31638
+ const transportHint = isRunnerTransportError(err) ? RUNNER_TRANSPORT_HINTS[err.kind] : void 0;
31604
31639
  const isInvalidGrant = INVALID_GRANT_PATTERN.test(errText);
31605
31640
  const isTransientError = !DEFINITE_AUTH_PATTERN.test(errText) && TRANSIENT_ERROR_PATTERN.test(errText);
31606
31641
  const isAuthError = !isTransientError && AUTH_ERROR_PATTERN.test(errText);
31607
31642
  const isGridLimitError = GRID_LIMIT_ERROR_PATTERN.test(errText);
31608
- const hint = isInvalidGrant ? INVALID_GRANT_HINT : isAuthError ? AUTH_HINT : isTransientError ? TRANSIENT_HINT : isGridLimitError ? GRID_LIMIT_HINT : "";
31643
+ const hint = transportHint ?? (isInvalidGrant ? INVALID_GRANT_HINT : isAuthError ? AUTH_HINT : isTransientError ? TRANSIENT_HINT : isGridLimitError ? GRID_LIMIT_HINT : "");
31609
31644
  try {
31610
31645
  const accounts = formatAccountList(await run(["auth", "list"]));
31611
31646
  return errorResult(`${errText}
@@ -31638,8 +31673,8 @@ function formatOneAccountHealth(a, now) {
31638
31673
  const age = ageInDays(a.created_at, now);
31639
31674
  const ageStr = age === null ? "" : ` Authorized ${age.toFixed(1)} day(s) ago.`;
31640
31675
  if (a.valid === false) {
31641
- const cause = INVALID_GRANT_PATTERN.test(a.error ?? "") ? 'refresh token expired or revoked \u2014 commonly the 7-day limit on OAuth consent screens still in "Testing" mode' : a.error?.trim() || "unknown error";
31642
- return `\u2717 ${email3}: NEEDS RE-AUTH \u2014 ${cause}.${ageStr} Re-authorize with gog_auth_add (browser) or gog_auth_add_url + gog_auth_add_complete (remote/headless).`;
31676
+ const cause2 = INVALID_GRANT_PATTERN.test(a.error ?? "") ? 'refresh token expired or revoked \u2014 commonly the 7-day limit on OAuth consent screens still in "Testing" mode' : a.error?.trim() || "unknown error";
31677
+ return `\u2717 ${email3}: NEEDS RE-AUTH \u2014 ${cause2}.${ageStr} Re-authorize with gog_auth_add (browser) or gog_auth_add_url + gog_auth_add_complete (remote/headless).`;
31643
31678
  }
31644
31679
  if (a.valid === true) {
31645
31680
  let line = `\u2713 ${email3}: token valid.${ageStr}`;
@@ -31681,7 +31716,7 @@ function registerAuthToolsWith(server, defaultServices) {
31681
31716
  }
31682
31717
  });
31683
31718
  server.registerTool("gog_auth_status", {
31684
- description: "Show gogcli auth configuration: keyring backend, credential files, and auth setup.",
31719
+ description: "Show gogcli auth CONFIGURATION: keyring backend, credential files, and auth setup. Despite the name this is not a health check \u2014 it reads local setup and does not contact Google, so it says nothing about whether an account can still authenticate. Use gog_auth_health for that.",
31685
31720
  annotations: { readOnlyHint: true },
31686
31721
  inputSchema: {}
31687
31722
  }, async () => {
@@ -31692,7 +31727,7 @@ function registerAuthToolsWith(server, defaultServices) {
31692
31727
  }
31693
31728
  });
31694
31729
  server.registerTool("gog_auth_health", {
31695
- description: 'Check the LIVE health of each stored Google account. Unlike gog_auth_status (which only reports keyring/config setup), this performs a real token refresh against Google, so it detects expired or revoked (invalid_grant) refresh tokens \u2014 the account-wide sign-out that blocks every service. Reports per account: whether the token is currently valid, the mapped cause when it is not, how long ago it was authorized, and a warning as it approaches the 7-day refresh-token limit that applies to OAuth apps whose consent screen is still in "Testing" mode. Run it proactively to re-authorize on your own schedule instead of mid-task.',
31730
+ description: 'Check the LIVE health of each stored Google account. Unlike gog_auth_status (which only reports keyring/config setup), this performs a real token refresh against Google, so it detects expired or revoked (invalid_grant) refresh tokens \u2014 the account-wide sign-out that blocks every service. Reports per account: whether the token is currently valid, the mapped cause when it is not, how long ago it was authorized, and a warning as it approaches the 7-day refresh-token limit that applies to OAuth apps whose consent screen is still in "Testing" mode. Run it proactively to re-authorize on your own schedule instead of mid-task. On the hosted connector this is the ONLY check that measures Google: a connector showing "connected" or "refreshed" has verified the connector key that reaches the gog machine, and nothing else \u2014 the Google credential lives on that machine and can be dead while the connection looks perfectly healthy.',
31696
31731
  annotations: { readOnlyHint: true },
31697
31732
  inputSchema: {}
31698
31733
  }, async () => {
@@ -31883,7 +31918,40 @@ function registerSlidesTools(server) {
31883
31918
  }
31884
31919
 
31885
31920
  // ../gogcli-mcp/src/server.ts
31886
- var VERSION = true ? "2.21.0" : "0.0.0";
31921
+ var VERSION = true ? "2.22.0" : "0.0.0";
31922
+
31923
+ // ../gogcli-mcp/src/auth-log.ts
31924
+ var FAILURES = /* @__PURE__ */ new Set([
31925
+ "token.mint-failed",
31926
+ "grant.dead",
31927
+ "replay.failed",
31928
+ "runner.auth-failed",
31929
+ "connect.key-rejected",
31930
+ // An enrolment that could not proceed is a failure even though nobody is at
31931
+ // fault: it is the only trace a half-enrolled connector leaves behind, and
31932
+ // the absence of exactly this record is why DEFECT 4 could not be explained.
31933
+ "connect.runner-unreachable",
31934
+ "connect.google-unhealthy",
31935
+ "refusal.google-unhealthy",
31936
+ // The loudest record on this branch, and the only one that means "we cannot
31937
+ // explain this". Google refused a real call while a live check of the same
31938
+ // credential, taken seconds later, succeeded — so neither the 7-day cliff nor
31939
+ // a revoked grant accounts for it. It is filed as a failure precisely because
31940
+ // it is the record nobody may scroll past: it is the only evidence that could
31941
+ // ever justify building something on the hosted path, and its absence over
31942
+ // time is what retires that theory for good.
31943
+ "refusal.google-ok"
31944
+ ]);
31945
+ var PREFIX = "gog-auth ";
31946
+ var TAG_CHARS = 12;
31947
+ function credentialTag(cacheKeyHash) {
31948
+ return cacheKeyHash.slice(0, TAG_CHARS);
31949
+ }
31950
+ function logAuthTransition(event, context) {
31951
+ const record2 = JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), event, ...context });
31952
+ const write = FAILURES.has(event) ? console.error : console.warn;
31953
+ write(PREFIX + redactSecrets2(record2));
31954
+ }
31887
31955
 
31888
31956
  // ../gogcli-mcp/src/google-token.ts
31889
31957
  var TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token";
@@ -31910,22 +31978,73 @@ function makeAccessTokenSource(env) {
31910
31978
  );
31911
31979
  };
31912
31980
  }
31913
- return async () => {
31914
- const key = await cacheKey(refreshToken, clientId);
31915
- const hit = cache.get(key);
31916
- if (hit && hit.expiresAt - EXPIRY_MARGIN_MS > Date.now()) return hit.accessToken;
31917
- let pending = inFlight.get(key);
31981
+ let keyPromise;
31982
+ const key = () => keyPromise ??= cacheKey(refreshToken, clientId);
31983
+ const logCacheHits = parseBoolEnv("GOG_AUTH_LOG_CACHE_HITS", { env });
31984
+ const read = async () => {
31985
+ const k = await key();
31986
+ const hit = cache.get(k);
31987
+ if (hit && hit.expiresAt - EXPIRY_MARGIN_MS > Date.now()) {
31988
+ if (logCacheHits) logAuthTransition("token.cache-hit", { credential: credentialTag(k) });
31989
+ return hit.accessToken;
31990
+ }
31991
+ let pending = inFlight.get(k);
31918
31992
  if (!pending) {
31919
31993
  pending = exchange(refreshToken, clientId, clientSecret).then((minted2) => {
31920
- cache.set(key, minted2);
31994
+ cache.set(k, minted2);
31995
+ logAuthTransition("token.minted", {
31996
+ credential: credentialTag(k),
31997
+ reason: `valid for ${Math.round((minted2.expiresAt - Date.now()) / 1e3)}s`
31998
+ });
31921
31999
  return minted2;
31922
- }).finally(() => inFlight.delete(key));
31923
- inFlight.set(key, pending);
32000
+ }).catch((err) => {
32001
+ logAuthTransition(err.grantDead ? "grant.dead" : "token.mint-failed", {
32002
+ credential: credentialTag(k),
32003
+ reason: err.message
32004
+ });
32005
+ throw err;
32006
+ }).finally(() => inFlight.delete(k));
32007
+ inFlight.set(k, pending);
31924
32008
  }
31925
32009
  const minted = await pending;
31926
32010
  return minted.accessToken;
31927
32011
  };
32012
+ const invalidate = async (rejected) => {
32013
+ const k = await key();
32014
+ const hit = cache.get(k);
32015
+ if (!hit || hit.accessToken !== rejected) {
32016
+ logAuthTransition("token.evict-noop", {
32017
+ credential: credentialTag(k),
32018
+ reason: hit ? "a concurrent caller had already replaced this credential\u2019s token" : "no token was cached for this credential"
32019
+ });
32020
+ return false;
32021
+ }
32022
+ cache.delete(k);
32023
+ logAuthTransition("token.evicted", {
32024
+ credential: credentialTag(k),
32025
+ reason: "Google rejected this access token; the next read will mint a new one"
32026
+ });
32027
+ return true;
32028
+ };
32029
+ return Object.assign(read, {
32030
+ invalidate,
32031
+ credentialId: async () => credentialTag(await key())
32032
+ });
31928
32033
  }
32034
+ var TokenExchangeError = class extends Error {
32035
+ /**
32036
+ * The REFRESH token is dead (Google's `invalid_grant`), not merely the access
32037
+ * token. Carried as a flag rather than re-read from the message, because
32038
+ * inferring the author of a failure from prose several authors can produce is
32039
+ * precisely the mistake this branch exists to undo. `instanceof` is safe: the
32040
+ * class is thrown and caught inside this one module.
32041
+ */
32042
+ grantDead;
32043
+ constructor(message, grantDead) {
32044
+ super(message);
32045
+ this.grantDead = grantDead;
32046
+ }
32047
+ };
31929
32048
  async function exchange(refreshToken, clientId, clientSecret) {
31930
32049
  let res;
31931
32050
  try {
@@ -31940,79 +32059,338 @@ async function exchange(refreshToken, clientId, clientSecret) {
31940
32059
  }).toString()
31941
32060
  });
31942
32061
  } catch (err) {
31943
- throw new Error(
31944
- `the Google token exchange could not be reached: ${err instanceof Error ? err.message : String(err)}`
32062
+ throw new TokenExchangeError(
32063
+ `the Google token exchange could not be reached: ${err instanceof Error ? err.message : String(err)}`,
32064
+ false
31945
32065
  );
31946
32066
  }
31947
32067
  const body = await res.json().catch(() => ({}));
31948
32068
  if (!res.ok) {
31949
32069
  if (body.error === "invalid_grant") {
31950
- throw new Error(
31951
- 'the stored refresh token has expired or been revoked, so this account must be re-authorized (commonly the 7-day limit on OAuth consent screens still in "Testing" mode). Re-enrol with gog_auth_add_url + gog_auth_add_complete and store the new refresh token.'
32070
+ throw new TokenExchangeError(
32071
+ 'the stored refresh token was rejected (invalid_grant): it has expired or been revoked, so this account must be re-authorized (commonly the 7-day limit on OAuth consent screens still in "Testing" mode). Re-enrol with gog_auth_add_url + gog_auth_add_complete and store the new refresh token.',
32072
+ true
31952
32073
  );
31953
32074
  }
31954
- throw new Error(
31955
- `the access token could not be refreshed (HTTP ${res.status}${body.error ? `, ${body.error}` : ""})`
32075
+ throw new TokenExchangeError(
32076
+ `the access token could not be refreshed (HTTP ${res.status}${body.error ? `, ${body.error}` : ""})`,
32077
+ false
31956
32078
  );
31957
32079
  }
31958
32080
  if (!body.access_token) {
31959
- throw new Error("the access token could not be refreshed: Google returned no access_token");
32081
+ throw new TokenExchangeError(
32082
+ "the access token could not be refreshed: Google returned no access_token",
32083
+ false
32084
+ );
31960
32085
  }
31961
32086
  const expiresInMs = (body.expires_in ?? 3600) * 1e3;
31962
32087
  return { accessToken: body.access_token, expiresAt: Date.now() + expiresInMs };
31963
32088
  }
31964
32089
 
32090
+ // ../gogcli-mcp/src/google-probe.ts
32091
+ var bool = (value) => typeof value === "boolean" ? value : void 0;
32092
+ var cause = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
32093
+ function readGoogleProbe(body) {
32094
+ const record2 = typeof body === "object" && body !== null ? body : {};
32095
+ const measured = bool(record2.measured);
32096
+ const reported = cause(record2.error);
32097
+ if (measured === false) {
32098
+ return {
32099
+ kind: "unmeasured",
32100
+ reason: reported ?? "the runner reported it could not measure the Google layer"
32101
+ };
32102
+ }
32103
+ if (measured === true) {
32104
+ if (bool(record2.ok) === true) return { kind: "ok" };
32105
+ return {
32106
+ kind: "unhealthy",
32107
+ reason: reported ?? "the runner reported the Google layer unhealthy with no cause"
32108
+ };
32109
+ }
32110
+ return {
32111
+ kind: "unmeasured",
32112
+ reason: reported ? `the runner did not report whether it measured the Google layer; it said: ${reported}` : "the runner did not report whether it measured the Google layer"
32113
+ };
32114
+ }
32115
+
31965
32116
  // ../gogcli-mcp/src/connector-runtime.ts
31966
32117
  var DEFAULT_TIMEOUT_MS = 3e4;
31967
32118
  var DEADLINE_GRACE_MS = 5e3;
32119
+ var MIN_REPLAY_BUDGET_MS = 1e3;
32120
+ var REFUSAL_PROBE_TIMEOUT_MS = 4e3;
32121
+ var MIN_PROBE_BUDGET_MS = 1e3;
32122
+ var PROBE_INTERVAL_MS = 6e4;
31968
32123
  var RUNNER_GOG_FAILED = 422;
31969
32124
  var RUNNER_DRAINING = 503;
32125
+ var RUNNER_BAD_REQUEST = 400;
32126
+ var RUNNER_BAD_KEY = 401;
32127
+ var GogFailedError = class extends Error {
32128
+ /** gog's stderr alone, with no echoed argv mixed in. */
32129
+ stderr;
32130
+ constructor(message, stderr) {
32131
+ super(message);
32132
+ this.stderr = stderr;
32133
+ }
32134
+ };
32135
+ var GOOGLE_TOKEN_REJECTED_PATTERN = /Google API error \(401\b|invalid[ _]authentication[ _]credentials|\bACCESS_TOKEN_EXPIRED\b|\binvalid_token\b/i;
32136
+ var REFRESH_TOKEN_DEAD_PATTERN = /\binvalid_grant\b/i;
32137
+ var READ_ONLY_SUBCOMMANDS = /* @__PURE__ */ new Set([
32138
+ "cat",
32139
+ "describe",
32140
+ "get",
32141
+ "info",
32142
+ "list",
32143
+ "list-slides",
32144
+ "ls",
32145
+ "metadata",
32146
+ "read-slide",
32147
+ "search",
32148
+ "services",
32149
+ "status",
32150
+ "structure"
32151
+ ]);
32152
+ function gogTarget(args) {
32153
+ const words = args.filter((arg) => typeof arg === "string");
32154
+ let service;
32155
+ for (let i = 0; i < words.length; i += 1) {
32156
+ const word = words[i];
32157
+ if (word.startsWith("-")) {
32158
+ if (word === "--account") i += 1;
32159
+ continue;
32160
+ }
32161
+ if (service === void 0) {
32162
+ service = word;
32163
+ continue;
32164
+ }
32165
+ return { service, subcommand: word };
32166
+ }
32167
+ return { service };
32168
+ }
32169
+ async function remintAfterGoogleRejection(err, used, args, readAccessToken, deadlineAt, probeGoogle) {
32170
+ if (!(err instanceof GogFailedError)) return void 0;
32171
+ const grantDead = REFRESH_TOKEN_DEAD_PATTERN.test(err.stderr);
32172
+ if (!grantDead && !GOOGLE_TOKEN_REJECTED_PATTERN.test(err.stderr)) return void 0;
32173
+ const { service, subcommand } = gogTarget(args);
32174
+ const credential = await readAccessToken?.credentialId?.();
32175
+ const where = { credential, service };
32176
+ if (grantDead) {
32177
+ logAuthTransition("grant.dead", {
32178
+ ...where,
32179
+ reason: "gog reported invalid_grant: the stored refresh token is dead, so no token can be minted and this account must be re-authorized"
32180
+ });
32181
+ return void 0;
32182
+ }
32183
+ if (!used) {
32184
+ await probeGoogle(where);
32185
+ logAuthTransition("replay.declined", {
32186
+ ...where,
32187
+ reason: "no access token was supplied with the call, so gog acted as the backend volume\u2019s own identity"
32188
+ });
32189
+ return void 0;
32190
+ }
32191
+ if (!readAccessToken?.invalidate) {
32192
+ logAuthTransition("replay.declined", {
32193
+ ...where,
32194
+ reason: "this token source cannot mint a replacement, so a replay would resend the rejected token"
32195
+ });
32196
+ return void 0;
32197
+ }
32198
+ const evicted = await readAccessToken.invalidate(used);
32199
+ if (subcommand === void 0 || !READ_ONLY_SUBCOMMANDS.has(subcommand)) {
32200
+ logAuthTransition("replay.declined", {
32201
+ ...where,
32202
+ reason: `not replayable: '${subcommand ?? "(none)"}' is not a known read-only subcommand and a write could double-apply`
32203
+ });
32204
+ return void 0;
32205
+ }
32206
+ if (!evicted) {
32207
+ logAuthTransition("replay.declined", {
32208
+ ...where,
32209
+ reason: "the rejected token was already superseded, so the cache holds the token a replay would send"
32210
+ });
32211
+ return void 0;
32212
+ }
32213
+ const fresh = await readAccessToken();
32214
+ if (!fresh) {
32215
+ logAuthTransition("replay.declined", {
32216
+ ...where,
32217
+ reason: "the token source produced no token after eviction; replaying without one would act as the backend"
32218
+ });
32219
+ return void 0;
32220
+ }
32221
+ const budgetMs = deadlineAt - Date.now();
32222
+ if (budgetMs < MIN_REPLAY_BUDGET_MS) {
32223
+ logAuthTransition("replay.declined", {
32224
+ ...where,
32225
+ reason: `only ${budgetMs}ms of the call\u2019s deadline remained, so a replay could only time out; the rejected token was evicted, so the next call mints a fresh one`
32226
+ });
32227
+ return void 0;
32228
+ }
32229
+ return { token: fresh, budgetMs, invalidate: readAccessToken.invalidate, ...where };
32230
+ }
31970
32231
  function makeFlyExecutor(endpoint, key, readAccessToken) {
32232
+ let lastProbeAt = Number.NEGATIVE_INFINITY;
32233
+ const probeGoogleAfterRefusal = async (where, deadlineAt) => {
32234
+ const record2 = { ...where, endpoint };
32235
+ const now = Date.now();
32236
+ const remainingMs = deadlineAt - now;
32237
+ if (remainingMs < MIN_PROBE_BUDGET_MS) {
32238
+ logAuthTransition("refusal.google-unmeasured", {
32239
+ ...record2,
32240
+ reason: `only ${remainingMs}ms of the call\u2019s deadline remained, so the Google layer was not measured rather than delay the caller\u2019s own error`
32241
+ });
32242
+ return;
32243
+ }
32244
+ if (now - lastProbeAt < PROBE_INTERVAL_MS) {
32245
+ logAuthTransition("refusal.google-unmeasured", {
32246
+ ...record2,
32247
+ // "attempted", not "measured". `lastProbeAt` is stamped before the
32248
+ // fetch and is deliberately NOT reset when the probe comes back with no
32249
+ // verdict (a 404 from a runner too old to have the endpoint, a timeout,
32250
+ // a dead socket) — the backend cost this throttle exists to bound was
32251
+ // paid either way, and resetting it would let a retry loop storm a
32252
+ // runner that is already unwell. So the timestamp stays and the sentence
32253
+ // has to be the true one: on this branch a log line may not assert a
32254
+ // measurement that never happened, and the previous probe may well have
32255
+ // measured nothing at all.
32256
+ reason: "a Google probe was attempted recently, so another was not sent: this probe spawns gog on the backend and takes the keyring\u2019s exclusive lock"
32257
+ });
32258
+ return;
32259
+ }
32260
+ lastProbeAt = now;
32261
+ let event;
32262
+ let reason;
32263
+ try {
32264
+ const res = await fetch(`${endpoint}/health/google`, {
32265
+ headers: { Authorization: `Bearer ${key}` },
32266
+ // Never more than the probe's own budget, never more than the call has
32267
+ // left. `Math.min` rather than a plain constant because the second
32268
+ // bound is the caller's, and it outranks ours.
32269
+ signal: AbortSignal.timeout(Math.min(REFUSAL_PROBE_TIMEOUT_MS, remainingMs))
32270
+ });
32271
+ if (!res.ok) {
32272
+ event = "refusal.google-unmeasured";
32273
+ reason = `the runner did not answer the Google probe (HTTP ${res.status})`;
32274
+ } else {
32275
+ const verdict = readGoogleProbe(await res.json());
32276
+ if (verdict.kind === "ok") {
32277
+ event = "refusal.google-ok";
32278
+ reason = "Google refused this call, yet a live token check on the same volume succeeded \u2014 so a dead or expired refresh token does not explain this refusal";
32279
+ } else {
32280
+ event = verdict.kind === "unhealthy" ? "refusal.google-unhealthy" : "refusal.google-unmeasured";
32281
+ reason = verdict.reason;
32282
+ }
32283
+ }
32284
+ } catch (err) {
32285
+ event = "refusal.google-unmeasured";
32286
+ reason = err instanceof Error ? err.message : String(err);
32287
+ }
32288
+ logAuthTransition(event, { ...record2, reason });
32289
+ };
31971
32290
  return async (args, opts) => {
31972
32291
  const deadlineMs = (opts?.timeout ?? DEFAULT_TIMEOUT_MS) + DEADLINE_GRACE_MS;
31973
32292
  const accessToken = await readAccessToken?.();
31974
- let res;
32293
+ const deadlineAt = Date.now() + deadlineMs;
31975
32294
  try {
31976
- res = await fetch(endpoint + "/run", {
31977
- method: "POST",
31978
- headers: {
31979
- Authorization: "Bearer " + key,
31980
- "Content-Type": "application/json"
31981
- },
31982
- body: JSON.stringify(accessToken ? { args, accessToken } : { args }),
31983
- signal: AbortSignal.timeout(deadlineMs)
31984
- });
32295
+ return await attempt(endpoint, key, args, accessToken, deadlineMs);
31985
32296
  } catch (err) {
31986
- const name = err instanceof Error ? err.name : "";
31987
- if (name === "TimeoutError" || name === "AbortError") {
31988
- throw new Error(
31989
- `gog-runner did not respond within ${deadlineMs}ms (${endpoint}) \u2014 the Fly backend may be cold or wedged`
31990
- );
32297
+ const replay = await remintAfterGoogleRejection(
32298
+ err,
32299
+ accessToken,
32300
+ args,
32301
+ readAccessToken,
32302
+ deadlineAt,
32303
+ (where2) => probeGoogleAfterRefusal(where2, deadlineAt)
32304
+ );
32305
+ if (replay === void 0) throw err;
32306
+ const where = { credential: replay.credential, service: replay.service, endpoint };
32307
+ logAuthTransition("replay.attempted", {
32308
+ ...where,
32309
+ reason: "Google rejected the access token; replaying this read once with a freshly minted one"
32310
+ });
32311
+ try {
32312
+ const stdout = await attempt(endpoint, key, args, replay.token, replay.budgetMs);
32313
+ logAuthTransition("replay.succeeded", where);
32314
+ return stdout;
32315
+ } catch (replayErr) {
32316
+ logAuthTransition("replay.failed", { ...where, reason: String(replayErr) });
32317
+ if (replayErr instanceof GogFailedError && GOOGLE_TOKEN_REJECTED_PATTERN.test(replayErr.stderr)) {
32318
+ await replay.invalidate(replay.token);
32319
+ }
32320
+ throw replayErr;
31991
32321
  }
31992
- throw err;
31993
32322
  }
31994
- if (!res.ok) {
31995
- const body = await res.json().catch(() => null);
31996
- const detail = body && typeof body.error === "string" ? body.stderr && body.stderr.trim() && body.stderr.trim() !== body.error.trim() ? `${body.error}
32323
+ };
32324
+ }
32325
+ async function attempt(endpoint, key, args, accessToken, deadlineMs) {
32326
+ let res;
32327
+ try {
32328
+ res = await fetch(endpoint + "/run", {
32329
+ method: "POST",
32330
+ headers: {
32331
+ Authorization: "Bearer " + key,
32332
+ "Content-Type": "application/json"
32333
+ },
32334
+ body: JSON.stringify(accessToken ? { args, accessToken } : { args }),
32335
+ signal: AbortSignal.timeout(deadlineMs)
32336
+ });
32337
+ } catch (err) {
32338
+ const name = err instanceof Error ? err.name : "";
32339
+ if (name === "TimeoutError" || name === "AbortError") {
32340
+ throw new RunnerTransportError(
32341
+ `gog-runner did not respond within ${deadlineMs}ms (${endpoint}) \u2014 the Fly backend may be cold or wedged`,
32342
+ "transport-retryable"
32343
+ );
32344
+ }
32345
+ throw err;
32346
+ }
32347
+ if (!res.ok) {
32348
+ const body = await res.json().catch(() => null);
32349
+ const detail = body && typeof body.error === "string" ? body.stderr && body.stderr.trim() && body.stderr.trim() !== body.error.trim() ? `${body.error}
31997
32350
  ${body.stderr}` : body.error : "";
31998
- if (res.status === RUNNER_GOG_FAILED) {
31999
- throw new Error(detail || "gog failed on the runner (no detail supplied)");
32000
- }
32001
- if (res.status === RUNNER_DRAINING || body?.retryable === true) {
32002
- throw new Error(
32003
- `gog-runner is restarting; retry this call.${detail ? ` ${detail}` : ""}`
32004
- );
32005
- }
32006
- if (detail) {
32007
- throw new Error(detail);
32008
- }
32009
- throw new Error(
32010
- `gog-runner HTTP ${res.status}: the response did not come from the runner, so the request never reached gog. The backend Machine was most likely starting or shutting down \u2014 this is transient, retry the same call.`
32351
+ if (res.status === RUNNER_GOG_FAILED) {
32352
+ throw new GogFailedError(
32353
+ detail || "gog failed on the runner (no detail supplied)",
32354
+ typeof body?.stderr === "string" ? body.stderr : ""
32011
32355
  );
32012
32356
  }
32013
- const { stdout } = await res.json();
32014
- return stdout;
32015
- };
32357
+ if (res.status === RUNNER_BAD_KEY) {
32358
+ logAuthTransition("runner.auth-failed", {
32359
+ service: gogTarget(args).service,
32360
+ endpoint,
32361
+ reason: "the gog-runner rejected the connector\u2019s bearer token, so gog never ran and no Google credential was read; GOG_RUNNER_KEY does not match the Fly app\u2019s RUNNER_KEY"
32362
+ });
32363
+ throw new RunnerTransportError(
32364
+ "gog-runner rejected the connector's bearer token, so the request never reached gog and no Google credential was involved. The Worker secret GOG_RUNNER_KEY no longer matches RUNNER_KEY on the Fly app; set them to the same value (wrangler secret put GOG_RUNNER_KEY / fly secrets set RUNNER_KEY) and retry.",
32365
+ "transport-auth",
32366
+ res.status
32367
+ );
32368
+ }
32369
+ if (res.status === RUNNER_BAD_REQUEST) {
32370
+ throw new RunnerTransportError(
32371
+ detail || "gog-runner rejected the request (no detail supplied)",
32372
+ "transport-request",
32373
+ res.status
32374
+ );
32375
+ }
32376
+ if (res.status === RUNNER_DRAINING || body?.retryable === true) {
32377
+ throw new RunnerTransportError(
32378
+ `gog-runner is restarting; retry this call.${detail ? ` ${detail}` : ""}`,
32379
+ "transport-retryable",
32380
+ res.status
32381
+ );
32382
+ }
32383
+ if (detail) {
32384
+ throw new Error(detail);
32385
+ }
32386
+ throw new RunnerTransportError(
32387
+ `gog-runner HTTP ${res.status}: the response did not come from the runner, so the request never reached gog. The backend Machine was most likely starting or shutting down \u2014 this is transient, retry the same call.`,
32388
+ "transport-retryable",
32389
+ res.status
32390
+ );
32391
+ }
32392
+ const { stdout } = await res.json();
32393
+ return stdout;
32016
32394
  }
32017
32395
 
32018
32396
  // ../gogcli-mcp/src/remote-runner.ts
package/manifest.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifest_version": "0.3",
4
4
  "name": "gogcli-mcp-slides",
5
5
  "display_name": "gogcli (Slides)",
6
- "version": "2.21.0",
6
+ "version": "2.22.0",
7
7
  "description": "Extended Google Slides for Claude via gogcli — auth + full Slides support (create, edit, export, templates, markdown)",
8
8
  "author": {
9
9
  "name": "Chris Hall",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gogcli-mcp-slides",
3
- "version": "2.21.0",
3
+ "version": "2.22.0",
4
4
  "mcpName": "io.github.chrischall/gogcli-mcp-slides",
5
5
  "description": "Extended Google Slides MCP server via gogcli — auth + full Slides support",
6
6
  "author": "Claude Code (AI) <https://www.anthropic.com/claude>",
package/server.json CHANGED
@@ -7,12 +7,12 @@
7
7
  "source": "github",
8
8
  "subfolder": "packages/gogcli-mcp-slides"
9
9
  },
10
- "version": "2.21.0",
10
+ "version": "2.22.0",
11
11
  "packages": [
12
12
  {
13
13
  "registryType": "npm",
14
14
  "identifier": "gogcli-mcp-slides",
15
- "version": "2.21.0",
15
+ "version": "2.22.0",
16
16
  "transport": {
17
17
  "type": "stdio"
18
18
  },