sn-app-template
AGENTS.md1 starsChanged 23 days agoMITView on GitHub
Instructions for AI coding agents (Claude Code, Codex, Pi, Copilot, Cursor, …) working in this repository. Human-facing docs are in README.md; Claude Code–specific notes are in CLAUDE.md. A ServiceNow scoped application built entirely from source with the ServiceNow SDK (now-sdk, Fluent). Three source layers, one deploy: Request flow: React page → fetch() with X-UserToken: window.g_ck → Scripted REST API (/api/x_snc_example/example_api/items) → x_snc_example.AppService → GlideRecordSecure (table ACLs apply to the caller). Always use the project-local SDK (npx now-sdk / npm run…
- Reads credentials
- Commits and pushes
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,542 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 repository5 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- add-tableSkill
- deploy-and-verifySkill
- add-tableSkill
- deploy-and-verifySkill
The file
We split this AGENTS.md into the rules it gives an agent
10 rules. About 0 are common, 1 is distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 34
Always use the project-local SDK (npx now-sdk / npm run …), never a global now-sdk or npx @servicenow/sdk@latest: the docs and behaviour …
- Very specific: line 48
Run npx now-sdk <command> --help before using any subcommand flag for the first time.
- Very specific: line 63
Fluent files are declarative: Every top-level statement must be an SDK call or an export const x = SdkCall(...).
- Very specific: line 75
Put enforceAcl on every route: a route without it gets the platform default ACL, which overrides the API-level one.
- Distinctive: line 79
No build configs (webpack/vite) — the SDK bundles the client.
- Very specific: line 80
Secrets never go in source: Use Property({ type: 'password2' }) with a // @fluent-disable-sync comment and set the value on the instance.
- Very specific: line 89
Add a table: follow the add-table skill (.agents/skills/add-table/SKILL.md): Table() in src/fluent/tables/, four record ACLs, AppService …
- Very specific: line 91
Use the object form actions: { read: true } — it controls *cross-scope* access, so grant writes only when another scope needs them.
- Very specific: line 96
Add a REST route: add to the routes of src/fluent/rest-api/app-api.now.ts with its own $id, method, path ({param} for path params, read via …
- Very specific: line 110
Every step gets its own $id.
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 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.
Files
AGENTS.md — ServiceNow scoped app (now-sdk + Fluent)
Instructions for AI coding agents (Claude Code, Codex, Pi, Copilot, Cursor, …) working in this repository.
Human-facing docs are in README.md; Claude Code–specific notes are in CLAUDE.md.
What this is
A ServiceNow scoped application built entirely from source with the ServiceNow SDK (now-sdk, Fluent).
Three source layers, one deploy:
| Layer | Path | What it holds |
| Fluent metadata | src/fluent/**/*.now.ts | Tables, roles, ACLs, REST API, script include and UI page declarations, business rules, menus, demo data, ATF tests |
| Server logic | src/server/*.server.js | Script Include code (AppService), bundled with Now.include() |
| Client UI | src/client/** | A React UI page (BYOUI) bundled by the SDK: index.html → app.jsx → components/ + services/ |
Request flow: React page → fetch() with X-UserToken: window.g_ck → Scripted REST API (/api/x_snc_example/example_api/items)
→ x_snc_example.AppService → GlideRecordSecure (table ACLs apply to the caller).
Commands
npm ci # install exact dependency versions
npm run lint # ESLint (client, server, scripts)
npm test # node:test suite in tests/ (setup.mjs on a temporary copy)
npm run build # compile Fluent + bundle the UI (writes src/fluent/generated/keys.ts)
npm run build:ci # build --frozenKeys: fails if keys.ts is stale (CI uses this)
npm run deploy -- --auth <alias> # now-sdk install to a dev/test instance
npm run test:instance -- --auth <alias> # run the "Example App" ATF suite on the instance
npx now-sdk explain <topic> --format=raw # SDK docs for the installed version (see below)
npx now-sdk query <table> -q '<query>' -o json --auth <alias> # read live instance dataAlways use the project-local SDK (npx now-sdk / npm run …), never a global now-sdk or npx @servicenow/sdk@latest:
the docs and behaviour must match the pinned version in package.json.
Orient with now-sdk explain first
The SDK ships version-matched documentation (about 260 topics). Before writing or changing Fluent code, look it up instead of guessing property names:
npx now-sdk explain --list --format=raw # all topics
npx now-sdk explain <term> --list --peek --format=raw # search
npx now-sdk explain table --format=raw # read one (e.g. table, acl, restapi, uipage, test, keys-file)Run npx now-sdk <command> --help before using any subcommand flag for the first time. ServiceNow's official agent skill
for the SDK (now-sdk, from github.com/ServiceNow/sdk) teaches the same workflow; see README → "AI coding agents".
Rules
- Scope prefix everywhere. Tables, fields, roles, REST paths and UI page endpoints start with
x_snc_example(x_snc_example_item,x_snc_example_name,x_snc_example.user,x_snc_example_app.do). A new app runsnpm run setup -- --scope x_<vendor>_<app> --name "<Name>"once; never hand-edit the scope. - Never delete a
Table(),Record(),BusinessRule()or other record definition without asking the user. Removing it from source makes the next install delete it on the instance (tracked inkeys.ts). UseNow.del()/npx now-sdk explain now-del-guidewhen deletion is intended. The same applies tonpm run deploy -- --reinstall: it uninstalls the app first and deletes everything on the instance that is not in source, including the records in the app's tables. Never run it without the user's explicit approval for that instance; telling them is not enough. - Commit
src/fluent/generated/keys.ts. It maps everyNow.ID[...]key to a stable sys_id. Never edit it by hand, never rename an existingNow.IDkey (that creates a new record and orphans the old one). CI builds with--frozenKeys. - Fluent files are declarative. Every top-level statement must be an SDK call or an
export const x = SdkCall(...); plainconstdeclarations, string concatenation in properties and other statements fail the build. Use one string literal per property. - Script Includes keep their constants private. Wrap each
.server.jsfile in a function that returns the class, so the class is the only name the file declares (seeAppService.server.js):var AppService = (function() { var FP = 'x_snc_example_'; … return AppService; })();. Top-levelvarconstants may be shared with other Script Includes that run in the same transaction, so a second file declaringFPorMAX_NAMEcould change this one's values. Each file defines the constants it needs; call other Script Includes by API name:new x_snc_example.AppService(). - Data access goes through
GlideRecordSecurein anything reachable from REST or the UI, so ACLs apply to the caller. PlainGlideRecordbypasses ACLs; use it only where elevated access is intended and say why in a comment. - REST routes stay thin and delegate to
AppService, which validates input and returns{ status, body }. PutenforceAclon every route: a route without it gets the platform default ACL, which overrides the API-level one. - UI pages call REST with
fetch(); GlideAjax does not work in UI pages. SendX-UserToken: window.g_ckon every request.index.htmlkeeps<sdk:now-ux-globals>,class="-polaris"and the?uxpcb=$[UxFrameworkScriptables.getFlushTimestamp()]cache-buster on the script tag; no DOCTYPE; write$[AMP]for&in HTML text. Import CSS from JS; no CSS modules. No build configs (webpack/vite) — the SDK bundles the client. - Secrets never go in source. Use
Property({ type: 'password2' })with a// @fluent-disable-synccomment and set the value on the instance. No credentials in.env,.mcp.json, scripts or commit messages;now-sdk authkeeps credentials in the OS keychain. - Instances refuse other vendors' prefixes. An install of
x_<vendor>_…fails with "Unable to install third party application" unless<vendor>is the instance'sglide.appcreator.company.code. If the scope is still the template's default (package.jsonversion 1.x and nameexample-app), runnpm run setupbefore deploying.
Recipes (details: npx now-sdk explain <topic>)
- Add a table: follow the
add-tableskill (.agents/skills/add-table/SKILL.md):Table()insrc/fluent/tables/, four record ACLs,AppServicemethods, REST routes, an ATF test, then register the file insrc/fluent/index.now.ts. Use the object formactions: { read: true }— it controls cross-scope access, so grant writes only when another scope needs them. KeepallowWebServiceAccess: trueif the REST Table API must reach the table. - Add a Script Include: code in
src/server/<Name>.server.js(Class.create()inside a function wrapper, rule 5), declaration insrc/fluent/script-includes/withscript: Now.include('../../server/<Name>.server.js'),apiName: 'x_snc_example.<Name>',accessibleFrom: 'package_private'unless other scopes call it. - Add a REST route: add to the
routesofsrc/fluent/rest-api/app-api.now.tswith its own$id,method,path({param}for path params, read viarequest.pathParams), andenforceAcl: [exampleApiAcl]. - Add a UI page: an HTML entry in
src/client/(same head asindex.html), a JSX entry, and aUiPage({ endpoint: 'x_snc_example_<name>.do', html: imported, direct: true })insrc/fluent/ui-pages/. For record-centric lists and forms, the SDK'sui-page-guiderecommends@servicenow/react-components(NowRecordListConnected,RecordProvider); this template's page deliberately shows the Scripted REST +fetch()pattern. - Call a platform API you have not used before (a new
GlideRecordmethod,GlideDateTime,RESTMessageV2, …): the app runs with runtime access tracking enforcing (now.config.json→accessControls), so the call fails withAccess to <API> from scope x_snc_example not alloweduntil it is declared. Add aCrossScopePrivilege(targetType: 'scriptable',operation: 'execute',targetScope: 'global',targetName: '<API>') tosrc/fluent/privileges/cross-scope-privileges.now.ts, then deploy and run the ATF suite. The app's own tables never need a privilege. - Add an ATF test:
Test()insrc/fluent/tests/and add it to theTestSuitethere. Server steps (recordInsert,recordValidation,runServerSideScript,createUserwithimpersonate, …) need no REST auth profile. Every step gets its own$id. ATF rolls back the data a test creates.
Done means
npm run lint,npm testandnpm run buildpass, andkeys.tschanges are committed with the code that caused them.- For behaviour changes: deployed to a dev instance and
npm run test:instancepasses; new behaviour has an ATF test. - Docs that describe the change (
README.md, this file,TROUBLESHOOTING.md,CHANGELOG.mdunder[Unreleased]) are updated in the same change.
Versioning and releases (template repository only)
package.json version is the single source of truth (it also becomes the app's sys_app version). Releases are
vX.Y.Z tags created with gh release create; the release workflow checks that the tag matches package.json.
See RELEASING.md. Derived apps reset the version to 0.1.0 in npm run setup.
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
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.

