Skip to content

feat: opt-in telemetry; why for every unit - #3

Merged
tenphi merged 10 commits into
mainfrom
claude/scope-gpookh
Nov 13, 2026
Merged

tenphi merged 10 commits into
mainfrom
claude/scope-gpookh

Conversation

@tenphi

@tenphi tenphi commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

This pull request has four changes:

  1. Opt-in telemetry. A team sees how agents and people use its harnesses (new spec chapter 14).
  2. why for every unit. The original fix in this PR.
  3. Optional peers in extends. A missing optional peer no longer warns.
  4. harnesspm's config rule loads only for the project's own files, not when an agent reads a dependency's harness.

1. Telemetry

Decisions

  • Off unless the team turns it on, in harnesspm.json, which is committed.
  • The team picks the handler: a command or a file. harnesspm has no vendor code (no Linear, PostHog or OTLP clients). Built-in vendor adapters are recorded as a removed option in 13.12.
  • No report command. Reporting harness problems is the project's own rule, not a harnesspm feature. Spec 14.8 gives a rule template. A harnesspm report command is recorded in 13.12 as a removed option, with what would bring it back.
  • Agent events are opt-in too. They come from harnesspm's own hooks, written only by a sync that a person runs.

Config

{
  "telemetry": {
    "events": "all",
    "send": { "file": ".harnesspm/events.jsonl" }
  }
}
  • send is required. It is either a command, which gets each event as JSON on stdin, or { "file": "<path>" }, which appends JSON Lines.
  • events defaults to "all". It can also be a list of the types below.
  • schema/harnesspm.schema.json has the new field.

Events

Type Sent when
run A script ends. Has exit and duration. A hook's script is a run with caller hook.
mcp An MCP server starts.
sync sync writes outputs. Has packages and versions, units added, removed and changed since the last lock, and pending packages.
why why finds a unit.
read Agent event: the agent reads a harness file (a rule, a generated rule, a docs page or index, a file in a skill folder), or Claude Code loads a file-scoped rule by itself. Has via (tool or auto) and, for docs, page.
skill Agent event: the agent loads a skill.
session Agent event: a session starts. Has source.

Every event has these common fields: schema (harnesspm.event/1), time, project, workspace, harnesspm (its version), caller (person, agent, hook or ci), agent, session, unit, package and version.

Events never hold:

  • script arguments, file contents, prompts, tool output or absolute paths;
  • units of added harnesses, which belong to a person.

Sending never waits or fails

  • File handler: harnesspm appends one line.
  • Command handler: harnesspm starts a detached process, which runs the command with a 10-second limit.
  • Errors go to node_modules/.harnesspm/telemetry.log. Nothing is printed, and no exit code changes.

Trust

The model is the same as for hooks (spec 6.2, rule 4):

  • A sync that a person runs records the handler in harnesspm.lock.json as "telemetry": { "send": … }.
  • Events go only to a handler whose send in harnesspm.json matches the lock.
  • A sync that the agent's model runs keeps the lock's handler. So a handler that an agent adds or changes is held: sync and status say so, until a person runs sync or approve.
  • Removing telemetry needs no person.
  • sync --check fails while the lock and harnesspm.json differ, so a reviewer sees the change.

Opting out on one machine. Each of these stops every event, and the next sync removes the hooks:

  • DO_NOT_TRACK=1 (now listed in spec 11);
  • "telemetry": false in harnesspm.local.json, which sync now keeps out of git;
  • "telemetry": false in ~/.harnesspm/config.json.

What agents see

Claude Code. A sync that a person runs writes these entries into .claude/settings.local.json:

  • PostToolUse with the matcher Read|Skill;
  • InstructionsLoaded with the matcher path_glob_match;
  • SessionStart.

All are "async": true. Each runs <project>/node_modules/.bin/harnesspm track --agent claude, not npx.

Codex. Only SessionStart, in .codex/hooks.json. Codex has no tool that reads a file: it reads through its shell tool, which hooks see as Bash. So a read or skill event cannot be mapped to a unit reliably, and Codex sends neither (sourced in the research doc).

How track works.

  1. It reads the hook's JSON from stdin.
  2. It maps the path, or the skill name, to a unit with an index that sync writes to node_modules/.harnesspm/telemetry.json.
  3. It hands the event off and exits 0, printing nothing.

