@harnesspm/cli 0.0.0-snapshot.412a718

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +259 -0
  2. package/LICENSE +21 -0
  3. package/README.md +70 -0
  4. package/dist/added.d.ts +51 -0
  5. package/dist/added.js +192 -0
  6. package/dist/check.d.ts +14 -0
  7. package/dist/check.js +263 -0
  8. package/dist/cli.d.ts +2 -0
  9. package/dist/cli.js +218 -0
  10. package/dist/commands.d.ts +58 -0
  11. package/dist/commands.js +1299 -0
  12. package/dist/config.d.ts +15 -0
  13. package/dist/config.js +45 -0
  14. package/dist/deliver.d.ts +1 -0
  15. package/dist/deliver.js +31 -0
  16. package/dist/doctor.d.ts +18 -0
  17. package/dist/doctor.js +99 -0
  18. package/dist/exec-outputs.d.ts +75 -0
  19. package/dist/exec-outputs.js +425 -0
  20. package/dist/exec-units.d.ts +68 -0
  21. package/dist/exec-units.js +151 -0
  22. package/dist/fetch.d.ts +16 -0
  23. package/dist/fetch.js +145 -0
  24. package/dist/frontmatter.d.ts +16 -0
  25. package/dist/frontmatter.js +49 -0
  26. package/dist/homes.d.ts +7 -0
  27. package/dist/homes.js +21 -0
  28. package/dist/lock.d.ts +47 -0
  29. package/dist/lock.js +245 -0
  30. package/dist/manifest.d.ts +78 -0
  31. package/dist/manifest.js +169 -0
  32. package/dist/new.d.ts +33 -0
  33. package/dist/new.js +228 -0
  34. package/dist/outputs.d.ts +124 -0
  35. package/dist/outputs.js +875 -0
  36. package/dist/parent.d.ts +41 -0
  37. package/dist/parent.js +182 -0
  38. package/dist/render.d.ts +91 -0
  39. package/dist/render.js +221 -0
  40. package/dist/resolve.d.ts +132 -0
  41. package/dist/resolve.js +522 -0
  42. package/dist/reviewed.d.ts +15 -0
  43. package/dist/reviewed.js +41 -0
  44. package/dist/run.d.ts +18 -0
  45. package/dist/run.js +133 -0
  46. package/dist/sections.d.ts +32 -0
  47. package/dist/sections.js +121 -0
  48. package/dist/telemetry-api.d.ts +26 -0
  49. package/dist/telemetry-api.js +60 -0
  50. package/dist/telemetry.d.ts +119 -0
  51. package/dist/telemetry.js +401 -0
  52. package/dist/user-outputs.d.ts +30 -0
  53. package/dist/user-outputs.js +239 -0
  54. package/dist/util.d.ts +137 -0
  55. package/dist/util.js +370 -0
  56. package/dist/workspaces.d.ts +2 -0
  57. package/dist/workspaces.js +62 -0
  58. package/docs/spec/01-overview.md +149 -0
  59. package/docs/spec/02-package-format.md +252 -0
  60. package/docs/spec/03-resolution.md +108 -0
  61. package/docs/spec/04-outputs.md +194 -0
  62. package/docs/spec/05-executables.md +170 -0
  63. package/docs/spec/06-trust.md +88 -0
  64. package/docs/spec/07-added.md +109 -0
  65. package/docs/spec/08-improving.md +79 -0
  66. package/docs/spec/09-cloud.md +68 -0
  67. package/docs/spec/10-cli.md +181 -0
  68. package/docs/spec/11-standards.md +52 -0
  69. package/docs/spec/12-dogfooding.md +51 -0
  70. package/docs/spec/13-open-questions.md +97 -0
  71. package/docs/spec/14-telemetry.md +199 -0
  72. package/docs/spec/README.md +33 -0
  73. package/harness/dev.harnesspm/rules/generated-files.md +9 -0
  74. package/harness/dev.harnesspm/rules/harnesspm-config.md +12 -0
  75. package/harness/plugin.json +13 -0
  76. package/harness/skills/harnesspm-export/SKILL.md +43 -0
  77. package/harness/skills/harnesspm-import/SKILL.md +40 -0
  78. package/harness/skills/harnesspm-improve/SKILL.md +38 -0
  79. package/package.json +73 -0
  80. package/schema/harnesspm.schema.json +58 -0
