agentleFS
kpcrmv4kpcrmv4/gas-best-practices/AGENTS.md

gas-best-practices

AGENTS.md4 starsChanged 4 months agoMITView on GitHub

Universal entry point for any AI coding assistant. Read this file first when working with Google Apps Script code. Apply these rules when you detect any of: - Files with .gs extension - appsscript.json in project root - .clasp.json in project root - User mentions "Google Apps Script", "GAS", or "clasp" (or Thai: "แอปสคริปต์", "สคริปต์ชีต") - Code uses SpreadsheetApp, DriveApp, HtmlService, UrlFetchApp, or other GAS services - doGet / doPost / onEdit / onFormSubmit handlers, or time-driven triggers - google.script.run…

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,736 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repositoryOne other file it gives its agents.

The file

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

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

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

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

    When working on GAS code, consult rules/<topic>.md based on the task:

    line 19
  2. Distinctive:

    When suggesting GAS code:

    line 62
  3. Distinctive:

    Use Thai for user-facing error messages, English for log messages

    line 65
  4. Very specific:

    Default to let/const, ES6+ (V8 runtime is standard now)

    line 66

≈ “Common” is an estimate: at least 1 in 5 of the 16,597 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

AGENTS.md — gas-best-practices

Universal entry point for any AI coding assistant. Read this file first when working with Google Apps Script code.

Trigger conditions

Apply these rules when you detect any of:

  • Files with .gs extension
  • appsscript.json in project root
  • .clasp.json in project root
  • User mentions "Google Apps Script", "GAS", or "clasp" (or Thai: "แอปสคริปต์", "สคริปต์ชีต")
  • Code uses SpreadsheetApp, DriveApp, HtmlService, UrlFetchApp, or other GAS services
  • doGet / doPost / onEdit / onFormSubmit handlers, or time-driven triggers
  • google.script.run calls in HTML files

How to use

When working on GAS code, consult rules/<topic>.md based on the task:

TaskRead
New project setup, file organizationrules/project-structure.md
Read/write Sheet, batch operations, merged cellsrules/spreadsheet-ops.md
Web app with google.script.runrules/web-app-rpc.md
HTML head, viewport, partial includesrules/htmlservice-frontend.md
External frontend (GitHub Pages) + GAS APIrules/external-frontend.md
PDF generation from templaterules/pdf-generation.md
Drive folders, file sharing, image previewrules/drive-ops.md
Concurrent operationsrules/lock-service.md
Caching queriesrules/cache-service.md
Overwrite protection, bulk-delete guard, post-edit verificationrules/data-integrity.md
Year/month/enum dropdownsrules/dynamic-dropdowns.md
Auth, role check, OAuth scopesrules/security.md
Adding tables/columns to live systemrules/schema-migrations.md
Error handling, Thai user messagesrules/error-handling.md
Custom Sheet menusrules/onopen-menu.md
Debug, log, execution historyrules/testing-debugging.md
Log at RPC boundaries (client + server)rules/logging-boundaries.md
Time-driven / onEdit / onFormSubmit triggersrules/triggers.md
External APIs, LINE Messaging API, webhooksrules/urlfetch-external-api.md
Deploy not updating, /dev vs /exec, rollback, .claspignorerules/deployment-versioning.md
Batch jobs beyond the 6-minute limitrules/long-running-jobs.md
Email notifications, quotas, admin error alertsrules/email-notifications.md
API keys / config — Properties vs Config sheetrules/properties-service.md

Core principles (cross-cutting)

  1. Every server function callable from client returns a Result<T> envelope — never throw to client
  2. Read sheets once with getDataRange().getValues() — batch-write when no merged cells; write cell-by-cell only in merged zones
  3. Lazy resource creation — folder IDs, sheets, columns auto-create on startup, store in Config sheet
  4. Cache user lookups + computed results via CacheService.getScriptCache() with explicit invalidation
  5. Wrap concurrent mutations in LockService.getScriptLock() with try/finally { releaseLock() }
  6. Admin-editable values go in the Config sheet, secrets go in Script Properties — never hardcoded
  7. Thai user-facing error messages + English Logger.log for developers
  8. Log every RPC boundary — console.log in client, Logger.log in server (entry + exit)
  9. Force text format for numeric fields with leading zeros — phone, ID card, postal code (setNumberFormat('@') + apostrophe prefix)
  10. Recompute critical values server-side — never trust client-calculated percentages/totals

Output format for the AI

When suggesting GAS code:

  • Reference the rule number/file (e.g., "per rules/spreadsheet-ops.md Rule #2")
  • Show ✗ Bad and ✓ Good patterns when correcting common mistakes
  • Use Thai for user-facing error messages, English for log messages
  • Default to let/const, ES6+ (V8 runtime is standard now)
  • Suggest LockService for any function that mutates shared state

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.