@hassangameryt/freeflow 0.8.0 → 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 (290) 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/README.md +96 -149
  7. package/capabilities/cognitive-routing/SKILL.md +21 -129
  8. package/capabilities/cognitive-routing/references/coordinator.md +163 -0
  9. package/capabilities/cognitive-routing/references/worker.md +38 -0
  10. package/capabilities/compaction/SKILL.md +3 -3
  11. package/capabilities/compaction/references/summary-format.md +26 -15
  12. package/capabilities/messaging/SKILL.md +49 -0
  13. package/capabilities/task-memory/SKILL.md +87 -0
  14. package/command-surface.json +6 -54
  15. package/gemini-extension.json +1 -1
  16. package/hooks/claude/hooks.json +13 -3
  17. package/hooks/codex/hooks.json +2 -1
  18. package/hooks/shared/runtime-context.mjs +69 -77
  19. package/package.json +25 -8
  20. package/pi-extension/dist/ask-user/ask.js +108 -0
  21. package/pi-extension/dist/ask-user/form.js +250 -0
  22. package/pi-extension/dist/ask-user/questions.js +66 -0
  23. package/pi-extension/dist/ask-user/tool.js +124 -0
  24. package/pi-extension/dist/cognitive-routing/assembler.js +35 -11
  25. package/pi-extension/dist/cognitive-routing/bootstrap.js +90 -0
  26. package/pi-extension/dist/cognitive-routing/config.js +3 -4
  27. package/pi-extension/dist/cognitive-routing/event-store.js +4 -1
  28. package/pi-extension/dist/cognitive-routing/gate.js +20 -5
  29. package/pi-extension/dist/cognitive-routing/handlers.js +15 -13
  30. package/pi-extension/dist/cognitive-routing/model-control.js +17 -8
  31. package/pi-extension/dist/cognitive-routing/projection.js +23 -6
  32. package/pi-extension/dist/cognitive-routing/provenance.js +3 -1
  33. package/pi-extension/dist/cognitive-routing/render.js +15 -15
  34. package/pi-extension/dist/cognitive-routing/runtime.js +4 -2
  35. package/pi-extension/dist/cognitive-routing/schemas.js +4 -4
  36. package/pi-extension/dist/cognitive-routing/session.js +3 -1
  37. package/pi-extension/dist/cognitive-routing/sources.js +29 -4
  38. package/pi-extension/dist/cognitive-routing/state.js +18 -8
  39. package/pi-extension/dist/cognitive-routing/status.js +4 -3
  40. package/pi-extension/dist/cognitive-routing/tools.js +29 -15
  41. package/pi-extension/dist/cognitive-routing/types.js +10 -1
  42. package/pi-extension/dist/compaction/carry.js +36 -22
  43. package/pi-extension/dist/compaction/config.js +4 -2
  44. package/pi-extension/dist/compaction/controller.js +52 -29
  45. package/pi-extension/dist/compaction/harness.js +19 -3
  46. package/pi-extension/dist/compaction/results.js +14 -13
  47. package/pi-extension/dist/compaction/tool.js +6 -6
  48. package/pi-extension/dist/host/catalog.js +20 -35
  49. package/pi-extension/dist/host/config-validation.js +233 -0
  50. package/pi-extension/dist/host/config.js +78 -91
  51. package/pi-extension/dist/host/inbound.js +142 -0
  52. package/pi-extension/dist/host/projection-tags.js +1 -1
  53. package/pi-extension/dist/host/prompts.js +24 -13
  54. package/pi-extension/dist/host/read-only-session.js +6 -1
  55. package/pi-extension/dist/host/request-history.js +7 -3
  56. package/pi-extension/dist/host/rows.js +25 -0
  57. package/pi-extension/dist/host/runtime-state.js +17 -2
  58. package/pi-extension/dist/host/section-keeper.js +85 -0
  59. package/pi-extension/dist/host/settings/freeflow-command.js +846 -93
  60. package/pi-extension/dist/host/settings/settings-view.js +27 -8
  61. package/pi-extension/dist/host/status.js +19 -5
  62. package/pi-extension/dist/index.js +638 -72
  63. package/pi-extension/dist/messaging/config.js +27 -0
  64. package/pi-extension/dist/messaging/messaging.js +398 -0
  65. package/pi-extension/dist/messaging/registry.js +57 -0
  66. package/pi-extension/dist/messaging/render.js +90 -0
  67. package/pi-extension/dist/messaging/tools.js +109 -0
  68. package/pi-extension/dist/messaging/transport.js +101 -0
  69. package/pi-extension/dist/provider-support/cache/keepalive.js +16 -4
  70. package/pi-extension/dist/task-memory/config.js +49 -0
  71. package/pi-extension/dist/task-memory/registry.js +119 -0
  72. package/pi-extension/dist/task-memory/render.js +107 -0
  73. package/pi-extension/dist/task-memory/runtime.js +994 -0
  74. package/pi-extension/dist/task-memory/tool.js +233 -0
  75. package/pi-extension/dist/tool-execution/apply-patch/tool.js +1 -1
  76. package/pi-extension/dist/tool-execution/background.js +220 -28
  77. package/pi-extension/dist/tool-execution/config.js +14 -3
  78. package/pi-extension/dist/tool-execution/file-tracking.js +24 -4
  79. package/pi-extension/dist/tool-execution/guidance-notices.js +124 -0
  80. package/pi-extension/dist/tool-execution/skill-reads.js +143 -0
  81. package/pi-extension/dist/tool-execution/tools.js +2 -2
  82. package/runtime/prompts/cognitive-routing.md +4 -4
  83. package/runtime/prompts/core.md +24 -14
  84. package/runtime/prompts/interaction-contract.md +7 -4
  85. package/runtime/prompts/tool-execution.md +3 -16
  86. package/runtime/prompts/working-method.md +16 -99
  87. package/skills/deliver-work/SKILL.md +76 -0
  88. package/skills/deliver-work/references/branch-closeout.md +134 -0
  89. package/skills/deliver-work/references/commit.md +83 -0
  90. package/skills/deliver-work/references/launch.md +94 -0
  91. package/skills/deliver-work/references/release.md +85 -0
  92. package/skills/deliver-work/scripts/commit-state.mjs +139 -0
  93. package/skills/deliver-work/scripts/delivery-state.mjs +107 -0
  94. package/skills/deliver-work/scripts/lib/git-state.mjs +178 -0
  95. package/skills/deliver-work/scripts/push-route.mjs +122 -0
  96. package/skills/deliver-work/scripts/release-preflight.mjs +177 -0
  97. package/skills/discuss-work/SKILL.md +148 -0
  98. package/skills/{discuss → discuss-work}/references/discussion-continuity.md +10 -27
  99. package/skills/discuss-work/references/learning-action.md +36 -0
  100. package/skills/discuss-work/scripts/choices.mjs +101 -0
  101. package/skills/discuss-work/scripts/lib/choices.mjs +159 -0
  102. package/skills/evaluate-behavior/SKILL.md +107 -0
  103. package/skills/evaluate-behavior/references/authoring.md +381 -0
  104. package/skills/evaluate-behavior/references/coding-tasks.md +145 -0
  105. package/skills/evaluate-behavior/references/conversations-pipelines-judges.md +177 -0
  106. package/skills/evaluate-behavior/references/design-and-measurement.md +273 -0
  107. package/skills/evaluate-behavior/references/running-and-evidence.md +245 -0
  108. package/skills/evaluate-behavior/scripts/claude-guard.mjs +76 -0
  109. package/skills/evaluate-behavior/scripts/guard-rules.mjs +309 -0
  110. package/skills/evaluate-behavior/scripts/lib/agreement.mjs +90 -0
  111. package/skills/evaluate-behavior/scripts/lib/arms.mjs +55 -0
  112. package/skills/evaluate-behavior/scripts/lib/budget.mjs +87 -0
  113. package/skills/evaluate-behavior/scripts/lib/build-source.mjs +287 -0
  114. package/skills/evaluate-behavior/scripts/lib/clear.mjs +74 -0
  115. package/skills/evaluate-behavior/scripts/lib/container.mjs +395 -0
  116. package/skills/evaluate-behavior/scripts/lib/decision.mjs +418 -0
  117. package/skills/evaluate-behavior/scripts/lib/definitions.mjs +1072 -0
  118. package/skills/evaluate-behavior/scripts/lib/freeflow.mjs +103 -0
  119. package/skills/evaluate-behavior/scripts/lib/grade-command.mjs +591 -0
  120. package/skills/evaluate-behavior/scripts/lib/grade-comparison.mjs +90 -0
  121. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-interaction.mjs +19 -18
  122. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-support.mjs +32 -5
  123. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-workspace.mjs +28 -12
  124. package/skills/evaluate-behavior/scripts/lib/grade.mjs +101 -0
  125. package/skills/evaluate-behavior/scripts/lib/hooks.mjs +98 -0
  126. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/confinement.mjs +196 -0
  127. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/constraints.mjs +111 -0
  128. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/index.mjs +48 -0
  129. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/isolation.mjs +74 -0
  130. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/launch.mjs +123 -0
  131. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/model-call.mjs +73 -0
  132. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/recorder.mjs +178 -0
  133. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/session.mjs +494 -0
  134. package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/skills.mjs +81 -0
  135. package/skills/evaluate-behavior/scripts/lib/hosts/index.mjs +31 -0
  136. package/skills/evaluate-behavior/scripts/lib/hosts/names.mjs +3 -0
  137. package/skills/evaluate-behavior/scripts/lib/hosts/pi/confinement.mjs +173 -0
  138. package/skills/evaluate-behavior/scripts/lib/hosts/pi/host.mjs +148 -0
  139. package/skills/evaluate-behavior/scripts/lib/hosts/pi/index.mjs +70 -0
  140. package/skills/evaluate-behavior/scripts/lib/hosts/pi/isolation.mjs +81 -0
  141. package/skills/evaluate-behavior/scripts/lib/hosts/pi/model-call.mjs +79 -0
  142. package/skills/evaluate-behavior/scripts/lib/hosts/pi/process.mjs +241 -0
  143. package/skills/{evaluate-skill/scripts/lib → evaluate-behavior/scripts/lib/hosts/pi}/rpc.mjs +144 -26
  144. package/skills/evaluate-behavior/scripts/lib/identity.mjs +82 -0
  145. package/skills/evaluate-behavior/scripts/lib/judge.mjs +688 -0
  146. package/skills/evaluate-behavior/scripts/lib/metrics.mjs +332 -0
  147. package/skills/evaluate-behavior/scripts/lib/model-call.mjs +17 -0
  148. package/skills/evaluate-behavior/scripts/lib/participants.mjs +616 -0
  149. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/process.mjs +22 -0
  150. package/skills/evaluate-behavior/scripts/lib/queue.mjs +54 -0
  151. package/skills/evaluate-behavior/scripts/lib/reference.mjs +343 -0
  152. package/skills/evaluate-behavior/scripts/lib/reuse.mjs +277 -0
  153. package/skills/evaluate-behavior/scripts/lib/review.mjs +933 -0
  154. package/skills/evaluate-behavior/scripts/lib/runner.mjs +732 -0
  155. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/sandbox.mjs +119 -14
  156. package/skills/evaluate-behavior/scripts/lib/scan-shell.mjs +457 -0
  157. package/skills/evaluate-behavior/scripts/lib/scan.mjs +479 -0
  158. package/skills/evaluate-behavior/scripts/lib/seal.mjs +91 -0
  159. package/skills/evaluate-behavior/scripts/lib/shell.mjs +560 -0
  160. package/skills/evaluate-behavior/scripts/lib/source-override.mjs +64 -0
  161. package/skills/evaluate-behavior/scripts/lib/subject-file.mjs +88 -0
  162. package/skills/{evaluate-skill/scripts/lib/pi.mjs → evaluate-behavior/scripts/lib/subject.mjs} +235 -265
  163. package/skills/evaluate-behavior/scripts/lib/task-copy.mjs +124 -0
  164. package/skills/evaluate-behavior/scripts/lib/trials.mjs +524 -0
  165. package/skills/evaluate-behavior/scripts/lib/validity.mjs +68 -0
  166. package/skills/evaluate-behavior/scripts/lib/view-html.mjs +454 -0
  167. package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/view.mjs +159 -18
  168. package/skills/{evaluate-skill → evaluate-behavior}/scripts/pi-command-tool.mjs +21 -6
  169. package/skills/evaluate-behavior/scripts/pi-container-route.mjs +23 -0
  170. package/skills/evaluate-behavior/scripts/pi-guard.mjs +77 -0
  171. package/skills/evaluate-behavior/scripts/pi-login-refresh.mjs +31 -0
  172. package/skills/evaluate-behavior/scripts/skill-eval.mjs +586 -0
  173. package/skills/execute-work/SKILL.md +96 -104
  174. package/skills/execute-work/references/code-practices.md +27 -51
  175. package/skills/execute-work/references/design.md +271 -0
  176. package/skills/execute-work/references/diagnose.md +117 -0
  177. package/skills/execute-work/references/migration.md +108 -0
  178. package/skills/execute-work/references/simplify.md +65 -0
  179. package/skills/execute-work/scripts/self-review.mjs +422 -0
  180. package/skills/execute-work/scripts/touch-map.mjs +290 -0
  181. package/skills/review-work/SKILL.md +89 -65
  182. package/skills/review-work/references/adjudication.md +94 -0
  183. package/skills/review-work/references/artifact.md +198 -0
  184. package/skills/review-work/references/evals-and-judges.md +66 -0
  185. package/skills/review-work/references/work.md +177 -0
  186. package/skills/review-work/scripts/check-brief.mjs +128 -0
  187. package/skills/review-work/scripts/review-packet.mjs +233 -0
  188. package/skills/setup-freeflow/SKILL.md +68 -17
  189. package/skills/track-work/SKILL.md +52 -20
  190. package/skills/track-work/references/handoff.md +190 -0
  191. package/skills/track-work/references/projects.md +51 -0
  192. package/skills/track-work/references/working-record-format.md +36 -18
  193. package/skills/track-work/scripts/lib/document.mjs +17 -13
  194. package/skills/track-work/scripts/lib/format.mjs +2 -0
  195. package/skills/track-work/scripts/lib/recover.mjs +254 -0
  196. package/skills/track-work/scripts/lib/registry.mjs +656 -0
  197. package/skills/track-work/scripts/lib/search.mjs +40 -0
  198. package/skills/track-work/scripts/lib/store.mjs +46 -15
  199. package/skills/track-work/scripts/lib/views.mjs +50 -1
  200. package/skills/track-work/scripts/working-record.mjs +232 -13
  201. package/skills/verify-work/SKILL.md +45 -37
  202. package/skills/verify-work/references/feature-map.md +120 -0
  203. package/skills/verify-work/references/runtime-evidence.md +203 -0
  204. package/skills/verify-work/references/test-design.md +25 -6
  205. package/skills/verify-work/scripts/test-changes.mjs +246 -0
  206. package/skills/write-docs/SKILL.md +113 -25
  207. package/skills/write-docs/references/documentation-shapes.md +68 -3
  208. package/skills/write-docs/references/spec-and-plan-shapes.md +308 -0
  209. package/skills/write-docs/scripts/artifact-check.mjs +148 -0
  210. package/skills/write-docs/scripts/docs-check.mjs +96 -6
  211. package/skills/write-docs/scripts/plan-lint.mjs +123 -0
  212. package/skills/write-skill/SKILL.md +92 -52
  213. package/skills/write-skill/references/activation-and-wording.md +143 -0
  214. package/skills/write-skill/references/placement-and-dependencies.md +154 -0
  215. package/skills/write-skill/scripts/lib/compare.mjs +701 -0
  216. package/skills/write-skill/scripts/lib/skill-author.mjs +197 -3
  217. package/skills/write-skill/scripts/skill-author.mjs +51 -8
  218. package/capabilities/cognitive-routing/references/both-mode.md +0 -36
  219. package/capabilities/cognitive-routing/references/executor-mode.md +0 -48
  220. package/capabilities/cognitive-routing/references/helper-mode.md +0 -47
  221. package/plugin.json +0 -33
  222. package/skills/action-selection/SKILL.md +0 -92
  223. package/skills/action-selection/references/trajectory-stalls.md +0 -73
  224. package/skills/bypass/SKILL.md +0 -153
  225. package/skills/commit-work/SKILL.md +0 -93
  226. package/skills/commit-work/references/git-state-edges.md +0 -94
  227. package/skills/commit-work/references/simple-push.md +0 -94
  228. package/skills/commit-work/references/staging-decisions.md +0 -106
  229. package/skills/decision-gate/SKILL.md +0 -87
  230. package/skills/design-for-depth/SKILL.md +0 -108
  231. package/skills/design-for-depth/references/design-pressure-signals.md +0 -84
  232. package/skills/design-for-depth/references/implementation-decisions.md +0 -76
  233. package/skills/design-for-depth/references/interface-design-loop.md +0 -105
  234. package/skills/design-for-depth/references/module-and-dependency-design.md +0 -117
  235. package/skills/design-for-depth/references/state-and-failure-boundaries.md +0 -125
  236. package/skills/diagnose-failure/SKILL.md +0 -140
  237. package/skills/diagnose-failure/references/diagnostic-loop-catalog.md +0 -50
  238. package/skills/diagnose-failure/references/flaky-and-performance-diagnosis.md +0 -51
  239. package/skills/discuss/SKILL.md +0 -140
  240. package/skills/evaluate-skill/SKILL.md +0 -188
  241. package/skills/evaluate-skill/references/evaluation-definition-schema.md +0 -415
  242. package/skills/evaluate-skill/references/evaluation-design.md +0 -112
  243. package/skills/evaluate-skill/references/execution-and-evidence.md +0 -111
  244. package/skills/evaluate-skill/references/review-and-revision.md +0 -94
  245. package/skills/evaluate-skill/scripts/lib/definitions.mjs +0 -448
  246. package/skills/evaluate-skill/scripts/lib/grade-comparison.mjs +0 -60
  247. package/skills/evaluate-skill/scripts/lib/grade.mjs +0 -64
  248. package/skills/evaluate-skill/scripts/lib/review.mjs +0 -196
  249. package/skills/evaluate-skill/scripts/lib/runner.mjs +0 -405
  250. package/skills/evaluate-skill/scripts/lib/trials.mjs +0 -103
  251. package/skills/evaluate-skill/scripts/pi-guard.mjs +0 -181
  252. package/skills/evaluate-skill/scripts/skill-eval.mjs +0 -182
  253. package/skills/execute-work/references/execute-work-edges.md +0 -78
  254. package/skills/finish-branch/SKILL.md +0 -117
  255. package/skills/finish-branch/references/integration-options.md +0 -80
  256. package/skills/handoff/SKILL.md +0 -82
  257. package/skills/handoff/references/handoff-templates.md +0 -150
  258. package/skills/launch-work/SKILL.md +0 -116
  259. package/skills/launch-work/references/launch-readiness.md +0 -85
  260. package/skills/migration-work/SKILL.md +0 -115
  261. package/skills/migration-work/references/migration-lifecycle.md +0 -82
  262. package/skills/release-work/SKILL.md +0 -118
  263. package/skills/release-work/references/release-evidence.md +0 -78
  264. package/skills/review-artifact/SKILL.md +0 -143
  265. package/skills/review-artifact/references/adjudicate-artifact-review.md +0 -101
  266. package/skills/review-artifact/references/independent-artifact-reviewer-contract.md +0 -159
  267. package/skills/review-work/references/adjudicate-work-review.md +0 -97
  268. package/skills/review-work/references/independent-work-reviewer-contract.md +0 -139
  269. package/skills/review-work/references/security-risk-lens.md +0 -67
  270. package/skills/setup-freeflow/references/activation-contract.md +0 -103
  271. package/skills/setup-freeflow/references/host-setup.md +0 -67
  272. package/skills/simplify-code/SKILL.md +0 -85
  273. package/skills/simplify-code/references/simplification-patterns.md +0 -70
  274. package/skills/verify-work/references/browser-runtime-evidence.md +0 -51
  275. package/skills/verify-work/references/integration-evidence.md +0 -49
  276. package/skills/verify-work/references/performance-evidence.md +0 -59
  277. package/skills/workflow/SKILL.md +0 -171
  278. package/skills/workflow/references/domain-skill-composition.md +0 -45
  279. package/skills/write-plan/SKILL.md +0 -92
  280. package/skills/write-plan/references/plan-shapes.md +0 -156
  281. package/skills/write-skill/references/activation-boundaries.md +0 -106
  282. package/skills/write-skill/references/agent-first-instructions.md +0 -133
  283. package/skills/write-skill/references/progressive-disclosure.md +0 -129
  284. package/skills/write-skill/references/skill-dependency-graphs.md +0 -192
  285. package/skills/write-spec/SKILL.md +0 -85
  286. package/skills/write-spec/references/artifact-standards.md +0 -86
  287. package/skills/write-spec/references/decision-records.md +0 -80
  288. package/skills/write-spec/references/spec-shapes.md +0 -143
  289. /package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/evidence.mjs +0 -0
  290. /package/skills/{evaluate-skill → evaluate-behavior}/scripts/pi-observer.mjs +0 -0
