|
| 1 | +--- |
| 2 | +name: agentcrumbs |
| 3 | +description: > |
| 4 | + Debug mode for AI coding agents. Drop structured traces inline while writing |
| 5 | + code, query them when something breaks, strip before merge. Covers the core |
| 6 | + workflow: trail, crumb, markers, collector, query, strip. Activate when using |
| 7 | + agentcrumbs, adding debug tracing, or when an agent needs to understand |
| 8 | + runtime behavior. |
| 9 | +type: core |
| 10 | +library: agentcrumbs |
| 11 | +library_version: "0.2.0" |
| 12 | +sources: |
| 13 | + - "triggerdotdev/trigger-labs:debug-mode/README.md" |
| 14 | + - "triggerdotdev/trigger-labs:debug-mode/src/trail.ts" |
| 15 | + - "triggerdotdev/trigger-labs:debug-mode/src/types.ts" |
| 16 | +--- |
| 17 | + |
| 18 | +# agentcrumbs |
| 19 | + |
| 20 | +Structured debug traces that agents drop inline while writing code, then query when something breaks. Stripped before merge, zero cost when off. |
| 21 | + |
| 22 | +## Workflow |
| 23 | + |
| 24 | +``` |
| 25 | +1. Write code + crumbs → crumb("user verified", { userId }); // @crumbs |
| 26 | +2. Run with collector → agentcrumbs collect & AGENTCRUMBS=1 node app.js |
| 27 | +3. Something breaks → agentcrumbs query --since 5m |
| 28 | +4. Fix the bug → (read the trail, find the cause, fix it) |
| 29 | +5. Strip before merge → agentcrumbs strip |
| 30 | +``` |
| 31 | + |
| 32 | +## Core API |
| 33 | + |
| 34 | +```typescript |
| 35 | +import { trail } from "agentcrumbs"; // @crumbs |
| 36 | +const crumb = trail("my-service"); // @crumbs — create once at module level |
| 37 | + |
| 38 | +// Basic crumb |
| 39 | +crumb("checkout started", { cartId: "c_91" }); // @crumbs |
| 40 | + |
| 41 | +// With tags (third arg) for filtering |
| 42 | +crumb("cache miss", { key }, { tags: ["perf"] }); // @crumbs |
| 43 | + |
| 44 | +// Child context for per-request tracing |
| 45 | +const reqCrumb = crumb.child({ requestId: req.id }); // @crumbs |
| 46 | +reqCrumb("handling request", { path: req.url }); // @crumbs |
| 47 | + |
| 48 | +// Scoped operations with automatic enter/exit/error tracking |
| 49 | +const user = await crumb.scope("validate-token", async (ctx) => { // @crumbs |
| 50 | + ctx.crumb("checking jwt"); // @crumbs |
| 51 | + return await verifyToken(token); // @crumbs |
| 52 | +}); // @crumbs |
| 53 | + |
| 54 | +// Guard expensive args |
| 55 | +if (crumb.enabled) { crumb("dump", { state: structuredClone(big) }); } // @crumbs |
| 56 | +``` |
| 57 | + |
| 58 | +## Markers |
| 59 | + |
| 60 | +Every crumb line needs a marker so `agentcrumbs strip` can remove it before merge. |
| 61 | + |
| 62 | +```typescript |
| 63 | +// Single-line marker |
| 64 | +crumb("event", { data }); // @crumbs |
| 65 | + |
| 66 | +// Block marker for multi-line sections |
| 67 | +// #region @crumbs |
| 68 | +const result = await crumb.scope("operation", async (ctx) => { |
| 69 | + ctx.crumb("step 1"); |
| 70 | + ctx.crumb("step 2"); |
| 71 | + return value; |
| 72 | +}); |
| 73 | +// #endregion @crumbs |
| 74 | +``` |
| 75 | + |
| 76 | +**Unmarked crumbs will leak into production code.** The strip command only removes lines with `// @crumbs` or code inside `#region @crumbs` blocks. |
| 77 | + |
| 78 | +## CLI quick reference |
| 79 | + |
| 80 | +```bash |
| 81 | +agentcrumbs collect # Start HTTP collector (required for query/tail) |
| 82 | +agentcrumbs tail # Live tail (--ns, --tag, --match filters) |
| 83 | +agentcrumbs query --since 5m # Query history (--ns, --tag, --session, --json) |
| 84 | +agentcrumbs strip # Remove all crumb markers from source |
| 85 | +agentcrumbs strip --check # CI gate — exits 1 if markers found |
| 86 | +agentcrumbs --help # Full command reference |
| 87 | +``` |
| 88 | + |
| 89 | +Run `agentcrumbs <command> --help` for detailed options on any command. |
| 90 | + |
| 91 | +## Enable tracing |
| 92 | + |
| 93 | +```bash |
| 94 | +AGENTCRUMBS=1 node app.js # Enable all namespaces |
| 95 | +AGENTCRUMBS='{"ns":"auth-*"}' node app.js # Filter by namespace |
| 96 | +``` |
| 97 | + |
| 98 | +When `AGENTCRUMBS` is not set, `trail()` returns a frozen noop. No conditionals, no overhead. |
| 99 | + |
| 100 | +## Critical mistakes |
| 101 | + |
| 102 | +1. **Missing markers** — Every crumb line needs `// @crumbs` or a `#region @crumbs` block. Without them, `strip` can't clean up. |
| 103 | +2. **Creating trail() in hot paths** — `trail()` parses the env var each call. Create once at module scope, use `child()` for per-request context. |
| 104 | +3. **No collector running** — Without `agentcrumbs collect`, crumbs go to stderr only and can't be queried. Start the collector before reproducing issues. |
| 105 | + |
| 106 | +## Further discovery |
| 107 | + |
| 108 | +- **CLI details**: `agentcrumbs --help` and `agentcrumbs <command> --help` |
| 109 | +- **TypeScript types**: Check the type definitions in `node_modules/agentcrumbs/dist/index.d.ts` |
| 110 | +- **Docs**: https://agentcrumbs.dev/docs |
| 111 | +- **Sessions and tags**: `crumb.session()` for grouping, `{ tags: [...] }` as third arg for filtering |
| 112 | +- **Testing**: `import { MemorySink, addSink } from "agentcrumbs"` to capture crumbs in tests |
| 113 | +- **Scopes**: `crumb.scope()`, `crumb.wrap()`, `crumb.snapshot()`, `crumb.assert()` for structured tracing |
0 commit comments