deliberate-lab / utils
AGENTS.md97 starsChanged 57 days agoApache-2.0View on GitHub
Shared TypeScript types, validation functions, and utilities consumed by both frontend and functions. Changes here can cause cascading breakage — always rebuild and run tests before committing. See also: root AGENTS.md for monorepo-wide conventions. From the repository root: utils must be rebuilt before frontend or functions pick up changes. During local dev, run_locally.sh starts a watcher automatically. [!TIP] If you change any exported type in utils, you must also run npm run update-schemas from the repo root to regenerate docs/assets/api/schemas.json…
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,774 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 repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- frontend/AGENTS.mdAGENTS.md
- functions/AGENTS.mdAGENTS.md
- scripts/AGENTS.mdAGENTS.md
- eval-prSkill
- ghSkill
- pr-test-planSkill
- retrospectiveSkill
- workspace-overviewSkill
- workspace-syncSkill
The file
We split this AGENTS.md into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is 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.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 51
Not every stage type has all of these files — only the ones it needs.
- Very specific: line 94
After any type change in utils, remember to:
≈ “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 — @deliberation-lab/utils
Shared TypeScript types, validation functions, and utilities consumed by
both frontend and functions. Changes here can cause cascading breakage —
always rebuild and run tests before committing.
See also: root AGENTS.md for monorepo-wide conventions.
Build & test
From the repository root:
npm run build -w utils # Build with tsup (outputs to dist/)
npm test -w utils # Run Jest tests (colocated with source)
npm run typecheck -w utilsutils must be rebuilt before frontend or functions pick up changes.
During local dev, run_locally.sh starts a watcher automatically.
[!TIP] If you change any exported type in
utils, you must also runnpm run update-schemasfrom the repo root to regeneratedocs/assets/api/schemas.jsonandscripts/deliberate_lab/types.py. CI will fail the schema sync check if these are out of date.
File naming conventions
General entities
| Pattern | Purpose |
<entity>.ts | Type definitions and interfaces |
<entity>.validation.ts | Runtime validation functions |
<entity>.test.ts | Tests (colocated with source) |
Stage files (src/stages/)
Each stage type follows a consistent naming pattern:
| Pattern | Purpose |
<stage_type>_stage.ts | Stage config types, participant answer types, public data types |
<stage_type>_stage.validation.ts | Validation for stage configs and answers |
<stage_type>_stage.manager.ts | BaseStageHandler subclass for agent actions and prompt display |
<stage_type>_stage.prompts.ts | Prompt construction helpers for LLM agents |
<stage_type>_stage.utils.ts | Stage-specific utility functions |
<stage_type>_stage.test.ts | Tests |
Not every stage type has all of these files — only the ones it needs. For example:
- Minimal (
tos_stage):.ts,.validation.ts,.manager.ts,.prompts.ts— just the basics - Full (
survey_stage):.ts,.validation.ts,.manager.ts,.prompts.ts,.prompts.test.ts— includes prompt tests
How to add a new stage type
- Define the
StageKind— add an entry to theStageKindenum insrc/stages/stage.ts - Create stage files — add files in
src/stages/following the naming pattern above (at minimum<stage_type>_stage.tsand<stage_type>_stage.validation.ts) - Add types to the unions — update the
StageConfig,StageParticipantAnswer, andStagePublicDataunion types insrc/stages/stage.ts - Add transfer migration entry — update
STAGE_KIND_REQUIRES_TRANSFER_MIGRATIONinsrc/stages/stage.ts - Register the handler — add a handler instance in
src/stages/stage.handler.ts(or import the defaultBaseStageHandler) - Export JSON schema — register the new types in
src/export-schemas.tsso consumers can validate JSON payloads - Update sibling workspaces — implement backend logic in
functions/src/stages/and UI components infrontend/src/components/stages/; register any new endpoints infunctions/src/index.ts
How to modify an existing stage
Modifying an existing stage is the most common type of change. The files you need to touch depend on what you're changing:
| What you're changing | Files to update |
| Stage config options | utils/src/stages/<stage>_stage.ts (types), <stage>_stage.validation.ts (defaults), and the frontend config editor in frontend/src/components/stages/<stage>_config.ts |
| Participant answer shape | utils/src/stages/<stage>_stage.ts (answer type + union in stage.ts), <stage>_stage.validation.ts, and the frontend answer component |
| Public stage data | Same as above, plus any trigger or backend logic in functions/src/stages/ that reads/writes public data |
| LLM agent behavior | utils/src/stages/<stage>_stage.manager.ts and/or <stage>_stage.prompts.ts |
| Backend logic only | functions/src/stages/<stage>.utils.ts and/or <stage>.endpoints.ts |
| UI only | frontend/src/components/stages/<stage>_*.ts and SCSS files |
After any type change in utils, remember to:
- Rebuild:
npm run build -w utils - Regenerate schemas:
npm run update-schemas - Run tests:
npm test -w utils
Variables system
variables.ts, variables.utils.ts, and variables.template.ts implement
a template variable system used in prompts and stage descriptions.
variables.schema.utils.ts handles schema-level variable processing.
Variables are defined as VariableDefinition objects (name, description,
default value) and referenced in text using double-brace syntax (e.g.,
{{variable_name}}). At runtime, resolveTemplateVariables replaces
placeholders with their resolved values.
Key files
| File | Role |
src/index.ts | Public API barrel file — all exports |
src/stages/stage.ts | StageKind enum, base types, union types |
src/stages/stage.handler.ts | BaseStageHandler class for stage actions |
src/export-schemas.ts | JSON schema generation for the docs site |
src/structured_prompt.ts | Structured prompt types (mediator + participant) |
src/structured_output.ts | Structured output parsing |
Common pitfalls
- Forgetting to update union types — when adding a new stage, you must
add it to the
StageConfig,StageParticipantAnswer, andStagePublicDataunions insrc/stages/stage.ts.
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.

