pi-cloudflare-agent-tracing0.5.1
Required Cloudflare custom-span runtime and read-only tracing reports for Pi Durable applications.
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
Pi Cloudflare Agent Tracing
A Pi package and required Worker runtime adapter for content-safe tracing of Pi Durable applications running on Cloudflare.
It adds one command:
/pi-trace [target] [--scope turn|thread|service] [--html]
One report combines a Pi-specific agent behavior timeline, skills and guidance, AI generation, tool execution, verified business effects, durable settlement, reliability, latency, usage, cost, fulfillment, recovery, anomalies, and evidence-linked improvements.
The package registers Cloudflare's official MCP server, applies an evidence-first investigation skill, and blocks cloudflare_execute unless every statically visible API request is an explicit GET.
What it does
- Profiles
wrangler.jsonc,wrangler.json, andwrangler.tomlprojects. - Supports a single Worker or a monorepo with multiple Wrangler configurations.
- Discovers
Harness.open()without assuming a source path. - Distinguishes Workers platform tracing from custom Pi telemetry.
- Queries deployments, versions, bindings, logs, traces, and bounded metrics.
- Builds machine-readable agent runs from submissions, tasks, phases, model calls, tools, effects, and settlement.
- Translates technical telemetry into source-grounded agent and business behavior without inventing hidden reasoning.
- Distinguishes configured skills from skills explicitly requested, selected, injected, observed, or fulfilled.
- Evaluates deterministic fulfillment from normalized, content-free evidence.
- Summarizes Pi Durable-shaped context exports without transcript or tool content.
- Emits
pi.durable.*andpi.ai.*spans through Cloudflare Workers custom spans. - Requires the runtime adapter on every production
Harness.open()before investigations run.
It does not deploy, repair state, mutate Cloudflare resources, or create diagnostic endpoints.
Install
1. Install the Pi investigation package
pi install npm:pi-cloudflare-agent-tracing
The pi-package keyword makes the published package eligible for discovery in the Pi package gallery.
2. Install the required Worker runtime dependency
From every Pi Durable Worker project that will be investigated:
pnpm add pi-cloudflare-agent-tracing
# or: npm install pi-cloudflare-agent-tracing
Enable Workers observability and tracing:
{
"observability": {
"enabled": true,
"traces": { "enabled": true },
},
}
Wire the package into every production Harness.open():
import { tracing } from "cloudflare:workers";
import { createCloudflareTelemetryContext } from "pi-cloudflare-agent-tracing/cloudflare";
const harness = await Harness.open(
storage,
{
...harnessOptions,
telemetry: createCloudflareTelemetryContext(tracing),
},
context,
);
The profiler requires all three conditions—the dependency, Workers tracing, and Harness.open() wiring. Investigation commands stop with setup guidance when any condition is missing because platform traces alone do not provide Pi execution telemetry.
Try from a local checkout
pi -e /absolute/path/to/pi-cloudflare-agent-tracing
Install for one project
From the target project:
pi install --local /absolute/path/to/pi-cloudflare-agent-tracing
This writes the package declaration to the target project's .pi/settings.json.
Install for your user
pi install /absolute/path/to/pi-cloudflare-agent-tracing
The same package can be installed from Git:
pi install git:github.com/oskarcode/pi-cloudflare-agent-tracing@v0.5.1
Use a pinned release tag or commit for reproducible investigations.
Start
Inside Pi:
/reload
/mcp
If Cloudflare authentication is required:
/mcp login cloudflare
Then run, for example:
/pi-trace
/pi-trace my-worker --since 30m
/pi-trace <ray-or-trace-id>
/pi-trace <submission-or-task-id>
/pi-trace <conversation-id>
/pi-trace my-worker --since 6h --html
The target automatically selects the narrowest useful scope: request, Ray, trace, submission, and task identifiers produce a turn report; a conversation produces a thread; a Worker or deployment plus time range produces a service report. Use --scope only to override that inference.
Each saved report produces matching .md, content-free .json, and standalone .html files under the target project's .pi/agent-tracing-reports/. The JSON preserves rich safe evidence for the coding agent. The printable, responsive, self-contained HTML translates that evidence into agent runs, behavior, skills, AI generation, tools, effects, fulfillment, and recommendations; Cloudflare infrastructure details appear later as supporting evidence.
How it works
slash command
→ extension dispatches /skill:cloudflare-agent-tracing
→ skill verifies required Pi runtime instrumentation
→ Cloudflare MCP performs bounded GET and read-only telemetry queries
→ optional authorized diagnostics provide durable evidence
→ evaluator produces a content-free verdict
The extension and skill have different responsibilities:
extensions/cloudflare-agent-tracing.tsowns executable Pi wiring, command registration, MCP registration, queue behavior, and the read-only gate.skills/cloudflare-agent-tracing/SKILL.mdowns investigation policy, evidence order, privacy rules, and report structure.skills/cloudflare-agent-tracing/scripts/contains dependency-free local evidence utilities.runtime/contains the required Worker adapter that forwards Pi telemetry to Cloudflare custom spans.
Project discovery
The profiler searches up to four directory levels for:
wrangler.jsoncwrangler.jsonwrangler.toml
If exactly one configuration exists, it selects it. A root-level configuration wins when present. If a monorepo has multiple candidates, select one explicitly:
node skills/cloudflare-agent-tracing/scripts/project-profile.mjs \
--cwd /path/to/project \
--config apps/agent/wrangler.jsonc
Source discovery is bounded and excludes build output, dependencies, and hidden directories. It searches common TypeScript and JavaScript files for every production Harness.open() and reports whether each call passes telemetry:. instrumentation.ready is true only when the package dependency and Wrangler tracing settings are also present.
The profiler is heuristic setup evidence. A sampled production span remains the runtime proof.
Fulfillment evaluation
Create normalized evidence using:
skills/cloudflare-agent-tracing/references/evaluation-input.example.json
Then run:
node skills/cloudflare-agent-tracing/scripts/evaluate.mjs /tmp/evidence.json
Deterministic evidence checks submission settlement, final answer presence, required tools, required durable effects, constraints, and terminal failures. Semantic evidence is optional; without authorized semantic evidence, a deterministic pass can remain indeterminate.
Agent evidence and human-review reports
Every investigation uses one normalized Pi trace schema. Its detailed JSON is the coding agent's authoritative artifact. agentRuns, behaviorTimeline, skills, modelCalls, toolCalls, and effects retain provenance and evidence IDs. Skill availability is never treated as observed use, and binding activity is never treated as a verified business effect without commit or read-back evidence. See:
skills/cloudflare-agent-tracing/references/report.example.json
Render a normalized report directly:
node skills/cloudflare-agent-tracing/scripts/render-report.mjs \
path/to/report.json \
--out path/to/report.html
If --out is omitted, the renderer writes beside the JSON input with an .html extension. The renderer validates schema version 2, kind: "pi-agent-trace", and the resolved turn, thread, or service scope. It caps CLI input at 2 MB, escapes every displayed value, and emits a restrictive content security policy. Unknown JSON fields are not rendered, reducing the risk of accidentally exposing unrelated diagnostic data. The HTML leads with agent behavior and user-facing recommendations, then presents performance, scope, and expandable technical evidence.
Saved reports should remain content-free and should normally be ignored by Git:
.pi/agent-tracing-reports/
Optional application diagnostics
The package intentionally has no project-specific transcript reader. A target application may expose an existing narrow, authorized diagnostic export. Keep raw output in /tmp, summarize it locally, and remove it.
For Pi Durable-shaped context JSON:
node skills/cloudflare-agent-tracing/scripts/summarize-session-context.mjs \
/tmp/session-context.json
The summary retains IDs, roles, tool names/statuses, stop reasons, token counts, and reported cost. It removes text, thinking, tool arguments, and tool results.
Required Pi telemetry adapter
pi-cloudflare-agent-tracing/cloudflare structurally implements Pi's telemetry context over Cloudflare Workers custom spans without importing project packages. It must be passed to every production Harness.open().
Pi Durable emits content-free admission, phase, task, tool, recovery, and commit evidence. Pi AI emits model, timing, usage, and cost evidence when the provider supplies it. The adapter redacts error messages by default. Workers custom spans do not expose native event and link APIs, so bounded events and links are encoded as attributes.
The package never persists a telemetry context in Durable Object state. Cloudflare's tracing.enterSpan() uses the active JavaScript async context for request-time nesting; resumed Durable Object work can begin a new trace when no caller span exists.
After integration, verify the adapter under workerd and then prove expected pi.durable.* and pi.ai.* spans with one bounded, authorized production smoke before relying on the reports.
Security model
- Cloudflare API work uses GET by default. The only permitted POST requests are Cloudflare's read-only Workers Observability telemetry
keys,values, andqueryendpoints. - Time ranges, result limits, and pagination must be bounded.
- Broad event output that could expose headers or payloads is prohibited by skill policy.
- Reports must not include credentials, prompts, answers, thinking, tool arguments/results, or attachments.
- The extension's static method gate is defense in depth, not a security sandbox.
- Pi extensions execute with the local Pi process's operating-system permissions. Review source before installation.
Testing
No package installation is required:
npm test
The suite uses Node's built-in test runner and covers extension registration, the exact read-only telemetry POST allowlist, mutation blocking, JSONC/TOML project discovery, evaluation, content summarization, and telemetry adaptation.
Package layout
extensions/cloudflare-agent-tracing.ts
skills/cloudflare-agent-tracing/SKILL.md
skills/cloudflare-agent-tracing/scripts/
render-report.mjs
skills/cloudflare-agent-tracing/references/
report.example.json
runtime/cloudflare-telemetry-context.js
runtime/cloudflare-telemetry-context.d.ts
test/extension.test.mjs
Compatibility
- Node.js 22 or newer
- Pi package loading and extension APIs described by
@earendil-works/pi-coding-agent - Cloudflare's official MCP server
- Cloudflare Workers observability for production evidence
Pi Durable provides the task, recovery, model, usage, and durable outcome evidence required by the unified trace report.