selftune
AGENTS.md18 starsChanged 9 months agoMITView on GitHub
selftune — Self-improving skills for AI agents. Watches real sessions, learns how users actually work, and evolves skill descriptions to match. Supports Claude Code, Codex, OpenCode, OpenClaw, and Pi. Stack: TypeScript on Bun for the CLI, Drizzle over Bun SQLite for operational/product state, a separate DuckDB observability-analytics domain, legacy/export JSONL recovery paths, Effect for owned runtime lifecycles, and a local React/Vite dashboard SPA. selftune is a skill consumed by AI agents, not a CLI tool used by humans directly. The…
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 33,398 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.
The file
We split this AGENTS.md into the rules it gives an agent
12 rules. About 0 are common, 5 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 12
Do not edit or import from .repos/effect.
- Very specific: line 13
Before writing Effect code, read .repos/effect/LLMS.md and inspect matching source, tests, and API signatures.
- Very specific: line 116
When changing one part of selftune, check if dependent files need updating.
- Distinctive: line 157
Keep one logical change per commit and use squash merge so the reviewed pull request becomes one attributable source-history event.
- Very specific: line 158
Add Co-authored-by trailers only for people who materially contributed to the change.
- Distinctive: line 162
Read this file, then follow pointers to relevant docs
- Distinctive: line 163
Read PRD.md for product context and the feedback loop model
- Very specific: line 166
Run sandbox harness: bun run tests/sandbox/run-sandbox.ts
- Very specific: line 167
Run make check (lint + test) or bun test
- Distinctive: line 168
Verify JSONL output schema matches appendix in PRD.md
- Distinctive: line 188
All knowledge lives in-repo, not in external tools
- Very specific: line 190
Keep runtime dependencies explicit and owned at the narrowest package boundary.
≈ “Common” is an estimate: at least 1 in 5 of the 43,423 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
Repository Overview
selftune — Self-improving skills for AI agents. Watches real sessions, learns how users actually work, and evolves skill descriptions to match. Supports Claude Code, Codex, OpenCode, OpenClaw, and Pi.
Stack: TypeScript on Bun for the CLI, Drizzle over Bun SQLite for operational/product state, a separate DuckDB observability-analytics domain, legacy/export JSONL recovery paths, Effect for owned runtime lifecycles, and a local React/Vite dashboard SPA.
Vendored Effect Reference
.repos/effectis the pinned Effect 4 source used as read-only reference material.- Do not edit or import from
.repos/effect; application code must continue importing normal package dependencies. - Before writing Effect code, read
.repos/effect/LLMS.mdand inspect matching source, tests, and API signatures. - Editor search, file watching, and auto-imports must remain excluded from
.repos/**.
Agent-First Architecture
selftune is a skill consumed by AI agents, not a CLI tool used by humans directly.
The user's interaction model is:
- Install the skill:
npx skills add selftune-dev/selftune - Tell their agent: "set up selftune" / "improve my skills" / "how are my skills doing?"
- The agent reads
skill/SKILL.md, routes to the correct workflow, and runs CLI commands
The selftune binary composed in apps/cli/ is the agent's API. The skill definition (skill/SKILL.md) is the product surface. Workflow docs (skill/workflows/) are the agent's instruction manual. Users rarely if ever run selftune commands directly — their coding agent does it for them.
When developing selftune:
- Changes to CLI behavior must be reflected in the corresponding
skill/workflows/*.mddoc - New CLI commands need a workflow doc and a routing entry in
skill/SKILL.md - Error messages should guide the agent, not the human (e.g., suggest the next CLI command, not "check the docs")
- The SKILL.md routing table and trigger keywords are as important as the CLI code itself — they determine whether the agent can find and use the feature
skill/SKILL.mdandskill/workflows/*.mdare shipped product surface for users' agents. Do not put repo-local contributor commands or monorepo workflow there (for example:cd oss/selftune,bun run dev, Vite/HMR details). Put contributor guidance inREADME.md,AGENTS.md, or internal docs instead.
Project Structure
selftune/
├── apps/
│ ├── cli/ # Command composition root; owns argument routing
│ ├── local/ # Process composition, Effect operations, HTTP routes, and OS service host
│ ├── local-dashboard/ # Shared React/Vite dashboard client
│ ├── desktop/ # Scoped Effect supervisor plus Electron window, tray, updater, and IPC adapters
│ ├── use-once-helper/ # Separate signed ephemeral shared-skill runner; never installs SelfTune
│ └── selfhost/ # One-container dashboard and Remote Library host
├── packages/
│ ├── api-contract/ # Shared typed HTTP contracts used by optional Cloud handoffs
│ ├── config/ # Persisted config schemas, path resolution, loading, and atomic writes
│ ├── runtime/ # Local filesystem, SQLite/Drizzle, and host adapters
│ ├── library/ # Catalog, Skill Sets, and Remote Library protocol core
│ ├── local-store/ # Effect-managed SQLite lifecycle, Drizzle schema, and migrations
│ ├── observability/ # Effect-owned DuckDB trace analytics and derived signal queries
│ ├── skill-intelligence/ # Pure classification, pattern discovery, validation, and outcomes
│ ├── source-management/ # Source identity, update contracts, and sync service
│ ├── orchestration/ # Setup convergence/onboarding plus sync, improve, run, and scheduling workflows
│ ├── harnesses/
│ │ ├── core/ # Harness-neutral hook protocol, source-adapter contract, and stdin/session utilities
│ │ ├── registry/ # Split descriptor/source registries for all shipped harnesses
│ │ ├── claude-code/ # Claude Code hooks and transcript ingestion
│ │ ├── codex/ # Codex hooks, installer, rollout ingestion, and wrapper
│ │ ├── opencode/ # OpenCode hooks, installer, and ingestion
│ │ ├── cline/ # Cline hooks and installer
│ │ ├── pi/ # Pi hooks, installer, and ingestion
│ │ └── openclaw/ # OpenClaw ingestion and cron adapter
│ ├── control-plane/ # Effect services, domain contracts, programs, and Layers
│ ├── dashboard-core/ # Host-neutral dashboard shell and route contracts
│ ├── telemetry-contract/ # Canonical telemetry contract
│ └── ui/ # Shared UI primitives and components
├── cli/selftune/ # Backward-compatible CLI and hook shims only
├── bin/selftune.cjs # npm binary shim into apps/cli
├── skill/ # Agent-facing routing table, workflows, and references
├── tests/ # Cross-package behavior and release tests
└── scripts/ # Release, packaging, and validation toolingThe root selftune package remains the publishable npm compatibility facade. New command
implementation belongs in apps/cli; local host behavior belongs in apps/local; reusable
behavior belongs in a package. Do not add implementation modules under cli/selftune.
Architecture
See ARCHITECTURE.md for domain map, module layering, and dependency rules.
Documentation Map
| Topic | Location | Status |
| System Overview | docs/design-docs/system-overview.md | Current |
| Operator Guide | docs/operator-guide.md | Current |
| Architecture | ARCHITECTURE.md | Current |
| Product Requirements | PRD.md | Current |
| Skill Definition | skill/SKILL.md | Current |
| Design Docs | docs/design-docs/index.md | Current |
| Core Beliefs | docs/design-docs/core-beliefs.md | Current |
| Live Dashboard SSE | docs/design-docs/live-dashboard-sse.md | Current |
| SQLite-First Migration | docs/design-docs/sqlite-first-migration.md | Current |
| Agent CLI Contract | docs/design-docs/agent-cli-contract.md | Current |
| Product Specs | docs/product-specs/index.md | Current |
| Active Plans (~4 epics) | docs/exec-plans/active/ | Current |
| Completed Plans | docs/exec-plans/completed/ | Current |
| Deferred Plans | docs/exec-plans/deferred/ | Current |
| Technical Debt | docs/exec-plans/tech-debt-tracker.md | Current |
| Risk Policy | risk-policy.json | Current |
| Golden Principles | docs/golden-principles.md | Current |
| Escalation Policy | docs/escalation-policy.md | Current |
| References | skill/references/ | Current |
| Launch Playbook | docs/launch-playbook-tracker.md | Current |
| Security Policy | SECURITY.md | Current |
| Contributing Guide | CONTRIBUTING.md | Current |
| Code of Conduct | CODE_OF_CONDUCT.md | Current |
| License | LICENSE | Current |
Change Propagation Map
When changing one part of selftune, check if dependent files need updating. This prevents stale docs and broken contracts.
| If you change... | Also update... |
CLI commands in apps/cli/src/main.ts (add/rename/remove) | skill/SKILL.md Quick Reference + Workflow Routing table, README.md Commands table, AGENTS.md project tree |
| CLI flags on any command | The command's skill/workflows/*.md doc (flags table + examples) |
| Persisted config schema or path policy | packages/config/, runtime/local-store compatibility exports, ARCHITECTURE.md ownership and dependency rules |
| JSONL log schema or new log file | packages/runtime/constants.ts, packages/runtime/types.ts, skill/references/logs.md, local DB writers/queries, ARCHITECTURE.md data architecture |
Dashboard contract (packages/runtime/dashboard-contract.ts) | apps/local-dashboard/src/types.ts, dashboard components that consume the changed fields |
Hook or adapter behavior (packages/harnesses/**) | skill/workflows/Initialize.md hook table, skill/settings_snippet.json, skill/workflows/PlatformHooks.md |
Orchestration behavior (packages/orchestration/**) | Relevant skill/workflows/*.md (for example Initialize or Orchestrate), plus ARCHITECTURE.md operating modes |
Agent files (skill/agents/*.md) | skill/SKILL.md Specialized Agents table |
| New workflow file | skill/SKILL.md Workflow Routing table + Resource Index |
| Evolution pipeline changes | skill/workflows/Evolve.md, docs/design-docs/evolution-pipeline.md |
| Platform adapter (ingestor) changes | skill/workflows/Ingest.md, README.md Platforms section |
CLI error handling (packages/runtime/utils/cli-error.ts) | docs/design-docs/agent-cli-contract.md error codes table, all CLI entry points that import CLIError |
| Repo org/name change | README.md badges + install, llms.txt, SECURITY.md, CONTRIBUTING.md, contribute.ts repo constant, package.json (homepage/repo/bugs) |
Mandatory Rules (If/Then)
These rules are non-negotiable. Before performing the action in the "If" column, you MUST complete the "Then" action first.
| If you are about to... | Then FIRST... |
Add, rename, or remove a CLI command in index.ts | Update skill/SKILL.md Quick Reference and Workflow Routing table |
| Modify CLI flags on any command | Update that command's skill/workflows/*.md doc (flags table + examples) |
Edit hook behavior in hooks/*.ts, hooks-shared/*, or adapters/*/hook.ts | Update skill/workflows/Initialize.md, skill/settings_snippet.json, and skill/workflows/PlatformHooks.md |
Change dashboard-contract.ts fields | Update apps/local-dashboard/src/types.ts and consuming dashboard components |
Add a new file to evolution/ | Update ARCHITECTURE.md domain map and module definitions table |
Modify the evolution pipeline (evolution/*.ts) | Update skill/workflows/Evolve.md |
Change error handling patterns (utils/cli-error.ts) | Update docs/design-docs/agent-cli-contract.md error codes table |
Create a new workflow file in skill/workflows/ | Add routing entry in skill/SKILL.md Workflow Routing table + Resource Index |
Edit orchestrate.ts behavior | Update skill/workflows/Orchestrate.md |
| Commit any changes | Run bunx oxlint and bunx oxfmt --check on changed files |
Development Workflow
Commit attribution
- Agent-authored commits must use Daniel's verified GitHub identity:
Daniel Petro <45949032+WellDunDun@users.noreply.github.com>. - Keep one logical change per commit and use squash merge so the reviewed pull request becomes one attributable source-history event.
- Add
Co-authored-bytrailers only for people who materially contributed to the change. Automation must not claim authorship for generated release metadata. - Changesets describe release intent. The publish workflow derives the next tag from changesets added since the previous stable tag; it must not create a Version Packages pull request or commit generated version files.
- Receive task via prompt
- Read this file, then follow pointers to relevant docs
- Read PRD.md for product context and the feedback loop model
- Implement changes following ARCHITECTURE.md layer rules
- Check the Change Propagation Map above — update dependent docs before committing
- Run sandbox harness:
bun run tests/sandbox/run-sandbox.ts - Run
make check(lint + test) orbun test - Verify JSONL output schema matches appendix in PRD.md
- Self-review: check log schema compatibility across all platforms
- Open PR with concise summary
Key Constraints
- selftune is agent-first: users interact through their coding agent, not the CLI directly. SKILL.md and workflow docs are the product surface; the CLI is the agent's API.
- Claude Code is the primary supported platform; Codex, OpenCode, OpenClaw, and Pi adapters are experimental (they exist but are not actively tested). All five write to the same shared log schema
- Source-truth transcripts/rollouts are authoritative; hooks are low-latency hints, not the canonical record
- Grading uses the user's existing agent subscription — no separate API key
- Hooks should be zero-config after installation where the host agent supports them
- SQLite is the sole operational/product write target. DuckDB is the separate rebuildable observability-analytics store for trace facts, metrics, and cross-trace aggregation; it never owns product lifecycle state. Legacy SelfTune JSONL files on disk are pre-cutover history only, while source-native transcripts, rollouts, and session stores remain authoritative import sources (see docs/design-docs/sqlite-first-migration.md).
- Evolution proposals require validation against eval set before deploy
selftune orchestrateis the primary autonomous loop;selftune cron setupinstalls OS-level scheduling (selftune scheduleis a backward-compatible alias)bun run devatomically claims a stable worktree-specific port block for the watched dashboard runtime and Vite; usedev:status,dev:open, and conservativedev:reaprather than assuming fixed ports- All knowledge lives in-repo, not in external tools
packages/configis the canonical owner of persisted config schemas, environment-derived paths, loading, and atomic writes. Runtime and local-store may re-export stable compatibility names but must not redefine that policy.- Keep runtime dependencies explicit and owned at the narrowest package boundary. The local database uses
drizzle-orm; process and resource lifecycles use Effect; platform I/O should still prefer Bun and Node built-ins. @selftune/telemetry-contractusesworkspace:*in the repo;prepackrewrites tofile:at publish time. Do NOT hardcodefile:(causes bun lockfile duplicates) or remove the prepack/postpack scripts (breaks registry installs). A CI test (tests/trust-floor/publish-deps.test.ts) enforces the full pipeline.
Golden Principles
See docs/golden-principles.md for the full set of mechanical taste rules.
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.

