Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Changed
- **Buzz forwarder orders same-second messages by Buzz's `ms` tag.** `docs/integrations/buzz.mjs` adds the sub-second `ms` tag (0-999, added to kind 9 in block/buzz#9548) to a message's time, so messages in one second keep Buzz's order and a delegation and its reply no longer swap. A missing or invalid `ms` counts as 0, so archives from before the tag behave as before. Covered by `test/buzz-forwarder.test.ts`.
- **Buzz guide re-pinned to `block/buzz@7e7ec73`** (source re-checked 2026-11-19). The goose `sessions.db` columns and the `toolRequest` / `toolResponse` JSON shapes that the forwarder reads are unchanged between goose v1.28.0 and v1.60.1. On 2026-11-19 a goose 1.60.1 run wrote a real `sessions.db`: the Developer shell set `AGENT_SESSION_ID` to that session id, and `gooseToolCalls` read the tool call and its `commit_sha`. The guide now states that Builderlab cloud-run agents are not covered by the desktop-archive forwarder.

## 0.33.0

### Added
Expand Down
6 changes: 4 additions & 2 deletions docs/integrations/buzz.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

**Amplitude Agent Analytics can ingest Buzz agent teams (a person, a coordinator agent and its workers in one channel thread) from the owner's local Buzz archive, with no SDK and no private key.**

Last verified: pending live capture. Pinned to `block/buzz@12f3d51` (Buzz desktop archive) and goose v1.28.0 (`sessions.db`). This is an Amplitude-authored guide. Buzz and goose are projects of Block, Inc.; this guide is not affiliated with or endorsed by Block. Corrections are welcome as a pull request.
Last verified: pending live capture. Pinned to `block/buzz@7e7ec73` (Buzz desktop archive, source re-checked 2026-11-19) and goose v1.28.0 (`sessions.db`). This is an Amplitude-authored guide. Buzz and goose are projects of Block, Inc.; this guide is not affiliated with or endorsed by Block. Corrections are welcome as a pull request.

**Provenance of Buzz details.** Every table and field below comes from Buzz and goose source at the pinned commits:

