Target:
@codepawl/tracepawl(Failure diagnosis and replay for coding agents) Core Identity: Offline, deterministic postmortem engine for coding agent runs. Uses rule-based JSON trace analysis to pinpoint failure onset, classify error categories, and suggest recovery actions without mandatory LLMs.
π Quick Start / Ingestion
- Install:
npm install @codepawl/tracepawl - CLI Analysis:
npx tracepawl analyze trace.json(analyzes a run deterministically). - CLI Recording:
npx tracepawl run -- bun run my-agent.ts(wraps a local command and captureslatest.json). - Demo Sandbox:
npx tracepawl demo --opengenerates a local, open-source diagnostic report of a mock failing agent.
π‘ Best Practices (Patterns)
- Atomic Finalization: Always wrap execution in a
try/finallyblock that callswriter.finalize()andawait writer.writeToFile(outputPath).finalizeis idempotent and βfirst-call-winsβ. - Cross-Referencing Events: Capture the
EventIdreturned byrecord*()methods. Inject these IDs into subsequent events via therawpassthrough object to map relational causality (e.g., linking afile_editto a priorfile_read). - Stable Identifiers: Allow
TraceWriterto own Event IDs (evt_001,evt_002) and usecrypto.randomUUID()for Run IDs. These are load-bearing strings for analyzer evidence pointers. - Narrow Scoped Edits: Ensure agents read target files immediately before patching. Limit edits to <5 distinct files and <200 LOC per targeted task to avoid triggering the
unsafe_or_broad_editwarning.
π¨ Anti-Patterns (What NOT to do)
- Reminting IDs on Parse: Do not regenerate event IDs when parsing or moving a trace. Modifying IDs severs the analyzerβs evidence pointers.
- Out-of-Order Logging: Do not record events retrospectively.
TraceWriterassumes events are recorded in execution order; logging an earlierfile_editafter a subsequenttool_callfinishes will corrupt the parserβs timeline logic. - Stale Context Editing: Do not let the agent execute a
file_editwithout a precedingfile_read. Doing so triggers thestale_context_editfailure rule (old_string not found,context mismatch). - Blind Looping: Do not loop identical
tool_callpayloads or failing shell commands >3 times without adapting arguments. This triggers theloop_or_stallanalyzer rule. - Misdirected Test Fixes: Do not let the agent edit unrelated files or silence failing assertions. This triggers the
test_failure_misdiagnosisrule.
π§ TraceWriter SDK (Manual Implementation)
- No Auto-instrumentation: TracePawl does not monkey-patch
node:fsorchild_process. All telemetry must be explicitly passed toTraceWriterviarecordModelCall,recordToolCall,recordFileRead,recordFileEdit,recordCommandRun,recordTestRun, orrecordGitDiff. - Atomic File Writes:
writer.writeToFile(path)uses atomic temp files (path.tmp.uuid) andfs.renameto prevent partial-write corruption on agent crashes. - Event Schema Fields: Requires
id,agent,userGoal,startedAt, andevents[]. Custom adapter metadata can be dumped into the genericrawpassthrough field without strict validation.
π¨ Gotchas / Warnings
- LLM is Strictly Advisory: Diagnosis uses pre-written deterministic rules (
src/analyzer/rules/*.ts) by default. Passing--llm-reviewsends a heavily redacted prompt (stripping bearer tokens and clippingstdout) to OpenAI-compatible endpoints or Ollama, but the deterministic rule remains the primary source of truth. - No Epoch Timestamps: The event schema strictly requires ISO 8601 strings (
new Date().toISOString()). Integer epoch milliseconds are not automatically normalized. - First Call Wins:
finalize(endedAt?)ignores subsequent calls. If multiple termination conditions exist, the first captured timestamp solidifies the trace completion.