@hassangameryt/freeflow 0.7.3 → 0.9.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 (426) hide show
  1. package/.agents/plugins/marketplace.json +2 -2
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +2 -2
  4. package/.codex-plugin/plugin.json +3 -3
  5. package/.cursor-plugin/plugin.json +1 -1
  6. package/NOTICE +14 -0
  7. package/README.md +101 -159
  8. package/capabilities/cognitive-routing/SKILL.md +47 -210
  9. package/capabilities/cognitive-routing/references/coordinator.md +163 -0
  10. package/capabilities/cognitive-routing/references/worker.md +38 -0
  11. package/capabilities/compaction/SKILL.md +49 -0
  12. package/capabilities/compaction/references/summary-format.md +250 -0
  13. package/capabilities/messaging/SKILL.md +49 -0
  14. package/capabilities/task-memory/SKILL.md +87 -0
  15. package/command-surface.json +8 -52
  16. package/gemini-extension.json +1 -1
  17. package/hooks/claude/hooks.json +13 -3
  18. package/hooks/codex/hooks.json +2 -1
  19. package/hooks/shared/runtime-context.mjs +73 -83
  20. package/licenses/Apache-2.0.txt +55 -0
  21. package/package.json +42 -12
  22. package/pi-extension/README.md +41 -0
  23. package/pi-extension/dist/ask-user/ask.js +108 -0
  24. package/pi-extension/dist/ask-user/form.js +250 -0
  25. package/pi-extension/dist/ask-user/questions.js +66 -0
  26. package/pi-extension/dist/ask-user/tool.js +124 -0
  27. package/pi-extension/dist/cognitive-routing/assembler.js +417 -0
  28. package/pi-extension/dist/cognitive-routing/bootstrap.js +90 -0
  29. package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/config.js +8 -6
  30. package/pi-extension/dist/cognitive-routing/economics.js +45 -0
  31. package/pi-extension/dist/cognitive-routing/event-schema.js +388 -0
  32. package/pi-extension/dist/{session-sources/events.js → cognitive-routing/event-store.js} +107 -41
  33. package/pi-extension/dist/cognitive-routing/gate.js +256 -0
  34. package/pi-extension/dist/cognitive-routing/handlers.js +901 -0
  35. package/pi-extension/dist/cognitive-routing/handoffs.js +350 -0
  36. package/pi-extension/dist/cognitive-routing/model-control.js +476 -0
  37. package/pi-extension/dist/cognitive-routing/projection.js +520 -0
  38. package/pi-extension/dist/cognitive-routing/provenance.js +83 -0
  39. package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/render.js +15 -15
  40. package/pi-extension/dist/cognitive-routing/runtime.js +398 -0
  41. package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/schemas.js +47 -11
  42. package/pi-extension/dist/cognitive-routing/session.js +223 -0
  43. package/pi-extension/dist/{session-sources → cognitive-routing}/sources.js +126 -87
  44. package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/state.js +55 -386
  45. package/pi-extension/dist/cognitive-routing/status.js +81 -0
  46. package/pi-extension/dist/cognitive-routing/tools.js +74 -0
  47. package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/types.js +14 -11
  48. package/pi-extension/dist/compaction/carry.js +205 -0
  49. package/pi-extension/dist/compaction/config.js +24 -0
  50. package/pi-extension/dist/compaction/controller.js +494 -0
  51. package/pi-extension/dist/compaction/harness.js +93 -0
  52. package/pi-extension/dist/compaction/results.js +159 -0
  53. package/pi-extension/dist/compaction/thresholds.js +35 -0
  54. package/pi-extension/dist/compaction/tool.js +57 -0
  55. package/pi-extension/dist/host/branch.js +13 -0
  56. package/pi-extension/dist/host/canonical.js +12 -0
  57. package/pi-extension/dist/host/catalog.js +62 -0
  58. package/pi-extension/dist/host/config-validation.js +233 -0
  59. package/pi-extension/dist/host/config.js +361 -0
  60. package/pi-extension/dist/host/inbound.js +142 -0
  61. package/pi-extension/dist/host/projection-tags.js +60 -0
  62. package/pi-extension/dist/host/prompts.js +93 -0
  63. package/pi-extension/dist/{session-sources → host}/read-only-session.js +117 -1
  64. package/pi-extension/dist/{runtime → host}/request-history.js +125 -39
  65. package/pi-extension/dist/host/rows.js +25 -0
  66. package/pi-extension/dist/host/runtime-state.js +204 -0
  67. package/pi-extension/dist/host/section-keeper.js +85 -0
  68. package/pi-extension/dist/host/settings/freeflow-command.js +2323 -0
  69. package/pi-extension/dist/{settings/settings-tui.js → host/settings/settings-view.js} +205 -73
  70. package/pi-extension/dist/host/staging.js +28 -0
  71. package/pi-extension/dist/host/status.js +115 -0
  72. package/pi-extension/dist/index.js +1004 -188
  73. package/pi-extension/dist/messaging/config.js +27 -0
  74. package/pi-extension/dist/messaging/messaging.js +398 -0
  75. package/pi-extension/dist/messaging/registry.js +57 -0
  76. package/pi-extension/dist/messaging/render.js +90 -0
  77. package/pi-extension/dist/messaging/tools.js +109 -0
  78. package/pi-extension/dist/messaging/transport.js +101 -0
  79. package/pi-extension/dist/provider-support/cache/anchor.js +21 -0
  80. package/pi-extension/dist/provider-support/cache/anthropic.js +102 -0
  81. package/pi-extension/dist/provider-support/cache/health.js +73 -0
  82. package/pi-extension/dist/provider-support/cache/index.js +58 -0
  83. package/pi-extension/dist/provider-support/cache/keepalive.js +222 -0
  84. package/pi-extension/dist/provider-support/cache/monitor.js +17 -0
  85. package/pi-extension/dist/provider-support/cache/openai-responses.js +48 -0
  86. package/pi-extension/dist/provider-support/effort.js +13 -0
  87. package/pi-extension/dist/provider-support/index.js +44 -3
  88. package/pi-extension/dist/provider-support/{astra → openai}/adapter.js +46 -29
  89. package/pi-extension/dist/provider-support/{astra → openai}/history.js +10 -8
  90. package/pi-extension/dist/provider-support/{astra → openai}/index.js +8 -4
  91. package/pi-extension/dist/provider-support/{astra → openai}/session-state.js +29 -38
  92. package/pi-extension/dist/provider-support/routes.js +17 -0
  93. package/pi-extension/dist/task-memory/config.js +49 -0
  94. package/pi-extension/dist/task-memory/registry.js +119 -0
  95. package/pi-extension/dist/task-memory/render.js +107 -0
  96. package/pi-extension/dist/task-memory/runtime.js +994 -0
  97. package/pi-extension/dist/task-memory/tool.js +233 -0
  98. package/pi-extension/dist/tool-execution/apply-patch/grammar.js +23 -0
  99. package/pi-extension/dist/tool-execution/apply-patch/match.js +38 -0
  100. package/pi-extension/dist/tool-execution/apply-patch/parser.js +177 -0
  101. package/pi-extension/dist/tool-execution/apply-patch/plan.js +201 -0
  102. package/pi-extension/dist/tool-execution/apply-patch/tool.js +84 -0
  103. package/pi-extension/dist/tool-execution/background.js +430 -0
  104. package/pi-extension/dist/tool-execution/bash-guard.js +23 -0
  105. package/pi-extension/dist/tool-execution/config.js +33 -0
  106. package/pi-extension/dist/tool-execution/edit-messages.js +120 -0
  107. package/pi-extension/dist/tool-execution/file-state.js +138 -0
  108. package/pi-extension/dist/tool-execution/file-tracking.js +163 -0
  109. package/pi-extension/dist/tool-execution/guidance-notices.js +124 -0
  110. package/pi-extension/dist/tool-execution/prompt.js +54 -0
  111. package/pi-extension/dist/tool-execution/skill-reads.js +143 -0
  112. package/pi-extension/dist/tool-execution/tools.js +16 -0
  113. package/pi-extension/freeflow/README.md +9 -0
  114. package/runtime/prompts/cognitive-routing.md +4 -4
  115. package/runtime/prompts/core.md +29 -72
  116. package/runtime/prompts/interaction-contract.md +18 -8
  117. package/runtime/prompts/tool-execution.md +25 -0
  118. package/runtime/prompts/working-method.md +25 -0
  119. package/skills/deliver-work/SKILL.md +76 -0
  120. package/skills/deliver-work/references/branch-closeout.md +134 -0
  121. package/skills/deliver-work/references/commit.md +83 -0
  122. package/skills/deliver-work/references/launch.md +94 -0
  123. package/skills/deliver-work/references/release.md +85 -0
  124. package/skills/deliver-work/scripts/commit-state.mjs +139 -0
  125. package/skills/deliver-work/scripts/delivery-state.mjs +107 -0
  126. package/skills/deliver-work/scripts/lib/git-state.mjs +178 -0
  127. package/skills/deliver-work/scripts/push-route.mjs +122 -0
  128. package/skills/deliver-work/scripts/release-preflight.mjs +177 -0
  129. package/skills/discuss-work/SKILL.md +148 -0
  130. package/skills/{discuss → discuss-work}/references/discussion-continuity.md +13 -50
  131. package/skills/discuss-work/references/learning-action.md +36 -0
  132. package/skills/discuss-work/scripts/choices.mjs +101 -0
  133. package/skills/discuss-work/scripts/lib/choices.mjs +159 -0
  134. package/skills/evaluate-behavior/SKILL.md +107 -0
  135. package/skills/evaluate-behavior/references/authoring.md +381 -0
  136. package/skills/evaluate-behavior/references/coding-tasks.md +145 -0
  137. package/skills/evaluate-behavior/references/conversations-pipelines-judges.md +177 -0
  138. package/skills/evaluate-behavior/references/design-and-measurement.md +273 -0
  139. package/skills/evaluate-behavior/references/running-and-evidence.md +245 -0
  140. package/skills/evaluate-behavior/scripts/claude-guard.mjs +76 -0
  141. package/skills/evaluate-behavior/scripts/guard-rules.mjs +309 -0
  142. package/skills/evaluate-behavior/scripts/lib/agreement.mjs +90 -0
  143. package/skills/evaluate-behavior/scripts/lib/arms.mjs +55 -0
  144. package/skills/evaluate-behavior/scripts/lib/budget.mjs +87 -0
  145. package/skills/evaluate-behavior/scripts/lib/build-source.mjs +287 -0
  146. package/skills/evaluate-behavior/scripts/lib/clear.mjs +74 -0
  147. package/skills/evaluate-behavior/scripts/lib/container.mjs +395 -0
  148. package/skills/evaluate-behavior/scripts/lib/decision.mjs +418 -0
  149. package/skills/evaluate-behavior/scripts/lib/definitions.mjs +1072 -0
  150. package/skills/evaluate-behavior/scripts/lib/freeflow.mjs +103 -0
  151. package/skills/evaluate-behavior/scripts/lib/grade-command.mjs +591 -0
  152. package/skills/evaluate-behavior/scripts/lib/grade-comparison.mjs +90 -0
  153. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-interaction.mjs +19 -18
  154. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-support.mjs +32 -5
  155. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-workspace.mjs +28 -12
  156. package/skills/evaluate-behavior/scripts/lib/grade.mjs +101 -0
  157. package/skills/evaluate-behavior/scripts/lib/hooks.mjs +98 -0
  158. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/confinement.mjs +196 -0
  159. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/constraints.mjs +111 -0
  160. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/index.mjs +48 -0
  161. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/isolation.mjs +74 -0
  162. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/launch.mjs +123 -0
  163. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/model-call.mjs +73 -0
  164. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/recorder.mjs +178 -0
  165. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/session.mjs +494 -0
  166. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/skills.mjs +81 -0
  167. package/skills/evaluate-behavior/scripts/lib/hosts/index.mjs +31 -0
  168. package/skills/evaluate-behavior/scripts/lib/hosts/names.mjs +3 -0
  169. package/skills/evaluate-behavior/scripts/lib/hosts/pi/confinement.mjs +173 -0
  170. package/skills/evaluate-behavior/scripts/lib/hosts/pi/host.mjs +148 -0
  171. package/skills/evaluate-behavior/scripts/lib/hosts/pi/index.mjs +70 -0
  172. package/skills/evaluate-behavior/scripts/lib/hosts/pi/isolation.mjs +81 -0
  173. package/skills/evaluate-behavior/scripts/lib/hosts/pi/model-call.mjs +79 -0
  174. package/skills/evaluate-behavior/scripts/lib/hosts/pi/process.mjs +241 -0
  175. package/skills/{evaluate-skill/scripts/lib → evaluate-behavior/scripts/lib/hosts/pi}/rpc.mjs +144 -26
  176. package/skills/evaluate-behavior/scripts/lib/identity.mjs +82 -0
  177. package/skills/evaluate-behavior/scripts/lib/judge.mjs +688 -0
  178. package/skills/evaluate-behavior/scripts/lib/metrics.mjs +332 -0
  179. package/skills/evaluate-behavior/scripts/lib/model-call.mjs +17 -0
  180. package/skills/evaluate-behavior/scripts/lib/participants.mjs +616 -0
  181. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/process.mjs +22 -0
  182. package/skills/evaluate-behavior/scripts/lib/queue.mjs +54 -0
  183. package/skills/evaluate-behavior/scripts/lib/reference.mjs +343 -0
  184. package/skills/evaluate-behavior/scripts/lib/reuse.mjs +277 -0
  185. package/skills/evaluate-behavior/scripts/lib/review.mjs +933 -0
  186. package/skills/evaluate-behavior/scripts/lib/runner.mjs +732 -0
  187. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/sandbox.mjs +121 -14
  188. package/skills/evaluate-behavior/scripts/lib/scan-shell.mjs +457 -0
  189. package/skills/evaluate-behavior/scripts/lib/scan.mjs +479 -0
  190. package/skills/evaluate-behavior/scripts/lib/seal.mjs +91 -0
  191. package/skills/evaluate-behavior/scripts/lib/shell.mjs +560 -0
  192. package/skills/evaluate-behavior/scripts/lib/source-override.mjs +64 -0
  193. package/skills/evaluate-behavior/scripts/lib/subject-file.mjs +88 -0
  194. package/skills/{evaluate-skill/scripts/lib/pi.mjs → evaluate-behavior/scripts/lib/subject.mjs} +239 -262
  195. package/skills/evaluate-behavior/scripts/lib/task-copy.mjs +124 -0
  196. package/skills/evaluate-behavior/scripts/lib/trials.mjs +524 -0
  197. package/skills/evaluate-behavior/scripts/lib/validity.mjs +68 -0
  198. package/skills/evaluate-behavior/scripts/lib/view-html.mjs +454 -0
  199. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/view.mjs +218 -11
  200. package/skills/evaluate-behavior/scripts/pi-command-tool.mjs +159 -0
  201. package/skills/evaluate-behavior/scripts/pi-container-route.mjs +23 -0
  202. package/skills/evaluate-behavior/scripts/pi-guard.mjs +77 -0
  203. package/skills/evaluate-behavior/scripts/pi-login-refresh.mjs +31 -0
  204. package/skills/evaluate-behavior/scripts/skill-eval.mjs +586 -0
  205. package/skills/execute-work/SKILL.md +96 -72
  206. package/skills/execute-work/references/code-practices.md +27 -49
  207. package/skills/execute-work/references/design.md +271 -0
  208. package/skills/execute-work/references/diagnose.md +117 -0
  209. package/skills/execute-work/references/migration.md +108 -0
  210. package/skills/execute-work/references/simplify.md +65 -0
  211. package/skills/execute-work/scripts/self-review.mjs +422 -0
  212. package/skills/execute-work/scripts/touch-map.mjs +290 -0
  213. package/skills/review-work/SKILL.md +94 -64
  214. package/skills/review-work/references/adjudication.md +94 -0
  215. package/skills/review-work/references/artifact.md +198 -0
  216. package/skills/review-work/references/evals-and-judges.md +66 -0
  217. package/skills/review-work/references/work.md +177 -0
  218. package/skills/review-work/scripts/check-brief.mjs +128 -0
  219. package/skills/review-work/scripts/review-packet.mjs +233 -0
  220. package/skills/setup-freeflow/SKILL.md +69 -16
  221. package/skills/track-work/SKILL.md +135 -151
  222. package/skills/track-work/references/handoff.md +190 -0
  223. package/skills/track-work/references/projects.md +51 -0
  224. package/skills/track-work/references/working-record-format.md +201 -344
  225. package/skills/track-work/scripts/lib/document.mjs +79 -19
  226. package/skills/track-work/scripts/lib/format.mjs +18 -1
  227. package/skills/track-work/scripts/lib/recover.mjs +254 -0
  228. package/skills/track-work/scripts/lib/registry.mjs +656 -0
  229. package/skills/track-work/scripts/lib/search.mjs +40 -0
  230. package/skills/track-work/scripts/lib/store.mjs +53 -21
  231. package/skills/track-work/scripts/lib/transitions.mjs +79 -4
  232. package/skills/track-work/scripts/lib/views.mjs +50 -1
  233. package/skills/track-work/scripts/working-record.mjs +263 -22
  234. package/skills/verify-work/SKILL.md +64 -47
  235. package/skills/verify-work/references/feature-map.md +120 -0
  236. package/skills/verify-work/references/runtime-evidence.md +203 -0
  237. package/skills/verify-work/references/test-design.md +27 -6
  238. package/skills/verify-work/scripts/test-changes.mjs +246 -0
  239. package/skills/write-docs/SKILL.md +171 -0
  240. package/skills/write-docs/references/documentation-shapes.md +184 -0
  241. package/skills/write-docs/references/spec-and-plan-shapes.md +308 -0
  242. package/skills/write-docs/scripts/artifact-check.mjs +148 -0
  243. package/skills/write-docs/scripts/docs-check.mjs +229 -0
  244. package/skills/write-docs/scripts/plan-lint.mjs +123 -0
  245. package/skills/write-skill/SKILL.md +165 -165
  246. package/skills/write-skill/references/activation-and-wording.md +143 -0
  247. package/skills/write-skill/references/placement-and-dependencies.md +154 -0
  248. package/skills/write-skill/scripts/lib/compare.mjs +701 -0
  249. package/skills/write-skill/scripts/lib/similarity.mjs +56 -0
  250. package/skills/write-skill/scripts/lib/skill-author.mjs +197 -3
  251. package/skills/write-skill/scripts/skill-author.mjs +67 -8
  252. package/capabilities/context-virtualization/SKILL.md +0 -103
  253. package/capabilities/conversation-history/SKILL.md +0 -53
  254. package/hooks/tests/check-host-adapters.test.mjs +0 -82
  255. package/hooks/tests/check-runtime-context-hook.sh +0 -212
  256. package/pi-extension/dist/cognitive-routing-v2/projection.js +0 -330
  257. package/pi-extension/dist/cognitive-routing-v2/runtime.js +0 -2181
  258. package/pi-extension/dist/cognitive-routing-v2/tools.js +0 -60
  259. package/pi-extension/dist/context-virtualization/commands.js +0 -89
  260. package/pi-extension/dist/context-virtualization/projector.js +0 -42
  261. package/pi-extension/dist/context-virtualization/runtime.js +0 -378
  262. package/pi-extension/dist/context-virtualization/state.js +0 -57
  263. package/pi-extension/dist/context-virtualization/types.js +0 -10
  264. package/pi-extension/dist/conversation-history/passages.js +0 -66
  265. package/pi-extension/dist/conversation-history/ranking.js +0 -105
  266. package/pi-extension/dist/conversation-history/runtime.js +0 -226
  267. package/pi-extension/dist/conversation-history/search.js +0 -56
  268. package/pi-extension/dist/conversation-history/types.js +0 -1
  269. package/pi-extension/dist/freeflow-context/resolver.js +0 -120
  270. package/pi-extension/dist/freeflow-context/runtime.js +0 -80
  271. package/pi-extension/dist/freeflow-context/source-projector.js +0 -95
  272. package/pi-extension/dist/freeflow-context/tool.js +0 -314
  273. package/pi-extension/dist/freeflow-context/types.js +0 -12
  274. package/pi-extension/dist/freeflow-context/visibility.js +0 -28
  275. package/pi-extension/dist/integrations/mcp-config.js +0 -29
  276. package/pi-extension/dist/runtime/runtime-context.js +0 -754
  277. package/pi-extension/dist/runtime/runtime-identity.js +0 -5
  278. package/pi-extension/dist/session-sources/provenance.js +0 -32
  279. package/pi-extension/dist/settings/settings-ui.js +0 -1360
  280. package/pi-extension/dist/ui/text-component.js +0 -57
  281. package/pi-extension/src/cognitive-routing-v2/budget.ts +0 -42
  282. package/pi-extension/src/cognitive-routing-v2/config.ts +0 -173
  283. package/pi-extension/src/cognitive-routing-v2/projection.ts +0 -375
  284. package/pi-extension/src/cognitive-routing-v2/render.ts +0 -277
  285. package/pi-extension/src/cognitive-routing-v2/runtime.ts +0 -2241
  286. package/pi-extension/src/cognitive-routing-v2/schemas.ts +0 -180
  287. package/pi-extension/src/cognitive-routing-v2/state.ts +0 -839
  288. package/pi-extension/src/cognitive-routing-v2/tools.ts +0 -62
  289. package/pi-extension/src/cognitive-routing-v2/types.ts +0 -254
  290. package/pi-extension/src/context-virtualization/commands.ts +0 -111
  291. package/pi-extension/src/context-virtualization/projector.ts +0 -62
  292. package/pi-extension/src/context-virtualization/runtime.ts +0 -428
  293. package/pi-extension/src/context-virtualization/state.ts +0 -79
  294. package/pi-extension/src/context-virtualization/types.ts +0 -92
  295. package/pi-extension/src/conversation-history/passages.ts +0 -81
  296. package/pi-extension/src/conversation-history/ranking.ts +0 -155
  297. package/pi-extension/src/conversation-history/runtime.ts +0 -250
  298. package/pi-extension/src/conversation-history/search.ts +0 -79
  299. package/pi-extension/src/conversation-history/types.ts +0 -31
  300. package/pi-extension/src/freeflow-context/resolver.ts +0 -139
  301. package/pi-extension/src/freeflow-context/runtime.ts +0 -100
  302. package/pi-extension/src/freeflow-context/source-projector.ts +0 -106
  303. package/pi-extension/src/freeflow-context/tool.ts +0 -366
  304. package/pi-extension/src/freeflow-context/types.ts +0 -70
  305. package/pi-extension/src/freeflow-context/visibility.ts +0 -53
  306. package/pi-extension/src/index.ts +0 -390
  307. package/pi-extension/src/integrations/mcp-config.ts +0 -32
  308. package/pi-extension/src/provider-support/astra/adapter.ts +0 -108
  309. package/pi-extension/src/provider-support/astra/history.ts +0 -145
  310. package/pi-extension/src/provider-support/astra/index.ts +0 -12
  311. package/pi-extension/src/provider-support/astra/session-state.ts +0 -113
  312. package/pi-extension/src/provider-support/index.ts +0 -5
  313. package/pi-extension/src/runtime/request-history.ts +0 -243
  314. package/pi-extension/src/runtime/runtime-context.ts +0 -860
  315. package/pi-extension/src/runtime/runtime-identity.ts +0 -8
  316. package/pi-extension/src/session-sources/events.ts +0 -230
  317. package/pi-extension/src/session-sources/provenance.ts +0 -39
  318. package/pi-extension/src/session-sources/read-only-session.ts +0 -170
  319. package/pi-extension/src/session-sources/sources.ts +0 -334
  320. package/pi-extension/src/settings/settings-tui.ts +0 -501
  321. package/pi-extension/src/settings/settings-ui.ts +0 -1652
  322. package/pi-extension/src/ui/text-component.ts +0 -66
  323. package/pi-extension/tests/cache-reuse/history.test.js +0 -117
  324. package/pi-extension/tests/cache-reuse/native.test.js +0 -91
  325. package/pi-extension/tests/cache-reuse/settings.test.js +0 -211
  326. package/pi-extension/tests/cognitive-routing-v2/communication.test.js +0 -577
  327. package/pi-extension/tests/cognitive-routing-v2/compaction-input.test.js +0 -183
  328. package/pi-extension/tests/cognitive-routing-v2/delegation.test.js +0 -557
  329. package/pi-extension/tests/cognitive-routing-v2/native.test.js +0 -474
  330. package/pi-extension/tests/cognitive-routing-v2/performance.test.js +0 -87
  331. package/pi-extension/tests/cognitive-routing-v2/persistence.test.js +0 -300
  332. package/pi-extension/tests/cognitive-routing-v2/projection.test.js +0 -241
  333. package/pi-extension/tests/cognitive-routing-v2/recovery.test.js +0 -1034
  334. package/pi-extension/tests/cognitive-routing-v2/render.test.js +0 -244
  335. package/pi-extension/tests/cognitive-routing-v2/runtime.test.js +0 -423
  336. package/pi-extension/tests/cognitive-routing-v2/stabilization.test.js +0 -521
  337. package/pi-extension/tests/cognitive-routing-v2/state.test.js +0 -586
  338. package/pi-extension/tests/context-virtualization/extension.test.js +0 -775
  339. package/pi-extension/tests/context-virtualization/projector.test.js +0 -110
  340. package/pi-extension/tests/context-virtualization/runtime.test.js +0 -230
  341. package/pi-extension/tests/conversation-history/runtime.test.js +0 -98
  342. package/pi-extension/tests/conversation-history/search.test.js +0 -97
  343. package/pi-extension/tests/fixtures/pi-host.js +0 -4
  344. package/pi-extension/tests/fixtures/routing-native.js +0 -191
  345. package/pi-extension/tests/integration/mode-free-core.test.js +0 -220
  346. package/pi-extension/tests/integration/pi-extension.test.js +0 -1447
  347. package/pi-extension/tests/integration/prompt-architecture.test.js +0 -447
  348. package/pi-extension/tests/integration/unaffected-regressions.test.js +0 -478
  349. package/pi-extension/tests/provider-support/astra-boundaries.test.js +0 -75
  350. package/pi-extension/tests/provider-support/astra.test.js +0 -306
  351. package/pi-extension/tests/provider-support/cli.test.js +0 -92
  352. package/pi-extension/tests/provider-support/native.test.js +0 -183
  353. package/pi-extension/tests/settings/settings-tui.test.js +0 -243
  354. package/pi-extension/tsconfig.json +0 -16
  355. package/plugin.json +0 -33
  356. package/runtime/prompts/context-virtualization.md +0 -3
  357. package/runtime/prompts/conversation-history.md +0 -3
  358. package/skills/action-selection/SKILL.md +0 -100
  359. package/skills/action-selection/references/trajectory-stalls.md +0 -71
  360. package/skills/bypass/SKILL.md +0 -153
  361. package/skills/commit-work/SKILL.md +0 -145
  362. package/skills/commit-work/references/git-state-edges.md +0 -94
  363. package/skills/commit-work/references/simple-push.md +0 -92
  364. package/skills/commit-work/references/staging-decisions.md +0 -106
  365. package/skills/decision-gate/SKILL.md +0 -106
  366. package/skills/design-for-depth/SKILL.md +0 -117
  367. package/skills/design-for-depth/references/design-pressure-signals.md +0 -182
  368. package/skills/design-for-depth/references/implementation-decisions.md +0 -76
  369. package/skills/design-for-depth/references/interface-design-loop.md +0 -136
  370. package/skills/design-for-depth/references/module-and-dependency-design.md +0 -147
  371. package/skills/design-for-depth/references/software-design-philosophy.md +0 -202
  372. package/skills/design-for-depth/references/state-and-failure-boundaries.md +0 -136
  373. package/skills/diagnose-failure/SKILL.md +0 -125
  374. package/skills/diagnose-failure/references/diagnostic-loop-catalog.md +0 -48
  375. package/skills/diagnose-failure/references/flaky-and-performance-diagnosis.md +0 -51
  376. package/skills/discuss/SKILL.md +0 -116
  377. package/skills/evaluate-skill/SKILL.md +0 -219
  378. package/skills/evaluate-skill/references/evaluation-definition-schema.md +0 -385
  379. package/skills/evaluate-skill/references/evaluation-design.md +0 -112
  380. package/skills/evaluate-skill/references/execution-and-evidence.md +0 -90
  381. package/skills/evaluate-skill/references/review-and-revision.md +0 -92
  382. package/skills/evaluate-skill/scripts/lib/definitions.mjs +0 -407
  383. package/skills/evaluate-skill/scripts/lib/grade-comparison.mjs +0 -60
  384. package/skills/evaluate-skill/scripts/lib/grade.mjs +0 -64
  385. package/skills/evaluate-skill/scripts/lib/runner.mjs +0 -368
  386. package/skills/evaluate-skill/scripts/pi-guard.mjs +0 -164
  387. package/skills/evaluate-skill/scripts/skill-eval.mjs +0 -102
  388. package/skills/execute-work/references/execute-work-edges.md +0 -68
  389. package/skills/finish-branch/SKILL.md +0 -117
  390. package/skills/finish-branch/references/integration-options.md +0 -80
  391. package/skills/handoff/SKILL.md +0 -82
  392. package/skills/handoff/references/handoff-templates.md +0 -150
  393. package/skills/launch-work/SKILL.md +0 -116
  394. package/skills/launch-work/references/launch-readiness.md +0 -85
  395. package/skills/migration-work/SKILL.md +0 -115
  396. package/skills/migration-work/references/migration-lifecycle.md +0 -82
  397. package/skills/release-work/SKILL.md +0 -118
  398. package/skills/release-work/references/release-evidence.md +0 -78
  399. package/skills/review-artifact/SKILL.md +0 -142
  400. package/skills/review-artifact/references/adjudicate-artifact-review.md +0 -101
  401. package/skills/review-artifact/references/independent-artifact-reviewer-contract.md +0 -159
  402. package/skills/review-work/references/adjudicate-work-review.md +0 -97
  403. package/skills/review-work/references/independent-work-reviewer-contract.md +0 -139
  404. package/skills/review-work/references/security-risk-lens.md +0 -69
  405. package/skills/setup-freeflow/references/activation-contract.md +0 -109
  406. package/skills/setup-freeflow/references/host-setup.md +0 -67
  407. package/skills/simplify-code/SKILL.md +0 -85
  408. package/skills/simplify-code/references/simplification-patterns.md +0 -70
  409. package/skills/verify-work/references/browser-runtime-evidence.md +0 -55
  410. package/skills/verify-work/references/integration-evidence.md +0 -47
  411. package/skills/verify-work/references/performance-evidence.md +0 -57
  412. package/skills/workflow/SKILL.md +0 -127
  413. package/skills/workflow/references/domain-skill-composition.md +0 -43
  414. package/skills/write-plan/SKILL.md +0 -92
  415. package/skills/write-plan/references/plan-shapes.md +0 -156
  416. package/skills/write-skill/references/activation-boundaries.md +0 -104
  417. package/skills/write-skill/references/agent-first-instructions.md +0 -121
  418. package/skills/write-skill/references/progressive-disclosure.md +0 -127
  419. package/skills/write-skill/references/skill-dependency-graphs.md +0 -190
  420. package/skills/write-spec/SKILL.md +0 -92
  421. package/skills/write-spec/references/artifact-standards.md +0 -86
  422. package/skills/write-spec/references/decision-records.md +0 -78
  423. package/skills/write-spec/references/spec-shapes.md +0 -143
  424. /package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/budget.js +0 -0
  425. /package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/evidence.mjs +0 -0
  426. /package/skills/{evaluate-skill → evaluate-behavior}/scripts/pi-observer.mjs +0 -0