- the archive schema: `desktop/src-tauri/src/archive/store.rs` (`archived_events`);
- kind 44200 decrypted at ingest and stored as plaintext JSON: `desktop/src-tauri/src/archive/pipeline.rs`;
- the kind 44200 payload: `docs/nips/NIP-AM.md`;
- thread tags (`["e", root, "", "root"]`, `["e", parent, "", "reply"]`): `crates/buzz-sdk/src/builders.rs`;
- thread tags (`["e", root, "", "root"]`, `["e", parent, "", "reply"]`) and the sub-second `ms` tag (added in commit `051dd2d`, #9548): `crates/buzz-sdk/src/builders.rs`;
- NIP-OA owner attestation (`["auth", owner, conditions, sig]`): `crates/buzz-sdk/src/nip_oa.rs`;
- goose `messages` (`session_id`, `role`, `content_json`, `created_timestamp`): `crates/goose/src/session/session_manager.rs`;
- `toolRequest` and `toolResponse` blocks: `crates/goose-provider-types/src/conversation/message.rs` and `tool_result_serde.rs`.
Expand Down Expand Up @@ -45,6 +45,7 @@ scheduled job on the owner's machine (for example, every 15 minutes)
- It never reads kind 24200 frames and never needs a private key. The desktop already stored kind 44200 as plaintext.
- It doesn't read tool calls for workers on other harnesses. A Claude Code or Codex worker reports its own tool calls through [claude-code.md](claude-code.md) or [codex.md](codex.md), and joins the team through `[Agent] Parent Agent ID`.
- Remote mode (a dedicated member key invited to channels) sees messages only. Archive mode is the documented path.
- Cloud-run agents. Builderlab cloud execution does not write the desktop archive, so this forwarder does not see those agents. Buzz's relay OpenTelemetry (`crates/buzz-relay/src/telemetry.rs`) is infrastructure tracing over OTLP gRPC, not agent spans, and Amplitude accepts OTLP over HTTP. Covering cloud-run agents needs either OTLP/HTTP GenAI spans carrying session, user, agent, parent agent, tokens, and cost, or a server-side feed of kind 0, 9, and 44200 events that this forwarder normalizes unchanged.

### What the archive must already contain

Expand Down Expand Up @@ -118,6 +119,7 @@ Copy [buzz.mjs](./buzz.mjs) unchanged next to the job (it also ships in the npm
| Buzz or goose | Agent Analytics |
|---|---|
| Thread root event (`e` tag marked `root`, else `reply`) | `[Agent] Session ID`; a message with no thread uses the channel plus the idle window |
| Kind 9 `ms` tag (0-999) | Sub-second offset added to the message's time, so messages in the same second keep Buzz's order. A missing or invalid value counts as 0 |
| A person's message | `[Agent] User Message` to the agent it mentions (`p` tag), else the thread's first agent |
| An agent's message | `[Agent] AI Response` from that agent |
| An agent's message that mentions another agent | the next input to that agent: a `[Agent] User Message` to the worker when it replies, with `[Agent] Parent Agent ID` set to the sender |
Expand Down
17 changes: 13 additions & 4 deletions docs/integrations/buzz.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Maps a Buzz desktop archive (archive.db) and goose workers' sessions.db to Amplitude [Agent] events.
// No network, no keys: the desktop stores kind 44200 already decrypted, and kind 24200 is never read.
//
// Pinned to block/buzz@12f3d51 (desktop/src-tauri/src/archive/store.rs) and goose v1.28.0
// (crates/goose/src/session/session_manager.rs). Unknown shapes throw BuzzSchemaError instead of guessing.
// Pinned to block/buzz@7e7ec73 (desktop/src-tauri/src/archive/store.rs, pipeline.rs; the `ms` tag from
// crates/buzz-sdk/src/builders.rs, checked 2026-11-19) and goose v1.28.0 (crates/goose/src/session/session_manager.rs).
// Unknown shapes throw BuzzSchemaError instead of guessing.
//
// rows: archived_events rows { id, kind, pubkey, created_at, raw_json }
// kind 9 raw_json is the Nostr event: channel in the `h` tag, thread in `e` tags, mentions in `p` tags
// kind 9 raw_json is the Nostr event: channel in the `h` tag, thread in `e` tags, mentions in `p` tags,
// and an optional `ms` tag (0-999) that orders messages within the same second
// kind 0 raw_json is the profile event; an `auth` tag (NIP-OA) marks the author as an agent
// kind 44200 raw_json is the decrypted NIP-AM payload { harness, model, channelId, sessionId, turnId, timestamp, turn, deltaReliable, stopReason }
// mapping: { users: { <pubkey>: <user id> }, agents?: { <pubkey>: { id?, name? } }, gooseMessages?: sessions.db rows,
Expand Down Expand Up @@ -148,6 +150,13 @@ function tagValues(event, name) {
return (Array.isArray(event.tags) ? event.tags : []).filter((tag) => Array.isArray(tag) && tag[0] === name);
}

// Sub-second offset from the `ms` tag. Anything other than an integer 0-999 (including a missing tag)
// counts as 0, so messages from before the tag was added keep second precision.
function subSecondMs(event) {
const ms = Number(tagValues(event, 'ms')[0]?.[1]);
return Number.isInteger(ms) && ms >= 0 && ms < 1000 ? ms : 0;
}

function threadRoot(event) {
const eTags = tagValues(event, 'e');
const root = eTags.find((tag) => tag[3] === 'root') ?? eTags.find((tag) => tag[3] === 'reply');
Expand Down Expand Up @@ -192,7 +201,7 @@ export function normalize(rows, mapping = {}) {
messages.push({
id: row.id,
pubkey: row.pubkey,
time: Number(row.created_at) * 1000,
time: Number(row.created_at) * 1000 + subSecondMs(event),
text: event.content,
channel: tagValues(event, 'h')[0]?.[1] ?? '',
root: threadRoot(event),
Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/fixtures/buzz-archive.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "Synthetic Buzz archive.db archived_events rows and a goose worker's sessions.db messages rows, shaped after block/buzz@12f3d51 and goose v1.28.0. Replace with a scrubbed live capture when one exists.",
"description": "Synthetic Buzz archive.db archived_events rows and a goose worker's sessions.db messages rows, shaped after block/buzz@7e7ec73 (same message shape; ms tag as in 051dd2d) and goose v1.28.0. Replace with a scrubbed live capture when one exists.",
"archive": [
{ "id": "p-coord", "kind": 0, "pubkey": "agent-coordinator", "created_at": 1767000000, "raw_json": "{\"kind\":0,\"content\":\"{\\\"name\\\":\\\"coordinator\\\"}\",\"tags\":[[\"auth\",\"owner-alice\",\"\",\"sig\"]]}" },
{ "id": "p-worker", "kind": 0, "pubkey": "agent-worker", "created_at": 1767000000, "raw_json": "{\"kind\":0,\"content\":\"{\\\"name\\\":\\\"worker\\\"}\",\"tags\":[[\"auth\",\"owner-alice\",\"\",\"sig\"]]}" },
Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/goose.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**goose (CLI and desktop) exports OpenTelemetry traces. Point them at Amplitude and each goose session becomes an Agent Analytics session.**

Last verified: pending live capture. Telemetry pinned to goose v1.28.0 or later; commit stamping needs goose v1.44.0 or later. This is an Amplitude-authored guide; goose is a project of Block, Inc., which does not endorse it. Corrections are welcome as a pull request.
Last verified: pending live capture. Telemetry pinned to goose v1.28.0 or later; commit stamping needs goose v1.44.0 or later. On 2026-11-19, goose 1.60.1's Developer shell set `AGENT_SESSION_ID` to the `sessions.db` session id, and that database parsed through the Buzz forwarder, including `commit_sha`. This is an Amplitude-authored guide; goose is a project of Block, Inc., which does not endorse it. Corrections are welcome as a pull request.

**Provenance.** Span and resource attributes come from goose source at v1.28.0: `crates/goose/src/otel/otlp.rs` (OTLP exporter and `EnvResourceDetector`, so `OTEL_RESOURCE_ATTRIBUTES` is honored) and the agent's `reply_stream`, chat and tool spans. goose v1.44.0 and later set `AGENT_SESSION_ID` to the session ID for the shell commands it runs, replacing any inherited value; the commit hook stamps it. Earlier versions pass an inherited `AGENT_SESSION_ID` through unchanged, so a goose started from another agent's shell stamps that agent's ID. Verified offline with goose v1.43.0 and v1.44.0; telemetry is not yet checked against a live capture.

Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
"id": "buzz",
"name": "Buzz",
"category": "coding_agent",
"pinned_version": "block/buzz@12f3d51",
"pinned_version": "block/buzz@7e7ec73",
"url": "https://github.com/amplitude/Amplitude-AI-Node/blob/main/docs/integrations/buzz.md",
"raw_url": "https://raw.githubusercontent.com/amplitude/Amplitude-AI-Node/main/docs/integrations/buzz.md",
"paths": ["archive_forwarder", "goose_sessions_db"],
Expand Down
68 changes: 68 additions & 0 deletions test/buzz-forwarder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,74 @@ describe('buzz forwarder', () => {
for (const c of golden.cases) expect([c.name, parseCommitSha(c.tool_name, c.input, c.output)]).toEqual([c.name, c.expected]);
});

describe('same-second ordering from the ms tag', () => {
const profiles = fixture.archive.filter((row) => row.kind === 0);
const message = (id: string, pubkey: string, createdAt: number, content: string, tags: string[][]) => ({
id,
kind: 9,
pubkey,
created_at: createdAt,
raw_json: JSON.stringify({ kind: 9, content, tags }),
});
const SECOND = 1767000100;

it('orders two messages in the same second by ms, even when event IDs sort the other way', () => {
// 'aa-reply' sorts before 'zz-root' by event ID, but its ms offset (900) puts it after the root (100).
const rows = [
...profiles,
message('zz-root', 'human-alice', SECOND, '@coordinator quick one', [
['h', 'chan-3'],
['p', 'agent-coordinator'],
['ms', '100'],
]),
message('aa-reply', 'agent-coordinator', SECOND, 'On it', [
['h', 'chan-3'],
['e', 'zz-root', '', 'root'],
['ms', '900'],
]),
];
const { events } = normalize(rows, mapping) as { events: Event[] };
const thread = events.filter((e) => e.event_properties['[Agent] Session ID'] === 'zz-root');
expect(thread.map((e) => e.event_type)).toEqual(['[Agent] User Message', '[Agent] AI Response']);
expect(thread[0]?.time).toBe(SECOND * 1000 + 100);
expect(thread[1]?.time).toBe(SECOND * 1000 + 900);
expect(thread.map((e) => e.event_properties['[Agent] Turn ID'])).toEqual([1, 2]);
expect(checkAgentEvents(thread).errors).toEqual([]);
});

it('keeps second precision when ms is not an integer from 0 to 999', () => {
const rows = [
...profiles,
message('zz-root', 'human-alice', SECOND, '@coordinator bad offsets', [
['h', 'chan-3'],
['p', 'agent-coordinator'],
['ms', '1200'],
]),
message('aa-reply', 'agent-coordinator', SECOND, 'Noted', [
['h', 'chan-3'],
['e', 'zz-root', '', 'root'],
['ms', 'x'],
]),
];
const { events } = normalize(rows, mapping) as { events: Event[] };
const thread = events.filter((e) => e.event_properties['[Agent] Session ID'] === 'zz-root');
expect(thread.map((e) => e.time)).toEqual([SECOND * 1000, SECOND * 1000]);
});

it('still binds a kind 44200 metric to its reply when the reply carries an ms offset', () => {
// Shift the worker reply (m3) to 900 ms. Its metric is 500 ms into the second, so binding must still hold.
const archive = fixture.archive.map((row) => {
if (row.id !== 'm3') return row;
const event = JSON.parse(String(row.raw_json));
return { ...row, raw_json: JSON.stringify({ ...event, tags: [...event.tags, ['ms', '900']] }) };
});
const { events } = normalize(archive, mapping) as { events: Event[] };
const reply = events.find((e) => e.insert_id === 'buzz:m3:reply')?.event_properties ?? {};
expect(reply).toMatchObject({ '[Agent] Input Tokens': 1200, '[Agent] Cost USD': 0.012 });
expect(checkAgentEvents(events).errors).toEqual([]);
});
});

it('carries the forwarder core byte-for-byte from sierra.md', () => {
expect(coreOf('buzz.md')).toBe(coreOf('sierra.md'));
});
Expand Down
Loading