agentleFS
Google CloudKnown publisherGoogleCloudPlatform/generative-ai/search/gemini-enterprise/group-licensing/AGENTS.md

generative-ai / group-licensing

AGENTS.md18k starsChanged 2 months agoApache-2.0View on GitHub

[!IMPORTANT] Before making any code changes, architectural decisions, or refactoring in this codebase, any skill, agent, or subagent MUST first read the service Technical Design Document (TDD) located at docs/TDD.md (in the docs/ subdirectory). This document contains the definitive architectural requirements, data flows, and design rationale for the service. No linter config is present; use go vet ./... for static checks. Strict Ports and Adapters (Hexagonal Architecture). The layers must not be mixed: Every adapter declares a compile-time interface satisfaction…

Trending

More talk lately.about the whole repository

Dec 2025: 2 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 6 mentionsApr 2026: 1 mentionMay 2026: 2 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 2 mentionsSep 2026: 2 mentionsOct 2026: 4 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the GoogleCloudPlatform/generative-ai repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about GoogleCloudPlatform/generative-ai

The biggest 5 of 52 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 52

Talked about on GitHub, Bluesky and Hacker News (52 times).

On GitHub · 43

38 more on GitHub

On Bluesky · 6

1 more on Bluesky

On Hacker News · 3

The file

We split this AGENTS.md into the rules it gives an agent

11 rules. About 1 is common, 4 are distinctive, and 6 are very specific to this project.

  • ≈1

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    No linter config is present.

    line 28
  2. Distinctive:

    Every adapter declares a compile-time interface satisfaction check:

    line 44
  3. Distinctive:

    Add this to any new adapter you write.

    line 48
  4. Distinctive:

    Never promote a soft-failure error to a hard failure.

    line 129
  5. Very specific:

    All tests are unit tests. go test ./...

    line 173
  6. Very specific:

    Use testify/mock for port mocks.

    line 174
  7. Common:

    Do not add integration tests or tests that require Google Cloud credentials.

    line 178
  8. Very specific:

    All logs are structured JSON emitted to stdout via log/slog (slog.NewJSONHandler).

    line 228
  9. Very specific:

    When working on complex tasks in this repository, you can delegate work to specialized subagents using invoke_subagent.

    line 234
  10. Distinctive:

    Mandatory TDD Review: When delegating any task that involves modifying code or architecture, explicitly instruct the invoked subagent or …

    line 253
  11. Very specific:

    Isolated Adapter Refactoring: When modifying an individual adapter or adding a new port/adapter implementation, delegate to a self subagent …

    line 255

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Gemini Enterprise Group Licensing — Agent Context

Mandatory First Step: Read the Service TDD

[!IMPORTANT] Before making any code changes, architectural decisions, or refactoring in this codebase, any skill, agent, or subagent MUST first read the service Technical Design Document (TDD) located at docs/TDD.md (in the docs/ subdirectory). This document contains the definitive architectural requirements, data flows, and design rationale for the service.

Project identity

  • Module: github.com/GoogleCloudPlatform/generative-ai/search/gemini-enterprise/group-licensing
  • Language: Go 1.25.4
  • Deployment: Google Cloud Run Jobs (serverless batch — no HTTP server)
  • Purpose: Automates Gemini Enterprise license lifecycle management by reconciling Google Cloud Identity group membership with Discovery Engine user license state. Runs two independent workflows from a single binary: joiner (grant) and garbage_collection (revoke).

Quick reference

# Run all unit tests (no credentials required)
go test ./...

# Build the binary
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /tmp/job ./cmd/job

# Build the container image
docker build -t gemini-box-office:latest .

No linter config is present; use go vet ./... for static checks.

Architecture

Strict Ports and Adapters (Hexagonal Architecture). The layers must not be mixed:

cmd/job/main.go          composition root — wires adapters into services, dispatches workflow
internal/ports/          Go interfaces (the ports) — the only API surface the service layer sees
internal/adapters/       Concrete Google SDK implementations of the ports
internal/services/       Pure business logic — imports ports only, never adapter or SDK packages
internal/models/         Domain types, enums, sentinel errors, constants — no external imports
internal/config/         Config loading and env-var parsing
internal/middleware/     slog logger retrieval from context

Every adapter declares a compile-time interface satisfaction check:

var _ ports.SomeClient = (*Adapter)(nil)

Add this to any new adapter you write.

Key files