@@ -1,448 +0,0 @@
1
- import { readFile, realpath } from "node:fs/promises";
2
- import path from "node:path";
3
-
4
- const ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
5
- const EVALUATION_TYPES = new Set(["description", "body"]);
6
- const VARIANTS = ["baseline", "candidate"];
7
- const EVALUATION_HOSTS = new Set(["pi"]);
8
- const PROMPT_MODES = new Set(["isolated", "host"]);
9
- export const COMMAND_TOOL = "run_command";
10
- const MAX_COMMAND_TIMEOUT_MS = 10 * 60 * 1000;
11
- const RESERVED_ENVIRONMENT_KEYS = new Set([
12
- "PATH",
13
- "HOME",
14
- "PWD",
15
- "OLDPWD",
16
- "SHELL",
17
- "BASH_ENV",
18
- "NODE_OPTIONS",
19
- "NODE_PATH",
20
- "PI_PACKAGE_DIR",
21
- ]);
22
-
23
- export class DefinitionError extends Error {
24
- constructor(code, message, definitionPath = null) {
25
- super(message);
26
- this.name = "DefinitionError";
27
- this.code = code;
28
- this.definitionPath = definitionPath;
29
- }
30
- }
31
-
32
- function fail(code, message, definitionPath) {
33
- throw new DefinitionError(code, message, definitionPath);
34
- }
35
-
36
- function isPlainObject(value) {
37
- return value !== null && typeof value === "object" && !Array.isArray(value);
38
- }
39
-
40
- function requireObject(value, label, definitionPath) {
41
- if (!isPlainObject(value)) fail("invalid-definition", `${label} must be an object`, definitionPath);
42
- return value;
43
- }
44
-
45
- function requireExactKeys(value, required, optional, label, definitionPath) {
46
- const object = requireObject(value, label, definitionPath);
47
- const allowed = new Set([...required, ...optional]);
48
- for (const key of required) {
49
- if (!Object.hasOwn(object, key)) fail("invalid-definition", `${label} is missing ${key}`, definitionPath);
50
- }
51
- for (const key of Object.keys(object)) {
52
- if (!allowed.has(key)) fail("invalid-definition", `${label} contains unsupported field ${key}`, definitionPath);
53
- }
54
- return object;
55
- }
56
-
57
- function requireId(value, label, definitionPath) {
58
- if (typeof value !== "string" || value.length > 64 || !ID.test(value)) {
59
- fail(
60
- "invalid-definition",
61
- `${label} must start with a lowercase letter and use lowercase letters, numbers, or single hyphens up to 64 characters`,
62
- definitionPath,
63
- );
64
- }
65
- return value;
66
- }
67
-
68
- function requireString(value, label, definitionPath) {
69
- if (typeof value !== "string" || value.trim() === "") {
70
- fail("invalid-definition", `${label} must be a non-empty string`, definitionPath);
71
- }
72
- return value;
73
- }
74
-
75
- function requireStringArray(value, label, definitionPath, { paths = false, unique = false } = {}) {
76
- if (!Array.isArray(value)) fail("invalid-definition", `${label} must be an array`, definitionPath);
77
- const seen = new Set();
78
- return value.map((entry, index) => {
79
- const string = requireString(entry, `${label}[${index}]`, definitionPath);
80
- if (paths) requireSafeRelativePath(string, `${label}[${index}]`, definitionPath);
81
- if (unique && seen.has(string)) {
82
- fail("invalid-definition", `${label} contains duplicate ${string}`, definitionPath);
83
- }
84
- seen.add(string);
85
- return string;
86
- });
87
- }
88
-
89
- function requireSafeRelativePath(value, label, definitionPath) {
90
- const string = requireString(value, label, definitionPath);
91
- const normalized = path.normalize(string);
92
- if (path.isAbsolute(string) || normalized === "." || normalized === ".." || normalized.startsWith(`..${path.sep}`)) {
93
- fail("unsafe-path", `${label} must stay inside the definition root`, definitionPath);
94
- }
95
- return string;
96
- }
97
-
98
- function requireSuiteReference(value, label, definitionPath) {
99
- const string = requireString(value, label, definitionPath);
100
- if (path.isAbsolute(string) || path.normalize(string) === ".") {
101
- fail("unsafe-path", `${label} must be relative to the suite file`, definitionPath);
102
- }
103
- return string;
104
- }
105
-
106
- function validateInput(value, definitionPath) {
107
- const input = requireExactKeys(value, [], ["prompt", "turns"], "group.input", definitionPath);
108
- const hasPrompt = Object.hasOwn(input, "prompt");
109
- const hasTurns = Object.hasOwn(input, "turns");
110
- if (hasPrompt === hasTurns) {
111
- fail("invalid-definition", "group.input must contain exactly one of prompt or turns", definitionPath);
112
- }
113
- if (hasPrompt) requireString(input.prompt, "group.input.prompt", definitionPath);
114
- if (hasTurns) {
115
- const turns = requireStringArray(input.turns, "group.input.turns", definitionPath);
116
- if (turns.length === 0) fail("invalid-definition", "group.input.turns must not be empty", definitionPath);
117
- }
118
- }
119
-
120
- function validateSource(value, label, definitionPath) {
121
- const source = requireObject(value, label, definitionPath);
122
- if (source.kind === "working-tree") {
123
- requireExactKeys(source, ["kind"], [], label, definitionPath);
124
- return;
125
- }
126
- if (source.kind === "git") {
127
- requireExactKeys(source, ["kind", "ref"], [], label, definitionPath);
128
- requireString(source.ref, `${label}.ref`, definitionPath);
129
- return;
130
- }
131
- fail("invalid-definition", `${label}.kind must be working-tree or git`, definitionPath);
132
- }
133
-
134
- function validateEnvironment(value, label, definitionPath) {
135
- const environment = requireExactKeys(value, ["source", "skills", "target", "context"], [], label, definitionPath);
136
- validateSource(environment.source, `${label}.source`, definitionPath);
137
- const skills = requireStringArray(environment.skills, `${label}.skills`, definitionPath, { paths: true });
138
- requireStringArray(environment.context, `${label}.context`, definitionPath, { paths: true });
139
- if (
140
- environment.target !== null &&
141
- (!Number.isInteger(environment.target) || environment.target < 0 || environment.target >= skills.length)
142
- ) {
143
- fail("invalid-definition", `${label}.target must be null or an index into skills`, definitionPath);
144
- }
145
- }
146
-
147
- function validateRuntime(value, definitionPath) {
148
- const runtime = requireExactKeys(
149
- value,
150
- ["host", "extensions", "environment", "session"],
151
- ["prompt"],
152
- "group.runtime",
153
- definitionPath,
154
- );
155
- if (!EVALUATION_HOSTS.has(runtime.host)) {
156
- fail("invalid-definition", "group.runtime.host must be pi", definitionPath);
157
- }
158
- if (Object.hasOwn(runtime, "prompt") && !PROMPT_MODES.has(runtime.prompt)) {
159
- fail("invalid-definition", "group.runtime.prompt must be isolated or host", definitionPath);
160
- }
161
- if (!Array.isArray(runtime.extensions)) {
162
- fail("invalid-definition", "group.runtime.extensions must be an array", definitionPath);
163
- }
164
- const bundleIds = new Set();
165
- for (const [index, entry] of runtime.extensions.entries()) {
166
- const bundle = requireExactKeys(
167
- entry,
168
- ["entry", "resources"],
169
- [],
170
- `group.runtime.extensions[${index}]`,
171
- definitionPath,
172
- );
173
- requireSafeRelativePath(bundle.entry, `group.runtime.extensions[${index}].entry`, definitionPath);
174
- const resources = requireStringArray(
175
- bundle.resources,
176
- `group.runtime.extensions[${index}].resources`,
177
- definitionPath,
178
- { paths: true, unique: true },
179
- );
180
- if (resources.length === 0) {
181
- fail("invalid-definition", `group.runtime.extensions[${index}].resources must not be empty`, definitionPath);
182
- }
183
- const bundleId = `${bundle.entry}\u0000${resources.join("\u0000")}`;
184
- if (bundleIds.has(bundleId)) {
185
- fail("invalid-definition", "group.runtime.extensions contains duplicate bundles", definitionPath);
186
- }
187
- bundleIds.add(bundleId);
188
- }
189
- if (typeof runtime.session !== "boolean") {
190
- fail("invalid-definition", "group.runtime.session must be a boolean", definitionPath);
191
- }
192
- const environment = requireExactKeys(
193
- runtime.environment,
194
- ["literal", "inherit"],
195
- [],
196
- "group.runtime.environment",
197
- definitionPath,
198
- );
199
- const literal = requireObject(environment.literal, "group.runtime.environment.literal", definitionPath);
200
- const inherited = requireStringArray(environment.inherit, "group.runtime.environment.inherit", definitionPath, {
201
- unique: true,
202
- });
203
- const literalKeys = new Set(Object.keys(literal).map((key) => key.toUpperCase()));
204
- for (const [key, value] of Object.entries(literal)) {
205
- const normalizedKey = key.toUpperCase();
206
- if (
207
- !/^[A-Za-z_][A-Za-z0-9_]*$/.test(key) ||
208
- isBlockedEnvironmentKey(normalizedKey) ||
209
- /TOKEN|SECRET|PASSWORD|API[_-]?KEY|PRIVATE[_-]?KEY|CREDENTIAL/i.test(key)
210
- ) {
211
- fail(
212
- "invalid-definition",
213
- `group.runtime.environment.literal contains a reserved or secret-like key: ${key}`,
214
- definitionPath,
215
- );
216
- }
217
- if (typeof value !== "string") {
218
- fail("invalid-definition", `group.runtime.environment.literal.${key} must be a string`, definitionPath);
219
- }
220
- }
221
- for (const key of inherited) {
222
- const normalizedKey = key.toUpperCase();
223
- if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key) || isBlockedEnvironmentKey(normalizedKey)) {
224
- fail("invalid-definition", `group.runtime.environment.inherit contains an invalid key: ${key}`, definitionPath);
225
- }
226
- if (literalKeys.has(normalizedKey)) {
227
- fail(
228
- "invalid-definition",
229
- `group.runtime.environment key is declared as both literal and inherited: ${key}`,
230
- definitionPath,
231
- );
232
- }
233
- }
234
- }
235
-
236
- function isBlockedEnvironmentKey(normalizedKey) {
237
- return (
238
- RESERVED_ENVIRONMENT_KEYS.has(normalizedKey) ||
239
- normalizedKey.startsWith("SKILL_EVAL_") ||
240
- normalizedKey.startsWith("PI_") ||
241
- normalizedKey.startsWith("LD_") ||
242
- normalizedKey.startsWith("DYLD_")
243
- );
244
- }
245
-
246
- function validateExpectations(value, definitionPath) {
247
- if (!Array.isArray(value)) fail("invalid-definition", "group.expectations must be an array", definitionPath);
248
- const ids = new Set();
249
- for (const [index, entry] of value.entries()) {
250
- const expectation = requireObject(entry, `group.expectations[${index}]`, definitionPath);
251
- requireId(expectation.id, `group.expectations[${index}].id`, definitionPath);
252
- requireString(expectation.kind, `group.expectations[${index}].kind`, definitionPath);
253
- if (ids.has(expectation.id)) {
254
- fail("invalid-definition", `group.expectations contains duplicate ID ${expectation.id}`, definitionPath);
255
- }
256
- ids.add(expectation.id);
257
- }
258
- }
259
-
260
- // Declared commands are fixed by the definition author; the subject may only choose which one runs.
261
- function validateCommands(group, definitionPath) {
262
- const toolDeclared = group.tools.includes(COMMAND_TOOL);
263
- if (!Object.hasOwn(group, "commands")) {
264
- if (toolDeclared) fail("invalid-definition", `${COMMAND_TOOL} requires declared group.commands`, definitionPath);
265
- return;
266
- }
267
- if (!toolDeclared) fail("invalid-definition", `group.commands requires the ${COMMAND_TOOL} tool`, definitionPath);
268
- if (group.type !== "body")
269
- fail("invalid-definition", "group.commands are supported only by body groups", definitionPath);
270
- if (!Array.isArray(group.commands) || group.commands.length === 0) {
271
- fail("invalid-definition", "group.commands must be a non-empty array", definitionPath);
272
- }
273
- const ids = new Set();
274
- for (const [index, entry] of group.commands.entries()) {
275
- const label = `group.commands[${index}]`;
276
- const command = requireExactKeys(entry, ["id", "argv"], ["timeout_ms"], label, definitionPath);
277
- requireId(command.id, `${label}.id`, definitionPath);
278
- if (ids.has(command.id))
279
- fail("invalid-definition", `group.commands contains duplicate ID ${command.id}`, definitionPath);
280
- ids.add(command.id);
281
- const argv = requireStringArray(command.argv, `${label}.argv`, definitionPath);
282
- if (argv.length === 0) fail("invalid-definition", `${label}.argv must not be empty`, definitionPath);
283
- if (
284
- Object.hasOwn(command, "timeout_ms") &&
285
- (!Number.isInteger(command.timeout_ms) || command.timeout_ms < 1 || command.timeout_ms > MAX_COMMAND_TIMEOUT_MS)
286
- ) {
287
- fail(
288
- "invalid-definition",
289
- `${label}.timeout_ms must be an integer from 1 to ${MAX_COMMAND_TIMEOUT_MS}`,
290
- definitionPath,
291
- );
292
- }
293
- }
294
- }
295
-
296
- function validateModel(value, definitionPath) {
297
- const model = requireExactKeys(value, ["model"], ["thinking"], "group.model", definitionPath);
298
- requireString(model.model, "group.model.model", definitionPath);
299
- if (Object.hasOwn(model, "thinking")) requireString(model.thinking, "group.model.thinking", definitionPath);
300
- }
301
-
302
- function validateGroup(value, definitionPath) {
303
- const group = requireExactKeys(
304
- value,
305
- [
306
- "schema_version",
307
- "kind",
308
- "id",
309
- "type",
310
- "input",
311
- "fixture",
312
- "tools",
313
- "variants",
314
- "expectations",
315
- "review_questions",
316
- ],
317
- ["model", "runtime", "commands"],
318
- "group",
319
- definitionPath,
320
- );
321
- if (group.schema_version !== 1) fail("unsupported-schema", "group.schema_version must be 1", definitionPath);
322
- if (group.kind !== "group") fail("invalid-definition", "group.kind must be group", definitionPath);
323
- requireId(group.id, "group.id", definitionPath);
324
- if (!EVALUATION_TYPES.has(group.type)) {
325
- fail("invalid-definition", "group.type must be description or body", definitionPath);
326
- }
327
- validateInput(group.input, definitionPath);
328
- if (group.fixture !== null) requireSafeRelativePath(group.fixture, "group.fixture", definitionPath);
329
- requireStringArray(group.tools, "group.tools", definitionPath, { unique: true });
330
- validateCommands(group, definitionPath);
331
- if (Object.hasOwn(group, "runtime")) validateRuntime(group.runtime, definitionPath);
332
- const variants = requireExactKeys(group.variants, VARIANTS, [], "group.variants", definitionPath);
333
- for (const variant of VARIANTS) validateEnvironment(variants[variant], `group.variants.${variant}`, definitionPath);
334
- if (variants.candidate.target === null && variants.candidate.skills.length > 0) {
335
- fail(
336
- "invalid-definition",
337
- "group.variants.candidate.target must identify the candidate target skill when candidate skills are declared",
338
- definitionPath,
339
- );
340
- }
341
- validateExpectations(group.expectations, definitionPath);
342
- requireStringArray(group.review_questions, "group.review_questions", definitionPath);
343
- if (Object.hasOwn(group, "model")) validateModel(group.model, definitionPath);
344
- return group;
345
- }
346
-
347
- function validateSuite(value, definitionPath) {
348
- const suite = requireExactKeys(value, ["schema_version", "kind", "id", "groups"], [], "suite", definitionPath);
349
- if (suite.schema_version !== 1) fail("unsupported-schema", "suite.schema_version must be 1", definitionPath);
350
- if (suite.kind !== "suite") fail("invalid-definition", "suite.kind must be suite", definitionPath);
351
- requireId(suite.id, "suite.id", definitionPath);
352
- const groups = requireStringArray(suite.groups, "suite.groups", definitionPath, { unique: true });
353
- for (const [index, reference] of groups.entries()) {
354
- requireSuiteReference(reference, `suite.groups[${index}]`, definitionPath);
355
- }
356
- if (groups.length === 0) fail("invalid-definition", "suite.groups must not be empty", definitionPath);
357
- return suite;
358
- }
359
-
360
- function isContained(root, target) {
361
- const relative = path.relative(root, target);
362
- return relative === "" || (!relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative));
363
- }
364
-
365
- async function readJsonFile(file, root) {
366
- const lexicalFile = path.resolve(file);
367
- if (!isContained(root, lexicalFile)) fail("unsafe-path", `Definition escapes root: ${file}`, lexicalFile);
368
-
369
- let canonicalRoot;
370
- let canonicalFile;
371
- try {
372
- [canonicalRoot, canonicalFile] = await Promise.all([realpath(root), realpath(lexicalFile)]);
373
- } catch {
374
- fail("unreadable-definition", `Cannot resolve definition: ${lexicalFile}`, lexicalFile);
375
- }
376
- if (!isContained(canonicalRoot, canonicalFile)) {
377
- fail("unsafe-path", `Definition symlink escapes root: ${lexicalFile}`, lexicalFile);
378
- }
379
-
380
- let contents;
381
- try {
382
- contents = await readFile(canonicalFile, "utf8");
383
- } catch {
384
- fail("unreadable-definition", `Cannot read definition: ${lexicalFile}`, lexicalFile);
385
- }
386
- try {
387
- return { value: JSON.parse(contents), file: lexicalFile };
388
- } catch {
389
- fail("invalid-json", `Definition is not valid JSON: ${lexicalFile}`, lexicalFile);
390
- }
391
- }
392
-
393
- export async function loadDefinition(file, { root = process.cwd() } = {}) {
394
- const definitionRoot = path.resolve(root);
395
- const loaded = await readJsonFile(file, definitionRoot);
396
- const object = requireObject(loaded.value, "definition", loaded.file);
397
- if (object.kind === "group") return validateGroup(object, loaded.file);
398
- if (object.kind !== "suite") fail("invalid-definition", "definition.kind must be group or suite", loaded.file);
399
-
400
- const suite = validateSuite(object, loaded.file);
401
- const groups = [];
402
- const ids = new Set();
403
- for (const reference of suite.groups) {
404
- const groupFile = path.resolve(path.dirname(loaded.file), reference);
405
- const groupLoaded = await readJsonFile(groupFile, definitionRoot);
406
- const group = validateGroup(groupLoaded.value, groupLoaded.file);
407
- if (ids.has(group.id)) fail("invalid-definition", `suite contains duplicate group ID ${group.id}`, loaded.file);
408
- ids.add(group.id);
409
- groups.push(group);
410
- }
411
- return { ...suite, groups };
412
- }
413
-
414
- function variantSelection(selected) {
415
- return {
416
- baseline: selected === null || selected === "baseline" ? "selected" : "not-selected",
417
- candidate: selected === null || selected === "candidate" ? "selected" : "not-selected",
418
- };
419
- }
420
-
421
- export function selectDefinition(definition, { group = null, variant = null } = {}) {
422
- if (variant !== null && !VARIANTS.includes(variant)) {
423
- fail("invalid-selector", "variant must be baseline or candidate", null);
424
- }
425
- if (definition.kind === "group" && group !== null) {
426
- fail("invalid-selector", "--group cannot be used with a direct group definition", null);
427
- }
428
-
429
- const available = definition.kind === "group" ? [definition] : definition.groups;
430
- let selected = available;
431
- if (group !== null) {
432
- const position = typeof group === "number" || /^\d+$/.test(group) ? Number(group) : null;
433
- selected =
434
- position === null ? available.filter((entry) => entry.id === group) : [available[position - 1]].filter(Boolean);
435
- if (selected.length === 0) fail("unknown-group", `Unknown group selector: ${group}`, null);
436
- }
437
-
438
- return {
439
- kind: "selection",
440
- definitionKind: definition.kind,
441
- id: definition.id,
442
- groups: selected.map((entry) => ({
443
- position: available.indexOf(entry) + 1,
444
- group: entry,
445
- variants: variantSelection(variant),
446
- })),
447
- };
448
- }
@@ -1,60 +0,0 @@
1
- import { isDeepStrictEqual } from "node:util";
2
-
3
- import { hasOwn } from "./grade-support.mjs";
4
-
5
- export function gradeComparisons(expectations, checks) {
6
- /** @type {Map<string, any[]>} */
7
- const grouped = new Map();
8
- const errors = /** @type {any[]} */ ([]);
9
- for (const expectation of expectations) {
10
- if (!hasOwn(expectation, "comparison")) continue;
11
- if (typeof expectation.comparison !== "string" || !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(expectation.comparison)) {
12
- errors.push({ id: expectation.id, reason: "invalid comparison identity" });
13
- continue;
14
- }
15
- const entries = grouped.get(expectation.comparison) ?? [];
16
- entries.push(expectation);
17
- grouped.set(expectation.comparison, entries);
18
- }
19
-
20
- /** @type {Map<string, any>} */
21
- const byCheck = new Map(checks.map((check) => [check.id, check]));
22
- const comparisons = /** @type {any[]} */ ([]);
23
- for (const [id, entries] of grouped) {
24
- const baselineExpectation = entries.find((entry) => entry.variant === "baseline");
25
- const candidateExpectation = entries.find((entry) => entry.variant === "candidate");
26
- if (entries.length !== 2 || !baselineExpectation || !candidateExpectation) {
27
- errors.push({ id, reason: "comparison requires one baseline and one candidate expectation" });
28
- continue;
29
- }
30
- const baseline = byCheck.get(baselineExpectation.id);
31
- const candidate = byCheck.get(candidateExpectation.id);
32
- if (!sameCheck(baseline, candidate)) {
33
- errors.push({ id, reason: "comparison expectations must describe the same deterministic check" });
34
- continue;
35
- }
36
- comparisons.push({
37
- id,
38
- kind: baseline.kind,
39
- baseline: { check: baseline.id, state: baseline.state },
40
- candidate: { check: candidate.id, state: candidate.state },
41
- transition: transition(baseline.state, candidate.state),
42
- });
43
- }
44
- return { comparisons, errors };
45
- }
46
-
47
- function sameCheck(baseline, candidate) {
48
- return (
49
- baseline !== undefined &&
50
- candidate !== undefined &&
51
- baseline.kind === candidate.kind &&
52
- isDeepStrictEqual(baseline.expected, candidate.expected)
53
- );
54
- }
55
-
56
- function transition(baseline, candidate) {
57
- return [baseline, candidate].every((state) => state === "pass" || state === "fail")
58
- ? `${baseline}-to-${candidate}`
59
- : "unavailable";
60
- }
@@ -1,64 +0,0 @@
1
- import { gradeComparisons } from "./grade-comparison.mjs";
2
- import {
3
- gradeContextText,
4
- gradeResourceRead,
5
- gradeResponseText,
6
- gradeSkillRead,
7
- gradeToolCall,
8
- } from "./grade-interaction.mjs";
9
- import { gradeChangedPaths, gradeFileText, gradeJson, gradePath } from "./grade-workspace.mjs";
10
-
11
- const GRADERS = new Map([
12
- ["skill-read", gradeSkillRead],
13
- ["resource-read", gradeResourceRead],
14
- ["path", gradePath],
15
- ["changed-paths", gradeChangedPaths],
16
- ["file-text", gradeFileText],
17
- ["json", gradeJson],
18
- ["response-text", gradeResponseText],
19
- ["context-text", gradeContextText],
20
- ["tool-call", gradeToolCall],
21
- ]);
22
-
23
- /**
24
- * @param {any} group
25
- * @param {any} runs
26
- * @param {any} evidence
27
- * @returns {Promise<any>}
28
- */
29
- export async function gradeDeterministic(group, runs, evidence) {
30
- const checks = /** @type {Array<any>} */ ([]);
31
- const errors = /** @type {Array<any>} */ ([]);
32
-
33
- for (const expectation of group.expectations) {
34
- const grader = GRADERS.get(expectation.kind);
35
- if (!grader) {
36
- errors.push({ id: expectation.id, reason: `unsupported expectation kind: ${expectation.kind}` });
37
- continue;
38
- }
39
- try {
40
- const result = await grader(group, runs, expectation);
41
- if (result.error) errors.push({ id: expectation.id, reason: result.error });
42
- else checks.push(result);
43
- } catch (error) {
44
- errors.push({ id: expectation.id, reason: error instanceof Error ? error.message : String(error) });
45
- }
46
- }
47
-
48
- const compared = gradeComparisons(group.expectations, checks);
49
- errors.push(...compared.errors);
50
- return {
51
- schema_version: 1,
52
- state: reportState(checks, errors),
53
- evidence,
54
- checks,
55
- comparisons: compared.comparisons,
56
- errors,
57
- };
58
- }
59
-
60
- function reportState(checks, errors) {
61
- if (errors.length > 0) return "grade-error";
62
- if (checks.length > 0 && checks.every((check) => check.state === "unavailable")) return "unavailable";
63
- return "complete";
64
- }