Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript
4.4 KB
Raw Blame

Google connector account identity and API access (key files cluster)

Subsystem index · Google connector + open-loop engine · Sweep page writes.

  • src/core/google/api-access.ts — #7004/#7073 account identity and API reachability. probeGoogleAccount(clients, services, { every }) asks Gmail profile and Calendar primary in order (stopping at the first address unless every), checks People by listing one connection (#7490: people/me needs the profile scope connect never requests; the probe names no account), then OAuth userinfo when none named the account, and records each failure per attempt. resolveGoogleAccount (persistence/connector-account.ts) is the managed sync's stop-at-first use: when nothing names the account it rethrows api_not_enabled first, then another credential error, then the first other failure (a network error stays transient), so connector_account_changed means a resolved account that differs from the pin. probeGoogleApiAccess probes every service of a setup or status run (an ungranted scope is scope_missing with no request) and returns { resolved_account, resolved_via, services, problems, fix }; googleApiProblem maps GoogleApiDisabledError and scope_missing to a GoogleApiProblem; googleApiAccessFix is one Action naming every problem (ask_user with each enable link when an API is disabled, else the user's gbrain google connect --reauth command), verified by gbrain google status --json.
    • The clients (google-clients.ts) throw GoogleApiDisabledError (api_not_enabled) for a 403 with reason accessNotConfigured, ErrorInfo SERVICE_DISABLED or the disabled-API message, carrying the API, its title, the project and the enable link from the error body (ErrorInfo activationUrl, then the Help link, then the message; only console.cloud.google.com and console.developers.google.com links are relayed, otherwise the client id's project number builds it). A 403 for insufficient authentication scopes (insufficientPermissions, ErrorInfo ACCESS_TOKEN_SCOPE_INSUFFICIENT) is scope_missing, never GoogleForbiddenError, so a calendar read never names it calendar_unreadable.
    • The sweep (google-source.ts) records each api_not_enabled / scope_missing failure, plus an unmanaged source's ungranted services, as api_access: { problems, at } in source state; a service leaves it when its sweep reaches the API again, at changes only when the problems do, and a partial managed run publishes it with the loop recovery state.
    • gbrain google status (with a probe) runs probeGoogleApiAccess per refreshed account over its linked sources' services (every granted service when none is linked) and reports accounts[].api_access; a problem makes ok: false and exit 1. gbrain google setup probes every requested service (--services, default all) before registering anything; a problem stops it with one report (status: api_access_blocked, exit 2, the rendered fix and the narrower --services command for the reachable services).
    • When the Gmail label list itself fails, the loop exclusion log (loops-enqueue.ts) says the names could not be checked, never that they are not labels of the account.
    • Tests: test/google-api-access-7073.test.ts, test/google-api-access-cmd-7073.serial.test.ts, test/google-api-access-managed-7073.test.ts (real PGLite, and Postgres under DATABASE_URL).
  • src/commands/doctor/checks/google-api-access.ts — doctor google_api_access (wave check, resolution operator, zero network): warns per Google source whose stored api_access names a service it still syncs, listing each disabled API with project and enable link, with googleApiAccessFix for the first source.
  • src/core/persistence/connector-google-receipts.ts — the managed Google attachment-repair preparer checks account/thread/message ownership from the current canonical snapshot, changes only the owned receipt frontmatter field, and installs provider-free text projections under the existing source-before-page publication locks. Page identity/revision, current authorization, source incarnation and file recovery guards remain mandatory; body, unrelated frontmatter, tags and the withdrawal ledger are preserved. It schedules no embeddings, loop detection or fact extraction. connector-sync.ts admits this narrow mutation and banks its committed receipts through the existing managed connector checkpoints.

Continue this subsystem.