cli.ts loads only the telemetry module for track. A call takes about 35 ms, close to a bare node start (about 30 ms); other commands take about 70 ms.

Always-on text is unchanged. The managed block gets nothing new.

Hook facts checked

  • Claude Code (docs plus a headless probe, version 2.1.323):
    • Read passes tool_input.file_path, and Skill passes tool_input.skill.
    • SessionStart passes source and session_id.
    • async hooks fire in -p runs, and -p kills async hooks still running at teardown. That is why delivery runs in a detached process.
    • CLAUDE_CODE_SESSION_ID reaches the commands the model runs.
  • Codex (source at commit 69231e1): the SessionStart input fields, and the async field on hooks.
  • All are in docs/research/agent-capabilities.md, with ✅ or 🔍 marks.

End-to-end run

Setup:

  • npm pack of this branch, installed in a scratch project with an isolated HOME.
  • A hand-made @acme/kit with an always-on rule, a file-scoped rule for **/*.tsx, a docs folder, a skill and a script.
  • A file handler with all events.

Steps and results:

  1. init run by the agent. The handler was held, and status said why.
  2. sync run by a person. It recorded the handler and wrote the async hooks.
  3. Task 1: a headless claude -p run with the prompt "Add a kit Button to src/App.tsx that says Save. Then review the file with the kit-review skill." It sent these events:
    session  source=startup
    read     kit:rules/tsx   via=tool
    read     kit:rules/tsx   via=auto   (the .claude/rules link, through InstructionsLoaded)
    read     kit:docs        page=llms.txt
    read     harnesspm:rules/harnesspm-config  via=auto   (the bug fixed in section 4)
    read     kit:docs        page=button.md
    run      kit:scripts/probe  exit=0 duration=30
    skill    kit:skills/kit-review
    
    A sample line:
    {"schema":"harnesspm.event/1","type":"run","time":"2026-11-13T15:17:49.159Z","project":"e2e-app","workspace":".","harnesspm":"0.1.1","caller":"agent","agent":"claude","session":"c491e094-…","unit":"kit:scripts/probe","package":"@acme/kit","version":"1.0.0","exit":0,"duration":30}
  4. Task 2: a project rule from the 14.8 template. The rule says to file harness problems in harness-reports.md with harnesspm why output. The prompt was "Add a kit Card titled Profile…". The kit's docs list Card, but its probe script does not know it.
    • Unprompted, the agent ran npx harnesspm why for kit:docs and kit:scripts/probe.
    • It wrote a well-formed entry to harness-reports.md, reverted its edit and explained.
    • Events arrived: run with exit: 1, then two why.
    • A headless run needs Bash(npx harnesspm why *) allowed. Spec 14.8 says so.
  5. A command handler from the packed build. It received the JSON on stdin through the detached process.

Found along the way, and recorded in the research doc:

  • Claude Code denies a Read through a symlink whose target is outside the project, so a file: dependency's stable path cannot be read in headless runs.
  • A paths pattern without a leading / matches at any depth. Fixed for harnesspm's own rule in section 4.

Reporting harness problems (spec 14.8)

A copyable rule for the project's harness. Add it with npx harnesspm new rule reporting-harness-problems:

# Reporting harness problems

- When a harness rule, doc, skill or tool is wrong, missing or fails, file a ticket in <tracker, such as the Linear team "Web" with the label `harness`>.
- Say what you tried, what happened and what you expected. Add the output of `npx harnesspm why <ID>`.
- Then go on with the task. Do not change the unit unless the user asks.

The agent files the ticket with its own tools, such as the Linear MCP server.

Example handlers in spec 14.7:

  • a 3-line Node script that posts each event to a URL;
  • an OpenTelemetry Collector filelog receiver that tails the JSON Lines file, with no code in harnesspm.

Spec and dogfooding

Spec changes:

  • New chapter 14-telemetry.md.
  • Chapter 1: the terms Event, Handler and Telemetry, and scenarios S14 and S15.
  • Also 3.7, 4.3, 5.1, 6.1–6.4, 10, 11 (JSON Lines, Console Do Not Track, OpenTelemetry), 13.11 and 13.12.
  • README.

harnesspm's own harness:

  • The harnesspm-config rule says agents change telemetry only when asked.
  • The harnesspm-import skill says how to turn telemetry on.
  • This repository's own harnesspm.json does not turn telemetry on. That would install hooks on every contributor's machine, so it is the maintainer's call.

2. why explains every unit (the original change)

The managed block prints an ID for every script, such as (tasty:scripts/styles). But harnesspm why looked up only rules, skills and docs, so it answered No unit tasty:scripts/styles for those IDs. The Glaze, UI Kit and Tasty pilots all hit this.

why now finds every unit ID in spec 2.8: scripts, hooks, MCP servers, sub-agents and permissions too.

$ npx harnesspm why kit:scripts/probe
owner       dependency @acme/kit 1.0.0
source      node_modules/.harnesspm/pkgs/@acme/kit/harness/dev.harnesspm/scripts/probe.mjs
run         npx harnesspm run kit:probe
trust       no: it stays off. Add "@acme/kit": true to "trust" in harnesspm.json to turn it on.
repository  …
editable    no. Add a `patch`, `replace` or `exclude` in harnesspm.json, or propose the change upstream.
  • source: the script or sub-agent file, or the package's hooks.json, mcp.json or permissions.json.
  • run: for a script, the command that runs it.
  • trust: for a script, hook, MCP server or sub-agent of a dependency, whether its package is trusted (yes, pinned, or how to turn it on). This is what an agent needs when a tool does not run. Permissions get no trust row, because deny and ask rules need no trust (6.1).
  • No unit: the hint now lists IDs of every kind, not only rules and skills.

Spec 10: the why row says it works for every unit ID and what it adds for scripts and executable units.

3. Optional peers in extends

  • A package's extends may name an optional peer dependency (optional: true in peerDependenciesMeta).
  • When the project has not installed it, sync skips it quietly.
  • Any other missing extends still warns.
  • Why: UI Kit can list @tenphi/eslint-plugin-tasty this way. Projects with the lint plugin get its harness through UI Kit, and projects without it see no warning on every sync.
  • Spec 3.3 has one new item.

4. harnesspm's config rule loads only for the project's own files

Problem. harnesspm:rules/harnesspm-config had paths: ["harnesspm.json", "harnesspm.local.json", "harness/**"]. Claude Code matched harness/** at any depth. So the rule loaded whenever an agent only read a dependency's harness file, such as node_modules/.harnesspm/pkgs/@tenphi/tasty/harness/…. Every project that depends on harnesspm got this noise.

Probe (headless Claude Code 2.1.323, an InstructionsLoaded hook that logs each load):

Rule pattern Agent reads vendor/pkg/harness/deep.md Agent reads harness/top.md
harness/**, plain file loads ❌ loads ✅
harness/**, symlink in .claude/rules/ loads ❌ loads ✅
/harness/**, plain file does not load ✅ loads ✅
/harness/**, symlink in .claude/rules/ does not load ✅ loads ✅

The docs' example says src/**/* matches only the project's src/. In practice, only a leading / anchors a pattern.

