deer-workflow
AGENTS.md526 starsChanged 4 months agoMITView on GitHub
deer-workflow is an open-source reimplementation of the Dynamic Workflow idea. The canonical repository is https://github.com/deerwork-ai/deer-workflow. The runtime keeps deterministic orchestration in TypeScript and delegates semantic work to replaceable Agent runtimes. The default Agent runtime is Codex CLI. Do not copy private or proprietary implementations. Reproduce public behavior through clean-room interfaces, tests, and documentation. - Use Bun for package management, scripts, tests, and process execution. - Use strict TypeScript. - Publish the package as @deerwork-ai/deer-workflow while keeping the CLI command named…
- 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 35,337 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.
- CLAUDE.mdCLAUDE.md
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
60 rules. About 1 is common, 16 are distinctive, and 43 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈16
Distinctive · estimate
This author's own choices. Worth a look.
43
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 7
Do not copy private or proprietary implementations.
- Distinctive: line 11
Use Bun for package management, scripts, tests, and process execution.
- Very specific: line 15
Document bun install --global @deerwork-ai/deer-workflow as the primary global CLI installation.
- Very specific: line 18
Never describe bare bun install as a global installation.
- Very specific: line 20
Keep deer-workflow run as the Workflow execution command.
- Very specific: line 21
Keep deer-workflow create as the Agent-backed generator.
- Very specific: line 25
Keep Codex as the default CLI Agent runtime.
- Distinctive: line 32
Run the create Agent with a read-only sandbox and allow Codex execution outside a Git repository.
- Very specific: line 39
Keep the final result on stdout in both default modes.
- Very specific: line 46
Use the tsconfig.json path aliases to exercise public @deerwork-ai/deer-workflow/* imports locally.
- Very specific: line 48
Keep runnable examples under examples/<example-name>/, with types in types.ts, the Workflow entry point in workflow.ts, and reciprocal …
- Very specific: line 53
Keep the CLI entry point at src/cli.ts.
- Very specific: line 54
Keep all Agent type aliases and interfaces in src/agents/types.ts.
- Very specific: line 55
Keep the vendor-neutral Agent binder in src/agents/agent.ts.
- Very specific: line 56
Keep Codex-specific process handling in src/agents/codex-agent.ts.
- Very specific: line 57
Keep Pi-specific process, structured-output, and tool-policy handling in src/agents/pi-agent.ts.
- Very specific: line 63
Keep all Flow type aliases and interfaces in src/flow/types.ts.
- Very specific: line 64
Keep deterministic orchestration primitives in src/flow/.
- Very specific: line 66
Keep all Logging type aliases and interfaces in src/logging/types.ts.
- Very specific: line 67
Keep Logging implementations in src/logging/ and tests in tests/logging/.
- Very specific: line 69
Keep all Workflow Event type aliases and interfaces in src/events/types.ts.
- Very specific: line 70
Keep Event implementations in src/events/ and tests in tests/events/.
- Very specific: line 71
Keep all Runner type aliases and interfaces in src/runner/types.ts.
- Very specific: line 72
Keep Runner implementations in src/runner/ and tests in tests/runner/.
- Very specific: line 73
Write log() messages directly to stderr when no Log Sink is active.
- Distinctive: line 78
Keep Workflow arguments and results out of events by default.
- Distinctive: line 97
Keep Workflow nesting limited to one level unless the public contract changes.
- Very specific: line 126
When a Workflow module exports both default and run, prefer default.
- Very specific: line 142
Keep CLI result serialization stable: undefined writes nothing, strings are written as text, and every other result is serialized with …
- Very specific: line 160
Run bun run check before handing off a change.
- Very specific: line 179
Keep script names stable. When adding or changing a script, update this table and the corresponding table in both language variants of …
- Very specific: line 184
Use ESLint Flat Config from eslint.config.js.
- Distinctive: line 185
Use Prettier as the only code formatter.
- Very specific: line 186
Keep .husky/pre-commit limited to lint-staged followed by the project-wide typecheck.
- Very specific: line 188
Keep staged-file commands in lint-staged.config.js.
- Distinctive: line 205
Keep the generic Agent interface independent from Codex CLI flags whenever possible.
- Very specific: line 222
Treat the user's instruction publish as explicit authorization to execute the complete release process end to end, including preparing and …
- Very specific: line 230
Start every release by creating or updating the root CHANGELOG.md.
- Distinctive: line 235
Update the English and Simplified Chinese installation and API documentation whenever a release changes package requirements, commands, or …
- Very specific: line 244
Before the next release, add and then maintain a package.json files allowlist containing the runtime src/ tree and bundled …
- Very specific: line 248
Run bun run check after the changelog, documentation, and version changes.
- Very specific: line 257
Commit the version, changelog, documentation, and packaging changes together as release: prepare v<version>, then push main before …
- Very specific: line 263
Verify the exact version and latest dist-tag with npm view, then install that exact registry version in a fresh temporary project and rerun …
- Very specific: line 266
Create and push the annotated v<version> Git tag only after the registry verification succeeds.
- Distinctive: line 274
If publication fails before npm accepts the version, fix the cause, rerun all checks, rebuild the tarball, and retry.
- Distinctive: line 282
Default to ephemeral Codex sessions.
- Very specific: line 283
Do not enable danger-full-access implicitly.
- Common: line 284
Never log credentials or copy the entire parent environment into diagnostics.
- Very specific: line 285
Create schema and result files in a unique temporary directory and remove it in finally.
- Very specific: line 291
Keep all test files under the top-level tests/ directory and mirror the relevant src/ structure where practical.
- Distinctive: line 293
Use a local stub process to test argument construction, stdin handling, structured output, and failures.
- Distinctive: line 294
Add integration tests that invoke Codex only behind an explicit environment flag.
- Distinctive: line 295
Test both text output and JSON Schema output for every Agent adapter.
- Distinctive: line 299
Prefer small modules with explicit public types.
- Very specific: line 301
Keep English documentation at the canonical *.md path and place Simplified Chinese translations beside it as *.zh-CN.md.
- Very specific: line 304
Keep both root README files focused on project positioning, CLI trial commands, examples, and documentation links.
- Very specific: line 317
Add Co-authored-by: Codex <codex@openai.com> to commits containing changes materially authored with Codex, unless the user requests …
- Distinctive: line 319
Document every public API with TypeDoc comments, including parameters, return values, generics, thrown errors, and non-obvious runtime …
- Very specific: line 321
Avoid any; use unknown at external boundaries and narrow it.
- Distinctive: line 323
Add comments only when they explain a non-obvious constraint.
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 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
deer-workflow
deer-workflow is an open-source reimplementation of the Dynamic Workflow idea. The canonical repository is https://github.com/deerwork-ai/deer-workflow.
The runtime keeps deterministic orchestration in TypeScript and delegates semantic work to replaceable Agent runtimes. The default Agent runtime is Codex CLI.
Do not copy private or proprietary implementations. Reproduce public behavior through clean-room interfaces, tests, and documentation.
Runtime
- Use Bun for package management, scripts, tests, and process execution.
- Use strict TypeScript.
- Publish the package as
@deerwork-ai/deer-workflowwhile keeping the CLI command nameddeer-workflow. - Document
bun install --global @deerwork-ai/deer-workflowas the primary global CLI installation. Use the GitHub installation only when explicitly describing an unreleased repository snapshot. - Never describe bare
bun installas a global installation; in this repository it installs local development dependencies and Git hooks. - Keep
deer-workflow runas the Workflow execution command. - Keep
deer-workflow createas the Agent-backed generator. It accepts a user prompt from arguments or stdin, explicitly directs the selected Agent to the bundledskills/workflow-creator/SKILL.md, appends the user prompt, and writes only generated source to stdout. - Keep Codex as the default CLI Agent runtime. Let the
createcommand select Codex, Claude Code, or Pi with--agent codex|claude|pi. Document the option and its Codex default in top-level andcreatehelp. - Resolve the bundled Skill relative to the
installed CLI module so
createworks from a global GitHub or npm installation. Do not depend on the caller having installedworkflow-creatorin a Codex Skill search directory. - Run the create Agent with a read-only sandbox and allow Codex execution outside a Git repository. Strip one enclosing Markdown source fence before writing stdout so shell redirection produces a runnable source file. Before starting the Agent, write a valid source comment naming the selected Agent to stdout so a redirected target is immediately non-empty.
- Route CLI Workflow events to stderr as JSON Lines when stderr is redirected.
In an interactive terminal, drive the run TUI from typed events instead.
Keep the final result on stdout in both default modes. With
run --printorrun -p, disable the TUI, write one JSON event per stdout line, reserve stderr for CLI diagnostics, and suppress the separate final result. Present Print Mode as the recommended interface for servers and automation. - Resolve optional run input in this order:
--input,--input-file, then non-empty stdin. Reject simultaneous--inputand--input-file; explicit options take precedence over stdin. - Use the
tsconfig.jsonpath aliases to exercise public@deerwork-ai/deer-workflow/*imports locally. - Keep runnable examples under
examples/<example-name>/, with types intypes.ts, the Workflow entry point inworkflow.ts, and reciprocal English and Simplified Chinese README files. - Link relevant examples from both language variants of the root README, Getting Started guide, and API reference.
- Keep the CLI entry point at
src/cli.ts. - Keep all Agent type aliases and interfaces in
src/agents/types.ts. - Keep the vendor-neutral Agent binder in
src/agents/agent.ts. - Keep Codex-specific process handling in
src/agents/codex-agent.ts. - Keep Pi-specific process, structured-output, and tool-policy handling in
src/agents/pi-agent.ts. - Detect a missing Codex executable before creating temporary files or starting a process. The error must include official CLI installation steps and state that Codex CLI and Codex Desktop are separate installations.
- Re-export the default
agent()function fromsrc/agents/index.ts. - Keep all Flow type aliases and interfaces in
src/flow/types.ts. - Keep deterministic orchestration primitives in
src/flow/. - Mirror flow tests under
tests/flow/. - Keep all Logging type aliases and interfaces in
src/logging/types.ts. - Keep Logging implementations in
src/logging/and tests intests/logging/. - Keep all Workflow Event type aliases and interfaces in
src/events/types.ts. - Keep Event implementations in
src/events/and tests intests/events/. - Keep all Runner type aliases and interfaces in
src/runner/types.ts. - Keep Runner implementations in
src/runner/and tests intests/runner/. - Write
log()messages directly to stderr when no Log Sink is active. - Emit Runner events as JSON Lines. A standalone Runner's default
logWritercallsconsole.logonce per event, while the CLI sends redirected events to stderr and uses typed events for its interactive TUI so stdout remains reserved for the final result. - Keep Workflow arguments and results out of events by default. Event payloads must remain JSON-safe and suitable for external process boundaries.
- Workflow modules export a handler as either
defaultorrun. - Workflow Creator output also exports a pure-literal
metaobject with a kebab-casename, one-linedescription, and uniquephaseswhose titles exactly matchphase()calls, plus JSON-safeexampleArgswhose keys match Handlerargsproperties. The Runner validates this export and emitsworkflow:meta; the interactive CLI uses its phase plan in the run TUI, andcreateuses the example args in its next command. - The interactive run TUI identifies the Workflow name, module path, and working directory. It displays metadata phases beside Markdown logs and uses a looping highlight sweep only on the active phase.
- Name the Handler's first caller-input parameter
args. It is an ordinary function parameter, not a JavaScript global. - Workflow modules import APIs explicitly from
@deerwork-ai/deer-workflowor its subpaths. The Runner injects async-local lifecycle, phase, event, and logging context; it does not install API functions onglobalThisor pass them as a destructured handler argument. - Resolve nested Workflow paths relative to their parent module.
- Keep Workflow nesting limited to one level unless the public contract changes.
Flow contract
parallel()starts every lazy task immediately, waits for all tasks to settle, and preserves input order. A synchronous throw or rejected Promise becomesnullwithout cancelling sibling tasks.pipeline()lets each item advance through its stages independently without a global stage barrier. A failed item becomesnull, skips its remaining stages, and does not cancel sibling items. Preserve stage-to-stage type inference for up to five stages.- The Flow primitives do not currently impose a concurrency or item-count limit. Adding limits, queues, retries, fail-fast behavior, or cancellation propagation is a public contract change.
- Callers must handle nullable
parallel()andpipeline()results explicitly and decide whether partial completion is acceptable. - Workflow branches share one phase state. Set
phase()before enteringparallel()orpipeline(); do not change the phase from concurrent tasks or stages. - Repeating the active phase title is a no-op. Changing the title ends the previous phase before starting the new one, and Workflow success or failure ends any active phase.
Workflow execution contract
- A host-started relative Workflow path resolves from the current working
directory. A nested relative path resolves from the parent Workflow module.
Continue to accept absolute paths,
file:URLs, and{ scriptPath }references. - When a Workflow module exports both
defaultandrun, preferdefault. Emitworkflow:startbefore loading the module, and emit exactly one terminalworkflow:endorworkflow:errorevent after execution begins. - Preserve the event protocol types:
workflow:start,workflow:meta,workflow:end,workflow:error,workflow:phase:start,workflow:phase:end, andlog. Keep their existing context, metadata, duration, phase, message, and serialized error fields compatible. WorkflowEventEmitterinvokes listeners synchronously in subscription order. Each Emitter assigns its own monotonically increasing sequence and ISO-8601 timestamp, and freezes the completed event object before delivery.- A
WorkflowRunnermay be reused and may run Workflows concurrently. Executions keep separate async-local Workflow and Logging contexts while sharing the Runner's Emitter and sequence space. WorkflowRunner.dispose()removes only the JSON writer installed by the Runner, preserves external event listeners, is idempotent, and prevents futurerun()calls.- Keep CLI result serialization stable:
undefinedwrites nothing, strings are written as text, and every other result is serialized withJSON.stringify()on one line. A serialization failure makes the command fail rather than falling back to descriptive text.
Commands
bun install
bun run lint
bun run format:check
bun run prepare
bun run typecheck
bun test
bun run check
bun run dev -- create "Create a research Workflow"Run bun run check before handing off a change.
package.json scripts
The root package.json is the source of truth for project commands:
| Script | Purpose |
bun run dev -- <args> | Run the TypeScript CLI entry point directly and forward arguments to it. |
bun run lint | Lint JavaScript and TypeScript without modifying files. |
bun run lint:fix | Apply safe ESLint fixes. |
bun run format | Format supported repository files with Prettier. |
bun run format:check | Check Prettier formatting without modifying files. |
bun run lint:staged | Run the pre-commit checks against Git-staged files. |
bun run prepare | Install the repository-managed Husky hooks. |
bun test | Run every test under the top-level tests/ directory. |
bun run typecheck | Type-check both src/ and tests/ without emitting files. |
bun run check | Run type-checking, lint, format checks, and the complete test suite. |
Keep script names stable. When adding or changing a script, update this table
and the corresponding table in both language variants of docs/index.md.
Quality gates
- Use ESLint Flat Config from
eslint.config.js. - Use Prettier as the only code formatter.
- Keep
.husky/pre-commitlimited tolint-stagedfollowed by the project-widetypecheck; do not run the complete test suite during a commit. - Keep staged-file commands in
lint-staged.config.js. - Preserve lint-staged's default backup stash and rollback behavior.
Agent contract
agent(prompt, options)represents a complete Agent Loop, not a single model completion.- JSON Schema constrains the final Agent response only.
- A schema-backed call returns parsed JSON; a call without a schema returns text.
- The Agent runtime is responsible for enforcing a supplied JSON Schema. The shared Deer Workflow contract transports the schema and parses the final response; the TypeScript output generic is not runtime validation.
- Per-run
AgentOptionsoverride runtime constructor defaults. Merge process, runtime, and per-run environments in that order; anundefinedvalue removes that environment variable. - An already-aborted signal must fail before starting the Agent process. Aborting an active run must terminate its subprocess, remove the abort listener, propagate the abort reason, and still clean up temporary files.
- Keep the generic Agent interface independent from Codex CLI flags whenever possible.
- New runtimes should implement the same
Agentinterface and remain swappable.
Public package contract
- Preserve the package root and the focused
./agents,./events,./flow,./logging, and./runnerexport paths. Add public APIs through the relevantindex.tsand re-export them fromsrc/index.tswhen they belong at the package root. - The package currently publishes Bun-runnable TypeScript source directly:
package exports point to
src/**/*.tsand the CLIbinpoints tosrc/cli.ts. Introducing compileddistartifacts, a build step, or Node.js runtime compatibility is a release architecture change that requires coordinated export, bin, installation, test, and documentation updates.
Release process
- Treat the user's instruction
publishas explicit authorization to execute the complete release process end to end, including preparing and committing release changes, pushingmain, publishing to npm, creating and pushing the tag, creating the GitHub Release, and publishing to GitHub Packages. Do not stop merely to ask for confirmation of these steps. - Releases are made from a clean
mainbranch that is synchronized withorigin/main. Do not publish from an uncommitted worktree or an unpushed commit. - Start every release by creating or updating the root
CHANGELOG.md. Move the relevant entries fromUnreleasedinto a version heading with an ISO date, then add a fresh emptyUnreleasedsection. Mention only substantial, user-visible changes as individual entries; consolidate small fixes instead of enumerating them, using a concise summary such asMinor bug fixes. - Update the English and Simplified Chinese installation and API documentation whenever a release changes package requirements, commands, or public behavior.
- Set an explicit release version with
bun pm version <version> --no-git-tag-version. Keeppackage.jsonandbun.locksynchronized, and inspect their diff before continuing. - Confirm the version is not already present in the registry before publishing. npm versions are immutable; never attempt to reuse a version that reached the registry.
- Before the next release, add and then maintain a
package.jsonfilesallowlist containing the runtimesrc/tree and bundledskills/workflow-creator/tree. README, license, and package metadata may be included as standard package files; exclude tests and repository tooling. - Run
bun run checkafter the changelog, documentation, and version changes. A release must not proceed unless the complete quality gate passes. - Inspect the npm payload with
bun pm pack --dry-run --ignore-scripts. Published files must be intentional and must not include tests, Git hooks, repository instructions, credentials, or unrelated development artifacts. - Build the exact release tarball with
bun pm pack --ignore-scripts --destination distin the ignoreddist/directory. Smoke-test that tarball in a new temporary project, including a package import anddeer-workflow --help. - Commit the version, changelog, documentation, and packaging changes together
as
release: prepare v<version>, then pushmainbefore publishing. - Publish the tested tarball with
bun publish <tarball> --access public --tag latest. Never expose npm passwords, one-time codes, recovery codes, or tokens in source, logs, commit messages, or diagnostics. - Verify the exact version and
latestdist-tag withnpm view, then install that exact registry version in a fresh temporary project and rerun the import and CLI smoke tests. - Create and push the annotated
v<version>Git tag only after the registry verification succeeds. Then create the GitHub Release from that existing tag withgh release create v<version> --verify-tag --generate-notes. - Creating the GitHub Release must trigger
.github/workflows/publish-github-package.yml. Monitor the corresponding GitHub Actions run through completion and verify that the exact version is available in GitHub Packages. If the release event does not trigger the workflow, dispatch it manually and monitor that run instead. - If publication fails before npm accepts the version, fix the cause, rerun all checks, rebuild the tarball, and retry. If npm accepted a broken version, never overwrite it; publish a new patch version.
Process safety
- Spawn commands with argument arrays. Never construct shell command strings from prompts.
- Send prompts over stdin instead of embedding them in a shell command.
- Default to ephemeral Codex sessions.
- Do not enable
danger-full-accessimplicitly. - Never log credentials or copy the entire parent environment into diagnostics.
- Create schema and result files in a unique temporary directory and remove it in
finally. - Preserve stderr on failures so callers can diagnose missing authentication, sandbox denials, and CLI errors.
Testing
- Unit tests must not call the real Codex service.
- Keep all test files under the top-level
tests/directory and mirror the relevantsrc/structure where practical. - Use a local stub process to test argument construction, stdin handling, structured output, and failures.
- Add integration tests that invoke Codex only behind an explicit environment flag.
- Test both text output and JSON Schema output for every Agent adapter.
Style
- Prefer small modules with explicit public types.
- Export types with
export type. - Keep English documentation at the canonical
*.mdpath and place Simplified Chinese translations beside it as*.zh-CN.md. Add reciprocal language links near the top of both files. - Keep both root README files focused on project positioning, CLI trial
commands, examples, and documentation links. Put API and runtime details in
docs/api.mdanddocs/api.zh-CN.md. - Organize each root README into two level-one reader paths: how to use the CLI and how to develop or contribute to the repository. Keep a two-level index that links each path and its level-two sections.
- Whenever a public API, event, Workflow, Agent, Runner, or CLI behavior
changes, update its tests,
docs/api.md,docs/api.zh-CN.md, andskills/workflow-creator/references/api.mdin the same change. - Also update
skills/workflow-creator/SKILL.md,skills/workflow-creator/references/patterns.md, andskills/workflow-creator/assets/workflow.tswhen a contract change affects generated Workflow guidance or templates. - Add
Co-authored-by: Codex <codex@openai.com>to commits containing changes materially authored with Codex, unless the user requests otherwise. - Document every public API with TypeDoc comments, including parameters, return values, generics, thrown errors, and non-obvious runtime semantics.
- Avoid
any; useunknownat external boundaries and narrow it. - Include actionable context in thrown errors without exposing secrets.
- Add comments only when they explain a non-obvious constraint.
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.

