@tduyng/pi-harness-loop 0.0.0-stage → 0.0.2

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.
package/LICENSE ADDED
@@ -0,0 +1,178 @@
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 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
+ Copyright 2026 tduyng
package/README.md CHANGED
@@ -1,3 +1,381 @@
1
- # Temporary Holding Version
1
+ # @tduyng/pi-harness-loop
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Reads what the sessions actually did, then proposes the harness part that would change it, and
4
+ keeps the lesson that transfers.
5
+
6
+ ## What it adds
7
+
8
+ The loop runs when the session goes idle. The extension reads the sessions of the project, and
9
+ if a failure recurred across them, it writes a brief with the evidence, one model call turns
10
+ that brief into the part, and the part is installed. Nothing has to be typed, and the loop
11
+ never takes the session over.
12
+
13
+ A part that does not lower the rate it was written for is taken back out by the next idle, so
14
+ the always-on context does not keep a rule the sessions did not need. `PI_HARNESS_LOOP=off`
15
+ stops all of it.
16
+
17
+ `/harness-loop` reports the setup, `/harness-loop propose [id]` runs a proposal now, and
18
+ `/harness-loop lint` reports only the problems. `/harness-loop clear` takes the report off the
19
+ screen, and the next prompt does it as well, so a report read once does not sit above the editor
20
+ for the rest of the session.
21
+
22
+ The harness tree: the skills and agent profiles pi loads, the problems in them, and what the
23
+ skill block costs on every request. The rules come from pi's own loader, so they do not drift
24
+ from it:
25
+
26
+ - a skill with no description is dropped at load, so it never reaches the model
27
+ - a skill whose frontmatter name differs from its directory is advertised under the frontmatter
28
+ name, and a prompt that names the folder does not name the skill
29
+ - a profile with no description is listed as "no description", so the model cannot choose it
30
+ - a skill that tells the agent to run `scripts/something.py` without shipping that file sends the
31
+ agent after a file that is not there
32
+
33
+ The findings: what recurred in this session's transcript. The same failure three times, the same
34
+ command three times, the same file read three times, a run that hit a failure and changed
35
+ nothing, a tool call with no result.
36
+
37
+ The recurrences: what recurred across the sessions of this project. The same failure in two
38
+ sessions, the same command in three, the same file read in five. A defect that shows up in one
39
+ run is noise. A defect that shows up in every run is a property of the harness, and the session
40
+ files already on disk are the runs. A signature that reduces to `<path>` or a bare `Script
41
+ failed` is not a finding, because it names nothing a part can change.
42
+
43
+ A failure also needs independent evidence. When every session that hit it edited a file and each
44
+ pair of those sessions shares one, they are one piece of work, and a rule written from it would
45
+ encode that task rather than the harness. The recurrence is listed and held back. A session that
46
+ edited nothing met the failure outside the edit loop, so it counts as independent.
47
+
48
+ The skills nobody opened: pi advertises every skill by name and description in the system prompt,
49
+ so a skill that was never opened is a tax on every request of every session. The report lists
50
+ the advertised ones with the number of characters they cost, and it says how many skills are not
51
+ advertised at all, because a skill the model cannot open cannot be opened by accident.
52
+
53
+ The lessons: the ones whose cue matches the request in the editor, read from
54
+ `.pi/harness/lessons.jsonl`.
55
+
56
+ ## The loop on its own
57
+
58
+ The session goes idle, and the loop looks at what the sessions of this project did. The scan is
59
+ cached in `.pi/harness/scan.json` with a fingerprint of the session files, so a session that
60
+ changed nothing does not pay for the scan again.
61
+
62
+ The parsed form of each session file is cached beside it in `.pi/harness/corpus-cache.json`. A
63
+ scan reads the files that changed, and the rest come back from the cache. At most 8 MB of new
64
+ session files are parsed per idle, and every parsed session is kept. The report says how many
65
+ it sees of the sessions on disk. The session being written is left out, so the file the loop is
66
+ in does not force a rescan.
67
+
68
+ The cache holds 400 sessions, so the oldest leave only when that ceiling is reached, not when
69
+ the newest few exceed a byte budget.
70
+
71
+ A failure that shows up in two sessions or more is a property of the harness, and the loop acts
72
+ on it. A command or a file that shows up in every session is a habit, and a habit is a
73
+ judgement call the operator makes, so the loop leaves those to `/harness-loop propose`.
74
+
75
+ A new error string that is a smaller variant of an edit matching failure the loop already tried
76
+ is not a new finding. The edit tool has one matching mechanic, so the 2-session "oldText must be
77
+ unique" is the 9-session "oldText must match" with a different error string, and a second
78
+ proposal for it is the same rule said twice.
79
+
80
+ The failure's own command is replayed before a proposal. When it passes, the failure no longer
81
+ reproduces, and the loop writes nothing. The same command runs again after an install, and its
82
+ result stays with the install.
83
+
84
+ A failure whose message the tree no longer carries is not a property of the harness any more.
85
+ Before it proposes, the loop cuts the ids, the paths and the numbers out of the message, and
86
+ searches the tree for what is left, then the dependencies. When neither has it and git shows a
87
+ commit that touched that text after the last session that hit it, the producer was removed and
88
+ the finding is skipped. The verdict is cached in `.pi/harness/producers.json`, keyed by the
89
+ commit and the last session, because it is a search of the tree.
90
+
91
+ The loop stands out of the way when the session has something else driving it. A goal that is
92
+ active and the day's budget of five proposals each stop it. The writer is one completion, not a
93
+ turn: it carries the brief, it has no tools, and it returns the files of the part as text. The
94
+ files are parsed, checked and installed by the loop, so nothing the writer says is executed. The
95
+ session is notified with what landed, and it keeps its own turn.
96
+
97
+ The lesson tool arms itself for the run whose request names a trigger of a lesson that is still
98
+ in force, and it is off otherwise, so the request with nothing to do with a lesson pays
99
+ nothing. The cost on the runs that do arm it is about 259 tokens: the schema, the snippet and
100
+ the guidelines.
101
+
102
+ ## The proposal
103
+
104
+ `/harness-loop propose [id]` runs the same path for one finding, one recurrence or one skill:
105
+ brief, part, install. The brief asks for a skill, an agent profile or a rule, and the writer
106
+ puts the files in `.pi/harness/<id>/`. The part is read back, checked against the same rules the
107
+ tree is checked against, and installed. A part that breaks a rule is not installed, and the rule
108
+ it broke is recorded with it. A reply with no file block leaves `REPLY.txt` beside the brief,
109
+ which is what the writer said instead.
110
+
111
+ A part under `global/` holds in every project. A skill under `global/` goes to the skills every
112
+ project loads, and a global rule goes to the context file every project reads. It is not
113
+ installed unless `global` is set in `.pi/harness.json`, because one project's failure does not
114
+ get to become every project's rule. Without it the part lands in the project: `.agents/skills/<name>/`,
115
+ `.pi/agents/<name>.md`, and the project's context file for a rule.
116
+
117
+ The prompt says what each form costs. A skill is paid for by its name and description, about 300
118
+ characters on every request, and its body costs nothing until the model opens it. A rule is paid
119
+ for by its length and always applies. The rule wins when the behaviour has to hold every time,
120
+ and the skill wins when the situation is specific enough to route on.
121
+
122
+ The part may also carry `CONFIRM.md`, one shell command that exits 0 only when the finding can
123
+ no longer happen. It must not write files or use the network. The loop runs it after the project
124
+ check, and a confirmation that fails puts the part back. The brief asks for the command, and a
125
+ part without one installs on the project check alone, recorded as unconfirmed.
126
+
127
+ When the part passes, the session records the lesson that transfers: the cue (the shape of
128
+ situation), the lesson (the operation on the harness), the way to confirm it worked, the
129
+ evidence it rests on, and a confidence. The model may decline with `NO_ENTRY`, and then nothing
130
+ is written. A block with no confirm line is dropped, because a rule nobody can check is a rule
131
+ of thumb. The lesson is appended to `.pi/harness/lessons.jsonl` and matched against later
132
+ requests by its trigger words. A lesson about a situation an earlier lesson already covers
133
+ replaces it: the old one keeps its record, stops matching, and the report names the install
134
+ that still holds the old rule.
135
+
136
+ The trigger words are the ones the prompts of this project actually used, because a word no
137
+ request ever carried cannot route to anything. A trigger seen once has to be at least eight
138
+ characters and pass a consonant check. A typo is the rarest token in the corpus, and it routes
139
+ nowhere.
140
+
141
+ A request matches when it carries two triggers, or one trigger of six characters or more that
142
+ the project rarely uses: one short word is a coincidence, and `key` is in half the requests of a
143
+ project that does not talk about credentials. Two processes that record the same cue leave two
144
+ lines in the file, and the read keeps the newest active one, so the same situation does not arm
145
+ twice. A match records a use, so a lesson nobody ever recalls is visible in the record.
146
+
147
+ ## The lint
148
+
149
+ `/harness-loop lint` is the harness check on its own: the skills and agent profiles pi loads,
150
+ against the rules pi's own loader applies, and the extension layer on top.
151
+
152
+ The skill rules are the ones that bite silently. A skill with no `description` is dropped at
153
+ load and never reaches the model. One whose frontmatter name does not match its directory is
154
+ advertised under one name and looked for under another. Another that calls a helper script it
155
+ does not ship points at a file that is not there. Two skills with the same name means the second
156
+ one is dropped. An agent profile with no `description` is listed as "no description".
157
+
158
+ The extension rules are the ones the repo's own scripts do not cover. A package under
159
+ `extensions/` that declares an entry the root manifest never loads is a package nobody gets.
160
+ An entry file that is not on disk is a manifest that points at nothing.
161
+
162
+ The rule rules matter because the project's check cannot fail for a rule. A rule is markdown in
163
+ a file no test reads, so the lint is the only gate it passes. A rule without a heading cannot
164
+ be replaced later, a rule longer than thirty lines pays for itself on every request of every
165
+ project, and a rule that carries a credential lands in a file every session reads.
166
+
167
+ ## The check decides
168
+
169
+ A part that passes the rules can still be wrong, and pi has no grader to say so. So the part is
170
+ installed and the project's own check runs against it. A rule part installs without a check,
171
+ because no test reads a markdown file, and the rate verdict below is what holds it. A skill or a
172
+ profile waits for the check. The check is the first of:
173
+
174
+ - `check` in `.pi/harness.json`
175
+ - the `test` script in `package.json`, run with `bun run test` or `npm test`
176
+ - the `test` recipe in `justfile`
177
+
178
+ The check runs before the change and after it. The part is installed first, so the common case
179
+ costs one run of the suite: when the check passes, the part stays. When it fails, the part goes
180
+ back the way it was and the check runs once more on the tree without it, so the verdict is about
181
+ the difference. A suite that was already failing the same way is not read as a verdict against
182
+ the change. A part that adds a failure is put back, and no lesson is recorded, because a part the check turned
183
+ down taught nothing.
184
+
185
+ When the part carries a `CONFIRM.md` command, that command runs after the project check. A
186
+ confirmation that fails puts the part back, because the part did not prove the finding gone. The
187
+ command and its output stay with the install.
188
+
189
+ When the finding carried a command, it is replayed after the install. Its result is recorded but
190
+ does not decide the install, because the project check and the confirm command are the gates.
191
+ Three installs a day is the ceiling for the loop, and the operator's own hand is not counted
192
+ against it. The count is in `.pi/harness/installs.jsonl`. The ceiling is a budget that frees
193
+ after a day, not a verdict: a proposal that lost to the budget stays open and the loop tries it
194
+ again, and the spend is counted once.
195
+
196
+ A second ceiling is the prompt itself. `maxStandingTokens`, 1,500 by default, is how many tokens
197
+ the active installs may add together to the front of every request. An install that would cross
198
+ it stays on disk with its brief, and the message names the current total, so the way through is
199
+ to revert a part that did not carry rather than to raise the cap. A rule is paid in full on every
200
+ request, which is why this ceiling counts the rule text and only the name and description of a
201
+ skill. The report prints the standing total in tokens. `0` turns the ceiling off.
202
+
203
+ A rule is identified by its heading, so a rule that is revised replaces the rule it revises
204
+ rather than saying it twice.
205
+
206
+ ## The sessions decide whether it held
207
+
208
+ The check says the part did not break the project. It cannot say the failure stopped, and for a
209
+ rule or a skill it cannot see the part at all, because no test reads a markdown file. So the
210
+ install is read against the sessions that come after it.
211
+
212
+ The signature of the finding is counted per session, before the install and after it. The rate
213
+ is failures per session, and every session counts whether it hit the failure or not, because a
214
+ session that did not fail is the evidence. The verdict:
215
+
216
+ - `held` when the rate fell to three quarters of what it was, including to zero, and the
217
+ sessions after it still call tools at more than half their old rate
218
+ - `flat` when it stayed within a quarter either way
219
+ - `worse` when it rose by a quarter or more
220
+ - `avoided` when the rate fell but the work did too, so the failure stopped because the agent
221
+ did less rather than because the part reached it
222
+ - `confounded` when a commit touched the failure in the window, so the rate is not the part's
223
+ - `early` until three sessions have run after the install
224
+ - `out-of-window` when the corpus no longer holds a session from before it
225
+
226
+ The work rate is the calls of every tool per session, read from the same parse as the
227
+ signature, and a cache written before it counted tool calls reads as unknown and skips the
228
+ check. The count is across tools rather than per tool, because a session that switched from
229
+ `edit` to `write` did the work and fixed the failure.
230
+
231
+ The verdict is computed on idle as well as in the report, so a lesson whose part did not carry
232
+ stops matching without anyone typing a command.
233
+
234
+ A `flat`, `worse` or `avoided` install is not the end of the finding. The loop tries it again,
235
+ the brief says the earlier form did not carry and shows the two rates and the form itself, and
236
+ the lesson that came with it stops matching, because a rule nobody can act on is worse than no
237
+ rule. A finding whose part was all markdown and still did not carry is marked `needs code`. The
238
+ loop stops proposing prose for it, because the failure lives in tool behavior and a rule cannot
239
+ reach it. The report shows the verdicts, and a `held` finding is the one thing the loop can call
240
+ done.
241
+
242
+ A finding comes back as soon as the failure grows past the count it had at the last proposal,
243
+ and a finding stops after three proposals, so one failure cannot spend the week's budget
244
+ rephrasing the same rule.
245
+
246
+ `/harness-loop revert <install>` puts the files back by hand, and the newest install goes first
247
+ when two of them touched the same file. A file whose content changed after the install is left
248
+ alone and named, because the operator's edit is not the loop's to overwrite. `/harness-loop
249
+ install <id>` runs the same path over a part that is already on disk. One install runs at a time,
250
+ through a lock beside the record.
251
+
252
+ `.pi/harness.json` turns the loop off or changes the ceiling:
253
+
254
+ ```json
255
+ {
256
+ "check": "bun run test",
257
+ "auto": false,
258
+ "autoInstall": false,
259
+ "global": false,
260
+ "maxInstallsPerDay": 3,
261
+ "maxStandingTokens": 1500,
262
+ "writerModel": "opencode-go/mimo-v2.6-flash"
263
+ }
264
+ ```
265
+
266
+ `writerModel` is the model that writes the part. The loop reads three answers in this order:
267
+ `writerModel` in the project's `.pi/harness.json`, `PI_HARNESS_WRITER_MODEL` in the environment,
268
+ then the `model` in `.pi/subagent.json` or `~/.pi/agent/subagent.json`, which is the model pi
269
+ already runs chores on. With none of them it uses the model of the session that is running, and
270
+ a session on an expensive model pays that model for a short chore. The writer sees the brief
271
+ and nothing else, so another model loses no context by writing it.
272
+
273
+ `auto` is read when the session goes idle, and it stops the loop from writing a part on its
274
+ own. The manual command still works. `autoInstall` is read when the part is ready, so a project
275
+ that wants every change by hand sets it to `false` and the part stays on disk.
276
+ `PI_HARNESS_LOOP=off` in the environment turns the automatic run off for every project without
277
+ changing a file, and the command still works.
278
+
279
+ A rule part installs without a project check, because no test reads a markdown file. A skill or
280
+ an agent profile needs the check, because it changes what the loader sees. What a rule is held
281
+ to instead is the rate of the failure it was written for: flat, worse or avoided after three
282
+ sessions and the loop reverts it, records `auto-reverted`, and stops proposing prose for that
283
+ finding.
284
+
285
+ ## Taking it back out
286
+
287
+ The loop reverts its own part when the sessions after it show the same rate or a worse one. The
288
+ files go back byte for byte, the install is recorded as reverted with the two rates, and the
289
+ finding is marked needs code, so the next attempt has to live in the tool rather than in a rule.
290
+ A file the operator changed after the install is left alone and named, because that edit is not
291
+ the loop's to overwrite.
292
+
293
+ ## What the loop spends
294
+
295
+ The loop is not free. A proposal costs one completion, and the completion carries the brief
296
+ with the evidence, which is the whole input. `writerModel` names the model that runs it, and
297
+ the output is the part. The tokens the provider reported are written to
298
+ `.pi/harness/spend.jsonl` with the outcome, so a budget of five proposals a day is five
299
+ completions and not five sessions. The report sums them.
300
+
301
+ A part also costs the prompt after it is installed, and that cost is not a completion. Every
302
+ install records the characters it adds to the front of the prompt, which is the rule as it is
303
+ appended or the name and description a skill is routed on, and the report sums the active ones.
304
+ The brief carries that sum, so the writer knows what this project already pays on every request
305
+ before it chooses a rule over a skill.
306
+
307
+ ## What it works with
308
+
309
+ The other extensions drive the same session, so the loop reads their state instead of guessing at it.
310
+
311
+ `pi-goal` owns the turns of a session with a goal. The loop does not propose while a goal is
312
+ active, and it waits to install while one is, because both of them would be driving the same
313
+ session at the same time.
314
+
315
+ `pi-goal` owns the check runner in `src/check.ts`. The loop uses the same runner, so
316
+ the two do not disagree about what a check said.
317
+
318
+ `pi-context` prunes the context the model sees, not the session, so the findings still see the
319
+ whole branch. The recurrences read the session files, which no compaction touches.
320
+
321
+ `pi-guard` blocks the shell from reading credentials. The rule it needs is in the global
322
+ context, and it says what to do instead of what is blocked.
323
+
324
+ ## What it found here
325
+
326
+ The measurements come from the sessions on this machine, so they are about this setup rather than
327
+ about pi.
328
+
329
+ - 12 of the 19 skills are not advertised at all, because their frontmatter says
330
+ `disable-model-invocation`, so they cost nothing. The other 7 are advertised, and the block
331
+ they make is 2,652 characters, about 663 tokens on every request of every project.
332
+
333
+ - 5 of those 7 were opened in none of the 26 sessions scanned last. They cost 1,447 of the 2,652
334
+ characters, about 362 tokens per request. `tdd` was the sixth, and the loop's finding for it
335
+ is the one change that came from a proposal and nothing else: 39 sessions, no open, and the
336
+ skill stopped being advertised on 2026-10-26.
337
+
338
+ An open is a read of a `SKILL.md` or a `/skill:<name>` command in a prompt, so a skill reached
339
+ by hand is not called dead. The report names the rest and the number, and the operator
340
+ decides, because a skill that was never needed is not the same as a skill that cannot be
341
+ found.
342
+
343
+ - The shell blocked 14 reads of credential files across 2 sessions, and every retry with another
344
+ shell reached the same block.
345
+
346
+ The rule that came out of it is in the global context, and it says what to do instead of what
347
+ is blocked.
348
+
349
+ - The edit tool rejected 9 old texts across 4 sessions, and each rejection reported a closest
350
+ match the model had paraphrased.
351
+
352
+ The rule that came out of it says to copy the old text out of the output of the read that
353
+ preceded the edit, and to read the file again when an edit is rejected.
354
+
355
+ - 4 reads were refused for being over 350 lines across 3 sessions, and each one was a file a
356
+ grep would have narrowed.
357
+
358
+ The rule that came out of it says to grep first.
359
+
360
+ ## Why the report is a command and not a tool
361
+
362
+ A tool would put its schema in the system prompt of every session, which is the tax this package
363
+ exists to reduce. The command costs nothing until it is typed.
364
+
365
+ The lesson tool is the one tool, and it arms itself for the run whose request names a trigger
366
+ of a lesson in force, so a session can record a lesson the moment it hits the failure that
367
+ taught it. It is 259 tokens on the runs that arm it and nothing on the others. The words that
368
+ count are the ones that say the situation: a word in more than a fiftieth of the prompts is
369
+ noise, and a word no prompt ever used cannot route. The tool is fixed for the run, so a failure
370
+ that surfaces in a later turn of the same run still finds it.
371
+
372
+ ## What it is not
373
+
374
+ It does not score the harness. It measures the rate of the failure a part was written for,
375
+ which is not the same as the work being better: a session ends, and nothing says whether the
376
+ work was good. The findings are the part that can be read without a grader, and the rate is the
377
+ part that says whether the part held.
378
+
379
+ It does not compare two runs of the same task. The comparison it makes is across the sessions
380
+ of this project, which are different tasks. The same task run twice is what a benchmark does,
381
+ and what a working session does not.
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@tduyng/pi-harness-loop",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.2",
4
+ "description": "Reads what the session repeated, proposes the harness part that would have prevented it, and records the lesson that transfers.",
5
+ "keywords": [
6
+ "pi",
7
+ "pi-package",
8
+ "pi-extension",
9
+ "harness",
10
+ "reflection"
11
+ ],
12
+ "homepage": "https://gitlab.com/tduyng/pi-agent/-/tree/main/extensions/pi-harness-loop#readme",
13
+ "bugs": "https://gitlab.com/tduyng/pi-agent/-/issues",
14
+ "license": "Apache-2.0",
15
+ "author": "tduyng",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://gitlab.com/tduyng/pi-agent.git",
19
+ "directory": "extensions/pi-harness-loop"
20
+ },
21
+ "type": "module",
22
+ "files": [
23
+ "src",
24
+ "!src/**/*.test.ts",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "peerDependencies": {
29
+ "@earendil-works/pi-ai": "*",
30
+ "@earendil-works/pi-coding-agent": "*"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "pi": {
36
+ "extensions": [
37
+ "./src/index.ts"
38
+ ]
39
+ },
40
+ "dependencies": {
41
+ "ata-validator": "^1.62.1"
42
+ }
43
+ }