본문으로 건너뛰기
cccskills
무료GitHub에 공개

live-mastracode-instrumentation

Reproduce Mastra Code bugs with a real model and compare timestamped logs across network, streaming, execution, and terminal interface layers. Use the evidence to locate timing problems, incorrect token rates, flicker, or stuck status displays.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

Reproduce and measure a Mastra Code runtime bug against a real model by driving the built TUI headlessly in tmux while every layer (network, provider stream, run engine, TUI) appends timestamped JSONL. Use when a bug depends on real provider timing, streaming order, or event flow that mocked tests and fixtures may not reproduce — e.g. wrong token rates, flicker, stuck status, ordering races, or "only happens sometimes with a real model".

실행 점수 미검증

설치 방법 보기

이럴 때 유용합니다

  • Investigating incorrect token rate displays
  • Reproducing intermittent bugs with a real model
  • Tracing flicker or stuck status displays
  • Comparing event timing across runtime layers

포함된 파일(1)

  • SKILL.md7.7 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Live Mastra Code instrumentation

Run the real TUI against a real model, have an agent type the prompts, and log timestamps at each layer. Comparing the layers step by step shows where timing or ordering goes wrong: at the provider, in the network wrapper, in stream conversion, in the run engine, or in the UI reducer.

Pair this with debugging-difficult-bugs: instrument, reproduce, read the log before fixing, and clean up afterwards. Afterwards, turn the finding into deterministic checked-in coverage (unit tests plus a TUI E2E scenario under mastracode/tui/e2e/tui/). A live run is evidence, not a regression test.

Cost and consent

The TUI uses the user's configured model and stored credentials (for example a Claude Max OAuth login), so every prompt spends their quota. Use short prompts. Tell the user which model you ran and roughly how many sessions.

1. Add temporary diagnostics

Append one JSON line per event to <cwd>/debug-token-rate.jsonl (or a similarly named file) with appendFileSync. Rules:

  • Metadata only: timestamps, event types, ids, lengths, and token counts. Never log prompt, response, or tool content.
  • Tag every record with a unique build marker (for example 'my-bug-diagnostics-v1'). That lets you confirm the build you ran contains the instrumentation and find every leftover when cleaning up.
  • Wrap each append in try {} catch {} so logging can never break the run.
  • Take the timestamp before writing. A synchronous append adds a little latency to the path you are measuring, which is fine for millisecond-scale timing. If you are measuring anything finer, push records onto an in-memory array and write them out once when the run ends.
  • Log at the earliest and latest point of each layer you care about, so the timestamps can be lined up per step.

Useful hook points, from outermost to innermost:

LayerWhereWhat to log
NetworkThe provider's fetch wrapper, e.g. buildAnthropicOAuthFetch in mastracode/sdk/src/providers/claude-max.tsrequest start; headers arrival (status, content-encoding); each body chunk via a pass-through TransformStream (bytes, SSE event: names). Re-wrap the body with new Response(body, { status, statusText, headers }).
Provider streamconvertFullStreamChunkToMastra in packages/core/src/stream/aisdk/v5/transform.tsraw chunk type and delta length as the AI SDK hands it over
Run engineprocessStreamChunk in packages/core/src/agent-controller/session-run-engine.tschunk type, getChunkProducedAt(chunk), current message id, step-start startedAt, usage. Skip per-delta chunks here if the provider layer already logs them.
TUImastracode/tui/src/tui/event-dispatch.ts (web mirror: mastracode/factory-ui/src/ui/domains/chat/services/runtime.ts)event type, ids, relevant state before and after, and any computed value (e.g. usage.computed with tokens, window, instantaneous and displayed rate)

For other providers, find the equivalent fetch option or wrapper in mastracode/sdk/src/providers/.

2. Build and verify the instrumentation shipped

pnpm install --frozen-lockfile   # fresh worktrees only
pnpm build:mastracode            # ~50s once deps are built
rg -l "my-bug-diagnostics-v1" mastracode/tui/dist packages/core/dist mastracode/sdk/dist

If rg finds nothing in a dist, the run will not produce that layer's records.

3. Drive the TUI in tmux

Start the TUI in a throwaway git repo so the agent's tool calls default to scratch files. Setting the working directory is not a sandbox: do not grant the session extra allowed paths, and keep prompts pointed at the scratch repo.

mkdir -p /tmp/mc-repro && git -C /tmp/mc-repro init -q
tmux new-session -d -s mcrepro -x 200 -y 50 -c /tmp/mc-repro \
  "node $PWD/mastracode/tui/dist/cli.js"