Fix:

  • The rule now uses /harnesspm.json, /harnesspm.local.json and /harness/**.
  • Pointer lines in AGENTS.md show patterns without the leading /, so they read the same as before. A bare /harnesspm.json could look like an absolute path to Codex.
  • Spec 2.5 and the harnesspm-export skill say to start a pattern with / to match only the project's own folder.
  • The research row has the probe result.
  • Two tests: an anchored pattern keeps its / in the .claude/rules/ link but not in the pointer line; and every pattern in harnesspm's own file-scoped rules starts with / or **/.

Trade-off. A workspace's own harness/ folder (spec 3.6) no longer triggers this rule. A pattern that matched it would also match a dependency's node_modules/<package>/harness/. Workspace harnesses are rare; dependency reads happen in every consumer.

Verified

  • npm run typecheck, npm test, npm run check and npm run sync pass. There are 65 tests: 7 new for telemetry, 1 for optional peers and 2 for anchored patterns.
  • Changesets:
    • minor for telemetry;
    • patch for optional peers;
    • patch for why;
    • patch for the anchored config rule.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Gr8S7Ed6WF7j8cpXBKzCuV

- ci.yml: typecheck, tests and `npm run check` on Node 24, and the built
  CLI (`--help`, `check`, `sync --check`) on Node 20 for `engines`.