@@ -0,0 +1,199 @@
1
+ # 14. Telemetry
2
+
3
+ **In short**
4
+
5
+ - Telemetry is off. A team turns it on in `harnesspm.json` with `telemetry`: which events to send, and a handler that gets them, either a command or a file. harnesspm has no vendor code.
6
+ - harnesspm sends what it sees: script runs, MCP server starts, `sync`, `why` and `help <target>`. With agent events on, its own hooks also report when Claude Code reads a harness file, loads a workspace's rules or a skill, and when a session starts.
7
+ - A project's own tools send `run` events through the same handler with `reportRun` from `@harnesspm/cli/telemetry` ([14.9](#149-events-from-a-projects-own-tools)).
8
+ - A `run` event's `outcome` tells a tool's answer, such as a lint's "found problems", from a failure. Events from a folder outside the project, such as with `-C`, carry `outside: true`.
9
+ - Events never hold arguments, file contents or prompts. Sending never slows down or fails a command.
10
+ - A handler gets events only as a person's `sync` recorded it in the lock. A person opts out with `DO_NOT_TRACK=1` or `"telemetry": false` in `harnesspm.local.json`.
11
+
12
+ ## 14.1 Turning it on
13
+
14
+ ```json
15
+ {
16
+ "telemetry": {
17
+ "events": "all",
18
+ "send": { "file": ".harnesspm/events.jsonl" }
19
+ }
20
+ }
21
+ ```
22
+
23
+ Then run `npx -y @harnesspm/cli sync`.
24
+
25
+ | Field | Default | Meaning |
26
+ | --- | --- | --- |
27
+ | `events` | `"all"` | The event types to send ([14.2](#142-events)), or `"all"`. |
28
+ | `send` | required | The **handler**. A command, such as `"node scripts/harness-events.mjs"`, gets each event as JSON on stdin. `{ "file": "<path>" }` appends each event as one line of JSON ([JSON Lines](https://jsonlines.org/)). Paths are relative to the project root. |
29
+
30
+ harnesspm adds a handler file inside the project to `.git/info/exclude` when it creates it.
31
+
32
+ ## 14.2 Events
33
+
34
+ | Type | When | Fields beyond the common ones |
35
+ | --- | --- | --- |
36
+ | `run` | `harnesspm run` finishes a script. A hook's script is a `run` with caller `hook`. | `unit`, `package`, `version`, `exit`, `outcome`, `duration` (ms) |
37
+ | `mcp` | `harnesspm mcp` starts an MCP server. | `unit`, `package`, `version` |
38
+ | `sync` | `harnesspm sync` writes the outputs. `--check` and runs with `CI=true` send nothing: every CI job runs an install, and so a sync. | `packages` (name and version), `added`, `removed` and `changed` (unit IDs since the last lock), `pending` (packages whose executable units wait for trust), and when the agent's model held entries back ([6.2](06-trust.md#62-trusting-a-package), rule 4): `held` (the entries as `sync` prints them, without the `-C <path>` of a hook above the project) and `reason` (what differs from the reviewed state) |
39
+ | `why` | `harnesspm why` finds a unit. | `unit`, `package`, `version` |
40
+ | `help` | `harnesspm help <target>` prints a package, a rule or a tool ([10.1](10-cli.md#help-for-a-package-a-rule-or-a-tool)). It shows whether agents follow the managed block's pointers, now that the block names rules instead of holding their text. | `package`, `version`; `unit` for a rule or a tool, missing for a whole package |
41
+ | `read` | Agent event: the agent reads a file of a unit, or loads a file-scoped rule or a workspace's managed block by itself. A block sends one event for each always-on rule it names: the agent saw the rule's line, not its text, which `help` prints. | `unit`, `package`, `version`, `via` (`tool` or `auto`), `page` for docs (the path inside the docs folder) |
42
+ | `skill` | Agent event: the agent loads a skill. | `unit`, `package`, `version` |
43
+ | `session` | Agent event: a session starts or resumes. | `source` (`startup`, `resume`, `clear`, `compact`, `fork`) |
44
+
45
+ A `run` event's `outcome` says what its `exit` means for that tool:
46
+
47
+ | `outcome` | When |
48
+ | --- | --- |
49
+ | `ok` | Exit `0`. |
50
+ | `answer` | The exit code is one of the script's **answers** ([5.1](05-executables.md#51-scripts)): the tool did its job and its answer is "no", such as a lint that found problems, a check that failed or a hook that blocks the agent. |
51
+ | `failed` | Any other exit code, and every run that a signal ended, whatever its answers. Such a run has `exit` `1`. |
52
+
53
+ A run without an exit code has no `outcome`. A script without `answers` reports every non-zero exit as `failed`.
54
+
55
+ Every event has these fields:
56
+
57
+ | Field | Meaning |
58
+ | --- | --- |
59
+ | `schema` | `harnesspm.event/1`. The number changes when a field changes meaning or goes away. A new field, such as `outcome` or `outside`, keeps it. |
60
+ | `type` | One of the types above. |
61
+ | `time` | ISO 8601, UTC. |
62
+ | `project` | The `name` in the root `package.json`. |
63
+ | `repository` | The repository's `origin` remote as `<host>/<path>`, such as `github.com/acme/app`, when it has one. It names the repository also where `project` is a placeholder, as the root of a monorepo often is. |
64
+ | `workspace` | The workspace folder from the root, or `.` for the root. |
65
+ | `harnesspm` | The harnesspm version. |
66
+ | `caller` | `person`; `agent` when the agent's model ran it ([6.2](06-trust.md#62-trusting-a-package), rule 4); `hook` when the agent ran it through a hook or an MCP server; `ci` when `CI=true`. |
67
+ | `agent` | `claude` or `codex`, when known. |
68
+ | `session` | The agent's session ID, when known. For Claude Code it is `CLAUDE_CODE_SESSION_ID` as its commands see it, so a hook's event and a command's event agree; a hook falls back to the payload's `session_id` ([14.4](#144-agent-events)). |
69
+ | `outside` | `true` when harnesspm runs from a folder outside the project, such as through `-C` ([10.1](10-cli.md#-c-dir)). Missing inside the project. Its `workspace` is `.`. `run`, `help` and `why` set it: the commands that `-C` serves. Agent events set it when the hook's `cwd` is outside the project, as in a session that started in a parent folder ([4.10](04-outputs.md#410-sessions-that-start-in-a-parent-folder)). It lets a handler tell an agent that works from another repository from a session inside the project whose hooks are missing. |
70
+ | `worktree` | `true` when the event comes from a folder in a [worktree](01-overview.md#15-terms): the caller's folder, or the hook's `cwd` for agent events. Missing otherwise, also in a submodule. A desktop app session in a worktree runs the main checkout's hooks ([Claude Code docs](https://code.claude.com/docs/en/worktrees#what-worktrees-share-with-the-main-checkout)), so its events show where the work happens and where the hooks come from. harnesspm reads the `.git` file and never runs git for it. |
71
+
72
+ ```json
73
+ {"schema":"harnesspm.event/1","type":"run","time":"2026-11-13T10:00:00.000Z","project":"app","repository":"github.com/acme/app","workspace":".","harnesspm":"0.2.0","caller":"agent","agent":"claude","session":"77c89d39-1164-4bc0-b046-7a3e9bc97863","unit":"uikit:scripts/probe","package":"@cube-dev/ui-kit","version":"0.206.1","exit":0,"outcome":"ok","duration":812}
74
+ ```
75
+
76
+ Rules:
77
+
78
+ 1. An event MUST NOT hold script arguments, file contents, prompts, tool output or absolute paths. This covers the fields that a project's own tool adds ([14.9](#149-events-from-a-projects-own-tools)).
79
+ 2. Events cover the dependency and project layers only. Units of added harnesses belong to a person, so they never reach the team's handler.
80
+ 3. Units are named by their IDs ([2.8](02-package-format.md#28-unit-ids)). A file that is not part of a unit sends nothing.
81
+
82
+ ## 14.3 Sending
83
+
84
+ - **File handler:** harnesspm appends one line.
85
+ - **Command handler:** harnesspm starts a detached process and returns at once. That process runs the command from the project root, with the event as JSON on stdin and the same environment, for at most 10 seconds. Each event starts the command once. The events of one hook run share one detached process, which runs the command for each in turn. For many events, prefer a file and ship it on a schedule.
86
+ - Telemetry MUST NOT change the result or the exit code of a command, and MUST NOT make it wait. harnesspm notes failures in `node_modules/.harnesspm/telemetry.log` on that machine and prints nothing.
87
+ - harnesspm does not retry or sample, and a command gets one event at a time. A handler can batch.
88
+
89
+ ## 14.4 Agent events
90
+
91
+ `read`, `skill` and `session` come from harnesspm's own hooks. A sync by a person writes them when `events` includes one of these types, the handler is recorded in the lock, and the machine has not opted out. They are hooks, so a model run never adds them ([6.2](06-trust.md#62-trusting-a-package), rule 4).
92
+
93
+ | Agent | Hooks harnesspm writes | What harnesspm reads from the hook's JSON |
94
+ | --- | --- | --- |
95
+ | Claude Code | `PostToolUse` with the matcher `Read\|Skill`, `InstructionsLoaded` with the matcher `path_glob_match\|nested_traversal\|include`, `SessionStart`. All are `"async": true`. | `tool_input.file_path` of `Read`; `tool_input.skill` of `Skill`; `file_path` of a file-scoped rule that Claude Code loads through its `.claude/rules/` link, or of a workspace's `AGENTS.md`; `source`; `cwd`; `session_id`, when `CLAUDE_CODE_SESSION_ID` is not set |
96
+ | Codex | `SessionStart`, `"async": true` | `source` and `session_id` |
97
+
98
+ Codex reads files and skills through shell commands. harnesspm cannot map a shell command to a unit reliably, so Codex sends no `read` or `skill` events. Codex also runs a project hook only after a person reviews it in `/hooks` ([research](https://github.com/tenphi/harnesspm/blob/main/docs/research/agent-capabilities.md#codex)).
99
+
100
+ A hook MUST never make the agent wait. The hooks are asynchronous, and the command is fast:
101
+
102
+ 1. It is `node <project>/node_modules/@harnesspm/cli/dist/cli.js track --agent <agent>`, an absolute path in a per-machine file, with the prefix of package hooks ([5.2](05-executables.md#52-hooks)). npx costs about 0.4 seconds per call. Without an installed harnesspm, or on Windows, harnesspm writes `npx -y @harnesspm/cli track …`.
103
+ 2. `track` reads the hook's JSON from stdin. It maps the file path, or the skill name, to units with an index that `sync` writes to `node_modules/.harnesspm/telemetry.json`. The index lists the rule files, generated rules and docs indexes, and the skill and docs folders, of each package, with its [docs copy](04-outputs.md#43-project-outputs), so a read of a copied page counts for the package's docs; each workspace's `AGENTS.md`, with the always-on rules its managed block names; and the repository, so a hook never asks git.
104
+ 3. It hands the events off as in [14.3](#143-sending), and exits `0` at once without printing.
105
+
106
+ The session of an event is the one Claude Code's commands see in `CLAUDE_CODE_SESSION_ID`, which `run` events use. On a person's machine a hook's `session_id` can differ from it, which split one session into one with only hook events and one with only command events ([research](https://github.com/tenphi/harnesspm/blob/main/docs/research/agent-capabilities.md#settings-hooks-permissions)). Without the variable, the hook uses `session_id`. That hooks see the same variable as commands is not confirmed yet ([13.11](13-open-questions.md#1311-agent-behavior-not-confirmed-yet)). Either way nothing is lost: where a hook's variable equals its `session_id`, the event is as before; where it equals the commands', the split closes.
107
+
108
+ In a parent folder the command is `… -C <project> track --agent <agent>`. `-C` names the project, because the session's `cwd` is above it, and the events carry `outside: true` ([4.10](04-outputs.md#410-sessions-that-start-in-a-parent-folder)).
109
+
110
+ A workspace's block reaches Claude Code in two loads: its `CLAUDE.md` with `nested_traversal`, then the `AGENTS.md` it imports with `include` ([research](https://github.com/tenphi/harnesspm/blob/main/docs/research/agent-capabilities.md#settings-hooks-permissions)). The index lists only the `AGENTS.md`, so each rule is sent once per load, with `via: auto`. A `Read` of that file, which the root block's `## Workspaces` section asks for ([4.5](04-outputs.md#45-monorepos)), sends nothing for the block: Claude Code loads the folder's `CLAUDE.md` when the agent opens a file there, and that load sends the rules. So each rule counts once.
111
+
112
+ Not seen: reads through other tools, such as `cat` in a shell or a search, and the rules in the root block, which the agent gets in every session.
113
+
114
+ ## 14.5 Trust
115
+
116
+ A command handler runs on every machine of the team. It follows the trust model of hooks ([6.2](06-trust.md#62-trusting-a-package), rule 4):
117
+
118
+ 1. A sync by a person records the handler in `harnesspm.lock.json`, as `"telemetry": { "send": … }`.
119
+ 2. harnesspm sends events only when `send` in `harnesspm.json` matches the lock. Otherwise the handler is **held**: nothing is sent, and `sync` and `status` say so.
120
+ 3. A sync by the agent's model keeps the handler the lock has. A handler that an agent adds or changes stays held until a person runs `npx -y @harnesspm/cli sync` or `npx -y @harnesspm/cli approve`. Removing `telemetry` needs no person.
121
+ 4. The lock diff shows a new or changed handler in review, like a new hook. `sync --check` fails while the lock and `harnesspm.json` differ.
122
+
123
+ The same rule covers file handlers, so there is one rule to learn.
124
+
125
+ ## 14.6 Opting out
126
+
127
+ The team decides in `harnesspm.json`. A person can still opt out on their machine. Each of these stops every event, and the next sync removes the agent hooks:
128
+
129
+ | Where | How |
130
+ | --- | --- |
131
+ | Environment | `DO_NOT_TRACK=1`, the [Console Do Not Track](https://consoledonottrack.com/) convention |
132
+ | One repository | `"telemetry": false` in `harnesspm.local.json`, which is never committed |
133
+ | Every repository on the machine | `"telemetry": false` in `~/.harnesspm/config.json` |
134
+
135
+ `npx -y @harnesspm/cli status` shows whether events are sent, held or off on this machine.
136
+
137
+ ## 14.7 Example handlers
138
+
139
+ A handler is the team's own code. Two common cases:
140
+
141
+ **Post each event to a service.**
142
+
143
+ ```js
144
+ // scripts/harness-events.mjs
145
+ let input = '';
146
+ for await (const chunk of process.stdin) input += chunk;
147
+ await fetch(process.env.HARNESS_EVENTS_URL, { method: 'POST', headers: { 'content-type': 'application/json' }, body: input });
148
+ ```
149
+
150
+ **Forward to OpenTelemetry.** Keep a file handler and let an OpenTelemetry Collector tail it with its [filelog receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/filelogreceiver). No code runs in harnesspm:
151
+
152
+ ```yaml
153
+ receivers:
154
+ filelog:
155
+ include: [/path/to/project/.harnesspm/events.jsonl]
156
+ operators:
157
+ - type: json_parser
158
+ ```
159
+
160
+ A handler that maps `run` events to spans or error counts sets an error status only for `outcome` `failed`. An `answer` is the tool doing its job.
161
+
162
+ ## 14.8 Reporting harness problems
163
+
164
+ Reporting is the project's own rule, not a harnesspm feature. A team that wants agents to report a wrong unit tells them where, in a rule of its own harness:
165
+
166
+ ```markdown
167
+ # Reporting harness problems
168
+
169
+ - 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`>.
170
+ - Say what you tried, what happened and what you expected. Add the output of `npx -y @harnesspm/cli why <ID>`.
171
+ - Then go on with the task. Do not change the unit unless the user asks.
172
+ ```
173
+
174
+ Add it with `npx -y @harnesspm/cli new rule reporting-harness-problems`, which writes `harness/dev.harnesspm/rules/reporting-harness-problems.md` in the project's own harness, paste the text, and run `npx -y @harnesspm/cli sync`. The agent files the ticket with its own tools, such as the tracker's MCP server. A tracker the agent cannot reach can be a file, such as `harness-reports.md`, that a person reads. An unattended run asks before it runs `npx -y @harnesspm/cli why`, so a team that runs agents that way allows `Bash(npx -y @harnesspm/cli why *)` in its Claude Code settings.
175
+
176
+ In a headless Claude Code run, such a rule led the agent to report a failing harness tool with the `why` output, without being asked ([research](https://github.com/tenphi/harnesspm/blob/main/docs/research/agent-capabilities.md#claude-code)).
177
+
178
+ ## 14.9 Events from a project's own tools
179
+
180
+ A project often tells agents to use tools that are not harnesspm scripts, such as a `yarn probe` script or a file in `scripts/`. Moving each into the project's harness would change the command that every doc and agent uses. So the tool reports its runs itself:
181
+
182
+ ```js
183
+ import { reportRun } from '@harnesspm/cli/telemetry';
184
+
185
+ reportRun({ unit: 'app:scripts/probe', fields: { mode: 'fast' }, duration: 812, exit: 1, answers: [1] });
186
+ ```
187
+
188
+ | Field | Required | Meaning |
189
+ | --- | --- | --- |
190
+ | `unit` | yes | An ID in the form of [2.8](02-package-format.md#28-unit-ids), such as `app:scripts/probe`. The tool does not have to be a unit of the harness. |
191
+ | `fields` | no | The tool's own fields. Rule 1 of [14.2](#142-events) applies: no arguments, file contents, prompts, tool output or absolute paths. A field with the name of a common field, such as `outside`, or of `unit`, `package`, `version`, `exit`, `outcome` or `duration`, is left out. |
192
+ | `cwd` | no | Where the tool runs. The project is the nearest folder above it with `harnesspm.json`. Default: the current folder. |
193
+ | `duration` | no | Milliseconds. |
194
+ | `exit` | no | The tool's exit code. |
195
+ | `answers` | no | The exit codes that are answers, as a script's `answers` ([5.1](05-executables.md#51-scripts)). They set `outcome` ([14.2](#142-events)). |
196
+
197
+ `reportRun` sends a `run` event as `harnesspm run` does: the same handler, the same `events` switch, every opt-out ([14.6](#146-opting-out)), nothing while the handler is held ([14.5](#145-trust)), the same `caller`, `agent` and `session`, and `outside` when the current folder, not `cwd`, is outside the project. It names the unit's package and version when the index of [14.4](#144-agent-events) knows its plugin. It never throws, never prints and never waits: a command handler gets the event in a detached process, so a tool can call it right before `process.exit()`. Problems go into `telemetry.log`, as in [14.3](#143-sending).
198
+
199
+ The package's `exports` field has this entry, `./telemetry`, and `./package.json`. Other files of the package are internal.
@@ -0,0 +1,33 @@
1
+ # harnesspm specification
2
+
3
+ **Version:** 0.7 draft
4
+
5
+ ## Reading order
6
+
7
+ | If you want to | Read |
8
+ | --- | --- |
9
+ | Understand harnesspm in five minutes | [1. Overview](01-overview.md) |
10
+ | Share a harness from a package | [2. Package format](02-package-format.md), then [5. Executables](05-executables.md) if it ships tools |
11
+ | Use harness in a project | [3. Resolution](03-resolution.md), [6. Trust and lock](06-trust.md) |
12
+ | Keep your own workflow and context | [7. Added harnesses](07-added.md), [9. Cloud sessions](09-cloud.md) |
13
+ | Let agents improve a harness | [8. Improving a harness](08-improving.md) |
14
+ | See how agents use a harness | [14. Telemetry](14-telemetry.md) |
15
+ | Implement harnesspm | Everything, including [4. Outputs](04-outputs.md) and [10. CLI](10-cli.md) |
16
+
17
+ Also: [11. Standards](11-standards.md), [12. Dogfooding](12-dogfooding.md), [13. Open questions](13-open-questions.md), [14. Telemetry](14-telemetry.md).
18
+
19
+ Every chapter starts with **In short**: the few points an agent or a person needs to act on it.
20
+
21
+ ## Conformance language
22
+
23
+ The words **MUST**, **MUST NOT**, **SHOULD**, **SHOULD NOT** and **MAY** have the meaning given in [RFC 2119](https://www.rfc-editor.org/rfc/rfc2119). They appear only where a rule is meant to be strict.
24
+
25
+ ## Verification markers
26
+
27
+ Statements about how an agent behaves are marked in [research/agent-capabilities.md](https://github.com/tenphi/harnesspm/blob/main/docs/research/agent-capabilities.md):
28
+
29
+ | Marker | Meaning |
30
+ | --- | --- |
31
+ | ✅ | Documented by the agent's vendor |
32
+ | 🔍 | Observed in a real session |
33
+ | ❓ | Not confirmed. Test it before building on it |
@@ -0,0 +1,9 @@
1
+ # Files generated by harnesspm
2
+
3
+ ## Never edit outputs
4
+
5
+ - Files and links that harnesspm writes, such as `.claude/agents/`, `.codex/agents/`, `.claude/skills/` and `.agents/skills/`, are outputs like the managed block. Never edit them. Change the source that `npx -y @harnesspm/cli why <ID>` names, with the `harnesspm-improve` skill.
6
+
7
+ ## Run sync after a change
8
+
9
+ - After changing `harnesspm.json` or a harness file, or after `npm install <pkg>` or `pnpm add`, run `npx -y @harnesspm/cli sync`.
@@ -0,0 +1,12 @@
1
+ ---
2
+ description: How to change harnesspm configuration and harness files safely
3
+ paths: ["/harnesspm.json", "/harnesspm.local.json", "/harness/**"]
4
+ ---
5
+
6
+ # Changing harnesspm configuration
7
+
8
+ - `harnesspm.json` and `harness/` belong to the team and are committed. `harnesspm.local.json` lists harnesses added for this repository only, and a person's telemetry opt-out. It is never committed.
9
+ - To change a few sections of an upstream rule, create a patch with `npx -y @harnesspm/cli new patch <rule ID>`, keep only the sections you change, and edit them. To change a whole rule, or a whole skill with a folder of your own, use `replace`. To drop a unit, use `exclude`. Do not copy the whole upstream harness.
10
+ - Executable units (scripts, hooks, MCP servers, allow permissions) run only for trusted packages. Do not add a package to `trust` without the user's agreement.
11
+ - `telemetry` sends events about harness use to the team's handler. Change it only when the user asks. A handler you add or change waits until the user runs `npx -y @harnesspm/cli sync` in their own terminal.
12
+ - After a change, run `npx -y @harnesspm/cli sync`, and `npx -y @harnesspm/cli check <folder>` for a changed harness folder. Fix every reported problem.
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
+ "name": "harnesspm",
4
+ "description": "How to work with harnesspm: generated files, configuration, harness authoring and added harnesses",
5
+ "homepage": "https://github.com/tenphi/harnesspm",
6
+ "repository": "https://github.com/tenphi/harnesspm",
7
+ "keywords": ["harnesspm", "harness", "agents"],
8
+ "extensions": {
9
+ "dev.harnesspm": {
10
+ "docs": "../docs/spec"
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: harnesspm-export
3
+ description: Share agent rules, docs, skills or tools from a package through harnesspm, or change what a package already shares. Use when the user wants a library's users to get its agent guidance, asks to create or edit files under harness/, or wants to pass on the harness of packages it builds on.
4
+ ---
5
+
6
+ # Sharing a harness from a package
7
+
8
+ ## 1. Start small
9
+
10
+ Install harnesspm as a dev dependency of the package: `npm i -D @harnesspm/cli`. The package needs no `npx -y @harnesspm/cli init` to share a harness.
11
+
12
+ If the package has no `harness/` folder, run `npx -y @harnesspm/cli new rule <name>`. It creates `harness/plugin.json` and one rule. That is a complete harness.
13
+
14
+ ## 2. Decide what goes in
15
+
16
+ Share what the package's **users** need. Keep contributor-only instructions (release steps, internal structure) in the repository's own `AGENTS.md`.
17
+
18
+ | Users need | Unit kind | Command |
19
+ | --- | --- | --- |
20
+ | A rule to always follow | Rule, no frontmatter | `npx -y @harnesspm/cli new rule <name>` |
21
+ | A rule for some files only | Rule with `paths` frontmatter. Start a pattern with `/` to match only the project's own folder, such as `/src/**`: without it, the pattern matches at any depth, `node_modules` too | same, then add `paths` |
22
+ | Background to read when needed | Docs, or a rule with `description` only | in `plugin.json`, set `"extensions": { "dev.harnesspm": { "docs": "../docs" } }`: the path of the docs folder, relative to `harness/` |
23
+ | A multi-step workflow | Skill, named `<plugin name>-<name>` | `npx -y @harnesspm/cli new skill <name>` |
24
+ | A specialist the agent can delegate to | Sub-agent, written for Claude Code and Codex | `npx -y @harnesspm/cli new agent <name>` |
25
+ | A tool to run | Script | `npx -y @harnesspm/cli new script <name>` |
26
+ | Something that runs on an agent event | Hook that runs a script | `npx -y @harnesspm/cli new hook <name>` |
27
+
28
+ Write each skill's `description` as what it does, then "Use when …" with the situations and words people use. Agents pick skills by that text, but not every time: when a skill must run in a situation, also add an always-on rule that names it.
29
+
30
+ Keep always-on rules short. One topic per file, split into small `##` sections, so users can patch one section, replace one file or drop it. The `AGENTS.md` block shows an always-on rule as one line, its title and its `##` and `###` headings, and agents read the text with `npx -y @harnesspm/cli help <package>`. So name each section by what it asks, such as "Never edit outputs".
31
+
32
+ ## 3. Pass on upstream harness
33
+
34
+ - List the packages it builds on in `extends` in `plugin.json`.
35
+ - To change one of their rules for all users, prefer a patch: `npx -y @harnesspm/cli new patch <rule ID>` registers it in `harness/plugin.json`. Keep and edit only the sections that change. Use `replace` for a whole rule or skill, and `exclude` to drop a unit. Find IDs in the `AGENTS.md` block or with `npx -y @harnesspm/cli why <ID>`.
36
+
37
+ ## 4. Check and publish
38
+
39
+ 1. If `package.json` has a `files` field, make sure it lists `harness` and the docs folder, if used.
40
+ 2. Run `npx -y @harnesspm/cli check`. Fix every problem.
41
+ 3. Add `"prepack": "harnesspm check"` to the `package.json` scripts.
42
+ 4. Add a short note to the README: the package ships a harness for coding agents, and a project gets it with `npm i -D @harnesspm/cli` and `npx -y @harnesspm/cli init`. A project that does not use harnesspm gets nothing by itself.
43
+ 5. To see the harness as users' agents will, run `npx -y @harnesspm/cli init` in this repository. Its own harness then shows in its `AGENTS.md` block.
@@ -0,0 +1,40 @@
1
+ ---
2
+ name: harnesspm-import
3
+ description: Set up harnesspm in a project, take agent harness from its dependencies, trust packages that ship tools, or add a harness on top, such as the user's team's or their own. Use when the user asks to use a package's agent rules or tools, to set up harnesspm, or to add a harness in this project or session.
4
+ ---
5
+
6
+ # Using harness in a project
7
+
8
+ ## 1. Set up the project (once)
9
+
10
+ ```bash
11
+ npm i -D @harnesspm/cli
12
+ npx -y @harnesspm/cli init
13
+ ```
14
+
15
+ `init` adds `harnesspm sync` to the `postinstall` script of a private package, or to `prepare` otherwise, so every full install updates the agent files. The `node -e` check in front of it skips the sync when harnesspm is not installed, as in `npm ci --omit=dev`. Keep it: a plain `harnesspm sync` fails such installs. When `doctor` reports the plain form, run `npx -y @harnesspm/cli init` again. After `npm install <pkg>` or `pnpm add`, run `npx -y @harnesspm/cli sync` yourself. Commit `package.json` and the package manager's lockfile, `harnesspm.json`, `harnesspm.lock.json`, the `AGENTS.md` block and the `CLAUDE.md` files that import `AGENTS.md`, also the ones next to nested `AGENTS.md` files.
16
+
17
+ In CI, run `npx -y @harnesspm/cli sync --check` after the install. With `CI=true`, `sync` leaves committed files as they are, so the check sees a missed sync. A job that commits them runs `npx -y @harnesspm/cli sync --write`.
18
+
19
+ ## 2. Check what arrived
20
+
21
+ Run `npx -y @harnesspm/cli status`. It lists the packages, pending tools and the always-on size.
22
+
23
+ - **Pending tools** come from packages the project does not trust yet. Ask the user before adding a package to `trust` in `harnesspm.json`, and say what each tool does: `harness/plugin.json` of its package has each script's `description`, and `"allow": true` when it asks to run without a prompt.
24
+ - **You cannot grant permissions.** When you run harnesspm, new allow rules, hooks and MCP servers stay pending, unless the default branch already records them. The held-back line says what differs. Ask the user to run `npx -y @harnesspm/cli approve` in their own terminal. In a Claude Code cloud session, where the user has no terminal, give them the line that harnesspm prints for the environment's setup script instead. Do not edit agent settings files to work around it.
25
+ - **One upstream rule does not fit** the project: run `npx -y @harnesspm/cli new patch <rule ID>` and edit only the sections that differ. Use a `replace` entry in `harnesspm.json` to change a whole rule or skill, or an `exclude` entry to drop a unit.
26
+ - **A job that does not install dependencies**, such as a review bot, runs `npx -y @harnesspm/cli fetch` first.
27
+ - **You work in a clone below your session's folder**, such as `work/app`: run `npx -y @harnesspm/cli -C work/app help` to list its tools, rules and skills, and add `-C work/app` to each tool command. Nothing in your own repository changes. Without the clone's install, self-contained scripts run from the fetched packages; a script that needs the install says so.
28
+ - **Sessions start in a folder above several repositories**, such as `/home/user` in a cloud session with more than one, or `~/work`: ask the user to run `npx -y @harnesspm/cli sync` in that folder, after the installs (in a cloud session, in the environment's setup script). It writes each repository's hooks there and a block in that folder's `AGENTS.md` that names each repository. If you run it, the block appears and the hooks stay held back.
29
+ - **The team wants to see how agents use the harness:** add `"telemetry": { "send": { "file": ".harnesspm/events.jsonl" } }` to `harnesspm.json`, or a command as `send`, and ask the user to run `npx -y @harnesspm/cli sync`. A person opts out with `DO_NOT_TRACK=1`. The spec's telemetry chapter, in the docs index, has the events and a rule template for reporting harness problems.
30
+
31
+ ## 3. Add a harness on top
32
+
33
+ ```bash
34
+ npx -y @harnesspm/cli add <source> # every repository on this machine
35
+ npx -y @harnesspm/cli add <source> --local # this repository only
36
+ ```
37
+
38
+ The source is `github:<owner>/<repo>`, `git:<url>`, `npm:<package>` or a folder path. Add a team's harness before the user's own, so the user's wins. The command prints the added rules. Follow them from now on in this session.
39
+
40
+ Outputs of added harnesses never go into the project's repository. Do not commit them. Then run `npx -y @harnesspm/cli doctor`: it finds a per-machine file that git could commit, and names the fix. Ask the user before you untrack a file.
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: harnesspm-improve
3
+ description: Change or add a rule, note, skill, script or other unit in any harnesspm harness (a dependency's, the project's, or one the user added, such as their team's or their own) and save the change the way its owner wants. Use when a rule is wrong or missing, when the user says "remember this", or asks to improve their harness.
4
+ ---
5
+
6
+ # Improving a harness
7
+
8
+ ## 1. Find the owner
9
+
10
+ For an existing unit, run `npx -y @harnesspm/cli why <ID>`. The ID is at the end of each line in the `AGENTS.md` block. It tells you the owner, the source file and whether you can edit it.
11
+
12
+ For something new, choose the owner:
13
+
14
+ | The change is about | Owner | Create with |
15
+ | --- | --- | --- |
16
+ | How a package should be used, for all its users | The package (dependency) | — propose upstream, see 3 |
17
+ | This project, for the whole team | The project | `npx -y @harnesspm/cli new <kind> <name>` |
18
+ | How the user or their team works, everywhere | The added harness (see `npx -y @harnesspm/cli status`) | `npx -y @harnesspm/cli new <kind> <name> --to <plugin>` |
19
+ | This project, only for the user or their team | The added harness, project entry | `npx -y @harnesspm/cli new <kind> <name> --to <plugin> --entry` |
20
+
21
+ Ask the user when it is not clear. Never put private data from this project into an added harness without the user's agreement.
22
+
23
+ ## 2. Edit the source
24
+
25
+ - Edit the source file that `why` names, never an output (the `AGENTS.md` block, `CLAUDE.local.md`, `.codex/`).
26
+ - Run `npx -y @harnesspm/cli sync`, then `npx -y @harnesspm/cli check <folder>` for the harness folder you changed.
27
+
28
+ ## 3. Save the change the owner's way
29
+
30
+ 1. Read `AGENTS.md` and `CONTRIBUTING.md` at the root of the owner's repository. Follow them.
31
+ 2. If they say nothing about saving:
32
+ 1. Show the user the change and ask before going on.
33
+ 2. Create a branch `harnesspm/<topic>` and commit with a message that says what and why.
34
+ 3. Push it and open a pull request or merge request with the tools you have.
35
+ 4. If a step is not possible, stop and tell the user what is done and what is left. In a cloud session, show the full change.
36
+ 3. Never push to the default branch unless the owner's rules allow it.
37
+
38
+ For a dependency: change it now with a patch (`npx -y @harnesspm/cli new patch <rule ID>`, add `--to <plugin>` to keep it in an added harness), or a `replace` or `exclude`. Then offer to open an issue or pull request at the package's repository.
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@harnesspm/cli",
3
+ "version": "0.0.0-snapshot.412a718",
4
+ "description": "The harness package manager: share agent rules, docs, skills and tools through npm packages",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "harnesspm": "dist/cli.js"
9
+ },
10
+ "exports": {
11
+ "./telemetry": {
12
+ "types": "./dist/telemetry-api.d.ts",
13
+ "default": "./dist/telemetry-api.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "schema",
20
+ "harness",
21
+ "docs/spec",
22
+ "CHANGELOG.md"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "engines": {
28
+ "node": ">=20"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/tenphi/harnesspm.git"
33
+ },
34
+ "homepage": "https://harnesspm.tenphi.me",
35
+ "keywords": [
36
+ "agents",
37
+ "harness",
38
+ "ai",
39
+ "claude-code",
40
+ "codex",
41
+ "agents-md",
42
+ "skills",
43
+ "mcp",
44
+ "agent-plugins"
45
+ ],
46
+ "scripts": {
47
+ "build": "tsc -p tsconfig.build.json && node -e \"require('node:fs').chmodSync('dist/cli.js', 0o755)\"",
48
+ "typecheck": "tsc -p tsconfig.json --noEmit",
49
+ "test": "node --test \"test/**/*.test.ts\"",
50
+ "sync": "node src/cli.ts sync",
51
+ "check": "node src/cli.ts check && node src/cli.ts sync --check",
52
+ "harnesspm": "node src/cli.ts",
53
+ "docs": "astro dev",
54
+ "build:docs": "astro build",
55
+ "docs:doctor": "cookbook doctor",
56
+ "docs:check": "cookbook check-build --out site-dist",
57
+ "prepack": "npm run build && node dist/cli.js check",
58
+ "changeset": "changeset",
59
+ "version-packages": "changeset version && npm install --package-lock-only --ignore-scripts && node src/cli.ts sync --write",
60
+ "release": "changeset publish"
61
+ },
62
+ "dependencies": {
63
+ "yaml": "^2.9.1"
64
+ },
65
+ "devDependencies": {
66
+ "@changesets/changelog-github": "^1.0.1",
67
+ "@changesets/cli": "^3.0.3",
68
+ "@tenphi/cookbook": "^0.34.1",
69
+ "@types/node": "^22.20.5",
70
+ "astro": "^7.4.11",
71
+ "typescript": "^7.0.2"
72
+ }
73
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://unpkg.com/@harnesspm/cli/schema/harnesspm.schema.json",
4
+ "title": "harnesspm.json",
5
+ "description": "Project configuration for harnesspm, the harness package manager. Every field is optional.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "properties": {
9
+ "$schema": { "type": "string" },
10
+ "exclude": {
11
+ "description": "Packages or unit IDs to drop, such as \"@tenphi/glaze\" or \"tasty:rules/legacy\".",
12
+ "type": "array",
13
+ "items": { "type": "string" }
14
+ },
15
+ "replace": {
16
+ "description": "Rule or skill ID → path of a project file, or skill folder with a SKILL.md, that takes its place.",
17
+ "type": "object",
18
+ "additionalProperties": { "type": "string" }
19
+ },
20
+ "patch": {
21
+ "description": "Rule ID → path of a patch that changes some of its sections.",
22
+ "type": "object",
23
+ "additionalProperties": { "type": "string" }
24
+ },
25
+ "trust": {
26
+ "description": "Packages whose executable units may run: true follows upgrades, \"pin\" needs an approval for each new version.",
27
+ "type": "object",
28
+ "additionalProperties": { "enum": [true, "pin"] }
29
+ },
30
+ "telemetry": {
31
+ "description": "Events about how agents and people use the harness, sent to the project's handler. Off when missing. See spec chapter 14.",
32
+ "type": "object",
33
+ "additionalProperties": false,
34
+ "required": ["send"],
35
+ "properties": {
36
+ "events": {
37
+ "description": "The event types to send, or \"all\" (the default). \"read\", \"skill\" and \"session\" come from harnesspm's own agent hooks.",
38
+ "oneOf": [
39
+ { "const": "all" },
40
+ { "type": "array", "uniqueItems": true, "items": { "enum": ["run", "mcp", "sync", "why", "help", "read", "skill", "session"] } }
41
+ ]
42
+ },
43
+ "send": {
44
+ "description": "The handler: a command that gets each event as JSON on stdin, run from the project root, or { \"file\": \"<path>\" }, which appends one JSON line per event. It gets events only as a person's sync recorded it in harnesspm.lock.json.",
45
+ "oneOf": [
46
+ { "type": "string", "minLength": 1 },
47
+ {
48
+ "type": "object",
49
+ "additionalProperties": false,
50
+ "required": ["file"],
51
+ "properties": { "file": { "type": "string", "minLength": 1, "description": "Path relative to the project root." } }
52
+ }
53
+ ]
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }