Skip to content

Commit 78cd403

Browse files
committed
chore: copy package README to repo root
1 parent 30d1f9b commit 78cd403

File tree

1 file changed

+184
-0
lines changed

1 file changed

+184
-0
lines changed

README.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# agentcrumbs
2+
3+
AI agents can read your code but they can't see what happened at runtime. agentcrumbs fixes that. Agents drop structured traces inline as they write code. When something breaks, the agent queries those traces and sees exactly what ran, with what data, in what order.
4+
5+
Crumbs are development-only. They get stripped before merge and cost nothing when disabled.
6+
7+
```
8+
Service A ──┐ ┌── $ agentcrumbs tail
9+
Service B ──┤── fetch() ──> Collector :8374 ──┤── $ agentcrumbs query --since 5m
10+
Service C ──┘ (fire & forget) └── ~/.agentcrumbs/crumbs.jsonl
11+
```
12+
13+
## Getting started
14+
15+
```bash
16+
npm install agentcrumbs
17+
npx @tanstack/intent install
18+
```
19+
20+
Then tell your agent: **"Run the agentcrumbs/init skill."**
21+
22+
The init skill scans your repo, discovers services and modules, and builds a **namespace catalog** that gets written to your agent config (CLAUDE.md, .cursorrules, etc.). Without the catalog, every agent invents its own namespace names: `auth`, `auth-service`, `authService`, `authentication`, all pointing at the same thing. The catalog locks it down. Every agent, every session, same names.
23+
24+
After init, the agent knows which namespaces to use and how to drop crumbs correctly.
25+
26+
## Agent skills
27+
28+
agentcrumbs ships with [@tanstack/intent](https://tanstack.com/blog/from-docs-to-agents) skills inside the npm package. Running `npx @tanstack/intent install` wires them into your agent config so the agent learns correct usage patterns, common mistakes to avoid, and the namespace catalog for your project.
29+
30+
| Skill | What it teaches |
31+
| --- | --- |
32+
| `agentcrumbs/init` | Scans repo, discovers namespaces, writes config |
33+
| `agentcrumbs/core` | `trail()`, `crumb()`, markers, env var, noop guarantee |
34+
| `agentcrumbs/scopes-and-context` | `scope()`, `wrap()`, `child()`, `snapshot()`, `assert()` |
35+
| `agentcrumbs/sessions-and-tags` | `session()`, tags, grouping and filtering |
36+
| `agentcrumbs/cli` | `collect`, `tail`, `query`, `strip`, `session` |
37+
38+
Skills travel with the package version. The agent always has docs matching the installed code.
39+
40+
## How it works
41+
42+
The agent writes crumbs as part of the code it's implementing:
43+
44+
```typescript
45+
import { trail } from "agentcrumbs"; // @crumbs
46+
const crumb = trail("auth-service"); // @crumbs
47+
48+
export async function handleLogin(token: string) {
49+
crumb("login attempt", { tokenPrefix: token.slice(0, 8) }); // @crumbs
50+
51+
const user = await validateToken(token);
52+
53+
crumb("login success", { userId: user.id }); // @crumbs
54+
return user;
55+
}
56+
```
57+
58+
When something goes wrong, the agent starts the collector and queries the trail:
59+
60+
```bash
61+
agentcrumbs collect --quiet &
62+
AGENTCRUMBS=1 node app.js
63+
agentcrumbs query --since 5m --ns auth-service
64+
```
65+
66+
```
67+
auth-service login attempt +0ms { tokenPrefix: "eyJhbGci" }
68+
auth-service token decode ok +3ms { userId: "u_8f3k" }
69+
auth-service permissions check +8ms { roles: [] }
70+
auth-service rejected: no roles +8ms { status: 401 }
71+
```
72+
73+
Now the agent knows: the token is valid, but the user has no roles. The fix is in role assignment, not token validation.
74+
75+
## Workflow
76+
77+
Crumbs live on your feature branch. They never ship to main.
78+
79+
1. **Agent writes code with crumbs.** As it implements a feature, it drops crumbs at every decision point.
80+
2. **Something breaks.** The agent starts the collector, re-runs the failing code with `AGENTCRUMBS=1`, and queries the trail.
81+
3. **Agent reads the trail.** It sees what actually executed, in what order, with what data. Fixes the root cause instead of guessing.
82+
4. **Strip before merge.** `agentcrumbs strip` removes all crumb code. Clean diff, clean main.
83+
5. **CI enforces it.** `agentcrumbs strip --check` exits 1 if any `@crumbs` markers are found.
84+
85+
## The noop guarantee
86+
87+
When a namespace is disabled, `trail()` returns a pre-built frozen noop function. There is no `if (enabled)` check on every call. The function itself is the noop.
88+
89+
The only cost is the function call itself, which V8 will likely inline after warmup. For hot paths with expensive arguments, gate on `crumb.enabled`.
90+
91+
## API overview
92+
93+
All methods are documented in detail at [docs.agentcrumbs.dev/api](https://docs.agentcrumbs.dev/api).
94+
95+
| Method | Purpose |
96+
| --- | --- |
97+
| `trail(namespace)` | Create a trail function for a namespace |
98+
| `crumb(msg, data?, options?)` | Drop a crumb with message and optional data |
99+
| `crumb.scope(name, fn)` | Wrap a function with entry/exit/error tracking |
100+
| `crumb.child(context)` | Create a child trail with inherited context |
101+
| `crumb.wrap(name, fn)` | Wrap any function with automatic scope tracking |
102+
| `crumb.time(label)` / `crumb.timeEnd(label)` | Measure operation duration |
103+
| `crumb.snapshot(label, obj)` | Capture a point-in-time deep clone |
104+
| `crumb.assert(condition, msg)` | Debug-only assertion (emits crumb, never throws) |
105+
| `crumb.session(name)` | Group crumbs into logical sessions |
106+
107+
## Crumb markers
108+
109+
Mark crumb lines with `// @crumbs` (single line) or `// #region @crumbs` / `// #endregion @crumbs` (block) so they can be stripped before merge. See the [markers docs](https://docs.agentcrumbs.dev/markers) for details and examples.
110+
111+
## Environment variable
112+
113+
Everything is controlled by a single `AGENTCRUMBS` environment variable.
114+
115+
| Value | Effect |
116+
| --- | --- |
117+
| `1`, `*`, `true` | Enable all namespaces |
118+
| `auth-service` | Exact namespace match |
119+
| `auth-*` | Wildcard match |
120+
| `auth-*,api-*` | Multiple patterns (comma or space separated) |
121+
| `* -internal-*` | Match all except excluded patterns |
122+
| `{"ns":"*","port":9999}` | JSON config with full control |
123+
124+
JSON config fields: `ns` (namespace filter, required), `port` (collector port, default 8374), `format` (`"pretty"` or `"json"`, default `"pretty"`).
125+
126+
## CLI
127+
128+
Common commands for reference. Run `agentcrumbs --help` for the full list.
129+
130+
```bash
131+
# Collector
132+
agentcrumbs collect --quiet & # Start in background
133+
agentcrumbs collect --port 9999 # Custom port
134+
135+
# Live tail
136+
agentcrumbs tail # All namespaces
137+
agentcrumbs tail --ns auth-service # Filter by namespace
138+
agentcrumbs tail --tag perf # Filter by tag
139+
140+
# Query
141+
agentcrumbs query --since 5m # Last 5 minutes
142+
agentcrumbs query --ns auth-service --since 1h
143+
agentcrumbs query --tag root-cause
144+
agentcrumbs query --json --limit 50
145+
146+
# Strip
147+
agentcrumbs strip --dry-run # Preview removals
148+
agentcrumbs strip # Remove all crumb code
149+
agentcrumbs strip --check # CI gate (exits 1 if markers found)
150+
151+
# Utilities
152+
agentcrumbs stats # Crumb counts, file size
153+
agentcrumbs clear # Delete stored crumbs
154+
```
155+
156+
Time units: `s` (seconds), `m` (minutes), `h` (hours), `d` (days).
157+
158+
## Multi-service architecture
159+
160+
All services write to the same collector. `agentcrumbs tail` shows interleaved output with namespace-colored labels. See the [multi-service docs](https://docs.agentcrumbs.dev/multi-service) for setup patterns.
161+
162+
## Cross-language compatibility
163+
164+
The collector is language-agnostic. Any language with HTTP support can send crumbs:
165+
166+
```bash
167+
curl -X POST http://localhost:8374/crumb \
168+
-H "Content-Type: application/json" \
169+
-d '{"ts":"2026-01-01T00:00:00Z","ns":"shell","msg":"hello","type":"crumb","dt":0,"pid":1}'
170+
```
171+
172+
## Runtime compatibility
173+
174+
Zero runtime dependencies. Node.js built-in modules only: `node:http`, `node:async_hooks`, `node:crypto`, `node:fs`, `node:util`.
175+
176+
Verified compatible with **Node.js 18+** and **Bun**.
177+
178+
## Docs
179+
180+
Full documentation at [docs.agentcrumbs.dev](https://docs.agentcrumbs.dev).
181+
182+
## License
183+
184+
MIT

0 commit comments

Comments
 (0)