FileRole
docs/TDD.mdTechnical Design Document (MUST READ FIRST before any changes) — definitive service architecture, data flows, and requirements
docs/PRD.mdProduct Requirements Document — background and user stories
cmd/job/main.goEntry point. 8-step startup: logger → config → settings → logger enrichment → project sharding → client init → workflow dispatch → exit
internal/ports/gemini.goGeminiClient interface (Discovery Engine)
internal/ports/idp.goIdpClient interface (Cloud Identity)
internal/ports/resourcemanager.goResourceManagerClient interface
internal/services/joiner.goJoiner workflow business logic
internal/services/gc.goGC workflow business logic + chunkLicenseUpdates (shared)
internal/services/mocks_test.gotestify/mock implementations of all three ports (package-internal)
internal/models/types.goDomain data structures: Member, UserLicense, LicenseUpdate, LicenseConfigKey, LicenseConfigEntry, LicenseConfigIndex
internal/models/enums.goAll typed-string enums: SKU, WorkflowType, LicenseState, LicenseAction, Location, MemberType
internal/models/errors.goAll sentinel errors — use errors.Is against these
internal/models/constants.goMaxBatchSize=100, MembersListPageSize=200, MaxPagesPerGroup=5000, ConfigFilePath
internal/models/dto/sync.goRequest and response DTOs (SyncAddRequest/Response, SyncRemoveRequest/Response)
internal/config/config.goJSON config parsing and validation rules for entitlement configuration
internal/config/job_settings.goParses and validates Cloud Run Job runtime environment variables (JOB_TYPE, DRY_RUN, etc.)
internal/adapters/discoveryengine/adapter.goMost complex adapter — see Known Constraints below
internal/adapters/cloudidentity/adapter.goCloud Identity Admin SDK adapter implementation
internal/adapters/resourcemanager/adapter.goCloud Resource Manager API v3 adapter implementation

Ports (interfaces)

// ports/gemini.go
type GeminiClient interface {
    FetchLicenseConfigIndex(ctx context.Context, billingAccountID string, directLaw bool) (models.LicenseConfigIndex, error)
    ListUserLicenses(ctx context.Context, projectID string, location models.Location, pageToken string) ([]models.UserLicense, string, error)
    BatchUpdateUserLicenses(ctx context.Context, projectID string, location models.Location, updates []models.LicenseUpdate) error
    FetchLicenseUsageStats(ctx context.Context, projectID string, location models.Location) (map[string]int64, error)
}

// ports/idp.go
type IdpClient interface {
    ListMembers(ctx context.Context, groupEmail, pageToken string) ([]models.Member, string, error)
    HasMember(ctx context.Context, groupEmail, userEmail string) (bool, error)
}

// ports/resourcemanager.go
type ResourceManagerClient interface {
    ResolveProjectNumber(ctx context.Context, projectID string) (string, error)
}

Workflows

Joiner (JOB_TYPE=joiner)

  1. FetchLicenseConfigIndex — builds a LicenseConfigIndex: map[LicenseConfigKey][]LicenseConfigEntry. Multiple active subscriptions for the same (SKU, ProjectNumber, Location) appear as distinct slice entries (multi-pool spill).
  2. ResolveProjectNumber — project IDs → numeric project numbers (Discovery Engine paths use numbers).
  3. Per project: page through all group members via ListMembers (with includeDerivedMembership=true), resolve the highest-precedence SKU per user via SKU.HasHigherPrecedenceThan.
  4. Group grant updates by LicenseConfigKey, chunk to MaxBatchSize=100, call BatchUpdateUserLicenses.
  5. On ErrLicensesExhausted: call FetchLicenseUsageStats for observability, retry remaining users in the batch 1-by-1 so no-op grants do not strand available seats, and carry ungranted remainder to the next subscription pool in the slice. After all pools exhausted, soft-fail remaining users (licenses_soft_failed in summary log). Exit 0.

Garbage Collection (JOB_TYPE=garbage_collection)

  1. Deduplicate locations from project config; iterate each location separately.
  2. Page through ListUserLicenses; skip State=REVOKED records.
  3. Per active license, evaluate shouldRevoke:
    • Staleness (only when staleness_threshold_days > 0): reference time = LastLoginTime → fallback AssignmentTime → fallback zero (treat as stale). Short-circuits the membership check.
    • Entitlement: HasMember for every group in the project config. First true → keep. All false → revoke.
  4. Collect revocation candidates per page, flush in MaxBatchSize chunks, then advance to the next page (bounds memory).

SKU precedence (highest → lowest)

