Skip to content

feat: wake 1.0 — Rust hook collector sending skill telemetry over OTLP - #101

Closed
moraisjose wants to merge 39 commits into
mainfrom
v2
Closed

moraisjose wants to merge 39 commits into
mainfrom
v2

Conversation

@moraisjose

@moraisjose moraisjose commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Wake 1.0 replaces the Go 0.x (local per-developer reports, consent machinery, full transcript rescans) with a small Rust binary that Claude Code hooks call asynchronously. Each SessionStart / Stop / SessionEnd reads only the new slice of the transcript. It derives one event per skill, subagent, MCP tool (aggregated) or slash command, and sends them as OTLP/HTTP JSON spans to a configured endpoint, Langfuse first.

  • Design: docs/superpowers/specs/2026-11-26-wake-v2-design.md
  • Plan: docs/superpowers/plans/2026-11-26-wake-v2-claude-code.md

What's in it

  • wake emit: incremental transcript reader that keeps allowlisted fields only. Skill windows come from the harness's own attributionSkill. Subagents are handled both foreground and background (background ones are closed by their <task-notification>). Subagent transcripts are followed up to depth 3, and tokens are never counted twice.
  • Delivery: one closed allowlist of attributes (spec §5.6) with gen_ai.* token and model fields so Langfuse prices them, and deterministic span ids. The order is enqueue, then save state, then one flush per run, with a bounded outbox (1,000 entries / 7 days; batches of 50; 5 s deadline).
  • State: per-session state with a non-blocking lock, forward-only offsets, and 14-day GC. Abandoned sessions get flushed only when both the state and the transcript have been idle for 30 min.
  • wake check: prints the resolved config without secrets and sends a test event.
  • wake install / wake uninstall [--purge]: merges three async hook groups into ~/.claude/settings.json and removes them again. It never touches APM-installed hooks, refuses files it can't parse safely, and the install + uninstall round trip is byte-identical.
  • Distribution: install.sh (checksum-verified), a GitHub Releases workflow (4 targets, ≤ 2 MB each, tag must match the crate version), and an APM package template under package/.
  • Docs: README, SECURITY.md and CONTRIBUTING rewritten for 1.0, plus docs/langfuse-setup.md.

v1 is tagged locally as v1-final. That tag is not pushed yet.

Test plan

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings: clean
  • cargo test: 179 passed, 0 failed (perf test ignored in the default run, run separately in CI)
  • Perf (release): one turn of a 22 MB transcript in 18.8 ms CPU and 4.8 MB RSS (budget 50 ms / 10 MB); binary 1.65 MB
  • Real headless Claude Code sessions against a local OTLP receiver:
    • a slash-invoked skill, a model-invoked skill and a background subagent each produced the expected span, with tokens and model;
    • no prompt text, tool output or local paths appeared in the bodies.
  • wake install → check → uninstall --purge on a copy of a real settings.json: byte-identical
  • Langfuse test project: pricing of gen_ai.*, and upsert of a resent span id
  • First run of release.yml (e.g. a v1.0.0-rc.1 tag, after bumping Cargo.toml)
  • Live MCP tool aggregate (covered by fixtures only)

Known follow-ups

  • A background subagent running more than 30 min while its own session is idle can be closed early by another session's stale flush.
  • A permanent 4xx on a batch drops the whole batch (up to 50 events).
  • A <synthetic> last model yields no model on a subagent span.

🤖 Generated with Claude Code

moraisjose and others added 30 commits November 26, 2026 11:34
…telemetry over OTLP

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Handle background subagents (async_launched, closed by task-notification),
allow '_' in the token allowlist, pass session_id to derive, tighten
slash-command detection, flush open invocations of sessions that never
got SessionEnd, keep APM-installed hooks out of wake install/uninstall,
and add Langfuse JSON and upsert checks. Spec drops StopFailure, sends
MCP aggregates per turn, and simplifies the inventory entry format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fig files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds langfuse.observation.type=generation on spans carrying a model or
tokens, so Langfuse prices them (plan Task 5 table and spec 5.6 updated).
Docs: https://langfuse.com/integrations/native/opentelemetry
      https://langfuse.com/docs/opentelemetry/get-started

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fields only

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…use in either order

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tions

Foreground Agent results close a Subagent invocation at once; background
ones wait in state.pending_agents for their task-notification or session
end. MCP tool_uses aggregate per (server, tool, enclosing skill) per derive
call. Non-skill slash commands become Command events. Adds the
subagent_transcript path helper.

