Skip to content
Draft
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
42 changes: 42 additions & 0 deletions .github/workflows/check-metrics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Check metrics plugin

on:
pull_request:
paths:
- metrics/**
- indexer/**
- package.json
- pnpm-lock.yaml
- .github/workflows/check-metrics.yml
push:
branches: [main]
paths:
- metrics/**
- indexer/**
- package.json
- pnpm-lock.yaml
- .github/workflows/check-metrics.yml

permissions:
contents: read

jobs:
check:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
- run: corepack enable
- run: pnpm install --frozen-lockfile
- run: pnpm test
- run: pnpm validate fixtures/index.json
- run: pnpm -C metrics install --frozen-lockfile
- run: pnpm -C metrics check
- name: Verify the committed runtime is reproducible
run: git diff --exit-code -- metrics/plugin.js
- run: pnpm run check-plugin metrics
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ https://raw.githubusercontent.com/block/buzz-plugins/index/index.json
| [`.github/`](./.github) | The workflows that publish the index and check new sources, and the list-a-plugin issue form |
| [`marketplace/`](./marketplace) | The Community Marketplace Buzz plugin that browses the index |
| [`template/`](./template) | A starter plugin for authors |
| [`metrics/`](./metrics) | Default-off metrics example with redacted local inspection; not listed or published automatically |
| [`PUBLISHING.md`](./PUBLISHING.md) | The checklist for getting a plugin listed, and the local check to run first |
| [`SPEC.md`](./SPEC.md) | The contract: listing keys, publicity check, audit, `index.json`, publishing |
| [`VERIFICATION.md`](./VERIFICATION.md) | How a listing becomes Verified by Buzz, and how that is withdrawn |
Expand Down
1 change: 1 addition & 0 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ indexer/ crawl, publicity check, audit, listing metadata, build ind
.github/ publish and check workflows, and the list-a-plugin issue form
marketplace/ the Community Marketplace Buzz plugin
template/ a minimal plugin for authors to copy
metrics/ a default-off metrics example; separate draft, no automatic listing
```

## Listing key
Expand Down
1 change: 1 addition & 0 deletions metrics/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
81 changes: 81 additions & 0 deletions metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Buzz Metrics — preview

An opt-in example plugin consuming Buzz's optional `ctx.telemetry` service. This is a draft for API/design feedback, not production analytics. It is separate from developer diagnostics and never uploads metrics records to a community relay automatically. While enabled, observed allowlisted searches carry the host's ephemeral query join fields; separately enabled Linked tracing adds `traceparent` to allowed relay requests.

## Consent and local inspection

1. Install the built folder, then open **Settings → Privacy → Metrics** or **Metrics preview**.
2. Enter exact HTTPS community origins separated by commas. Leave personal communities out. An unknown, malformed or non-allowlisted community is never recorded or traced.
3. Choose a level and **Apply settings and clear pending data**. Collection is still off.
4. Explicitly enable collection. Tracing and export are separate opt-ins. Closing the page does not disable enabled collection.
5. Turn collection off, disable/reload the plugin, or choose **Clear pending data** to discard pending records and private search state. Reload resets every setting and consent to off. Already exported data cannot be recalled.

Granularity buttons and consent switches apply immediately and clear pending data. Community/backend text fields use **Apply settings**. Invalid settings stop collection and reset the confirmed configuration instead of leaving an old allowlist or export target running behind an error.

The search subscription itself is admitted only while the host exposes a ready origin:viewer snapshot for a selected allowlisted community. It detaches and clears private search state when that scope changes or becomes unknown. A host without that capability keeps search collection off; this is subscription admission, never attribution of a completed UI timing. Other plugins can independently enable host observers outside this plugin's control.

The preview displays only the exact redacted records eligible for export. No settings, consent, metrics or raw query state is written to disk by this plugin. The consumer must trust installed plugins; same-process plugins are not sandboxed.

### Granularity

- **Off** by default: no telemetry subscriptions, trace provider or plugin timers.
- **Level 1 — Counts:** aggregate request counts and one search-session summary on close. Request categories combine the allowlisted communities and omit community identifiers too. No IDs, timings, query order or per-query/click records. An unused dialog produces no record.
- **Level 2 — Linked:** request timings and bytes, ephemeral session/query/attempt joins, query shape/relation, and result activation metadata. Opened message event IDs and positions may let a backend link to content it can access. Raw query text, result labels, filter values and message content are never records.
- **Level 3** query-text export is deliberately unavailable.

Counts omits IDs from plugin records. The current host still adds its own ephemeral `query_id`/`attempt` to observed searches, including Counts, while this plugin's search subscription is active in an allowlisted community. Those join fields are not a trace-context provider and do not enter Counts export records.

Navigation-only sessions (at least one non-message open and no message open) are retained with `navigation_session: true`, including their group/bucket opens and Linked `below_messages`. The local queued-message open-rate and session-success preview explicitly exclude those sessions. Until a host supplies explicit dispatch evidence, current-host rates cover only queries positively established by relay-ranked results: unproven empty/failed searches are omitted. These are incomplete-coverage diagnostics, not overall search-quality rates. A backend must apply the same exclusion. Rates describe only session summaries currently in the bounded local queue, not lifetime totals.

## Search aggregation and redaction

Raw host events are projected through explicit allowlists; no raw payload is spread into a record. Counts discards query content after classification. In Linked mode, query content and filter signatures exist only in private bounded in-memory state for classification. They expire after 30 seconds, and all private state is cleared on scope/privacy/settings changes or disposal. Result labels and message content are never retained.

A proven eligible query has text and evidence that it sent a message search. Finished/failed results must remain shown for 2 seconds, or be acted on, to settle. Queries replaced/closed first are marked superseded/unsettled. Filter-only queries are not eligible. Settled eligible/empty/failed/opened counts are summarized at dialog close. Linked records preserve the host's `query_id` and `attempt` and add a local sequence.

The optional session `queries` count and Linked `seq` track logical host query IDs. A higher `attempt` on the current query ID is a retry/re-evaluation, not another query: it keeps seq, relation, eligibility and opened evidence, updates the latest attempt, and restarts unfinished-result waiting. It cannot add another eligible denominator or a phantom superseded query. Only settled dispatch-proven `eligible` fields belong in message search rates. Relations are computed on device against the previous dispatch-proven query within a 30-second issuance gap, including across dialog openings: same, refilter, extends, shortens, edits (shared word), or new. Only shape (counts, flags and operator names) leaves that classifier; never tokens or filter values.

### Draft host-contract gaps

The preview expects the passive requests/ui/search contracts from the telemetry-service prototype, and safely tolerates missing services/topics:

- Current `uiTiming` events lack a community. They are dropped, not attributed to the currently selected community. A host should add an authoritative `community` field.
- Current `queryIssued` fires before an actual message request and lacks explicit dispatch evidence. The plugin accepts an optional boolean `messageSearch: true`; otherwise relay-ranked result rows establish dispatch. Empty/failed searches without that evidence are **not counted eligible**, rather than invented as empty/failed searches. The host should expose dispatch explicitly.
- Session summaries preserve a bounded `reason`, including `subscribers_changed`, so backends can identify observer-cohort fragments rather than assume every summary is a complete dialog. Reconnects or unknown selected scope detach search and discard the open session conservatively.
- Group projection uses known English display labels and falls back to `other`; a stable host group ID is a follow-up for localization/custom groups.
- Host activation `kind` is a destination kind, not open/action. Known message/channel/person/agent/chat/page/plugin destinations map to open; explicit action/other map to action. Current host Search actions that emit no activation cannot be counted. Unknown group labels become `other`, never free-form strings.
- This draft reports `app_version: "unknown"` because the current contract does not expose it.
- Request 4xx other than 429 follow the host's current network outcome classification. Browser operational WS/live-phase and native media coverage remain host work; the plugin cannot manufacture missing events.
- Trace and query IDs are transport joins only. Relay recording/extraction and a production deployment test remain separate work; they are not established by this plugin.

## Bounded buffers, export and teardown

The record/count queue holds at most 200 records, dropping oldest on overflow; one in-flight batch holds at most 25 additional records. At most 8 search sessions are active and each retains at most 64 already-redacted Linked records until close so its navigation flag can be determined. Session overflow is marked `truncated`. Private current/previous query strings are bounded to 4096 characters and 30 seconds. No replay or retry queue is persisted.

Export sends one at-most-once JSON batch every 10 seconds (or **Send one batch**) only after separate export consent. Errors drop that batch without retrying, logging response bodies, or displaying arbitrary error text. The ring is shared: heavy request traffic can evict pending search records; delivery is not reliable and per-type quotas remain a design question. Turning off or reconfiguring invalidates in-flight completion and protected-request eligibility, removes all listeners/providers, and cancels all plugin clocks. A request already delivered to a backend cannot be undone.

### Local-only default / pluggable backend

`manifest.json` deliberately declares an empty `host.networkOrigins`. The default build cannot export. A distributor can add its chosen backend's exact HTTPS origin, rebuild, and install/review that changed manifest. For example, a backend at an operator-owned origin would receive:

```json
{ "schema": 1, "records": [] }
```

The Settings endpoint may be any path at a declared origin, but cannot contain credentials, query parameters or a fragment. Transport uses only `ctx.host.requestOnce` with a 10-second native deadline and a live eligibility callback; there is no direct-fetch or older-request fallback. An old host without that protected API remains local-only. Export authentication is not implemented in the example adapter; a distributor can provide another `MetricsBackend` implementation using its permitted host capabilities and appropriate secret handling. Do not put credentials in the endpoint URL.

Tracing is Linked-only, separately enabled, and generates valid random W3C version-00 IDs only for exact allowlisted relay origins. Flags are `00` (no sampling request). Only context generated by this plugin can enter its request records. Opt-out/disposal unregisters the provider immediately. W3C mode is implemented; a separately configured correlation-ID mode is deferred.

## Development / listing

Requires Node 24 and pnpm, following the repository template. The pinned preview author types remain vendored; newer optional services are structurally feature-detected rather than forced into `inject`.

```sh
pnpm install --frozen-lockfile
pnpm -C metrics install --frozen-lockfile
pnpm -C metrics check
pnpm test
pnpm run check-plugin metrics
```

`check` type-checks, builds one self-contained `plugin.js`, and tests logic, Settings interactions with real Cordis lifetime ownership, protected export, privacy bounds, and the indexer's manifest/listing/audit rules. `plugin.js` must be tracked next to the manifest. The local listing CLI correctly fails while built files are uncommitted or commits are unpushed; rerun it after the authorized local commit/push. No `sources.txt` entry or automatic listing/publishing is added by this draft.
20 changes: 20 additions & 0 deletions metrics/buzz-listing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
tagline: Opt-in metrics with local redaction and an explicit community allowlist
description: |
Collection starts off and resets on plugin reload. Inspect bounded, redacted
records on this device. Raw search query text stays only in short-lived memory
for settle/relation classification and is never placed in the record queue,
preview, or export. Linked mode preserves ephemeral query join fields.

The default build declares no network origins and is local-only. A distributor
can declare its metrics backend origin and rebuild; export uses only Buzz's
protected host request API. Metrics records are not uploaded to a community
relay automatically. While enabled, allowlisted searches carry the host's
ephemeral query join fields; optional Linked tracing adds trace context to
allowed relay requests.
category: developer-tools-and-integrations
tags: [metrics, privacy, search]
setup:
- title: Choose communities and granularity
detail: Open Settings → Privacy → Metrics, enter exact community origins, and choose Counts or Linked.
- title: Opt in explicitly
detail: Enable collection for this plugin activation. Export and tracing are separate opt-ins.
11 changes: 11 additions & 0 deletions metrics/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "xyz.block.metrics",
"name": "Buzz Metrics",
"apiVersion": 1,
"description": "Default-off, community-scoped metrics with redacted local inspection and optional export.",
"host": { "networkOrigins": [] },
"discovery": {
"category": "developer-tools-and-integrations",
"tags": ["Metrics", "Privacy", "Search"]
}
}
28 changes: 28 additions & 0 deletions metrics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "xyz.block.metrics",
"private": true,
"type": "module",
"packageManager": "pnpm@11.8.0",
"engines": {
"node": "24.x"
},
"scripts": {
"build": "tsc && vite build",
"test": "vite build && vitest run",
"check": "tsc && vite build && vitest run"
},
"devDependencies": {
"@buzz/author": "file:vendor/buzz-author-0.0.0-preview.1-89e2d15.tgz",
"@deepseek-ai/cordis": "4.0.2",
"@testing-library/react": "16.3.3",
"@types/node": "24.13.6",
"@types/react": "19.2.18",
"@types/react-dom": "19.2.7",
"jsdom": "30.0.1",
"react": "19.2.8",
"react-dom": "19.2.8",
"typescript": "7.0.2",
"vite": "8.2.2",
"vitest": "4.1.11"
}
}
Loading