@forwardimpact/libharness 0.1.22 → 1.1.0

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 (87) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +196 -80
  3. package/bin/fit-benchmark.js +44 -0
  4. package/bin/fit-harness.js +358 -0
  5. package/bin/fit-selfedit.js +165 -0
  6. package/bin/fit-trace.js +510 -0
  7. package/package.json +41 -11
  8. package/src/agent-runner.js +256 -0
  9. package/src/benchmark/apm-installer.js +207 -0
  10. package/src/benchmark/env-loader.js +158 -0
  11. package/src/benchmark/hook-env.js +40 -0
  12. package/src/benchmark/invariants.js +141 -0
  13. package/src/benchmark/judge.js +187 -0
  14. package/src/benchmark/npm-installer.js +87 -0
  15. package/src/benchmark/report.js +604 -0
  16. package/src/benchmark/result.js +127 -0
  17. package/src/benchmark/runner.js +688 -0
  18. package/src/benchmark/scheduler.js +78 -0
  19. package/src/benchmark/task-family.js +260 -0
  20. package/src/benchmark/workdir.js +344 -0
  21. package/src/commands/assert.js +153 -0
  22. package/src/commands/benchmark-definition.js +175 -0
  23. package/src/commands/benchmark-invariants.js +73 -0
  24. package/src/commands/benchmark-report.js +51 -0
  25. package/src/commands/benchmark-run.js +175 -0
  26. package/src/commands/by-discussion.js +94 -0
  27. package/src/commands/callback.js +119 -0
  28. package/src/commands/discuss.js +132 -0
  29. package/src/commands/facilitate.js +123 -0
  30. package/src/commands/output.js +36 -0
  31. package/src/commands/run.js +152 -0
  32. package/src/commands/supervise.js +136 -0
  33. package/src/commands/task-input.js +54 -0
  34. package/src/commands/tee.js +53 -0
  35. package/src/commands/trace.js +630 -0
  36. package/src/commands/work-tracker.js +35 -0
  37. package/src/cost.js +79 -0
  38. package/src/discuss-tools.js +173 -0
  39. package/src/discusser.js +394 -0
  40. package/src/events/github.js +161 -0
  41. package/src/facilitator.js +205 -0
  42. package/src/inbox-poller.js +81 -0
  43. package/src/index.js +72 -2
  44. package/src/judge.js +210 -0
  45. package/src/message-bus.js +118 -0
  46. package/src/orchestration-loop.js +330 -0
  47. package/src/orchestration-toolkit.js +441 -0
  48. package/src/orchestrator-helpers.js +23 -0
  49. package/src/profile-prompt.js +266 -0
  50. package/src/redaction.js +253 -0
  51. package/src/render/line-renderer.js +54 -0
  52. package/src/render/orchestrator-filter.js +19 -0
  53. package/src/render/palette.js +63 -0
  54. package/src/render/tool-hints.js +154 -0
  55. package/src/render/turn-renderer.js +96 -0
  56. package/src/reply-emitter.js +47 -0
  57. package/src/sequence-counter.js +21 -0
  58. package/src/signature-filter.js +27 -0
  59. package/src/supervisor.js +236 -0
  60. package/src/tee-writer.js +150 -0
  61. package/src/trace-collector.js +444 -0
  62. package/src/trace-github.js +473 -0
  63. package/src/trace-multi.js +101 -0
  64. package/src/trace-query.js +748 -0
  65. package/src/trace-render.js +211 -0
  66. package/src/trace-usage.js +249 -0
  67. package/src/fixture/assertions.js +0 -42
  68. package/src/fixture/cache.js +0 -50
  69. package/src/fixture/eval.js +0 -146
  70. package/src/fixture/index.js +0 -9
  71. package/src/fixture/pathway.js +0 -451
  72. package/src/fixture/services.js +0 -56
  73. package/src/mock/clients.js +0 -135
  74. package/src/mock/config.js +0 -45
  75. package/src/mock/data.js +0 -46
  76. package/src/mock/fs.js +0 -111
  77. package/src/mock/grpc.js +0 -94
  78. package/src/mock/http.js +0 -60
  79. package/src/mock/index.js +0 -36
  80. package/src/mock/infra.js +0 -219
  81. package/src/mock/logger.js +0 -42
  82. package/src/mock/observer.js +0 -74
  83. package/src/mock/resource-index.js +0 -95
  84. package/src/mock/service-callbacks.js +0 -39
  85. package/src/mock/services.js +0 -79
  86. package/src/mock/spy.js +0 -44
  87. package/src/mock/storage.js +0 -118
package/LICENSE CHANGED
@@ -1,201 +1,21 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to the Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright 2026 Dick Olsson
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Zachary Rice
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,97 +2,213 @@
2
2
 
3
3
  <!-- BEGIN:description — Do not edit. Generated from package.json. -->
4
4
 
5
- Shared mocks and test fixtures so every library and service tests the same way.
5
+ Agent evaluation framework — prove whether agent changes improved outcomes with
6
+ reproducible evidence.
6
7
 
7
8
  <!-- END:description -->
8
9
 
9
- ## Usage
10
+ `libharness` provides the runtime and tool surface for multi-LLM coordination —
11
+ an agent talks to a supervisor, a facilitator chairs a meeting, a lead drives
12
+ an asynchronous discussion — plus a CLI suite that runs evals, queries the
13
+ traces they produce, and edits skill files under controlled conditions.
10
14
 
11
- ```js
12
- import {
13
- // Mock primitive (replaces node:test's mock.fn)
14
- spy,
15
- // Config / storage / logger / fs
16
- createMockConfig,
17
- createMockStorage,
18
- createSilentLogger,
19
- createMockFs,
20
- // gRPC / RPC
21
- createMockGrpcFn,
22
- MockMetadata,
23
- createMockObserverFn,
24
- createMockTracer,
25
- createMockAuthFn,
26
- // Clients
27
- createMockMemoryClient,
28
- createMockLlmClient,
29
- createMockAgentClient,
30
- createMockVectorClient,
31
- createMockGraphClient,
32
- createMockToolClient,
33
- // Infra
34
- createMockSupabaseClient,
35
- createMockS3Client,
36
- createTurtleHelpers,
37
- createMockProcess,
38
- withSilentConsole,
39
- createMockQueries,
40
- // Agent-aligned engineering standard fixtures (pathway data)
41
- createTestStandard,
42
- createTestLevel,
43
- createTestSkill,
44
- createTestDiscipline,
45
- createTestTrack,
46
- createTestBehaviour,
47
- createTestCapability,
48
- createTestDriver,
49
- createTestPerson,
50
- createTestRoster,
51
- createTestEvidenceRow,
52
- // libeval stream/message helpers
53
- createToolUseMsg,
54
- createTextBlockMsg,
55
- createTestTrace,
56
- collectStream,
57
- stripAnsi,
58
- writeLines,
59
- createMockAgentQuery,
60
- // Assertions
61
- assertThrowsMessage,
62
- assertRejectsMessage,
63
- createDeferred,
64
- // Caching
65
- memoizeAsync,
66
- memoizeOnSubject,
67
- } from "@forwardimpact/libharness";
15
+ ## CLIs
16
+
17
+ | CLI | Purpose |
18
+ | --------------- | ---------------------------------------------------------------------- |
19
+ | `fit-harness` | Run agents in `run`/`supervise`/`facilitate`/`discuss` subcommands. |
20
+ | `fit-trace` | Download, query, and analyze NDJSON traces produced by `fit-harness`. |
21
+ | `fit-benchmark` | Run task families for N runs each and aggregate pass@k. |
22
+ | `fit-selfedit` | Write stdin to `.claude/**` paths, gated by settings.json + branch. |
23
+
24
+ `fit-harness`'s subcommands share one orchestration loop and one async tool
25
+ surface, below. The `judge` role is a profile passed to `supervise`.
26
+
27
+ ## Modes
28
+
29
+ | Mode | Lead | Participants | Terminal tool |
30
+ | ------------ | ------------- | ------------- | ---------------------- |
31
+ | `run` | (none) | one agent | task completion |
32
+ | `supervise` | `supervisor` | one `agent` | `Conclude` |
33
+ | `facilitate` | `facilitator` | N named | `Conclude` |
34
+ | `discuss` | `lead` | N named | `Adjourn` or `Recess` |
35
+ | `judge` | `judge` | (none) | `Conclude` |
36
+
37
+ `run` and `judge` are one-shot. The other three share `OrchestrationLoop`
38
+ plus an async Ask/Answer/Announce/RollCall tool surface; the loop fans
39
+ messages out over an in-memory bus and emits a `{source, seq, event}`
40
+ NDJSON envelope for every line.
41
+
42
+ ## Async Ask / Answer / Announce
43
+
44
+ ```text
45
+ Ask({ question, to? }) → { askIds: [N, …] }
46
+ Answer({ message, askId? }) → routed to the asker
47
+ Announce({ message }) → broadcast, no reply expected
68
48
  ```
69
49
 
70
- The full export list lives in `src/index.js`. Subpath entries
71
- `@forwardimpact/libharness/fixture` and `@forwardimpact/libharness/mock` remain
72
- for narrower imports.
50
+ Every Ask returns immediately and registers a pending entry keyed by an
51
+ `askId`. The reply arrives later on the asker's inbox as `[answer#N]
52
+ <participant>: <text>`. Broadcast: omit `to` on a multi-participant
53
+ lead. Answer's `askId` is optional — the handler is forgiving:
54
+
55
+ - **Provided + matches an ask owed by the caller** → routes to that asker.
56
+ - **Provided but unknown or wrong addressee** → `isError` with a pointed message.
57
+ - **Omitted + exactly one ask owed to the caller** → auto-picks it.
58
+ - **Omitted + 0 or many asks owed** → broadcasts as Announce.
59
+
60
+ Inbox lines on resume:
61
+
62
+ ```text
63
+ [ask#42] facilitator: What is your current condition?
64
+ [answer#41] agent-1: We're at 7 out of 10.
65
+ [shared] agent-2: FYI I'm switching to Bun 1.2.
66
+ [system] @orchestrator: You have an unanswered ask from facilitator (askId=42)…
67
+ ```
68
+
69
+ Async means the lead can issue Asks, end its turn, and plan in the gap
70
+ while participants work in parallel — nothing blocks the LLM thread.
71
+
72
+ ### Discuss-mode replies
73
+
74
+ In discussion mode, Answer calls routed to the lead are streamed to
75
+ the discussion thread as they are produced — each agent's Answer becomes
76
+ a separate reply posted immediately, not batched at session end. The
77
+ lead and agents can also call `Acknowledge` to post brief messages
78
+ directly to the thread (status updates, human follow-up responses).
79
+ The message bus intercepts answers and appends them to `ctx.replies[]`.
80
+
81
+ `RequestForComment` is a separate coordination tool available on agent
82
+ roles (facilitated agents and discuss agents). It queues an intent to
83
+ open a new Discussion thread for long-horizon coordination on open
84
+ questions; these are accumulated in `ctx.rfcs[]`, separate from the
85
+ thread replies in `ctx.replies[]`.
86
+
87
+ ## Orchestration loop
88
+
89
+ Each participant drains the bus (or waits), runs/resumes the LLM with
90
+ drained messages as tagged lines, and on an unanswered owed Ask injects
91
+ one synthetic reminder before emitting `protocol_violation` and
92
+ unblocking the asker with a synthetic null answer.
93
+
94
+ Termination uses two flags. `ctx.concluded` is explicit
95
+ `Conclude`/`Adjourn`/`Recess` — also cancels in-flight Asks so askers
96
+ see why their question won't be answered. `stopped` is broader: lead
97
+ error, agent crash, abort path. Loops watch `stopped`; `ctx.concluded`
98
+ only feeds the summary's `success`/`verdict`.
73
99
 
74
- ## When to extend libharness
100
+ ## Tool surface, by role
75
101
 
76
- Before adding a helper locally in a test file, check `src/index.js`. If the
77
- helper doesn't exist and would be reused across two or more files, add it to
78
- libharness in the same PR instead of inlining. See
79
- [CONTRIBUTING.md](../../CONTRIBUTING.md) READ-DO and DO-CONFIRM checklists for
80
- the enforced policy and `scripts/check-libharness.mjs` for the pre-commit guard
81
- that flags inline reimplementations.
102
+ | Role | Ask | Answer | Announce | RollCall | Conclude | Other |
103
+ | ------------ | --- | ------ | -------- | -------- | -------- | ------------------------------ |
104
+ | Facilitator | ✓ | ✓ | ✓ | ✓ | ✓ | |
105
+ | Fac. agent | ✓ | ✓ | ✓ | ✓ | | `RequestForComment` |
106
+ | Supervisor | ✓ | ✓ | ✓ | ✓ | ✓ | |
107
+ | Sup. agent | ✓ | ✓ | ✓ | ✓ | | |
108
+ | Discuss lead | ✓ | ✓ | ✓ | ✓ | | `Recess`, `Adjourn`, `Acknowledge` |
109
+ | Discuss agt | ✓ | ✓ | ✓ | ✓ | | `RequestForComment`, `Acknowledge` |
110
+ | Judge | | | | | ✓ | |
82
111
 
83
- ## `spy` vs `node:test`'s `mock.fn`
112
+ Ask's `to` accepts a participant name on multi-participant roles
113
+ (facilitator, discuss lead, all participants). The supervise pair has
114
+ only one possible target so `to` is rejected there.
84
115
 
85
- `spy()` matches `mock.fn`'s shape exactly:
116
+ ## Minimal example: two-participant facilitator
86
117
 
87
118
  ```js
88
- const fn = spy((x) => x * 2);
89
- fn(5);
90
- fn.mock.calls[0].arguments; // [5]
91
- fn.mock.calls[0].result; // 10
92
- fn.mock.callCount(); // 1
93
- fn.mock.resetCalls();
94
- fn.mock.mockImplementation((x) => x + 1);
119
+ import { createFacilitator, createRedactor } from "@forwardimpact/libharness";
120
+ import { query } from "@anthropic-ai/claude-agent-sdk";
121
+
122
+ const facilitator = createFacilitator({
123
+ facilitatorCwd: process.cwd(),
124
+ agentConfigs: [
125
+ { name: "alice", role: "explorer", agentProfile: "alice" },
126
+ { name: "bob", role: "tester", agentProfile: "bob" },
127
+ ],
128
+ query,
129
+ output: process.stdout,
130
+ redactor: createRedactor(),
131
+ facilitatorProfile: "improvement-coach",
132
+ });
133
+
134
+ const result = await facilitator.run("Run a kata storyboard meeting.");
135
+ // result.success / result.turns / NDJSON trace on process.stdout
95
136
  ```
96
137
 
97
- Prefer `spy` over `node:test`'s `mock.fn` — `spy` works under both `bun test`
98
- (the default runner) and `node --test`.
138
+ The facilitator gets `Ask`/`Answer`/`Announce`/`RollCall`/`Conclude`;
139
+ each agent gets the same minus `Conclude`. Every tool call, bus
140
+ message, and orchestrator event becomes one trace line.
141
+
142
+ ## Trace format and redaction
143
+
144
+ Each line is `{ "source": "<participant|orchestrator>", "seq": N, "event":
145
+ {…} }`. `seq` is monotonic across the whole trace; `orchestrator` emits
146
+ `session_start`, `agent_start`, `protocol_violation`, `lead_turn_limit`,
147
+ and `summary`. `event` is the SDK event verbatim or the orchestrator
148
+ payload. `fit-trace` consumes this format.
149
+
150
+ Redaction is on by default for `fit-harness run`/`supervise`/`facilitate`
151
+ and composes two layers:
152
+
153
+ - **Env-var allowlist** — `ANTHROPIC_API_KEY`, `GH_TOKEN`, `GITHUB_TOKEN`
154
+ by default; override with `LIBHARNESS_REDACTION_ENV_VARS=NAME1,…`
155
+ (replaces, not extends). Runtime values become `[REDACTED:env:NAME]`
156
+ everywhere they appear.
157
+ - **Credential-shape patterns** — `sk-ant-`, `ghp_`, `ghs_`, `gho_`,
158
+ `github_pat_`. Hits become `[REDACTED:pattern:KIND]`.
159
+
160
+ Set `LIBHARNESS_REDACTION_DISABLED=1` to disable (one stderr warning per
161
+ run). Never on CI for a public repo — workflow artifacts are
162
+ downloadable through retention.
163
+
164
+ ## Module map
165
+
166
+ | Module | Purpose |
167
+ | ----------------------------------------------------------- | -------------------------------------------------------------------- |
168
+ | `agent-runner.js` | One Claude Agent SDK session; emits NDJSON via the redactor. |
169
+ | `message-bus.js` | Per-participant queues + `waitForMessages` Promise wakeup. |
170
+ | `orchestration-toolkit.js` | Shared Ask/Answer/Announce/Conclude/RollCall/RequestForComment handlers + builders. |
171
+ | `orchestration-loop.js` | Unified lead+participant loop; reminder/violation handling. |
172
+ | `facilitator.js` / `supervisor.js` / `discusser.js` / `judge.js` | Per-mode class + factory + system prompt. |
173
+ | `discuss-tools.js` | Discuss-only `Recess`/`Adjourn`/`Acknowledge`. |
174
+ | `reply-emitter.js` | Fire-and-forget POST of reply/ack events to the callback URL. |
175
+ | `inbox-poller.js` | Long-poll the bridge inbox for injected human messages. |
176
+ | `trace-collector.js` / `trace-query.js` / `trace-github.js` | Trace ingestion / querying / GitHub-attachment helpers. |
177
+ | `redaction.js` | Env-var allowlist + credential-shape pattern redaction. |
178
+
179
+ ## fit-selfedit
180
+
181
+ A narrow, audited bypass for sessions where `Edit`/`Write` (and bash
182
+ writes) are blocked against paths the project's own allowlist permits.
183
+ Reads stdin, writes the target, exits 0 / 2 (safeguard violation) / 1
184
+ (I/O error).
185
+
186
+ ```sh
187
+ echo "<content>" | bunx fit-selfedit <path>
188
+ ```
189
+
190
+ Two safeguards, checked in order:
191
+
192
+ 1. **Settings-allow.** Walk upward from the target with
193
+ [`Finder.findUpward`](../libutil/src/finder.js) to find the nearest
194
+ `.claude/settings.json`. The target relative to its grandparent
195
+ directory must match at least one `Edit(<glob>)` rule in
196
+ `permissions.allow[]` (matched with
197
+ [`minimatch`](https://github.com/isaacs/minimatch), `dot: true`).
198
+ Settings.json is the single source of truth — widen the project
199
+ allowlist and the CLI follows. Traversal like `.claude/../README.md`
200
+ is rejected as a side effect: `path.resolve` collapses `..` first,
201
+ then the resolved path tests against the rules.
202
+
203
+ 2. **Branch scope.** `git rev-parse --abbrev-ref HEAD` must not be
204
+ `HEAD` (detached) or `main`. Edits ride a feature branch through
205
+ whatever merge gates the project has configured.
206
+
207
+ Failure messages name the safeguard that rejected; safeguard 1 also
208
+ lists the `Edit()` rules that were tried.
209
+
210
+ ## Documentation
211
+
212
+ - [Agent Evaluations Guide](https://www.forwardimpact.team/docs/libraries/agent-evaluations/index.md) — how to run an eval and read its trace.
213
+ - [Agent Collaboration Guide](https://www.forwardimpact.team/docs/libraries/agent-collaboration/index.md) — supervise / facilitate / discuss in depth.
214
+ - [Trace Analysis Guide](https://www.forwardimpact.team/docs/libraries/trace-analysis/index.md) — analysing NDJSON traces with `fit-trace`.
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+
3
+ import "@forwardimpact/libpreflight/node22";
4
+
5
+ import { createCli } from "@forwardimpact/libcli";
6
+ import { createDefaultRuntime } from "@forwardimpact/libutil/runtime";
7
+ import { createLogger } from "@forwardimpact/libtelemetry";
8
+
9
+ import { definition } from "../src/commands/benchmark-definition.js";
10
+
11
+ const runtime = createDefaultRuntime();
12
+ const logger = createLogger("benchmark", runtime);
13
+
14
+ async function main() {
15
+ const cli = createCli(definition, {
16
+ runtime,
17
+ packageJsonUrl: new URL("../package.json", import.meta.url),
18
+ });
19
+ const parsed = cli.parse(runtime.proc.argv.slice(2));
20
+ if (!parsed) return runtime.proc.exit(0);
21
+
22
+ const { positionals } = parsed;
23
+ if (positionals.length === 0) {
24
+ cli.usageError("no command specified");
25
+ return runtime.proc.exit(2);
26
+ }
27
+
28
+ const command = positionals[0];
29
+ if (!definition.commands.some((c) => c.name === command)) {
30
+ cli.usageError(`unknown command "${command}"`);
31
+ return runtime.proc.exit(2);
32
+ }
33
+
34
+ const result = await cli.dispatch(parsed, { deps: { runtime } });
35
+ const envelope = result ?? { ok: true };
36
+ if (!envelope.ok && envelope.error) cli.error(envelope.error);
37
+ runtime.proc.exit(envelope.ok ? 0 : (envelope.code ?? 1));
38
+ }
39
+
40
+ main().catch((error) => {
41
+ logger.exception("main", error);
42
+ createCli(definition, { runtime }).error(error.message);
43
+ process.exit(1);
44
+ });