pi-harness-runtime 1.1.515 → 1.1.516

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 (107) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/harness/approval-decision-store.ts +94 -0
  3. package/harness/delegated-approval-runtime.ts +375 -0
  4. package/harness/delegated-approval-types.ts +179 -0
  5. package/harness/delegation-store.ts +108 -0
  6. package/harness/exploration-checkpoint-tool.ts +216 -0
  7. package/harness/exploration-guard-runtime.ts +23 -0
  8. package/harness/jev-rejection-escalation.ts +248 -0
  9. package/harness/plan-handoff-bridge.ts +27 -6
  10. package/harness/plan-handoff-receiver.ts +258 -0
  11. package/harness/plan-handoff-registration.ts +28 -13
  12. package/index.ts +516 -23
  13. package/package.json +1 -1
  14. package/packages/agent-policy/package.json +1 -1
  15. package/packages/auth/package.json +1 -1
  16. package/packages/autonomous-runtime/package.json +1 -1
  17. package/packages/checkpoint/package.json +1 -1
  18. package/packages/clipboard/package.json +1 -1
  19. package/packages/codex-watcher/package.json +1 -1
  20. package/packages/config-capture/package.json +1 -1
  21. package/packages/contracts/package.json +1 -1
  22. package/packages/cookie-sanitizer/dist/atomic-write.d.ts +16 -0
  23. package/packages/cookie-sanitizer/dist/atomic-write.d.ts.map +1 -1
  24. package/packages/cookie-sanitizer/dist/atomic-write.js +28 -0
  25. package/packages/cookie-sanitizer/dist/atomic-write.js.map +1 -1
  26. package/packages/cookie-sanitizer/dist/index.d.ts +1 -1
  27. package/packages/cookie-sanitizer/dist/index.d.ts.map +1 -1
  28. package/packages/cookie-sanitizer/dist/index.js +1 -1
  29. package/packages/cookie-sanitizer/dist/index.js.map +1 -1
  30. package/packages/cookie-sanitizer/package.json +1 -1
  31. package/packages/cookie-sanitizer/src/atomic-write.ts +29 -0
  32. package/packages/cookie-sanitizer/src/index.ts +1 -0
  33. package/packages/evaluation-engine/package.json +1 -1
  34. package/packages/event-bus/package.json +1 -1
  35. package/packages/event-store/package.json +1 -1
  36. package/packages/experience-replay/package.json +1 -1
  37. package/packages/exploration-guard/dist/checkpoint.d.ts +12 -0
  38. package/packages/exploration-guard/dist/checkpoint.d.ts.map +1 -1
  39. package/packages/exploration-guard/dist/checkpoint.js +33 -1
  40. package/packages/exploration-guard/dist/checkpoint.js.map +1 -1
  41. package/packages/exploration-guard/dist/observation.d.ts +7 -0
  42. package/packages/exploration-guard/dist/observation.d.ts.map +1 -1
  43. package/packages/exploration-guard/dist/observation.js +90 -27
  44. package/packages/exploration-guard/dist/observation.js.map +1 -1
  45. package/packages/exploration-guard/dist/tracker.d.ts.map +1 -1
  46. package/packages/exploration-guard/dist/tracker.js +3 -1
  47. package/packages/exploration-guard/dist/tracker.js.map +1 -1
  48. package/packages/exploration-guard/dist/types.d.ts +1 -1
  49. package/packages/exploration-guard/dist/types.d.ts.map +1 -1
  50. package/packages/exploration-guard/package.json +1 -1
  51. package/packages/exploration-guard/src/checkpoint.ts +44 -1
  52. package/packages/exploration-guard/src/observation.ts +120 -26
  53. package/packages/exploration-guard/src/tracker.ts +3 -1
  54. package/packages/exploration-guard/src/types.ts +1 -1
  55. package/packages/file-copy-helper/package.json +1 -1
  56. package/packages/intent-analyzer/package.json +1 -1
  57. package/packages/jev-judge/dist/continuation-controller.d.ts +43 -0
  58. package/packages/jev-judge/dist/continuation-controller.d.ts.map +1 -1
  59. package/packages/jev-judge/dist/continuation-controller.js +54 -7
  60. package/packages/jev-judge/dist/continuation-controller.js.map +1 -1
  61. package/packages/jev-judge/package.json +1 -1
  62. package/packages/jev-judge/src/continuation-controller.ts +89 -7
  63. package/packages/learning-engine/package.json +1 -1
  64. package/packages/logging/package.json +1 -1
  65. package/packages/memory-engine/package.json +1 -1
  66. package/packages/notification/dist/adapters/telegram-adapter.d.ts.map +1 -1
  67. package/packages/notification/dist/adapters/telegram-adapter.js +1 -0
  68. package/packages/notification/dist/adapters/telegram-adapter.js.map +1 -1
  69. package/packages/notification/dist/notification-center.d.ts.map +1 -1
  70. package/packages/notification/dist/notification-center.js +7 -0
  71. package/packages/notification/dist/notification-center.js.map +1 -1
  72. package/packages/notification/dist/notification-policy.d.ts.map +1 -1
  73. package/packages/notification/dist/notification-policy.js +6 -0
  74. package/packages/notification/dist/notification-policy.js.map +1 -1
  75. package/packages/notification/dist/types.d.ts +9 -1
  76. package/packages/notification/dist/types.d.ts.map +1 -1
  77. package/packages/notification/package.json +1 -1
  78. package/packages/notification/src/adapters/telegram-adapter.ts +1 -0
  79. package/packages/notification/src/notification-center.ts +7 -0
  80. package/packages/notification/src/notification-policy.ts +6 -0
  81. package/packages/notification/src/types.ts +8 -0
  82. package/packages/paperclip-integration/package.json +1 -1
  83. package/packages/performance-optimizer/package.json +1 -1
  84. package/packages/plan-handoff/dist/mailbox.d.ts +7 -0
  85. package/packages/plan-handoff/dist/mailbox.d.ts.map +1 -1
  86. package/packages/plan-handoff/dist/mailbox.js +9 -0
  87. package/packages/plan-handoff/dist/mailbox.js.map +1 -1
  88. package/packages/plan-handoff/package.json +1 -1
  89. package/packages/plan-handoff/src/mailbox.ts +12 -0
  90. package/packages/privilege-broker/package.json +1 -1
  91. package/packages/prompt-compiler/package.json +1 -1
  92. package/packages/providers/package.json +1 -1
  93. package/packages/qdrant-skills/package.json +1 -1
  94. package/packages/quota-manager/package.json +1 -1
  95. package/packages/relay/package.json +1 -1
  96. package/packages/skill-mcp-client/package.json +1 -1
  97. package/packages/skills/package.json +1 -1
  98. package/packages/todo-bd-sync/package.json +1 -1
  99. package/packages/token-estimation/package.json +1 -1
  100. package/packages/tooling-preference/package.json +1 -1
  101. package/packages/trajectory/package.json +1 -1
  102. package/packages/tui/package.json +1 -1
  103. package/packages/two-phase-review/package.json +1 -1
  104. package/packages/types/package.json +1 -1
  105. package/packages/webmcp-tester/package.json +1 -1
  106. package/packages/wiki/package.json +1 -1
  107. package/packages/write-review/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,100 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.1.516](https://github.com/ManotLuijiu/pi-harness-runtime/compare/v1.1.448...v1.1.516) (2026-11-17)
6
+
7
+
8
+ ### Features
9
+
10
+ * **actions:** register the job resume, the GLM countdown and the queued continuations ([177c964](https://github.com/ManotLuijiu/pi-harness-runtime/commit/177c964555b0057e6bc7d293dafab10c95eabbf9))
11
+ * **approval:** the refusal of the judge is asked of the human ([8cc14cd](https://github.com/ManotLuijiu/pi-harness-runtime/commit/8cc14cd46fec1fa5ea2b2e5f8b6675a38673bee9))
12
+ * **cookies:** the space-separated export is imported, the quota refresh is shared ([85e01dc](https://github.com/ManotLuijiu/pi-harness-runtime/commit/85e01dcc3836fc08ba33ea4aee9cc946c559bcb3))
13
+ * **delegation:** a child is only a child when it really ran ([ac4e678](https://github.com/ManotLuijiu/pi-harness-runtime/commit/ac4e6782d7d4bc4941e458425c8a9f38a51fc9d4))
14
+ * **delegation:** the scope of a request is measured before it is judged ([684b6a5](https://github.com/ManotLuijiu/pi-harness-runtime/commit/684b6a55184f63d3be24c48dcecfb0b13410dc15))
15
+ * **guard:** the exploration is bounded, the repeated reads are seen ([f14d51a](https://github.com/ManotLuijiu/pi-harness-runtime/commit/f14d51aa8aa2b664994d78313c13c6fdd7c0ee08))
16
+ * **harness:** the startup tells the user that the session keeps its issues with bd ([81d63c5](https://github.com/ManotLuijiu/pi-harness-runtime/commit/81d63c5dc2452b9f08001756866db80046a2532a))
17
+ * **honcho:** the memory service speaks the native MCP of Pi ([f9f740c](https://github.com/ManotLuijiu/pi-harness-runtime/commit/f9f740c12869bae4c4380afbe8c76e12388bb744))
18
+ * **jev:** one decision per question, bound to the question it was evaluated for ([03448aa](https://github.com/ManotLuijiu/pi-harness-runtime/commit/03448aaa17f2d0c3bcf644b0b1d5949727dfff8c))
19
+ * **jev:** the evaluation of a choice sees what the options mean ([f0c207e](https://github.com/ManotLuijiu/pi-harness-runtime/commit/f0c207e074701e6b7dab0965170ec39453d9d502))
20
+ * **jev:** the pending question carries the ask and the answer ([a792133](https://github.com/ManotLuijiu/pi-harness-runtime/commit/a792133e517fb8c12d3363e98942f3af30270f27))
21
+ * **jev:** the pending question counts down to the decision ([d0cc171](https://github.com/ManotLuijiu/pi-harness-runtime/commit/d0cc171223986b2d32c670b6c1c74712fe0a4ad8))
22
+ * **keys:** tell the user what to do about an exposed key file ([7031003](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7031003574307351b7a8f28ee14159b58e17b793))
23
+ * **keys:** the key files are repaired when their permissions are unsafe ([e9c2c26](https://github.com/ManotLuijiu/pi-harness-runtime/commit/e9c2c26b287665b56ed749de269737e8403bb8af))
24
+ * **mcp:** the harness connects the registered servers when nobody else does ([7fef951](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7fef95137ad4664df57f045cd91b7d233315b0bc))
25
+ * **merge:** a manual run can leave the merge to the pull request event ([b3d1950](https://github.com/ManotLuijiu/pi-harness-runtime/commit/b3d1950b5941c78ccd56951acdafd1d4afbe1bff))
26
+ * **phase:** the agent owns the todo list and the harness says so ([c489370](https://github.com/ManotLuijiu/pi-harness-runtime/commit/c489370bd7926aece8cb1a77aa20ca2d2672f1fb))
27
+ * **providers:** a shared registry of the pending automatic actions and a bounded recovery ([c5f955b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/c5f955bc82adcb6999a89d5bc278fa87fccee022))
28
+ * **providers:** one failure has one executor, and the retry bridge is checked ([e73c4c7](https://github.com/ManotLuijiu/pi-harness-runtime/commit/e73c4c76ff20a9708083659bdcefe74870a84837))
29
+ * **questions:** refuse the deletion of a temporary path without the judge ([ab29694](https://github.com/ManotLuijiu/pi-harness-runtime/commit/ab29694f36c1ff020b3b19ca542a27b37847055c))
30
+ * **quota:** a fresh capture and a low allowance decide the MiniMax recovery ([06d7b8e](https://github.com/ManotLuijiu/pi-harness-runtime/commit/06d7b8e971e0da58a344f75778c98edb442562bd))
31
+ * **quota:** the empty week waits for the human, the overload of a compaction shares the executor ([bbb0c39](https://github.com/ManotLuijiu/pi-harness-runtime/commit/bbb0c3909b11735343e84be690c4c47e67a563bb))
32
+ * **recovery:** a MiniMax quota exhaustion waits for the captured reset plus ten minutes ([5af08a0](https://github.com/ManotLuijiu/pi-harness-runtime/commit/5af08a0e86c8c93fa5b7ff64a7b08e4514bc68f3))
33
+ * **review:** the review starts on its own when the implementation is done ([04f51f5](https://github.com/ManotLuijiu/pi-harness-runtime/commit/04f51f599cd3222b6c74dd8fadb1373bd72d9bd7))
34
+ * **scope:** a marked resume and a backlog that only an approval starts ([19d3320](https://github.com/ManotLuijiu/pi-harness-runtime/commit/19d33204819cf05e678996fddf4c4621f0dd7d2f))
35
+ * **status:** the status line names the phase, the progress and the children ([0167bf3](https://github.com/ManotLuijiu/pi-harness-runtime/commit/0167bf396a0b987c1d44f3b869351976a951dd65))
36
+ * **test:** the task waits for the final tier of the validation plan ([fa147db](https://github.com/ManotLuijiu/pi-harness-runtime/commit/fa147dbf7d50d56e6ea48c6d8fbb4fcb190caf8a))
37
+ * **validation:** a large job starts with a measured pilot ([425964b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/425964b04a3d4fa02adfabed47ff62c5ec2b9c28))
38
+ * **validation:** the size of a job is a fact, not a phrase ([8aa6c11](https://github.com/ManotLuijiu/pi-harness-runtime/commit/8aa6c119565d0f8412dc8aeafa6b295d47d3f093))
39
+ * **workspace:** a Frappe bench names the mode of the workspace ([9d58517](https://github.com/ManotLuijiu/pi-harness-runtime/commit/9d585172063a330992fee933316e268ae9985e3c))
40
+
41
+
42
+ ### Bug Fixes
43
+
44
+ * **ci:** every run of a required check counts, and the worst one decides ([da9e0da](https://github.com/ManotLuijiu/pi-harness-runtime/commit/da9e0da6b0ca29cb320764fd5fc1b8a8dee8b1e0))
45
+ * **ci:** the newest attempt of a run decides, not the attempt that failed ([9d7adcc](https://github.com/ManotLuijiu/pi-harness-runtime/commit/9d7adcc31cbacc517c3c1a9bcd3956be94c908ef))
46
+ * **harness:** a raw control byte hid the request scope from the review ([852b1ff](https://github.com/ManotLuijiu/pi-harness-runtime/commit/852b1ff3afc21adb71e92b85d21ff1c88e14816a))
47
+ * **honcho:** a handshake that never finishes is named instead of hanging the startup ([d66005f](https://github.com/ManotLuijiu/pi-harness-runtime/commit/d66005f928a4f8df5de5b8a0579cbd4f8df37ff9))
48
+ * **honcho:** a probe that the end of the session cuts off is not a failure ([493fd93](https://github.com/ManotLuijiu/pi-harness-runtime/commit/493fd938ba09fdcf57bed4aaf259d81c4040909e))
49
+ * **honcho:** a slow connector is not a failed one, the row is corrected when the tools appear ([b62ac5b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/b62ac5b16ad93e2bfb10cbec589b80a09b7e20b3))
50
+ * **honcho:** a tools listing that the end of the session cuts off is not a failure ([62cc8c3](https://github.com/ManotLuijiu/pi-harness-runtime/commit/62cc8c376aade01c953ce2a1c6501ed07b74a1e9))
51
+ * **honcho:** the report names the state of the MCP server, not the registration ([762f4d5](https://github.com/ManotLuijiu/pi-harness-runtime/commit/762f4d59e4eabcab9a1c21a61aa522c3267621b3))
52
+ * **hooks:** a tag is checked through the commit behind it ([c823e8e](https://github.com/ManotLuijiu/pi-harness-runtime/commit/c823e8e1f6973c62b5449a97c101759a4d5cbba5))
53
+ * **jev:** a completion question, a stale check and a pending validation ([827120b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/827120b4138b6f5ae253e69154de190085703de8))
54
+ * **jev:** a new request does not inherit the completion of the old one ([0f863c7](https://github.com/ManotLuijiu/pi-harness-runtime/commit/0f863c7fcaf35e261beabebef15b8ab634132fdc))
55
+ * **jev:** a prohibition must not hide a destructive action ([78a6cc1](https://github.com/ManotLuijiu/pi-harness-runtime/commit/78a6cc199e647f812e145483f7e94991358d8f34))
56
+ * **jev:** a refusal without punctuation, and only a decline of an action ([ef3dbf8](https://github.com/ManotLuijiu/pi-harness-runtime/commit/ef3dbf87a2a1725373281613a0d48881ed5d2239))
57
+ * **jev:** a rejection during the countdown pauses the work ([9b018ce](https://github.com/ManotLuijiu/pi-harness-runtime/commit/9b018ce1152b6724dee73cdc901b8a360ecc91ab))
58
+ * **jev:** a session switch ends the wait of the old session ([ca03d39](https://github.com/ManotLuijiu/pi-harness-runtime/commit/ca03d399c0d4a1b2dd428ac39836ab53c0e51ab6))
59
+ * **jev:** an open question is not a permission to answer it ([e20eca2](https://github.com/ManotLuijiu/pi-harness-runtime/commit/e20eca24bb88d385198bb12ee3ebf573af9aea86))
60
+ * **jev:** keep a comparative caveat with the option it constrains ([7be306b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7be306b0d0872713ebca9386d613ae5a8da9d5b6))
61
+ * **jev:** the action of the question on its own text, and a reply is not an authorization ([7c3fdd6](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7c3fdd6822b58bd6ccfa3bcdf1c5282cb3db52dd))
62
+ * **jev:** the action of the question, and an open question blocks the work ([1f9ff39](https://github.com/ManotLuijiu/pi-harness-runtime/commit/1f9ff39efc4ee17464c54c2ca9b583245093dbac))
63
+ * **jev:** the alternatives of a question are parsed without a quadratic pattern ([63016a3](https://github.com/ManotLuijiu/pi-harness-runtime/commit/63016a3f0488acb801990dd46770c00d382b5858))
64
+ * **jev:** the countdown of an obsolete question does not outlive the work ([fe78b29](https://github.com/ManotLuijiu/pi-harness-runtime/commit/fe78b29e6fc513b11a6993bc68fd9418dc77f79b))
65
+ * **jev:** the facts of an option survive the wording of the agent ([5a6250c](https://github.com/ManotLuijiu/pi-harness-runtime/commit/5a6250c07aa8d965bc6ae242cccbf519477598f8))
66
+ * **jev:** the scope decides the question, the identity guards the awaits ([ed348b2](https://github.com/ManotLuijiu/pi-harness-runtime/commit/ed348b2f94460a3b3ac11c01afd4420ee4ec1020))
67
+ * **jev:** the scope of a request on every human path, and the todos it touched ([cec8f36](https://github.com/ManotLuijiu/pi-harness-runtime/commit/cec8f3644333b1d13a203340df80a30fef5c1ac0))
68
+ * **jev:** the subject of the scope decides, a clarification is preserved ([faf6a0f](https://github.com/ManotLuijiu/pi-harness-runtime/commit/faf6a0fe7d0dce94d4fa48d0d7a57d126556ba6d))
69
+ * **keys:** the key directory is audited as a tree ([081cc75](https://github.com/ManotLuijiu/pi-harness-runtime/commit/081cc75ac8ceff36b0d619c3f76371dc08459d3c))
70
+ * **logging:** the query window no longer rots with the wall clock ([cd3f5b1](https://github.com/ManotLuijiu/pi-harness-runtime/commit/cd3f5b18d8a4b8850a201d060699e18bf789a647))
71
+ * **logging:** the sanitizer of a message writes its control characters as escapes ([f4bbdb9](https://github.com/ManotLuijiu/pi-harness-runtime/commit/f4bbdb94bc1801d4228142bc1a1b31505c42a575))
72
+ * **mcp:** the connector and the watcher stop with the session ([4d1b87d](https://github.com/ManotLuijiu/pi-harness-runtime/commit/4d1b87d14d015749025b62bf54d6d0b6137295f7))
73
+ * **mcp:** the connector survives a runtime that cannot list the servers ([d0f555f](https://github.com/ManotLuijiu/pi-harness-runtime/commit/d0f555fa14f51de33591e572a41ded5b59a3e4dd))
74
+ * **merge:** the boolean input is read as a boolean ([971b716](https://github.com/ManotLuijiu/pi-harness-runtime/commit/971b7169a43db382dbdeb6bb9bab02ab56e0351c))
75
+ * **merge:** the manual job needs the right of the merge ([7ba685e](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7ba685ec43d815f90aa35b742579e87e76c69209))
76
+ * **merge:** the merge of the pull request is the GraphQL mutation ([972bab4](https://github.com/ManotLuijiu/pi-harness-runtime/commit/972bab4b0f7faf1b0047f3bb767ef6db3de4b2fa))
77
+ * **merge:** the workflow merges the pull request the gates cleared ([d7639ec](https://github.com/ManotLuijiu/pi-harness-runtime/commit/d7639ec9b83723510acb4a5c4e23d5d6167c3af6))
78
+ * **providers:** the escape of the user stops the recovery, and a permanent failure clears it ([cfe5797](https://github.com/ManotLuijiu/pi-harness-runtime/commit/cfe57976bf463c327e45b874fd297c3e942246b8))
79
+ * **providers:** the pause wins over a retry, and the retry starts when the run settles ([e016dd2](https://github.com/ManotLuijiu/pi-harness-runtime/commit/e016dd2a5add5b0f3c848a225a28a59e0f5fc7f3))
80
+ * **recovery:** a cancelled countdown does not own the next attempt ([7b79f30](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7b79f301389fae48201e696d3086d257ed722fb9))
81
+ * **recovery:** a cancelled retry of Pi is a cancelled decision, a spent budget is not ([7e13f15](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7e13f156a279cded2b2d4b0c99358100b3d5e038))
82
+ * **recovery:** a manual request takes the work back from the countdown ([fa81d8f](https://github.com/ManotLuijiu/pi-harness-runtime/commit/fa81d8fd9d6160166a095e07bdf17049bbafa32d))
83
+ * **recovery:** the predicate of Pi decides the retry, the provider identity is normalized ([6c8c17b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/6c8c17b53302cea1602d192251eacd0ebbd3e8c9))
84
+ * **release:** a manual release keeps the version of its manifest ([122e661](https://github.com/ManotLuijiu/pi-harness-runtime/commit/122e661ea48cb8aff14c71dbd0221a4cf0ba4c8e))
85
+ * **release:** the alignment names the reason of a failure ([5814dd0](https://github.com/ManotLuijiu/pi-harness-runtime/commit/5814dd0b780f5839cf8011ed0cbbbb31e7eb0418))
86
+ * **release:** the channels of the package name the release ([a7a273f](https://github.com/ManotLuijiu/pi-harness-runtime/commit/a7a273ffe8398e2b5b07ef1c321777de41792c6e))
87
+ * **release:** the lockfile knows the new workspace package ([6d0a143](https://github.com/ManotLuijiu/pi-harness-runtime/commit/6d0a143fe9853deafbaa8a04433a53da36355c43))
88
+ * **release:** the release publishes and leaves the channels alone ([5871746](https://github.com/ManotLuijiu/pi-harness-runtime/commit/5871746589c1281d855dbeb591b02419fa43f22e))
89
+ * **release:** the release pull request names the version of its branch ([a846e83](https://github.com/ManotLuijiu/pi-harness-runtime/commit/a846e83e6de6e529f4bca05e869db0b5eebb37c5))
90
+ * **release:** the release scans the tree of the commit it publishes ([7d47a0b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7d47a0b5406480a1e1d3a52623a76aabd1e2d0ba))
91
+ * **scope:** a session that ends leaves no proposal behind ([9aad01e](https://github.com/ManotLuijiu/pi-harness-runtime/commit/9aad01e1f13446da1d01032e9967cadf66772792))
92
+ * **scope:** the findings of the review of the scope expansion ([92372e5](https://github.com/ManotLuijiu/pi-harness-runtime/commit/92372e51ca31198593025ce8671b226d2ca7182e))
93
+ * **scope:** the question of a proposal is not obsolete and a rejection is named ([d4c58c3](https://github.com/ManotLuijiu/pi-harness-runtime/commit/d4c58c3e63e27449ef1de0f8e4e55ebbf342ff7d))
94
+ * **test:** the quota capture integration needs the runtime of bun ([86fae7d](https://github.com/ManotLuijiu/pi-harness-runtime/commit/86fae7de31e76414aa31bb75eb136155f62d7a40))
95
+ * **workspace:** a strong bench signal decides, and the question is not a fact of an option ([303a828](https://github.com/ManotLuijiu/pi-harness-runtime/commit/303a828f55aa7c4e0a611231f482489b530ff5a3))
96
+ * **workspace:** keep a client name out of the comment about the search depth ([b572e0a](https://github.com/ManotLuijiu/pi-harness-runtime/commit/b572e0af16ff562203bda2b5c47b41807cff5a95))
97
+ * **workspace:** the repository names the mode before the mode stays unknown ([188a32c](https://github.com/ManotLuijiu/pi-harness-runtime/commit/188a32c7a6af1465dd24714278fccc73d06f6477))
98
+
5
99
  ### [1.1.515](https://github.com/ManotLuijiu/pi-harness-runtime/compare/v1.1.448...v1.1.515) (2026-11-17)
6
100
 
7
101
 
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The decisions that were made about an approval.
3
+ *
4
+ * The decision of a deadline is claimed with an exclusive create: the file
5
+ * exists only when the claim was won. A second caller sees the file and
6
+ * does not get a second decision, and a restart does not hand the same
7
+ * decision out again.
8
+ *
9
+ * The claim is durable on purpose. A decision that was claimed and whose
10
+ * resume was lost in a crash must not be handed out a second time: the
11
+ * work would continue twice.
12
+ */
13
+
14
+ import { existsSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
15
+ import { join } from "node:path";
16
+ import { atomicCreateFileSync } from "../packages/cookie-sanitizer/dist/index.js";
17
+ import type { ApprovalDecision } from "./delegated-approval-types.ts";
18
+
19
+ /** Make a part of a path safe for the file system. */
20
+ function safePart(value: string): string {
21
+ return value.replace(/[^a-zA-Z0-9_.-]/g, "_").slice(-120);
22
+ }
23
+
24
+ /**
25
+ * The decisions of the machine.
26
+ */
27
+ export class ApprovalDecisionStore {
28
+ /** The root of the store. */
29
+ private readonly root: string;
30
+
31
+ constructor(root: string) {
32
+ this.root = root;
33
+ }
34
+
35
+ /** The directory of the decisions. */
36
+ private decisionsDir(): string {
37
+ return join(this.root, "decisions");
38
+ }
39
+
40
+ /** The path of the decision of a request. */
41
+ private pathOf(requestId: string): string {
42
+ return join(this.decisionsDir(), `${safePart(requestId)}.json`);
43
+ }
44
+
45
+ /**
46
+ * Claim the decision of a request.
47
+ *
48
+ * The result is true for the caller that won the claim and false for
49
+ * every other one.
50
+ */
51
+ claim(decision: ApprovalDecision): boolean {
52
+ mkdirSync(this.decisionsDir(), { recursive: true });
53
+ try {
54
+ // The exclusive create is the claim: it fails when the decision
55
+ // of this request was already claimed.
56
+ atomicCreateFileSync(
57
+ this.pathOf(decision.requestId),
58
+ JSON.stringify(decision, null, 2),
59
+ );
60
+ return true;
61
+ } catch {
62
+ return false;
63
+ }
64
+ }
65
+
66
+ /** The decision of a request, when there is one. */
67
+ get(requestId: string): ApprovalDecision | undefined {
68
+ const path = this.pathOf(requestId);
69
+ if (!existsSync(path)) return undefined;
70
+ return readJson<ApprovalDecision>(path);
71
+ }
72
+
73
+ /** The decisions that were made. */
74
+ list(): ApprovalDecision[] {
75
+ const dir = this.decisionsDir();
76
+ if (!existsSync(dir)) return [];
77
+ const found: ApprovalDecision[] = [];
78
+ for (const name of readdirSync(dir)) {
79
+ if (!name.endsWith(".json")) continue;
80
+ const decision = readJson<ApprovalDecision>(join(dir, name));
81
+ if (decision) found.push(decision);
82
+ }
83
+ return found;
84
+ }
85
+ }
86
+
87
+ /** Read a JSON file, or nothing when it cannot be read. */
88
+ function readJson<T>(path: string): T | undefined {
89
+ try {
90
+ return JSON.parse(readFileSync(path, "utf8")) as T;
91
+ } catch {
92
+ return undefined;
93
+ }
94
+ }
@@ -0,0 +1,375 @@
1
+ /**
2
+ * The runtime of the delegated approval.
3
+ *
4
+ * An operation that the human has to approve is open as a request. The
5
+ * request is delivered to the channels, and two things can end it:
6
+ *
7
+ * - the human answers. The first answer wins, and it is recorded with the
8
+ * source `"human"`.
9
+ * - the deadline passes. The deadline is not an answer: the operation
10
+ * continues only when the user delegated that outcome in advance, and
11
+ * only for the kinds of operation the delegation names. The decision is
12
+ * recorded with the source `"delegated-timeout"`, never as a click of
13
+ * the human.
14
+ *
15
+ * The claim of the decision is atomic and durable, so exactly one resume
16
+ * is queued: a duplicate click, a late inference and a restart cannot
17
+ * queue a second one.
18
+ *
19
+ * The runtime never forces a turn and never decides for the human. It
20
+ * records what happened and hands the decision to the caller.
21
+ */
22
+
23
+ import type { ApprovalDecisionStore } from "./approval-decision-store.ts";
24
+ import type { DelegationStore } from "./delegation-store.ts";
25
+ import type {
26
+ ApprovalDecision,
27
+ ApprovalOutcome,
28
+ ApprovalRequest,
29
+ DelegatedOperationKind,
30
+ Delegation,
31
+ } from "./delegated-approval-types.ts";
32
+ import { delegationCovers } from "./delegated-approval-types.ts";
33
+
34
+ /** What the caller wants to ask the human. */
35
+ export interface OpenApprovalInput {
36
+ /** The canonical id of the request. It is the id of the pending question. */
37
+ requestId: string;
38
+ /** The workspace of the operation. */
39
+ workspace: string;
40
+ /** The session of the request. */
41
+ sessionId: string;
42
+ /** The generation of the request. */
43
+ generation: number;
44
+ /** The kind of the operation. */
45
+ kind: DelegatedOperationKind;
46
+ /** The exact operation, in the words of the human. */
47
+ operation: string;
48
+ /** What stays blocked while the request is open. */
49
+ blocked?: string[];
50
+ /** Why the operation is not simply running. */
51
+ reason?: string;
52
+ /** The deadline of the answer. It is absolute. */
53
+ deadlineAt: number;
54
+ }
55
+
56
+ /** The result of opening a request. */
57
+ export interface OpenApprovalOutcome {
58
+ /** The request. It is expired when the delivery failed. */
59
+ request: ApprovalRequest;
60
+ /** Did at least one route accept the message? */
61
+ delivered: boolean;
62
+ /** The routes that refused the message. */
63
+ failures: string[];
64
+ }
65
+
66
+ export interface DelegatedApprovalDeps {
67
+ /** The clock of the runtime. */
68
+ now(): number;
69
+ /** The delegations the user recorded in advance. */
70
+ delegations: DelegationStore;
71
+ /** The decisions that were made. */
72
+ decisions: ApprovalDecisionStore;
73
+ /**
74
+ * Deliver the request to the human.
75
+ *
76
+ * The result says whether at least one route accepted the message.
77
+ */
78
+ deliver(
79
+ request: ApprovalRequest,
80
+ ): Promise<{ delivered: boolean; failures: string[] }>;
81
+ /**
82
+ * The resume that continues the work.
83
+ *
84
+ * It is queued at most once per request: the claim of the decision is
85
+ * what guarantees it.
86
+ */
87
+ resume(request: ApprovalRequest, decision: ApprovalDecision): void;
88
+ /**
89
+ * Is the work of the request still active?
90
+ *
91
+ * A request that was cancelled, replaced or completed must not be
92
+ * continued by a timeout.
93
+ */
94
+ active?(request: ApprovalRequest): boolean;
95
+ /** The work is paused. */
96
+ paused?(): boolean;
97
+ /** The log of the runtime. */
98
+ log?(message: string): void;
99
+ }
100
+
101
+ /**
102
+ * The runtime of the delegated approval.
103
+ */
104
+ export class DelegatedApprovalRuntime {
105
+ private readonly deps: DelegatedApprovalDeps;
106
+ /** The requests that are open. */
107
+ private readonly requests = new Map<string, ApprovalRequest>();
108
+ /** The timer of the earliest deadline. */
109
+ private timer: ReturnType<typeof setTimeout> | null = null;
110
+
111
+ constructor(deps: DelegatedApprovalDeps) {
112
+ this.deps = deps;
113
+ }
114
+
115
+ /** The request of an id, when there is one. */
116
+ get(requestId: string): ApprovalRequest | undefined {
117
+ return this.requests.get(requestId);
118
+ }
119
+
120
+ /**
121
+ * Stop the timer.
122
+ *
123
+ * The session stops it when it ends: a deadline that fires after the
124
+ * session is gone must not continue anything.
125
+ */
126
+ stop(): void {
127
+ if (this.timer) {
128
+ clearTimeout(this.timer);
129
+ this.timer = null;
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Arm the timer of the earliest deadline.
135
+ *
136
+ * One timer serves every request: the deadline that comes first is the
137
+ * one that is watched, and the timer is armed again for the next one
138
+ * when it ran.
139
+ */
140
+ private armTimer(): void {
141
+ this.stop();
142
+ const now = this.deps.now();
143
+ const next = this.pending()
144
+ .filter((request) => request.deadlineAt > now)
145
+ .sort((a, b) => a.deadlineAt - b.deadlineAt)[0];
146
+ if (!next) return;
147
+ const delay = Math.max(0, next.deadlineAt - now);
148
+ const timer = setTimeout(() => {
149
+ this.timer = null;
150
+ this.expire(next.requestId);
151
+ this.armTimer();
152
+ }, delay);
153
+ // The timer must not hold the process of the harness open.
154
+ (timer as { unref?: () => void }).unref?.();
155
+ this.timer = timer;
156
+ }
157
+
158
+ /** The requests that are open. */
159
+ pending(): ApprovalRequest[] {
160
+ return [...this.requests.values()].filter(
161
+ (request) => request.state === "pending",
162
+ );
163
+ }
164
+
165
+ /**
166
+ * Open a request and deliver it to the human.
167
+ *
168
+ * The window starts only when a route accepted the message: a question
169
+ * that nobody was told about must not consume the opportunity of the
170
+ * human to answer.
171
+ *
172
+ * The caller may pass the result of a delivery it made itself. The
173
+ * delivery of the question and the window are then one decision, and
174
+ * the message is not sent twice.
175
+ */
176
+ async open(
177
+ input: OpenApprovalInput,
178
+ delivery?: { delivered: boolean; failures: string[] },
179
+ ): Promise<OpenApprovalOutcome> {
180
+ const existing = this.requests.get(input.requestId);
181
+ if (existing && existing.state === "pending") {
182
+ // The same question is not asked twice: a repeated delivery
183
+ // would only wear the human down.
184
+ this.deps.log?.(
185
+ `The approval request ${input.requestId} is already open - it is not asked again.`,
186
+ );
187
+ return { request: existing, delivered: true, failures: [] };
188
+ }
189
+ const request: ApprovalRequest = {
190
+ requestId: input.requestId,
191
+ workspace: input.workspace,
192
+ sessionId: input.sessionId,
193
+ generation: input.generation,
194
+ kind: input.kind,
195
+ operation: input.operation,
196
+ blocked: input.blocked ?? [],
197
+ reason: input.reason,
198
+ deadlineAt: input.deadlineAt,
199
+ state: "pending",
200
+ };
201
+ this.requests.set(request.requestId, request);
202
+ const result = delivery ?? (await this.deps.deliver(request));
203
+ if (!result.delivered) {
204
+ // The operation stays blocked: nobody was asked, so nobody
205
+ // authorized anything.
206
+ request.state = "expired";
207
+ this.deps.log?.(
208
+ `The approval request ${request.requestId} was not delivered: ${result.failures.join(", ")}. The operation stays blocked.`,
209
+ );
210
+ return { request, delivered: false, failures: result.failures };
211
+ }
212
+ // The window starts with the delivery: the deadline is watched
213
+ // from here on.
214
+ this.armTimer();
215
+ return { request, delivered: true, failures: [] };
216
+ }
217
+
218
+ /**
219
+ * The answer of the human.
220
+ *
221
+ * The first answer wins: a second click, a click of another channel
222
+ * and a late answer of a stale button do nothing.
223
+ */
224
+ answer(
225
+ requestId: string,
226
+ outcome: ApprovalOutcome,
227
+ ): ApprovalDecision | null {
228
+ const request = this.requests.get(requestId);
229
+ if (!request) return null;
230
+ if (request.state !== "pending") {
231
+ this.deps.log?.(
232
+ `The approval request ${requestId} was answered already - the answer is stale.`,
233
+ );
234
+ return null;
235
+ }
236
+ const decision: ApprovalDecision = {
237
+ requestId,
238
+ outcome,
239
+ source: "human",
240
+ reason: "the human answered",
241
+ at: this.deps.now(),
242
+ };
243
+ // The claim is atomic: two answers that arrive at the same moment
244
+ // still produce one decision.
245
+ if (!this.deps.decisions.claim(decision)) {
246
+ this.deps.log?.(
247
+ `The approval request ${requestId} was answered already - the answer is stale.`,
248
+ );
249
+ return null;
250
+ }
251
+ request.state = "answered";
252
+ request.answer = { outcome, source: "human", at: decision.at };
253
+ // The deadline of an answered request is not watched any more.
254
+ this.armTimer();
255
+ return decision;
256
+ }
257
+
258
+ /**
259
+ * The deadline of a request passed.
260
+ *
261
+ * The state of the work is checked before the claim, the claim is
262
+ * atomic, and the resume is queued at most once.
263
+ */
264
+ expire(requestId: string): ApprovalDecision | null {
265
+ const request = this.requests.get(requestId);
266
+ if (!request) return null;
267
+ // The human wins: an answer that arrived before the claim is kept,
268
+ // and the deadline never overrides it.
269
+ if (request.state === "answered") {
270
+ this.deps.log?.(
271
+ `The approval request ${requestId} was answered by the human - the deadline does not override it.`,
272
+ );
273
+ return null;
274
+ }
275
+ if (request.state !== "pending") return null;
276
+ // A request that was cancelled, replaced or completed must not be
277
+ // continued by a deadline.
278
+ if (this.deps.active && !this.deps.active(request)) {
279
+ this.deps.log?.(
280
+ `The approval request ${requestId} is not active - the deadline does not continue it.`,
281
+ );
282
+ return null;
283
+ }
284
+ if (this.deps.paused?.() === true) {
285
+ this.deps.log?.(
286
+ `The approval request ${requestId} is paused - the deadline does not continue it.`,
287
+ );
288
+ return null;
289
+ }
290
+ // The scope of the delegation decides: an operation that no
291
+ // delegation covers stays blocked.
292
+ const delegation = this.delegationForRequest(request);
293
+ const outcome: ApprovalOutcome =
294
+ delegation?.defaultOutcome === "continue" ? "yes" : "no";
295
+ const decision: ApprovalDecision = {
296
+ requestId,
297
+ outcome,
298
+ source: "delegated-timeout",
299
+ ...(delegation ? { delegationId: delegation.id } : {}),
300
+ reason: delegation
301
+ ? `the deadline passed under the delegation ${delegation.id}`
302
+ : "no delegation covers the operation",
303
+ at: this.deps.now(),
304
+ };
305
+ // The claim is atomic and durable: the decision is handed out once,
306
+ // and a restart does not hand it out again.
307
+ if (!this.deps.decisions.claim(decision)) {
308
+ this.deps.log?.(
309
+ `The decision of the approval request ${requestId} was claimed already.`,
310
+ );
311
+ return null;
312
+ }
313
+ request.state = "claimed";
314
+ request.answer = { outcome, source: "delegated-timeout", at: decision.at };
315
+ if (outcome === "yes") {
316
+ // Exactly one resume: the claim is what guarantees it.
317
+ this.queueResume(request, decision);
318
+ } else {
319
+ this.deps.log?.(
320
+ `The operation of the approval request ${requestId} stays blocked: ${decision.reason}.`,
321
+ );
322
+ }
323
+ return decision;
324
+ }
325
+
326
+ /**
327
+ * The delegation that covers an operation of a workspace.
328
+ *
329
+ * The most recent delegation wins: a delegation that was recorded
330
+ * later replaces the one before it.
331
+ */
332
+ delegationFor(input: {
333
+ kind: DelegatedOperationKind;
334
+ workspace: string;
335
+ }): Delegation | undefined {
336
+ const now = this.deps.now();
337
+ return this.deps.delegations
338
+ .list(input.workspace)
339
+ .filter((delegation) =>
340
+ delegationCovers(
341
+ delegation,
342
+ input.kind,
343
+ input.workspace,
344
+ now,
345
+ ),
346
+ )
347
+ .sort((a, b) => b.recordedAt - a.recordedAt)[0];
348
+ }
349
+
350
+ /**
351
+ * The delegation that covers the operation of a request.
352
+ */
353
+ private delegationForRequest(request: ApprovalRequest): Delegation | undefined {
354
+ return this.delegationFor({
355
+ kind: request.kind,
356
+ workspace: request.workspace,
357
+ });
358
+ }
359
+
360
+ /** Queue the resume of the work. It never throws. */
361
+ private queueResume(
362
+ request: ApprovalRequest,
363
+ decision: ApprovalDecision,
364
+ ): void {
365
+ try {
366
+ this.deps.resume(request, decision);
367
+ } catch (error) {
368
+ this.deps.log?.(
369
+ `The resume of the approval request ${request.requestId} failed: ${
370
+ error instanceof Error ? error.message : String(error)
371
+ }`,
372
+ );
373
+ }
374
+ }
375
+ }