@agentswf/lab 0.0.0-stage → 0.3.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 (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -2
  3. package/package.json +46 -4
  4. package/schema/case-check.schema.json +64 -0
  5. package/schema/case-config.schema.json +187 -0
  6. package/schema/case-final.schema.json +48 -0
  7. package/schema/case-good-record.schema.json +70 -0
  8. package/schema/case-grade.schema.json +49 -0
  9. package/schema/case-key.schema.json +117 -0
  10. package/schema/case-label.schema.json +32 -0
  11. package/schema/case-loop-report.schema.json +210 -0
  12. package/schema/case-loop.schema.json +141 -0
  13. package/schema/case-plan.schema.json +117 -0
  14. package/schema/case-previous.schema.json +70 -0
  15. package/schema/case-proposal.schema.json +52 -0
  16. package/schema/case-report.schema.json +892 -0
  17. package/schema/case-run.schema.json +253 -0
  18. package/schema/case-runs.schema.json +125 -0
  19. package/schema/case-score.schema.json +319 -0
  20. package/schema/case-spread.schema.json +110 -0
  21. package/schema/case-trial.schema.json +543 -0
  22. package/schema/case-try.schema.json +113 -0
  23. package/schema/local.json +155 -0
  24. package/src/cli.ts +9 -0
  25. package/src/env/capture.ts +48 -0
  26. package/src/env/compare.ts +201 -0
  27. package/src/env/facts.ts +51 -0
  28. package/src/env/fetch.ts +57 -0
  29. package/src/env/files.ts +228 -0
  30. package/src/env/grade-case.ts +80 -0
  31. package/src/env/grade-helper.ts +352 -0
  32. package/src/env/grader.ts +128 -0
  33. package/src/env/index.ts +727 -0
  34. package/src/env/mock.ts +374 -0
  35. package/src/env/routes.ts +90 -0
  36. package/src/env/sources.ts +19 -0
  37. package/src/env/state.ts +79 -0
  38. package/src/env/trial.ts +182 -0
  39. package/src/format/key.ts +144 -0
  40. package/src/format/loop.ts +178 -0
  41. package/src/format/output.ts +481 -0
  42. package/src/format/records.ts +440 -0
  43. package/src/format/schema-files.ts +64 -0
  44. package/src/format/settings.ts +552 -0
  45. package/src/format/trial-env.ts +64 -0
  46. package/src/format/trial-file.ts +134 -0
  47. package/src/help/awf-lab.txt +29 -0
  48. package/src/help/case.txt +38 -0
  49. package/src/help/config.txt +14 -0
  50. package/src/help/label.txt +12 -0
  51. package/src/help/loop.txt +44 -0
  52. package/src/help/report.txt +20 -0
  53. package/src/help/run.txt +60 -0
  54. package/src/help/runs.txt +10 -0
  55. package/src/help/score.txt +27 -0
  56. package/src/judge/criteria.workflow.ts +237 -0
  57. package/src/judge/version.ts +6 -0
  58. package/src/lab/answer.ts +47 -0
  59. package/src/lab/blame.ts +204 -0
  60. package/src/lab/box.ts +249 -0
  61. package/src/lab/capture-command.ts +298 -0
  62. package/src/lab/capture.ts +234 -0
  63. package/src/lab/check-command.ts +187 -0
  64. package/src/lab/cli.ts +324 -0
  65. package/src/lab/code-graders.ts +108 -0
  66. package/src/lab/columns.ts +138 -0
  67. package/src/lab/command-context.ts +436 -0
  68. package/src/lab/compare.ts +123 -0
  69. package/src/lab/config-command.ts +278 -0
  70. package/src/lab/criteria.ts +69 -0
  71. package/src/lab/dataset.ts +356 -0
  72. package/src/lab/eval-files.ts +185 -0
  73. package/src/lab/expect.ts +79 -0
  74. package/src/lab/facts.ts +59 -0
  75. package/src/lab/families.ts +32 -0
  76. package/src/lab/folders.ts +153 -0
  77. package/src/lab/git.ts +128 -0
  78. package/src/lab/good.ts +224 -0
  79. package/src/lab/grading-stub.txt +8 -0
  80. package/src/lab/grading.ts +332 -0
  81. package/src/lab/inspect.ts +226 -0
  82. package/src/lab/labels.ts +206 -0
  83. package/src/lab/loop-code.ts +255 -0
  84. package/src/lab/loop-command.ts +770 -0
  85. package/src/lab/loop-records.ts +144 -0
  86. package/src/lab/loop.ts +859 -0
  87. package/src/lab/marker.ts +23 -0
  88. package/src/lab/outcome.ts +196 -0
  89. package/src/lab/pooled.ts +106 -0
  90. package/src/lab/project-env.ts +39 -0
  91. package/src/lab/rates.ts +150 -0
  92. package/src/lab/reach.ts +111 -0
  93. package/src/lab/record-copies.ts +202 -0
  94. package/src/lab/refusal.ts +2 -0
  95. package/src/lab/report-command.ts +156 -0
  96. package/src/lab/report.ts +838 -0
  97. package/src/lab/reuse.ts +126 -0
  98. package/src/lab/run-command.ts +853 -0
  99. package/src/lab/run-logs.ts +89 -0
  100. package/src/lab/run-report.ts +259 -0
  101. package/src/lab/runs-command.ts +163 -0
  102. package/src/lab/runs.ts +172 -0
  103. package/src/lab/scaffold.ts +91 -0
  104. package/src/lab/score-command.ts +189 -0
  105. package/src/lab/score.ts +396 -0
  106. package/src/lab/store.ts +383 -0
  107. package/src/lab/text.ts +29 -0
  108. package/src/lab/trial-settings.ts +100 -0
  109. package/src/lab/trial-stub.txt +18 -0
  110. package/src/lab/trial.ts +443 -0
  111. package/src/lab/usage.ts +273 -0
  112. package/src/lab/verdict.ts +161 -0
  113. package/src/lab/workflow-graders.ts +161 -0
  114. package/src/lab/workspace.ts +489 -0
  115. package/src/loop/propose.workflow.ts +84 -0
  116. package/src/shared/allowance.ts +185 -0
  117. package/src/shared/compare/index.ts +3 -0
  118. package/src/shared/compare/paired.ts +397 -0
  119. package/src/shared/compare/stats.ts +139 -0
  120. package/src/shared/compare/types.ts +75 -0
  121. package/src/shared/config.ts +15 -0
  122. package/src/shared/runner.ts +321 -0
  123. package/src/shared/validate.ts +181 -0
  124. package/src/shared/version.ts +41 -0
  125. package/src/write-schemas.ts +10 -0
@@ -0,0 +1,128 @@
1
+ import type { Part } from "../format/records";
2
+ import type { Key } from "../format/settings";
3
+ import { checkVersion } from "../shared/version";
4
+ import { checkGraderName, readsOf, refuseUnknown } from "./files";
5
+ import type { Fact } from "./index";
6
+
7
+ /** What a code grader's export carries, checked by the helper that loads `grading.ts`. */
8
+ export const GRADER_KIND = "awf.case-grader/0";
9
+
10
+ /** What a grader reads: `"facts"`, the facts alone; `"trial"`, also the record and saved files. */
11
+ export type Reads = "facts" | "trial";
12
+
13
+ /** What every grader is given: the case, the facts and the trial's parameters. */
14
+ export type GradeInput = {
15
+ case: {
16
+ name: string;
17
+ /** The built case folder: the dataset's shared files and the case's own, and `input.json`. */
18
+ dir: string;
19
+ // biome-ignore lint/suspicious/noExplicitAny: typed by the reader, as `trial.input` is.
20
+ input: any;
21
+ /** The case's key, without its marker. */
22
+ key: Omit<Key, "marker">;
23
+ /** The case's `key/` folder, the files a grader needs, when it has one. */
24
+ keyDir?: string;
25
+ };
26
+ /** What `grading.ts`'s `facts` read off the trial record. */
27
+ facts: Record<string, Fact>;
28
+ /** The trial's parameters. */
29
+ params: Record<string, string>;
30
+ };
31
+
32
+ /** What a grader with `reads: "trial"` is given besides: the record's values and the saved files. */
33
+ export type TrialInput<R = unknown> = {
34
+ /**
35
+ * The workflow's whole result. Typed as `R`: a case that stops at `stopAfterStage`
36
+ * gives `null`, and its grader says so itself.
37
+ */
38
+ result: R;
39
+ /** The stages' values, by name. */
40
+ stages: Record<string, unknown>;
41
+ /**
42
+ * The trial's working folder, as the workflow left it; null under `score`, which grades a kept
43
+ * trial: a grader that needs one rebuilds it from the case.
44
+ */
45
+ scratch: string | null;
46
+ /** Where the files `evidence` named were saved from the scratch folder. */
47
+ kept: string;
48
+ };
49
+
50
+ /** A count out of a total, or a plain value; pooled per column in the report. */
51
+ export type GradeNumber = { count: number; of: number } | { value: number };
52
+
53
+ export type Grade = {
54
+ verdict?: "passed" | "failed" | "undecided";
55
+ numbers?: Record<string, GradeNumber>;
56
+ /** Why, each about a field, a criterion or a part of the result. */
57
+ reasons?: { about: string; text: string }[];
58
+ /** One per thing judged, such as a criterion or a finding, with its verdict or label and votes. */
59
+ parts?: Part[];
60
+ /** The grader doesn't apply to this case, and why; given with no verdict and no numbers. */
61
+ notApplies?: string;
62
+ };
63
+
64
+ export type CodeGrader = {
65
+ readonly kind: typeof GRADER_KIND;
66
+ readonly name: string;
67
+ readonly version: string;
68
+ readonly reads: Reads;
69
+ readonly manual: boolean;
70
+ grade(input: GradeInput & Partial<TrialInput>): Grade | Promise<Grade>;
71
+ };
72
+
73
+ type GraderOptions = {
74
+ /** How `score --grader` and the report name it. */
75
+ name: string;
76
+ /**
77
+ * Semver, required: bump its major or minor, or give it a pre-release tag, when it grades
78
+ * differently, so `score` grades again; a patch or build part says it grades the same.
79
+ */
80
+ version: string;
81
+ /** Run only by `score --grader`; never decides a verdict. */
82
+ manual?: boolean;
83
+ };
84
+
85
+ /**
86
+ * A code grader, listed in `grading.ts`'s `graders`: a rule that holds for every case. It runs
87
+ * in the list's order after `expect`, in a process of its own in your checkout. `reads: "facts"`
88
+ * gives it the facts `grading.ts`'s `facts` read; `reads: "trial"` also the result, the stages'
89
+ * values and the files `evidence` saved.
90
+ *
91
+ * `version`, semver, is stored on every grade: a grade is kept while its major, minor and
92
+ * pre-release tag stay the same.
93
+ */
94
+ export function defineGrader(
95
+ spec: GraderOptions & {
96
+ reads: "facts";
97
+ grade(input: GradeInput): Grade | Promise<Grade>;
98
+ },
99
+ ): CodeGrader;
100
+ export function defineGrader<R = unknown>(
101
+ spec: GraderOptions & {
102
+ reads: "trial";
103
+ grade(input: GradeInput & TrialInput<R>): Grade | Promise<Grade>;
104
+ },
105
+ ): CodeGrader;
106
+ export function defineGrader(
107
+ spec: GraderOptions & {
108
+ reads: Reads;
109
+ // biome-ignore lint/suspicious/noExplicitAny: either overload's input.
110
+ grade(input: any): Grade | Promise<Grade>;
111
+ },
112
+ ): CodeGrader {
113
+ refuseUnknown("defineGrader", spec, ["name", "version", "reads", "manual", "grade"]);
114
+ const name = checkGraderName("defineGrader", spec.name);
115
+ const version = spec.version;
116
+ const bad = checkVersion(version);
117
+ if (bad) throw new Error(`defineGrader ${name}: ${bad}`);
118
+ if (typeof spec.grade !== "function")
119
+ throw new Error(`defineGrader ${name}: grade is a function`);
120
+ return {
121
+ kind: GRADER_KIND,
122
+ name,
123
+ version,
124
+ reads: readsOf(`defineGrader ${name}`, spec.reads),
125
+ manual: spec.manual === true,
126
+ grade: spec.grade,
127
+ };
128
+ }