sleep 14   # startup

Send each prompt, then send Enter as a separate key press, then wait and read the screen:

tmux send-keys -t mcrepro "/new"; sleep 1; tmux send-keys -t mcrepro Enter; sleep 3
tmux send-keys -t mcrepro "Please do these one at a time as separate tool calls (not in parallel): write 3 files named a1.md through a3.md, each with a ~100 word paragraph about a different tree, writing a sentence of explanation before each tool call. Then run ls -la with execute_command and summarize in three sentences."
sleep 1; tmux send-keys -t mcrepro Enter
sleep 50
tmux capture-pane -t mcrepro -p | grep -v '^\s*$' | tail -3   # status line is last

Tips:

  • Pick prompts that exercise the path under test. A multi-step, one-tool-at-a-time prompt produces a mix of thinking, text, and tool-argument steps.
  • Loop the prompt several times, starting each with /new, because intermittent behavior needs a sample. Record what the screen showed each time so you can check the log against what the user would have seen.
  • Rebuild and restart the tmux session after every code change. The TUI runs from dist.

4. Analyze per step

Group the log records by step (for example, split at each usage.computed or step-finish record) with a short python3 script. For each step, compare durations across layers: request → headers → first content → last content at the network layer, and the same span at the provider, engine, and UI layers.

  • Spans equal across layers mean the pipeline adds no distortion, so the behavior comes from the provider.
  • A span that shrinks or grows between two layers is where the bug lives.
  • To test a hypothesis, change one variable (for example send accept-encoding: identity), rebuild, and rerun.

Report the evidence as a small table (normal steps vs. anomalous steps), along with the model used, the number of runs and steps, and what the data cannot prove.

5. Clean up

tmux kill-session -t mcrepro
rg -n "my-bug-diagnostics" mastracode packages --glob '!**/dist/**'   # must print nothing
git diff                                                               # read it: only intended changes remain
rm -f debug-token-rate.jsonl /tmp/mc-repro/debug-token-rate.jsonl

Also revert any experiment toggles (like changed request headers) and confirm with rg before saying they are gone. Rebuild so dist no longer contains the instrumentation.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Design and audit an agent's system prompt, the instructions that guide its work. Define a concrete outcome, starting input, available tools, completion checks, fallback behavior, and final report so the prompt describes a complete run.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Designing the core instructions for a new agent
  • Auditing a prompt before saving it
  • Defining behavior when tools or permissions are missing
mastra-ai/mastra2.9만2026년 10월 23일 업데이트

Create a dedicated test project linked to the current worktree and check Agent Builder through APIs and browser interactions. It covers agent and skill management, permissions, defaults, and related features, with selectable test sections.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Validate an Agent Builder feature branch before review
  • Check role-based permissions and authentication
  • Test agent and skill management through APIs and the UI
mastra-ai/mastra2.9만2026년 10월 23일 업데이트

Reviews pull requests for bugs, error handling, code quality, and style consistency. Organizes feedback into an overview, must-fix issues with file locations, improvement suggestions, and positive notes so reviewers can distinguish urgent problems from refinements.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Finding bugs that must be fixed before merging
  • Reviewing TypeScript types and asynchronous code
  • Checking naming, imports, and leftover debug statements
mastra-ai/mastra2.9만2026년 10월 23일 업데이트

Design instructions for agents that write, fix, review, or refactor code. Define behavior based on file access, select suitable tools, and set clear verification and completion rules for repository changes or copyable code output.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Designing an agent for repository bug fixes
  • Defining a pull request review agent
  • Creating a code generator without workspace access
mastra-ai/mastra2.9만2026년 10월 23일 업데이트

Configure Factory board behavior and GitHub or Linear event handlers in deployment code. Adjust stage transitions, phase meanings, and tool-result handling, then check the changes with focused tests and versioned audit records.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Add approval requirements to board transitions
  • Change GitHub or Linear event handling
  • Define custom board phases and tool-result rules
mastra-ai/mastra2.9만2026년 10월 23일 업데이트

Design agents that draft blog posts, social posts, newsletters, and marketing copy. Define the audience, brand voice, length, and required output so each agent delivers a complete draft with a headline and supporting notes.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Build a blog writing agent with a consistent brand voice
  • Design an agent for LinkedIn product posts
  • Define delivery rules for newsletter drafts
mastra-ai/mastra2.9만2026년 10월 23일 업데이트

mastra-ai의 스킬 모두 보기

이 스킬의 문제 신고