Also folds in ruling R15: a command moves the interrupt turn start and ends
other invocations' slash-merge window, an invocation no longer counts its
own start Skill tool_use, and close() builds by OpenInvocation.kind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…agent transcripts

Subagent span keys include the launching Agent tool_use id, so a continued
subagent (same agentId) gets a distinct span. Background agents without a
tool_use id are not kept, and empty notification ids match nothing.
SessionState.root_parent_key (R17) parents skills, subagents, MCP
aggregates and commands that have no enclosing skill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…v2 docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e pins

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…age entries

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uses it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…skills, and carry the model

R29: a subagent span's tokens are its transcript total minus the tokens of the
skill invocations derived from that same transcript (both requestId-deduped, so
disjoint), and its gen_ai.request.model is the model of the transcript's last
assistant entry with usage, so Langfuse can price it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… are both idle

R27 (amends R18): SessionState saves the transcript path on every hook run. The
stale flush needs the state file and the transcript (when known and present)
both untouched for 30 minutes, so a long single turn or a long background
subagent in another live session is no longer closed early. Subagents closed by
the stale flush are followed into their own transcripts with the R16/R29 token
and model logic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R28: queued payloads are merged 50 at a time into one ExportTraceServiceRequest
(their resourceSpans concatenated), no POST starts once the flush has run 5 s,
and the outbox is rewritten after each batch that succeeds or is rejected for
good, so a kill mid-flush keeps the progress made. The first transient failure
still ends the flush. A queued body that is not OTLP is sent on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R30: the outbox lock and the outbox writer created the state dir with the
default umask, and the outbox and its tmp file were 0644 although they hold
encoded spans (user email, repo). Every state directory is now created 0700 and
the outbox is written through a fresh 0600 tmp file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
moraisjose and others added 9 commits November 26, 2026 13:18
SECURITY.md still described v1 (consent tables, wake remote, doctor, the
loopback dashboard, no outbound spool, HMAC repo identity). It now covers what
v2 sends (the spec 5.6 allowlist, wake.repo in clear, email or salted
pseudonym), what stays local (0600 config with credentials, 0700 state dir,
0600 outbox of queued spans), install never touching hooks it does not own,
wake check never printing secrets, and the Langfuse key caveat (spec 5.8).
The reporting channel is unchanged.

wake --version / -V prints "wake <version>", as the report template asks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…shing

The launcher exits 0 without running anything when the binary it picks is not
executable, so a package committed without the exec bit installs cleanly and
silently sends nothing. The template README now has the chmod +x and
git update-index --chmod=+x step, and how to check for mode 100755.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R30: a new version job compares the pushed tag (without its leading v) with the
crate version from cargo metadata, and every build job needs it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… comment fixes

R30: the README now lists the per-repo .claude/settings.local.json env level
for WAKE_DISABLED (spec 5.2), documents $XDG_CONFIG_HOME/wake/config.json, and
explains identity_salt (anonymous mode sends no user without it).
CONTRIBUTING places the hook enum in harness/claude_code/mod.rs, and the
transcript reader's header says prompt text is read transiently and never
retained or sent, rather than never held.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R30: trace_id("s1") and span_id("k1") are pinned to hex computed
independently with shasum, so a change to the id derivation (which would re-key
every span already stored in a backend) fails a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…otes

R30: the hook command is "<exe>" emit <event>, run by a shell. A path
containing ", $, a backtick or a backslash would break out of or be expanded
inside those quotes, so install now refuses it with InstallError::UnsafeExePath
and a clear message, before writing anything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…from public_key/secret_key

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude Code's transcript input_tokens excludes cached tokens, while the OTel GenAI
semconv (and Langfuse) treat gen_ai.usage.input_tokens as the total and subtract the
cache fields from it. Verified against Langfuse Cloud: input 10 + cache 52,000 was
recorded as input 0; sending the total (52,010) records input 10 and prices it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@moraisjose moraisjose closed this Nov 26, 2026
@moraisjose
moraisjose deleted the v2 branch November 26, 2026 15:24
@moraisjose moraisjose changed the title feat: wake v2 — Rust hook collector sending skill telemetry over OTLP feat: wake 1.0 — Rust hook collector sending skill telemetry over OTLP Nov 26, 2026
@moraisjose

Copy link
Copy Markdown
Collaborator Author

Superseded by 102 after renaming the branch from v2 to rust-rewrite: #102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant