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

gas-best-practices

Skill4 starsChanged 4 months agoMITView on GitHub

Google Apps Script best practices for production web apps and automation — project layout with clasp, Spreadsheet/Drive ops, LockService for concurrency, ScriptCache, web app RPC pattern with Thai error messages, PDF generation with placeholders, schema migrations, data-integrity guards for overwrite/bulk-delete protection, OAuth scopes, time-driven triggers, onFormSubmit, UrlFetchApp / LINE Messaging API, email quotas, deployment versioning (/dev vs /exec), and 6-minute limit workarounds. Use whenever working with .gs/.js files in clasp projects, when appsscript.json or .clasp.json exists, when code uses SpreadsheetApp / DriveApp / HtmlService / UrlFetchApp / doGet / doPost / onEdit / google.script.run, or when the user mentions Google Apps Script, GAS, clasp, Apps Script — including Thai phrasing such as "แอปสคริปต์", "สคริปต์ชีต", "ทำระบบด้วย Google Sheet", "ส่งเมลจากชีต", "แจ้งเตือน LINE จากชีต", or automating Google Sheets/Forms/Drive in any way.

  • In this repositoryOne other file it gives its agents.

The file

Files
SKILL.md

Google Apps Script — Best Practices

ใช้กฎเหล่านี้เมื่อทำงานกับ Google Apps Script (ตรวจสอบจาก .clasp.json, appsscript.json, ไฟล์ .gs, หรือผู้ใช้พูดถึง "Apps Script" / "clasp")

วิธีอ่าน

แต่ละไฟล์ใน rules/ มีโครงสร้าง:

  • Rule — กฎข้อเดียวสั้น ๆ
  • Why — ทำไม (มักเป็น bug จริงที่เคยเจอ)
  • ✗ Bad — โค้ดที่ทำให้พัง
  • ✓ Good — แม่แบบที่ถูก
  • Edge cases — ข้อยกเว้น ถ้ามี

ไฟล์ยาว (spreadsheet-ops, pdf-generation, external-frontend, drive-ops) มีสารบัญต้นไฟล์ — ข้ามไป rule ที่ตรงกับงานได้เลย

เมื่อ trigger

ใช้ rule ตามบริบทของ task (อ่านได้หลายไฟล์ถ้างานคาบเกี่ยว):

ผู้ใช้กำลังทำอ่านกฎเหล่านี้
Setup โปรเจ็คใหม่, จัดไฟล์rules/project-structure.md
Read/write Sheet, batch updaterules/spreadsheet-ops.md
ทำ web app ที่เรียกผ่าน google.script.runrules/web-app-rpc.md
HTML head, viewport, partial include, template syntaxrules/htmlservice-frontend.md
ใช้กล้อง/PWA/SW — frontend แยกไป GitHub Pagesrules/external-frontend.md
สร้าง PDF จาก templaterules/pdf-generation.md
จัดการ folder/file ใน Driverules/drive-ops.md
operation ที่ user หลายคนอาจชนกันrules/lock-service.md
query ที่ซ้ำบ่อยrules/cache-service.md
เขียนทับข้อมูลจริง, กันลบยกชุด, ตรวจข้อมูลหลังแก้rules/data-integrity.md
custom menu ใน Sheetrules/onopen-menu.md
dropdown ปี/เดือน/enum ที่ไม่ฟิกตายตัวrules/dynamic-dropdowns.md
auth, role check, OAuth scoperules/security.md
เพิ่มตาราง/คอลัมน์ใหม่ในระบบที่ ship แล้วrules/schema-migrations.md
handle error + user-facing messagerules/error-handling.md
debug, log, execution historyrules/testing-debugging.md
log boundary RPC client+server, mask sensitive, debug ฝั่ง userrules/logging-boundaries.md
ตั้งงานอัตโนมัติรายวัน/รายชั่วโมง, onEdit, onFormSubmitrules/triggers.md
เรียก API ภายนอก, LINE Messaging API, webhookrules/urlfetch-external-api.md
deploy แล้วเว็บไม่อัพเดท, /dev vs /exec, rollback, .claspignorerules/deployment-versioning.md
งาน batch ใหญ่ / เกิน 6-minute limitrules/long-running-jobs.md
ส่งอีเมลแจ้งเตือน, quota email, แจ้ง admin เมื่อ errorrules/email-notifications.md
เก็บ API key / config — Properties vs Config sheetrules/properties-service.md

หลักการรวม

  1. ทุก server function ที่ client เรียกได้ ต้องคืน Result<T> envelope — ไม่ throw ออกไป client เห็น stack trace
  2. Sheet อ่านครั้งเดียวด้วย getDataRange().getValues() — เขียนแบบ batch ถ้าไม่มี merged cells, เขียนทีละเซลล์เฉพาะโซนที่มี merge
  3. Lazy resource creation — folder ID, sheet, column สร้างให้อัตโนมัติตอน startup เก็บไว้ใน Config sheet
  4. Cache user lookup + ผลคำนวณซ้ำ ผ่าน CacheService.getScriptCache() พร้อม invalidate
  5. LockService รอบ mutation ที่ชนได้ เช่น generate PDF, delete/append row — พร้อม try/finally { releaseLock() }
  6. เก็บค่าที่ admin ต้องแก้ได้ใน Config sheet, เก็บ secret ใน Script Properties — ไม่ hardcode
  7. Error message ภาษาไทยที่ user เข้าใจ + Logger.log ภาษาอังกฤษสำหรับ developer
  8. Log ทุก RPC boundary — console.log ฝั่ง client, Logger.log ฝั่ง server (entry + exit)
  9. บังคับ text format ให้ฟิลด์เลขที่มี leading zero — เบอร์โทร, เลขบัตร, รหัส (setNumberFormat('@') + apostrophe)
  10. คำนวณค่าสำคัญซ้ำฝั่ง server — ไม่เชื่อเปอร์เซ็นต์/ยอดรวมที่ client ส่งมา

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.