SEARCH_AND_ASSISTANT (13) → ENTERPRISE (12) → SEARCH (11) → NOTEBOOK_LM (10) → AGENTSPACE_BUSINESS (9) → AGENTSPACE_STARTER (8) → FRONTLINE_WORKER (7) → FRONTLINE_STARTER (6) → ENTERPRISE_EMERGING (5) → EDU_PRO (4) → EDU (3) → EDU_PRO_EMERGING (2) → EDU_EMERGING (1)

Error handling model

ErrorClassificationBehavior
ErrLicensesExhaustedSoft failure (joiner only)Fetch usage stats, retry 1-by-1, spill to next pool, WARN log, exit 0
ErrInvalidMemberKeySoft failure (GC only)Skip user, WARN log with problematic_username, no revocation
ErrAPIRateLimitedHard failureReturn error, job exits 1
All other errorsHard failureReturn error, job exits 1

Never promote a soft-failure error to a hard failure. Never demote a hard failure to a soft one without explicit justification.

Configuration

Runtime config is read from /run/secrets/entitlements.json (mounted from Secret Manager):

{
  "billing_account_id": "ABCDE-12345-FGHIJ",
  "projects": {
    "customer-project-alpha": [
      {
        "subscription_tier": "SUBSCRIPTION_TIER_ENTERPRISE",
        "location": "global",
        "groups": ["eng-team@example.com"]
      }
    ]
  },
  "settings": {
    "staleness_threshold_days": 30
  }
}

Validation rules enforced at startup (internal/config/config.go):

  • billing_account_id must be non-empty
  • Project IDs must match ^[a-z][a-z0-9\-]{4,28}[a-z0-9]$
  • Each project must have at least one entry with a valid SKU, a valid location (global/us/eu), and at least one group email
  • staleness_threshold_days must be >= 0 (0 = disabled)

Environment variables (internal/config/job_settings.go):

VariableRequiredDefaultNotes
JOB_TYPEYes—joiner or garbage_collection
DRY_RUNNofalseSkips all write API calls when true
DIRECT_LAWNofalseWhen true, assignments map to admin-specified subscription IDs
GC_SKIP_GROUP_EVALNofalseWhen true, GC skips group membership checks and revokes based on staleness only
GC_GROUP_CACHING_MODENofalseWhen true, GC pre-fetches and caches group members in memory
CLOUD_RUN_TASK_INDEXNo0Injected by Cloud Run
CLOUD_RUN_TASK_COUNTNo1Injected by Cloud Run

Testing conventions

  • All tests are unit tests. go test ./... requires no credentials and no network.
  • Use testify/mock for port mocks. The three mock implementations live in internal/services/mocks_test.go (package services, not exported). Add new mock methods there rather than creating separate mock files.
  • Adapter tests inject testable interfaces via package-private newWith* constructors (e.g., cloudidentity.newWithMembers, discoveryengine.newWithClient). Follow this pattern for any new adapter.
  • Service tests are white-box (same package, package services). Use table-driven tests with t.Run sub-tests.
  • Config tests write fixture JSON to t.TempDir() — never write to the module root.
  • Do not add integration tests or tests that require Google Cloud credentials.

Known constraints and non-obvious decisions

Revoke field mask omits license_config: BatchUpdateUserLicenses for REVOKE sends only ["license_assignment_state"] in the update mask. Including license_config alongside NO_LICENSE state triggers a known API bug ("subscription reaches the limit"). Do not change this without re-testing against the live API.

Discovery Engine gRPC client caching uses double-checked locking: The discoveryengine adapter lazily creates one gRPC client per location using a sync.Mutex. The lock is released before the blocking dial, then re-acquired before writing the cache. A post-write check guards against concurrent winners. Do not simplify this without understanding the race.

Project sharding is deterministic: main.go sorts project map keys with slices.SortedFunc before applying modulo arithmetic. This ensures each project is processed by exactly one task instance. Any change to the sharding logic must preserve determinism across all concurrent task instances.

LicenseConfigIndex maps to a slice, not a single entry: A billing account can have multiple active subscriptions for the same (SKU, ProjectNumber, Location). The slice preserves all pools in order; the joiner iterates them to spill ungranted users from an exhausted pool into the next one. Never collapse this to a single entry.

MaxPagesPerGroup=5000 is a safety net, not a hard error: When the limit is hit, a WARN is logged and processing continues with partial results. This applies to both collectGroupMembers (joiner) and the license listing loop (GC). Partial results are always preferred over a full job failure for a scheduled reconciliation job.