- release.yml: every PR publishes `0.0.0-snapshot.<sha>` under
  `pr_<number>` with a sticky comment; pushes to main open the version PR
  or publish with provenance, a `v<version>` tag and a GitHub Release.
  Both jobs use npm trusted publishing in the `release` environment.
- Changesets replace the hand-written "Unreleased" line; AGENTS.md
  describes the new flow. The 0.1.0 notes stay in CHANGELOG.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7Ed6WF7j8cpXBKzCuV
npm refuses a provenance statement from a private repository (E422), and
with trusted publishing it adds one by itself once the repository is
public. Also print the real OIDC availability in the publish jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7Ed6WF7j8cpXBKzCuV
A re-run builds the same commit, so it got the same snapshot version, and
npm never accepts a version twice. Add the attempt number on a re-run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7Ed6WF7j8cpXBKzCuV
…ions

`harnesspm why` found only rules, skills and docs, so it answered "No unit"
for the script IDs the managed block prints. It now finds every unit kind,
shows its source file, the command that runs a script, and whether the
package of an executable unit is trusted. Test fixtures use `alex`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7Ed6WF7j8cpXBKzCuV
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

📦 Snapshot release

Published 0.0.0-snapshot.7debf78.

npx @tenphi/[email protected] --help
npm install -D @tenphi/[email protected]

A team turns on `telemetry` in harnesspm.json: which events, and a handler
that gets them, a command (JSON on stdin) or a JSON Lines file. harnesspm
sends events for script runs, MCP server starts, sync and why. With agent
events on, a person's sync writes harnesspm's own async hooks: Claude Code
reports reads of harness files, skills it loads and file-scoped rules it
loads by itself; Claude Code and Codex report session starts. The hook runs
the local binary (`track`), maps the path to a unit with an index that sync
writes, hands the event off and exits 0.

Events never hold arguments, file contents, prompts or absolute paths, and
cover only the dependency and project layers. Sending never waits or fails a
command: a command handler runs in a detached process with a 10 s limit.

A handler gets events only as a person's sync recorded it in the lock. A
model run keeps the recorded handler, so one an agent adds stays held until
a person syncs. A person opts out with DO_NOT_TRACK=1 or "telemetry": false
in harnesspm.local.json or ~/.harnesspm/config.json.

Spec: new chapter 14 (with a rule template for reporting harness problems),
terms and scenarios S14 and S15, 3.7, 4.3, 5.1, 6, 10, 11, and removed
options in 13.12. Research: hook payloads and async hooks for both agents,
from the docs, Codex source and a headless Claude Code probe.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7Ed6WF7j8cpXBKzCuV
When a package's `extends` names a package that is not installed, sync
warns. A package can now list an extends target as an optional peer
dependency (`optional: true` in `peerDependenciesMeta`): projects that
install it get its harness through the package, and projects that do not
see no warning on every sync. Any other missing extends still warns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7Ed6WF7j8cpXBKzCuV
@tenphi tenphi changed the title fix(why): explain scripts, hooks, MCP servers, sub-agents and permissions feat: opt-in telemetry; why for every unit Nov 13, 2026
Claude Code matches a `paths` pattern without a leading `/` at any depth.
So `harness/**` loaded harnesspm's config rule whenever an agent only read
a dependency's harness files in node_modules. A probe with Claude Code
2.1.323 showed that `/harness/**` loads for the project's own folder only,
both as a plain file and as a symlink in .claude/rules/.

- harnesspm-config: `/harnesspm.json`, `/harnesspm.local.json`, `/harness/**`
- pointer lines show patterns without the leading `/`
- spec 2.5 and the export skill say how to anchor a pattern
- research: the probe result

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7Ed6WF7j8cpXBKzCuV
@tenphi
tenphi merged commit 0aa47d8 into main Nov 13, 2026
4 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 13, 2026

This branch was previously deployed

1 inactive deployment
release — 994759e9 Deployed Nov 13, 2026 by tenphi via Snapshot release #10
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.

2 participants