@@ -1,7 +1,13 @@
1
1
  import { readFile, realpath, stat } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
 
4
- const VARIANTS = ["baseline", "candidate"];
4
+ import { ARM_NAME, comparisonArms, storedArms } from "./arms.mjs";
5
+ import { renderClaim, trialCounts } from "./decision.mjs";
6
+ import { judgedAggregateLines, judgedLines } from "./judge.mjs";
7
+ import { aggregateMetricsLines, runMetricsLines } from "./metrics.mjs";
8
+ import { participantLines } from "./participants.mjs";
9
+ import { readClearances } from "./scan.mjs";
10
+
5
11
  const DEFAULT_SELECTORS = /** @type {{group: string | null, variant: string | null}} */ ({
6
12
  group: null,
7
13
  variant: null,
@@ -20,8 +26,19 @@ class ViewError extends Error {
20
26
  * @param {{root?: string}} [options]
21
27
  */
22
28
 
23
- export async function renderResult(target, selectors = DEFAULT_SELECTORS, { root = process.cwd() } = {}) {
24
- const resultDirectory = await resolveResult(target, root);
29
+ export async function renderResult(
30
+ target,
31
+ selectors = DEFAULT_SELECTORS,
32
+ { root = process.cwd(), results = null } = {},
33
+ ) {
34
+ const resultDirectory = await resolveResult(target, root, results);
35
+ const aggregateFile = path.join(resultDirectory, "aggregate.json");
36
+ if (await stat(aggregateFile).catch(() => null)) {
37
+ if (selectors.group !== null || selectors.variant !== null) {
38
+ throw new ViewError("selectors are not supported for an aggregate; view an individual trial instead");
39
+ }
40
+ return renderAggregate(resultDirectory, await readJson(aggregateFile, "aggregate"));
41
+ }
25
42
  const summary = await readJson(path.join(resultDirectory, "summary.json"), "result summary");
26
43
  let groups = Array.isArray(summary.groups) ? summary.groups : [];
27
44
  if (summary.definitionKind === "group" && selectors.group !== null) {
@@ -35,11 +52,31 @@ export async function renderResult(target, selectors = DEFAULT_SELECTORS, { root
35
52
  : groups.filter((group) => group.position === position);
36
53
  if (groups.length === 0) throw new ViewError(`Unknown group selector: ${selectors.group}`);
37
54
  }
38
- if (selectors.variant !== null && !VARIANTS.includes(selectors.variant)) {
39
- throw new ViewError("variant must be baseline or candidate");
55
+ if (selectors.variant !== null && !ARM_NAME.test(selectors.variant)) {
56
+ throw new ViewError("variant must be an arm name, such as baseline or candidate");
40
57
  }
41
58
 
42
59
  const lines = [`Result ${summary.id} [${summary.state}]`, `Path: ${escapeCell(resultDirectory)}`];
60
+ // This invocation's own spend; in a trial, the budget's total is the whole run's so far.
61
+ if (summary.cost) {
62
+ const unmeasured = summary.cost.unmeasured ? [`unmeasured=${summary.cost.unmeasured}`] : [];
63
+ lines.push(
64
+ compactRow("cost", [
65
+ `spent=${formatNumber(summary.cost.spent)}`,
66
+ `subjects=${summary.cost.subjects}`,
67
+ ...unmeasured,
68
+ ]),
69
+ );
70
+ }
71
+ if (summary.budget) {
72
+ lines.push(
73
+ compactRow("budget", [
74
+ `max-cost=${formatNumber(summary.budget.maxCost)}`,
75
+ `run-total=${formatNumber(summary.budget.runTotal ?? summary.budget.spent)}`,
76
+ `exhausted=${summary.budget.exhausted}`,
77
+ ]),
78
+ );
79
+ }
43
80
  for (const group of groups) {
44
81
  lines.push("", ...(await renderGroup(resultDirectory, group, selectors.variant)));
45
82
  }
@@ -51,11 +88,18 @@ async function renderGroup(resultDirectory, group, selectedVariant) {
51
88
  const definition = await readJson(path.join(groupDirectory, "definition.json"), `definition for ${group.id}`);
52
89
  const gradeFile = path.join(groupDirectory, group.artifacts?.grade ?? "deterministic-grade.json");
53
90
  const grade = await readJson(gradeFile, `grade for ${group.id}`);
54
- const variants = selectedVariant === null ? VARIANTS : [selectedVariant];
91
+ const arms = storedArms(group, definition);
92
+ if (selectedVariant !== null && !arms.includes(selectedVariant)) {
93
+ throw new ViewError(`variant ${selectedVariant} is not an arm of group ${group.id}`);
94
+ }
95
+ const variants = selectedVariant === null ? arms : [selectedVariant];
55
96
  const lines = [`Group ${group.id} [${group.state}] type=${definition.type}`];
56
97
 
57
98
  appendSharedEvidence(lines, definition);
58
99
  appendGradeEvidence(lines, grade, group, definition, selectedVariant);
100
+ await appendAdvisoryReview(lines, groupDirectory, variants);
101
+ lines.push(...(await judgedLines(groupDirectory, variants)));
102
+ lines.push(...(await participantLines(groupDirectory, variants)));
59
103
  for (const variant of variants) {
60
104
  await appendVariantEvidence(lines, resultDirectory, groupDirectory, group.id, variant);
61
105
  }
@@ -122,17 +166,169 @@ function appendGradeEvidence(lines, grade, group, definition, selectedVariant) {
122
166
  if (selectedVariant === null && Array.isArray(grade.comparisons) && grade.comparisons.length > 0) {
123
167
  lines.push("Comparisons:");
124
168
  for (const comparison of grade.comparisons) {
169
+ if (comparison.arms === undefined) {
170
+ lines.push(
171
+ compactRow("comparison", [
172
+ comparison.id,
173
+ comparison.kind,
174
+ comparison.transition,
175
+ `baseline=${comparison.baseline.check}:${comparison.baseline.state}`,
176
+ `candidate=${comparison.candidate.check}:${comparison.candidate.state}`,
177
+ ]),
178
+ );
179
+ continue;
180
+ }
181
+ // Each non-reference arm's transition from the reference, then every arm's check and state.
182
+ const { arms, transitions } = comparisonArms(comparison);
183
+ lines.push(
184
+ compactRow("comparison", [
185
+ comparison.id,
186
+ comparison.kind,
187
+ ...Object.entries(transitions).map(([arm, transition]) => `${arm}:${transition}`),
188
+ ...Object.entries(arms).map(([arm, outcome]) => `${arm}=${outcome?.check}:${outcome?.state}`),
189
+ ]),
190
+ );
191
+ }
192
+ }
193
+ }
194
+
195
+ // Advisory answers stay visually separate from deterministic grades; they are not canonical evidence.
196
+ async function appendAdvisoryReview(lines, groupDirectory, variants) {
197
+ const file = path.join(groupDirectory, "semantic-grade.json");
198
+ if (!(await stat(file).catch(() => null))) return;
199
+ const review = await readJson(file, "advisory review");
200
+ lines.push(`Advisory review [${review.state}] model=${review.model} (not canonical evidence)`);
201
+ for (const [index, answer] of (review.answers ?? []).entries()) {
202
+ lines.push(
203
+ compactRow("review", [
204
+ `Q${index + 1}`,
205
+ ...variants.map((variant) => `${variant}=${answer[variant]}`),
206
+ answer.rationale,
207
+ ]),
208
+ );
209
+ }
210
+ if (review.subject?.familyRelation) lines.push(compactRow("judge", [`family=${review.subject.familyRelation}`]));
211
+ if (review.swap?.agreement) {
212
+ const { agreed, questions } = review.swap.agreement;
213
+ lines.push(compactRow("judge", [`order swap agreed on ${agreed}/${questions}`]));
214
+ const byArm = Object.entries(review.swap.agreement.arms ?? {});
215
+ if (byArm.length > 0) {
216
+ lines.push(
217
+ compactRow("judge", [
218
+ `order swap agreed per arm: ${byArm.map(([arm, counts]) => `${arm}=${counts.agreed}/${counts.questions}`).join(" ")}`,
219
+ ]),
220
+ );
221
+ }
222
+ }
223
+ for (const gap of review.contractGaps ?? []) lines.push(compactRow("judge", [`contract gap: ${gap}`]));
224
+ for (const error of review.errors ?? []) lines.push(compactRow("error", ["review", error]));
225
+ }
226
+
227
+ function renderAggregate(resultDirectory, aggregate) {
228
+ const lines = [
229
+ `Aggregate ${aggregate.id} [${aggregate.state}] trials=${trialCounts(aggregate)}`,
230
+ `Path: ${escapeCell(resultDirectory)}`,
231
+ ];
232
+ if (aggregate.budget) {
233
+ lines.push(
234
+ compactRow("budget", [
235
+ `max-cost=${formatNumber(aggregate.budget.maxCost)}`,
236
+ `spent=${formatNumber(aggregate.budget.spent)}`,
237
+ `exhausted=${aggregate.budget.exhausted}`,
238
+ ]),
239
+ );
240
+ }
241
+ for (const entry of aggregate.held ?? []) {
242
+ lines.push(compactRow("held", [entry.trial, entry.group, entry.arm, `flags=${entry.flags.join(",")}`]));
243
+ }
244
+ for (const trial of aggregate.trials) {
245
+ lines.push(
246
+ compactRow("trial", [
247
+ trial.id,
248
+ trial.state,
249
+ ...(trial.cost === undefined ? [] : [`cost=${formatNumber(trial.cost)}`]),
250
+ ]),
251
+ );
252
+ }
253
+ lines.push(...renderClaim(aggregate));
254
+ for (const group of aggregate.groups) {
255
+ const unreadable = group.unreadableGrades ? ` unreadable-grades=${group.unreadableGrades}` : "";
256
+ const gradeErrors = group.gradeErrors ? ` grade-errors=${group.gradeErrors}` : "";
257
+ lines.push("", `Group ${group.id} trials=${group.trials}${unreadable}${gradeErrors}`);
258
+ for (const [variant, states] of Object.entries(group.runStates ?? {})) {
259
+ const notComplete = Object.entries(states).filter(([state]) => state !== "complete");
260
+ if (notComplete.length > 0) {
261
+ lines.push(
262
+ compactRow("runs", [variant, ...Object.entries(states).map(([state, count]) => `${state}=${count}`)]),
263
+ );
264
+ }
265
+ }
266
+ for (const comparison of group.comparisons) {
267
+ if (comparison.arms !== undefined) {
268
+ appendArmComparison(lines, comparison);
269
+ continue;
270
+ }
125
271
  lines.push(
126
272
  compactRow("comparison", [
127
273
  comparison.id,
128
274
  comparison.kind,
129
- comparison.transition,
130
- `baseline=${comparison.baseline.check}:${comparison.baseline.state}`,
131
- `candidate=${comparison.candidate.check}:${comparison.candidate.state}`,
275
+ `baseline=${passRate(comparison.baseline)}`,
276
+ `candidate=${passRate(comparison.candidate)}`,
277
+ ...Object.entries(comparison.transitions).map(([transition, count]) => `${transition}=${count}`),
132
278
  ]),
133
279
  );
280
+ if (comparison.pairs) {
281
+ const pairs = Object.entries(comparison.pairs).filter(([, count]) => count > 0);
282
+ lines.push(
283
+ compactRow("comparison", [
284
+ comparison.id,
285
+ `pairs: ${pairs.map(([pair, count]) => `${pair}=${count}`).join(" ")}`,
286
+ ]),
287
+ );
288
+ }
289
+ }
290
+ for (const check of group.checks) {
291
+ const counts =
292
+ typeof check.passAll === "boolean"
293
+ ? [
294
+ `pass=${passRate(check)}`,
295
+ `fail=${check.fail}`,
296
+ `unavailable=${check.unavailable}`,
297
+ `pass^${check.trials}=${check.passAll ? "yes" : "no"}`,
298
+ ]
299
+ : [`pass=${passRate(check)}`];
300
+ lines.push(compactRow("check", [check.id, check.variant, check.kind, ...counts]));
134
301
  }
302
+ lines.push(...aggregateMetricsLines(group.metrics));
303
+ lines.push(...judgedAggregateLines(group.judged));
135
304
  }
305
+ return `${lines.join("\n")}\n`;
306
+ }
307
+
308
+ /** An arm-keyed aggregate comparison: every arm's pass rate, then each arm's transitions and pairs against the reference. */
309
+ function appendArmComparison(lines, comparison) {
310
+ lines.push(
311
+ compactRow("comparison", [
312
+ comparison.id,
313
+ comparison.kind,
314
+ ...Object.entries(comparison.arms).map(([arm, counts]) => `${arm}=${passRate(counts)}`),
315
+ ]),
316
+ );
317
+ for (const [arm, versus] of Object.entries(comparison.outcomes ?? {})) {
318
+ const pairs = Object.entries(versus.pairs ?? {}).filter(([, count]) => count > 0);
319
+ lines.push(
320
+ compactRow("comparison", [
321
+ comparison.id,
322
+ `${arm} against ${comparison.reference}`,
323
+ ...Object.entries(versus.transitions ?? {}).map(([transition, count]) => `${transition}=${count}`),
324
+ `pairs: ${pairs.map(([pair, count]) => `${pair}=${count}`).join(" ")}`,
325
+ ]),
326
+ );
327
+ }
328
+ }
329
+
330
+ function passRate(counts) {
331
+ return `${counts.pass}/${counts.pass + counts.fail + counts.unavailable}`;
136
332
  }
137
333
 
138
334
  function selectedGradeErrors(errors, definition, selectedVariant) {
@@ -165,6 +361,12 @@ async function appendVariantEvidence(lines, resultDirectory, groupDirectory, gro
165
361
  lines.push("", `${title(variant)} [${run.state}]`);
166
362
  appendRunEvidence(lines, run);
167
363
  const variantDirectory = path.dirname(runFile);
364
+ // Transcript-scan flags, each with whether a person cleared it and why; an uncleared one holds the run.
365
+ const cleared = new Map((await readClearances(variantDirectory)).map((entry) => [entry.flag, entry.reason]));
366
+ for (const flag of run.postRun?.scan?.flags ?? []) {
367
+ const status = cleared.has(flag.id) ? `cleared: ${cleared.get(flag.id)}` : "not cleared";
368
+ lines.push(compactRow(" flag", [flag.id, flag.detail, status]));
369
+ }
168
370
  const artifacts = [["run", relativeArtifact(resultDirectory, runFile)]];
169
371
  if (typeof run.workspace === "string") {
170
372
  artifacts.push(["workspace", relativeArtifact(resultDirectory, run.workspace)]);
@@ -185,9 +387,13 @@ async function appendVariantEvidence(lines, resultDirectory, groupDirectory, gro
185
387
  );
186
388
  }
187
389
 
188
- async function resolveResult(target, root) {
390
+ /** A result or aggregate directory: an explicit path, or a stored ID under `results` (default `<root>/.skill-eval/runs`). */
391
+ export async function resolveResult(target, root, results = null) {
189
392
  const explicit = path.resolve(root, target);
190
- const stored = path.join(root, ".skill-eval", "runs", target);
393
+ const stored = path.join(
394
+ results === null ? path.join(root, ".skill-eval", "runs") : path.resolve(root, results),
395
+ target,
396
+ );
191
397
  const isPath = path.isAbsolute(target) || target.includes("/") || target.includes("\\") || target.startsWith(".");
192
398
  const candidates = isPath ? [explicit] : [stored, explicit];
193
399
  for (const candidate of candidates) {
@@ -259,6 +465,7 @@ function appendRunEvidence(lines, run) {
259
465
  if (typeof run.usage.cost?.total === "number") usage.push(`cost=${formatNumber(run.usage.cost.total)}`);
260
466
  lines.push(compactRow(" usage", usage));
261
467
  }
468
+ lines.push(...runMetricsLines(run));
262
469
  if (run.process?.assistantError) lines.push(` assistant-error: ${run.process.assistantError}`);
263
470
  if (run.process?.terminationReason) {
264
471
  lines.push(` termination: ${run.process.terminationReason}`);
@@ -0,0 +1,159 @@
1
+ import { spawn } from "node:child_process";
2
+
3
+ import { containerExecArgv, dockerClientEnvironment, parseContainerTarget } from "./lib/container.mjs";
4
+ import { COMMAND_TOOL } from "./lib/definitions.mjs";
5
+ import { LOGIN_VARIABLES } from "./lib/hosts/claude-code/isolation.mjs";
6
+
7
+ const DEFAULT_TIMEOUT_MS = 120 * 1000;
8
+ const OUTPUT_LIMIT_BYTES = 32 * 1024;
9
+ const TERMINATION_GRACE_MS = 2000;
10
+
11
+ function parseCommands(value) {
12
+ const parsed = JSON.parse(value ?? "[]");
13
+ if (!Array.isArray(parsed) || parsed.length === 0) throw new Error("SKILL_EVAL_COMMANDS must declare commands");
14
+ return parsed;
15
+ }
16
+
17
+ // A declared command runs the workspace's own code, so it gets neither the evaluator's control variables nor a
18
+ // pointer to the login: Pi's agent directory, which holds the copied provider login, and any login variable. On the
19
+ // host this keeps the login out of easy reach, not out of reach (the run's network "host"); in a container the
20
+ // command gets none of this environment at all.
21
+ const WITHHELD = new Set(["PI_CODING_AGENT_DIR", ...LOGIN_VARIABLES]);
22
+
23
+ function commandEnvironment() {
24
+ return Object.fromEntries(
25
+ Object.entries(process.env).filter(([key]) => !key.startsWith("SKILL_EVAL_") && !WITHHELD.has(key)),
26
+ );
27
+ }
28
+
29
+ function captureStream(stream) {
30
+ const chunks = [];
31
+ const capture = { bytes: 0, kept: 0, truncated: false };
32
+ stream.on("data", (chunk) => {
33
+ capture.bytes += chunk.length;
34
+ const room = OUTPUT_LIMIT_BYTES - capture.kept;
35
+ if (room <= 0) {
36
+ capture.truncated = true;
37
+ return;
38
+ }
39
+ const kept = chunk.length > room ? chunk.subarray(0, room) : chunk;
40
+ if (kept.length < chunk.length) capture.truncated = true;
41
+ chunks.push(kept);
42
+ capture.kept += kept.length;
43
+ });
44
+ capture.text = () => Buffer.concat(chunks).toString("utf8");
45
+ return capture;
46
+ }
47
+
48
+ function signalGroup(child, signal) {
49
+ try {
50
+ if (process.platform === "win32") child.kill(signal);
51
+ else process.kill(-child.pid, signal);
52
+ } catch {
53
+ // The process group already exited.
54
+ }
55
+ }
56
+
57
+ // Runs one author-declared argv in the workspace, or, in a container environment, through `docker exec` in the
58
+ // subject's container, where bash runs too, so both use the image's toolchain. A nonzero exit or timeout is
59
+ // ordinary evidence, not a tool error.
60
+ function runCommand(command, cwd, signal, container) {
61
+ const timeoutMs = command.timeout_ms ?? DEFAULT_TIMEOUT_MS;
62
+ const argv = container === null ? command.argv : containerExecArgv(container, command.argv);
63
+ return new Promise((resolve, reject) => {
64
+ const child = spawn(argv[0], argv.slice(1), {
65
+ cwd,
66
+ env: container === null ? commandEnvironment() : dockerClientEnvironment(),
67
+ shell: false,
68
+ detached: process.platform !== "win32",
69
+ stdio: ["ignore", "pipe", "pipe"],
70
+ });
71
+ const stdout = captureStream(child.stdout);
72
+ const stderr = captureStream(child.stderr);
73
+ let timedOut = false;
74
+ let forced;
75
+ const stop = () => {
76
+ signalGroup(child, "SIGTERM");
77
+ forced = setTimeout(() => signalGroup(child, "SIGKILL"), TERMINATION_GRACE_MS);
78
+ };
79
+ const timer = setTimeout(() => {
80
+ timedOut = true;
81
+ stop();
82
+ }, timeoutMs);
83
+ const onAbort = () => stop();
84
+ signal?.addEventListener("abort", onAbort, { once: true });
85
+ child.once("error", (error) => {
86
+ clearTimeout(timer);
87
+ clearTimeout(forced);
88
+ signal?.removeEventListener("abort", onAbort);
89
+ reject(error);
90
+ });
91
+ child.once("close", (exitCode, exitSignal) => {
92
+ clearTimeout(timer);
93
+ clearTimeout(forced);
94
+ signal?.removeEventListener("abort", onAbort);
95
+ resolve({ exitCode, signal: exitSignal, timedOut, timeoutMs, stdout, stderr });
96
+ });
97
+ });
98
+ }
99
+
100
+ function renderOutput(label, capture) {
101
+ const note = capture.truncated ? ` (truncated: showing ${capture.kept} of ${capture.bytes} bytes)` : "";
102
+ return `--- ${label}${note} ---\n${capture.text()}`;
103
+ }
104
+
105
+ export default function registerCommandTool(pi) {
106
+ const commands = parseCommands(process.env.SKILL_EVAL_COMMANDS);
107
+ const workspace = process.env.SKILL_EVAL_WRITABLE_ROOT;
108
+ if (!workspace) throw new Error("SKILL_EVAL_WRITABLE_ROOT is required");
109
+ const byId = new Map(commands.map((command) => [command.id, command]));
110
+ // Set by the evaluator only for a container environment; the guard routes bash by the same value.
111
+ const container = parseContainerTarget(process.env.SKILL_EVAL_CONTAINER);
112
+
113
+ pi.registerTool({
114
+ name: COMMAND_TOOL,
115
+ label: "Run command",
116
+ description: `Run one declared command in the workspace. Available commands: ${commands
117
+ .map((command) => `${command.id} (${command.argv.join(" ")})`)
118
+ .join("; ")}.`,
119
+ parameters: {
120
+ type: "object",
121
+ additionalProperties: false,
122
+ required: ["command"],
123
+ properties: {
124
+ command: { type: "string", enum: commands.map((command) => command.id), description: "Declared command ID" },
125
+ },
126
+ },
127
+ executionMode: "sequential",
128
+ async execute(_toolCallId, input, signal) {
129
+ const command = byId.get(input?.command);
130
+ if (!command) throw new Error(`Command is not declared for this evaluation: ${String(input?.command)}`);
131
+ const result = await runCommand(command, workspace, signal, container);
132
+ const status = result.timedOut
133
+ ? `timed out after ${result.timeoutMs} ms`
134
+ : `exit code: ${result.exitCode ?? `signal ${result.signal}`}`;
135
+ return {
136
+ content: [
137
+ {
138
+ type: "text",
139
+ text: [
140
+ `$ ${command.argv.join(" ")}`,
141
+ status,
142
+ renderOutput("stdout", result.stdout),
143
+ renderOutput("stderr", result.stderr),
144
+ ].join("\n"),
145
+ },
146
+ ],
147
+ details: {
148
+ id: command.id,
149
+ argv: command.argv,
150
+ exitCode: result.exitCode,
151
+ signal: result.signal,
152
+ timedOut: result.timedOut,
153
+ stdout: { bytes: result.stdout.bytes, truncated: result.stdout.truncated },
154
+ stderr: { bytes: result.stderr.bytes, truncated: result.stderr.truncated },
155
+ },
156
+ };
157
+ },
158
+ });
159
+ }
@@ -0,0 +1,23 @@
1
+ // Pi's last extension in a subject with a container environment: it moves each shell tool's command (bash, and
2
+ // Freeflow's bash_background and monitor) into the subject's container. The guard (pi-guard.mjs, loaded first) has
3
+ // already decided the call; this runs after every other extension's tool_call handler, so those handlers see the
4
+ // command the model wrote, and only then does it become the docker client command Pi's shell runs. Pi runs every
5
+ // handler in load order and stops only on a refusal, so a call that runs has passed through here. The guard refuses
6
+ // container shell calls when this extension is not loaded.
7
+
8
+ import { CONTAINER_ROUTE, decideToolCall, guardState, SHELL_TOOLS } from "./guard-rules.mjs";
9
+
10
+ export default function registerSkillEvalContainerRoute(pi) {
11
+ const state = guardState(process.env);
12
+ globalThis[CONTAINER_ROUTE] = true;
13
+ pi.on("tool_call", (event, ctx) => {
14
+ if (!SHELL_TOOLS.has(event.toolName)) return undefined;
15
+ const decision = decideToolCall(state, event.toolName, event.input, ctx.cwd, process.env);
16
+ if (decision?.block) return decision;
17
+ if (decision?.command === undefined) {
18
+ return { block: true, reason: `${event.toolName} has no container to run in for this evaluation` };
19
+ }
20
+ event.input.command = decision.command;
21
+ return undefined;
22
+ });
23
+ }
@@ -0,0 +1,77 @@
1
+ import {
2
+ CONTAINER_ROUTE,
3
+ decideToolCall,
4
+ escapeXml,
5
+ guardState,
6
+ loadDeclaredContext,
7
+ renderDeclaredContext,
8
+ } from "./guard-rules.mjs";
9
+
10
+ function buildSubjectSystemPrompt(options, declaredContext) {
11
+ const tools = options.selectedTools ?? [];
12
+ const toolLines = tools.map((tool) => `- ${tool}: ${options.toolSnippets?.[tool] ?? "Declared evaluation tool"}`);
13
+ const lines = [
14
+ "You are an expert coding assistant operating inside pi, a coding agent harness.",
15
+ "Help the user with the task using only the tools and resources listed below.",
16
+ "",
17
+ "Available tools:",
18
+ ...(toolLines.length > 0 ? toolLines : ["(none)"]),
19
+ "",
20
+ "Guidelines:",
21
+ "- Use read to load a skill's SKILL.md when the task matches its description.",
22
+ "- Resolve relative skill resources from the skill directory.",
23
+ "- Be concise in your response.",
24
+ ];
25
+ const skills = (options.skills ?? []).filter((skill) => !skill.disableModelInvocation);
26
+ if (skills.length > 0) {
27
+ lines.push("", "<available_skills>");
28
+ for (const skill of skills) {
29
+ lines.push(
30
+ " <skill>",
31
+ ` <name>${escapeXml(skill.name)}</name>`,
32
+ ` <description>${escapeXml(skill.description)}</description>`,
33
+ ` <location>${escapeXml(skill.filePath)}</location>`,
34
+ " </skill>",
35
+ );
36
+ }
37
+ lines.push("</available_skills>");
38
+ }
39
+ if (declaredContext.length > 0) lines.push("", renderDeclaredContext(declaredContext));
40
+ lines.push(`Current working directory: ${options.cwd}`);
41
+ return lines.join("\n");
42
+ }
43
+
44
+ // "isolated" replaces the host prompt with an evaluator-owned one; "host" keeps the host's own prompt
45
+ // (and anything declared extensions compose onto it) so evidence reflects the production prompt.
46
+ function beforeAgentStartHandler(promptMode, declaredContext) {
47
+ if (promptMode === "isolated") {
48
+ return (event) => ({ systemPrompt: buildSubjectSystemPrompt(event.systemPromptOptions, declaredContext) });
49
+ }
50
+ return (event) =>
51
+ declaredContext.length === 0
52
+ ? undefined
53
+ : { systemPrompt: `${event.systemPrompt}\n\n${renderDeclaredContext(declaredContext)}` };
54
+ }
55
+
56
+ export default function registerSkillEvalGuard(pi) {
57
+ const state = guardState(process.env);
58
+ const declaredContext = loadDeclaredContext(process.env.SKILL_EVAL_CONTEXT_MANIFEST);
59
+ const promptMode = process.env.SKILL_EVAL_PROMPT_MODE || "isolated";
60
+ if (promptMode !== "isolated" && promptMode !== "host") {
61
+ throw new Error(`SKILL_EVAL_PROMPT_MODE must be isolated or host: ${promptMode}`);
62
+ }
63
+
64
+ pi.on("before_agent_start", beforeAgentStartHandler(promptMode, declaredContext));
65
+
66
+ pi.on("tool_call", (event, ctx) => {
67
+ const decision = decideToolCall(state, event.toolName, event.input, ctx.cwd, process.env);
68
+ if (decision?.command === undefined) return decision;
69
+ // A shell tool's command runs in the subject's container. The route extension, loaded after every other one,
70
+ // rewrites it there, so extensions that read the command (Freeflow refuses a trailing `&` in bash) see the one
71
+ // the model wrote. Without the route nothing would move it into the container, so the call is refused.
72
+ if (globalThis[CONTAINER_ROUTE] !== true) {
73
+ return { block: true, reason: "the evaluator's container route is not loaded, so this command cannot run" };
74
+ }
75
+ return undefined;
76
+ });
77
+ }
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Asks the installed Pi to make one provider's stored OAuth login valid for at least the given minutes,
4
+ // refreshing it if needed. Pi does the refresh itself, under its own lock on auth.json, exactly as it does in
5
+ // ordinary use. Usage: pi-login-refresh.mjs <auth.json path> <provider> <minutes>
6
+ // Prints the login's new expiry as epoch milliseconds.
7
+
8
+ import { execFileSync } from "node:child_process";
9
+ import { realpathSync } from "node:fs";
10
+ import path from "node:path";
11
+ import { pathToFileURL } from "node:url";
12
+
13
+ const [authPath, provider, minutes] = process.argv.slice(2);
14
+ if (!authPath || !provider || !/^\d+$/.test(minutes ?? "")) {
15
+ process.stderr.write("usage: pi-login-refresh.mjs <auth.json path> <provider> <minutes>\n");
16
+ process.exit(2);
17
+ }
18
+
19
+ // The installed Pi's package root, found from the `pi` command so the refresh uses the same Pi the runs use.
20
+ const binary = realpathSync(execFileSync("which", ["pi"], { encoding: "utf8" }).trim());
21
+ let packageRoot = path.dirname(binary);
22
+ while (path.basename(packageRoot) !== "pi-coding-agent" && packageRoot !== path.dirname(packageRoot)) {
23
+ packageRoot = path.dirname(packageRoot);
24
+ }
25
+ const { ModelRuntime } = await import(pathToFileURL(path.join(packageRoot, "dist", "index.js")).href);
26
+ const runtime = await ModelRuntime.create({ authPath });
27
+ await runtime.getAuth(provider, { minOAuthValidityMs: Number(minutes) * 60_000 });
28
+
29
+ const { readFileSync } = await import("node:fs");
30
+ const stored = JSON.parse(readFileSync(authPath, "utf8"))[provider];
31
+ process.stdout.write(`${stored?.expires ?? ""}\n`);