DTOs carry vestigial HTTP tags: dto.SyncAddRequest and dto.SyncRemoveRequest have json struct tags referencing POST /sync/add and POST /sync/remove. These are from an earlier HTTP server design. The structs are constructed directly in main.go; no HTTP deserialization occurs. Do not add an HTTP server without re-evaluating the entire auth model.

PII policy: User email addresses must not appear in log output at INFO level or higher. The sole exception is the problematic_username field in the GC ErrInvalidMemberKey warning — it is deliberate and logged to help operators diagnose malformed emails stored in Discovery Engine.

GROUP-typed members are discarded in the joiner: ListMembers is called with includeDerivedMembership=true, which causes the Admin SDK to return flattened leaf members. Any Member whose Type != MemberTypeUser is skipped. Do not attempt to recurse into nested groups manually.

External API surface

The service is a client of three Google Cloud APIs. It exposes no server endpoints.

APISDKMethods used
Cloud Identity Admin (admin/directory/v1)REST via google.golang.org/apimembers.list (paginated, includeDerivedMembership=true), members.hasMember
Discovery Engine gRPC SDKcloud.google.com/go/discoveryengine/apiv1ListUserLicenses (iterator), BatchUpdateUserLicenses (LRO, adapter waits)
Discovery Engine REST v1alphaREST via google.golang.org/apibillingAccounts.billingAccountLicenseConfigs.list, projects.locations.userStores.licenseConfigsUsageStats.list
Cloud Resource Manager v3REST via google.golang.org/apiprojects.get

Non-global Discovery Engine gRPC calls use regional endpoints:

  • us → us-discoveryengine.googleapis.com:443
  • eu → eu-discoveryengine.googleapis.com:443
  • global → default endpoint

IAM requirements

The Cloud Run Job service account needs:

  • roles/discoveryengine.admin — list and update user licenses
  • roles/cloudidentity.groups.viewer — enumerate group members and check membership
  • roles/secretmanager.secretAccessor — read the entitlement config volume mount
  • roles/billing.viewer — read billing account license configs

OAuth scopes used:

  • https://www.googleapis.com/auth/cloud-platform
  • https://www.googleapis.com/auth/admin.directory.group.member.readonly

Logging

All logs are structured JSON emitted to stdout via log/slog (slog.NewJSONHandler). Every log line automatically carries workflow and task_index (set once in main.go step 4). Retrieve the logger in service/adapter code via middleware.LoggerFromContext(ctx) — never call slog.Default() directly from library code.

Required fields on summary log lines: duration_ms, workflow-specific counts (licenses_granted, licenses_revoked, licenses_soft_failed, groups_processed, users_evaluated), dry_run.

Available Subagents & Delegation

When working on complex tasks in this repository, you can delegate work to specialized subagents using invoke_subagent.

Built-in Subagents

SubagentCapabilitiesBest Used For
researchRead-only codebase exploration, file reading, and web searchRunning broad codebase surveys, searching documentation, or investigating multi-package patterns without cluttering the primary conversation context.
selfFull inheritance of parent agent's configuration, read/write/execute tools, and modelRunning independent implementation tasks, refactoring isolated adapters, or executing comprehensive test suites in a separate conversation context.
owlMulti-agent orchestrator with deep strategic planning and verificationSolving complex architectural tasks, large-scale refactoring, or difficult bugs requiring multi-perspective analysis and rigorous verification.

Custom Subagents

You can also define custom subagents using define_subagent and invoke them with invoke_subagent. Subagent workspaces can be configured as:

  • inherit: Uses the same workspace as the parent agent (default).
  • branch: Creates an isolated workspace branched or cloned from the parent.
  • share: Creates a new workspace sharing the underlying repository directory (similar to a git worktree) for independent branching without storage duplication.

Delegation Guidelines for this Repository

  • Mandatory TDD Review: When delegating any task that involves modifying code or architecture, explicitly instruct the invoked subagent or skill to read docs/TDD.md before making any changes.
  • Research & Exploration: For tasks requiring exploration across multiple adapters (discoveryengine, cloudidentity, resourcemanager), delegate investigation to a research subagent.
  • Isolated Adapter Refactoring: When modifying an individual adapter or adding a new port/adapter implementation, delegate to a self subagent in a branch or share workspace to keep changes isolated and test them cleanly before merging back.
  • Direct Implementation: For focused, single-package edits (e.g., updating a sentinel error in models/errors.go or modifying a service test), perform the work directly in the main conversation.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.