@namzu/sdk 62.13.0 → 62.15.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 (192) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/agents/file-definitions.d.ts +7 -0
  3. package/dist/agents/file-definitions.d.ts.map +1 -1
  4. package/dist/agents/file-definitions.js +20 -0
  5. package/dist/agents/file-definitions.js.map +1 -1
  6. package/dist/agents/index.d.ts +1 -1
  7. package/dist/agents/index.d.ts.map +1 -1
  8. package/dist/agents/index.js +1 -1
  9. package/dist/agents/index.js.map +1 -1
  10. package/dist/bridge/acp/server.d.ts +8 -1
  11. package/dist/bridge/acp/server.d.ts.map +1 -1
  12. package/dist/bridge/acp/server.js +12 -0
  13. package/dist/bridge/acp/server.js.map +1 -1
  14. package/dist/connector/mcp/stdio.d.ts.map +1 -1
  15. package/dist/connector/mcp/stdio.js +3 -0
  16. package/dist/connector/mcp/stdio.js.map +1 -1
  17. package/dist/constants/data-epoch.d.ts +18 -0
  18. package/dist/constants/data-epoch.d.ts.map +1 -0
  19. package/dist/constants/data-epoch.js +18 -0
  20. package/dist/constants/data-epoch.js.map +1 -0
  21. package/dist/constants/index.d.ts +1 -0
  22. package/dist/constants/index.d.ts.map +1 -1
  23. package/dist/constants/index.js +1 -0
  24. package/dist/constants/index.js.map +1 -1
  25. package/dist/constants/telemetry/index.d.ts +12 -0
  26. package/dist/constants/telemetry/index.d.ts.map +1 -1
  27. package/dist/constants/telemetry/index.js +12 -0
  28. package/dist/constants/telemetry/index.js.map +1 -1
  29. package/dist/eval/compare.d.ts +54 -0
  30. package/dist/eval/compare.d.ts.map +1 -1
  31. package/dist/eval/compare.js +146 -1
  32. package/dist/eval/compare.js.map +1 -1
  33. package/dist/eval/experiment.d.ts.map +1 -1
  34. package/dist/eval/experiment.js +46 -6
  35. package/dist/eval/experiment.js.map +1 -1
  36. package/dist/eval/index.d.ts +6 -2
  37. package/dist/eval/index.d.ts.map +1 -1
  38. package/dist/eval/index.js +3 -1
  39. package/dist/eval/index.js.map +1 -1
  40. package/dist/eval/report-stats.d.ts +6 -0
  41. package/dist/eval/report-stats.d.ts.map +1 -1
  42. package/dist/eval/report-stats.js +10 -0
  43. package/dist/eval/report-stats.js.map +1 -1
  44. package/dist/eval/run-options.d.ts +25 -0
  45. package/dist/eval/run-options.d.ts.map +1 -1
  46. package/dist/eval/run-options.js +36 -0
  47. package/dist/eval/run-options.js.map +1 -1
  48. package/dist/eval/run-summary.d.ts +8 -0
  49. package/dist/eval/run-summary.d.ts.map +1 -1
  50. package/dist/eval/run-summary.js +13 -3
  51. package/dist/eval/run-summary.js.map +1 -1
  52. package/dist/eval/settings.d.ts +74 -0
  53. package/dist/eval/settings.d.ts.map +1 -0
  54. package/dist/eval/settings.js +161 -0
  55. package/dist/eval/settings.js.map +1 -0
  56. package/dist/eval/split.d.ts +48 -0
  57. package/dist/eval/split.d.ts.map +1 -0
  58. package/dist/eval/split.js +41 -0
  59. package/dist/eval/split.js.map +1 -0
  60. package/dist/eval/types.d.ts +12 -0
  61. package/dist/eval/types.d.ts.map +1 -1
  62. package/dist/execution/local.d.ts.map +1 -1
  63. package/dist/execution/local.js +2 -1
  64. package/dist/execution/local.js.map +1 -1
  65. package/dist/peers/envelope.d.ts +11 -0
  66. package/dist/peers/envelope.d.ts.map +1 -1
  67. package/dist/peers/envelope.js +29 -0
  68. package/dist/peers/envelope.js.map +1 -1
  69. package/dist/peers/index.d.ts +3 -3
  70. package/dist/peers/index.d.ts.map +1 -1
  71. package/dist/peers/index.js +2 -2
  72. package/dist/peers/index.js.map +1 -1
  73. package/dist/peers/protocol.d.ts +26 -0
  74. package/dist/peers/protocol.d.ts.map +1 -1
  75. package/dist/peers/protocol.js +22 -2
  76. package/dist/peers/protocol.js.map +1 -1
  77. package/dist/peers/record.d.ts +2 -0
  78. package/dist/peers/record.d.ts.map +1 -1
  79. package/dist/plugin/index.d.ts +1 -1
  80. package/dist/plugin/index.d.ts.map +1 -1
  81. package/dist/plugin/index.js +1 -1
  82. package/dist/plugin/index.js.map +1 -1
  83. package/dist/plugin/loader.d.ts +11 -0
  84. package/dist/plugin/loader.d.ts.map +1 -1
  85. package/dist/plugin/loader.js +15 -2
  86. package/dist/plugin/loader.js.map +1 -1
  87. package/dist/plugin/shell-hook.d.ts.map +1 -1
  88. package/dist/plugin/shell-hook.js +2 -1
  89. package/dist/plugin/shell-hook.js.map +1 -1
  90. package/dist/process/session-child.d.ts +21 -0
  91. package/dist/process/session-child.d.ts.map +1 -0
  92. package/dist/process/session-child.js +32 -0
  93. package/dist/process/session-child.js.map +1 -0
  94. package/dist/public-runtime.d.ts +8 -6
  95. package/dist/public-runtime.d.ts.map +1 -1
  96. package/dist/public-runtime.js +9 -5
  97. package/dist/public-runtime.js.map +1 -1
  98. package/dist/public-types.d.ts +1 -1
  99. package/dist/public-types.d.ts.map +1 -1
  100. package/dist/runtime/query/cancelled-before-start.d.ts.map +1 -1
  101. package/dist/runtime/query/cancelled-before-start.js +2 -0
  102. package/dist/runtime/query/cancelled-before-start.js.map +1 -1
  103. package/dist/runtime/query/index.d.ts.map +1 -1
  104. package/dist/runtime/query/index.js +2 -0
  105. package/dist/runtime/query/index.js.map +1 -1
  106. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  107. package/dist/runtime/query/iteration/stream-turn.js +5 -0
  108. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  109. package/dist/runtime/query/result.d.ts.map +1 -1
  110. package/dist/runtime/query/result.js +2 -0
  111. package/dist/runtime/query/result.js.map +1 -1
  112. package/dist/runtime/system-events.d.ts +3 -3
  113. package/dist/runtime/system-events.d.ts.map +1 -1
  114. package/dist/runtime/system-events.js +2 -1
  115. package/dist/runtime/system-events.js.map +1 -1
  116. package/dist/sandbox/provider/local.d.ts +1 -0
  117. package/dist/sandbox/provider/local.d.ts.map +1 -1
  118. package/dist/sandbox/provider/local.js +5 -2
  119. package/dist/sandbox/provider/local.js.map +1 -1
  120. package/dist/sandbox/terminal.d.ts.map +1 -1
  121. package/dist/sandbox/terminal.js +2 -1
  122. package/dist/sandbox/terminal.js.map +1 -1
  123. package/dist/skills/index.d.ts +1 -1
  124. package/dist/skills/index.d.ts.map +1 -1
  125. package/dist/skills/index.js +1 -1
  126. package/dist/skills/index.js.map +1 -1
  127. package/dist/skills/loader.d.ts +15 -1
  128. package/dist/skills/loader.d.ts.map +1 -1
  129. package/dist/skills/loader.js +17 -3
  130. package/dist/skills/loader.js.map +1 -1
  131. package/dist/telemetry/genai.d.ts +98 -0
  132. package/dist/telemetry/genai.d.ts.map +1 -0
  133. package/dist/telemetry/genai.js +189 -0
  134. package/dist/telemetry/genai.js.map +1 -0
  135. package/dist/telemetry/runtime-accessors.d.ts +5 -0
  136. package/dist/telemetry/runtime-accessors.d.ts.map +1 -1
  137. package/dist/telemetry/runtime-accessors.js +11 -1
  138. package/dist/telemetry/runtime-accessors.js.map +1 -1
  139. package/dist/tools/command-shell.d.ts.map +1 -1
  140. package/dist/tools/command-shell.js +7 -1
  141. package/dist/tools/command-shell.js.map +1 -1
  142. package/dist/toolsets/manager.d.ts.map +1 -1
  143. package/dist/toolsets/manager.js +12 -0
  144. package/dist/toolsets/manager.js.map +1 -1
  145. package/dist/types/acp/index.d.ts +18 -0
  146. package/dist/types/acp/index.d.ts.map +1 -1
  147. package/dist/types/message/index.d.ts +1 -1
  148. package/dist/types/message/index.d.ts.map +1 -1
  149. package/dist/types/message/index.js +1 -0
  150. package/dist/types/message/index.js.map +1 -1
  151. package/package.json +1 -1
  152. package/src/agents/file-definitions.ts +21 -0
  153. package/src/agents/index.ts +1 -0
  154. package/src/bridge/acp/server.ts +20 -0
  155. package/src/connector/mcp/stdio.ts +3 -0
  156. package/src/constants/data-epoch.ts +17 -0
  157. package/src/constants/index.ts +1 -0
  158. package/src/constants/telemetry/index.ts +13 -0
  159. package/src/eval/compare.ts +245 -2
  160. package/src/eval/experiment.ts +58 -4
  161. package/src/eval/index.ts +32 -1
  162. package/src/eval/report-stats.ts +11 -0
  163. package/src/eval/run-options.ts +51 -0
  164. package/src/eval/run-summary.ts +19 -1
  165. package/src/eval/settings.ts +225 -0
  166. package/src/eval/split.ts +83 -0
  167. package/src/eval/types.ts +12 -0
  168. package/src/execution/local.ts +2 -1
  169. package/src/peers/envelope.ts +36 -0
  170. package/src/peers/index.ts +3 -1
  171. package/src/peers/protocol.ts +24 -2
  172. package/src/plugin/index.ts +7 -1
  173. package/src/plugin/loader.ts +16 -2
  174. package/src/plugin/shell-hook.ts +2 -1
  175. package/src/process/session-child.ts +38 -0
  176. package/src/public-runtime.ts +38 -0
  177. package/src/public-types.ts +1 -0
  178. package/src/runtime/query/cancelled-before-start.ts +2 -0
  179. package/src/runtime/query/index.ts +2 -0
  180. package/src/runtime/query/iteration/stream-turn.ts +10 -0
  181. package/src/runtime/query/result.ts +2 -0
  182. package/src/runtime/system-events.ts +2 -1
  183. package/src/sandbox/provider/local.ts +5 -1
  184. package/src/sandbox/terminal.ts +3 -1
  185. package/src/skills/index.ts +1 -0
  186. package/src/skills/loader.ts +21 -3
  187. package/src/telemetry/genai.ts +202 -0
  188. package/src/telemetry/runtime-accessors.ts +11 -1
  189. package/src/tools/command-shell.ts +7 -1
  190. package/src/toolsets/manager.ts +22 -0
  191. package/src/types/acp/index.ts +20 -0
  192. package/src/types/message/index.ts +1 -0
@@ -1,6 +1,7 @@
1
1
  import { EvalUsageError, validateSeed } from './bootstrap.js'
2
2
  import { type SuiteFacts, buildDisclosure, describeDisclosure } from './disclosure.js'
3
3
  import {
4
+ clarifyDeclared,
4
5
  describeIntervals,
5
6
  describeSplits,
6
7
  duplicateMessage,
@@ -9,6 +10,15 @@ import {
9
10
  statsOver,
10
11
  } from './report-stats.js'
11
12
  import { currentEvalRunOptions } from './run-options.js'
13
+ import { defaultSettingsSnapshot } from './settings.js'
14
+ import {
15
+ HELD_OUT_FRACTION,
16
+ TASK_SPLIT_SEED,
17
+ assignSplit,
18
+ taskId,
19
+ validateSplitFilter,
20
+ } from './split.js'
21
+ import type { ReportTaskSplit } from './split.js'
12
22
  import type {
13
23
  CaseResult,
14
24
  CaseStatus,
@@ -106,8 +116,28 @@ export async function runExperiment<TInput>(
106
116
  const alike = duplicateName(config.cases.map((c) => c.name))
107
117
  if (alike !== undefined) throw new Error(duplicateMessage(config.name, alike))
108
118
 
119
+ // Which tasks run: every one, or the half assigned to one split. The
120
+ // assignment is a function of the task's identity, so it does not move.
121
+ const requested = validateSplitFilter(options.split)
122
+ const assigned = config.cases.map((c) => ({
123
+ evalCase: c,
124
+ ...assignSplit(config.name, c.name, c.split),
125
+ }))
126
+ const chosen = assigned.filter((t) => requested === 'all' || t.split === requested)
127
+ const cases = chosen.map((t) => t.evalCase)
128
+ const taskSplit: ReportTaskSplit = {
129
+ requested,
130
+ seed: TASK_SPLIT_SEED,
131
+ heldOutFraction: HELD_OUT_FRACTION,
132
+ tasks: chosen.map((t) => ({
133
+ id: taskId(config.name, t.evalCase.name),
134
+ split: t.split,
135
+ declared: t.declared,
136
+ })),
137
+ }
138
+
109
139
  // Case-major, so a case's repeats sit together in the report.
110
- const total = config.cases.length * repeats
140
+ const total = cases.length * repeats
111
141
  const results: CaseResult[] = new Array(total)
112
142
  let cursor = 0
113
143
 
@@ -115,7 +145,7 @@ export async function runExperiment<TInput>(
115
145
  for (;;) {
116
146
  const index = cursor++
117
147
  if (index >= total) return
118
- const evalCase = config.cases[Math.floor(index / repeats)] as EvalCase<TInput>
148
+ const evalCase = cases[Math.floor(index / repeats)] as EvalCase<TInput>
119
149
 
120
150
  const result = await evaluateCase(config, evalCase, threshold, timeoutMs)
121
151
  result.repeat = (index % repeats) + 1
@@ -159,10 +189,16 @@ export async function runExperiment<TInput>(
159
189
  splits: stats.splits,
160
190
  disclosure: buildDisclosure(
161
191
  config.disclosure,
162
- { cases: config.cases.length, repeats, seed },
192
+ { cases: cases.length, repeats, seed },
163
193
  options,
164
194
  new Date().toISOString(),
165
195
  ),
196
+ settings: {
197
+ ...(options.settings ?? defaultSettingsSnapshot()),
198
+ read: options.settingsUse?.read ?? false,
199
+ readKeys: [...(options.settingsUse?.keys ?? [])].sort(),
200
+ },
201
+ taskSplit,
166
202
  }
167
203
  }
168
204
 
@@ -468,9 +504,27 @@ export function formatReport(report: ExperimentReport): string {
468
504
  }
469
505
  }
470
506
  if (report.splits) {
471
- for (const line of describeSplits(report.splits)) lines.push(` ${line}`)
507
+ for (const line of describeSplits(report.splits)) {
508
+ // The task split is the held-out one: the line about cases a suite
509
+ // declared as developed against would contradict the run's own header.
510
+ if (report.taskSplit?.requested === 'held-out' && line.startsWith('no held-out cases'))
511
+ continue
512
+ lines.push(` ${report.taskSplit ? clarifyDeclared(line) : line}`)
513
+ }
472
514
  }
473
515
  if (report.disclosure) lines.push(` ${describeDisclosure(report.disclosure)}`)
516
+ if (report.settings) {
517
+ const r = report.settings
518
+ lines.push(
519
+ ` settings: "${r.name}", sha256 ${r.digest.slice(0, 12)}${r.read || Object.keys(r.values).length === 0 ? '' : ' (this suite does not read them)'}`,
520
+ )
521
+ }
522
+ if (report.taskSplit) {
523
+ const t = report.taskSplit
524
+ lines.push(
525
+ ` split: ${t.requested}, ${t.tasks.length} task${t.tasks.length === 1 ? '' : 's'} ran`,
526
+ )
527
+ }
474
528
  lines.push('')
475
529
 
476
530
  // Surfaced above the failures, because an inconclusive case means the
package/src/eval/index.ts CHANGED
@@ -52,7 +52,33 @@ export type {
52
52
  SuiteFacts,
53
53
  } from './disclosure.js'
54
54
  export { sdkVersion } from './disclosure.js'
55
- export { currentEvalRunOptions, withEvalRunOptions } from './run-options.js'
55
+ export {
56
+ currentEvalRunOptions,
57
+ currentEvalSettings,
58
+ evalSetting,
59
+ withEvalRunOptions,
60
+ } from './run-options.js'
61
+ export {
62
+ DEFAULT_SETTINGS_NAME,
63
+ SETTINGS_DIGEST_ALGORITHM,
64
+ buildSettingsSnapshot,
65
+ canonicalJson,
66
+ defaultSettingsSnapshot,
67
+ diffSettings,
68
+ findSecretIn,
69
+ validateSettingsName,
70
+ } from './settings.js'
71
+ export type { ReportSettings, SettingDifference, SettingsSnapshot } from './settings.js'
72
+ export {
73
+ HELD_OUT_FRACTION,
74
+ SPLIT_FILTERS,
75
+ TASK_SPLIT_SEED,
76
+ assignSplit,
77
+ hashedSplit,
78
+ taskId,
79
+ validateSplitFilter,
80
+ } from './split.js'
81
+ export type { ReportTaskSplit, SplitFilter, TaskSplit } from './split.js'
56
82
  export type { EvalRunOptions } from './run-options.js'
57
83
  export { formatRunSummary, summarizeRun } from './run-summary.js'
58
84
  export type { RunDisclosure, RunSummary } from './run-summary.js'
@@ -67,7 +93,12 @@ export type {
67
93
  EvalComparison,
68
94
  Flips,
69
95
  LoadedReportFile,
96
+ LoadedSettings,
70
97
  LoadedSuite,
98
+ SettingsComparison,
99
+ SideSplit,
100
+ SnapshotRef,
101
+ WithheldReason,
71
102
  SideNumbers,
72
103
  } from './compare.js'
73
104
  export { describeUncertainty, uncertaintyOf } from './uncertainty.js'
@@ -255,3 +255,14 @@ export function describeSplits(splits: RunStats['splits']): string[] {
255
255
  }
256
256
  return lines
257
257
  }
258
+
259
+ /**
260
+ * The line about cases a suite declared as held-out is the suite's own
261
+ * statement. Beside the run's `split:` line it reads as a contradiction, since
262
+ * the hashed split puts some of the same tasks in held-out; say which is which.
263
+ */
264
+ export function clarifyDeclared(line: string): string {
265
+ return line.startsWith('no held-out cases')
266
+ ? `${line} (declared by the suite; the split above is the hashed one)`
267
+ : line
268
+ }
@@ -1,4 +1,6 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks'
2
+ import type { SettingsSnapshot } from './settings.js'
3
+ import type { SplitFilter } from './split.js'
2
4
 
3
5
  /**
4
6
  * Settings an operator gives a whole eval run, handed to every
@@ -24,6 +26,25 @@ export interface EvalRunOptions {
24
26
  readonly commit?: string
25
27
  /** Version of the suite being run, when known. */
26
28
  readonly suiteVersion?: string
29
+ /**
30
+ * The settings the run was given. Written into every report. A suite shapes
31
+ * itself by them through {@link currentEvalSettings}; one that does not is
32
+ * reported as not having read them.
33
+ */
34
+ readonly settings?: SettingsSnapshot
35
+ /** Which tasks run. Absent means all of them. */
36
+ readonly split?: SplitFilter
37
+ /** Set by {@link currentEvalSettings} when a suite asks for the settings. Owned by the runner. */
38
+ readonly settingsUse?: { read: boolean; keys?: Set<string> }
39
+ }
40
+
41
+ /** Stands in the list of read keys for a suite that asked for the whole settings object. */
42
+ export const READ_ALL = '*'
43
+
44
+ function markRead(use: { read: boolean; keys?: Set<string> }, key: string): void {
45
+ const keys = use.keys ?? new Set<string>()
46
+ keys.add(key)
47
+ use.keys = keys
27
48
  }
28
49
 
29
50
  const STORE_KEY = Symbol.for('namzu.eval.runOptions')
@@ -47,3 +68,33 @@ export function withEvalRunOptions<T>(options: EvalRunOptions, work: () => T): T
47
68
  export function currentEvalRunOptions(): EvalRunOptions {
48
69
  return store().getStore() ?? {}
49
70
  }
71
+
72
+ /**
73
+ * The values of the settings the run was given, or an empty object when it was
74
+ * given none. Asking marks the suite as one that read them, which its report
75
+ * says: a setting nobody reads cannot have changed what a suite measured.
76
+ */
77
+ export function currentEvalSettings(): Readonly<Record<string, unknown>> {
78
+ const options = currentEvalRunOptions()
79
+ if (options.settingsUse) {
80
+ options.settingsUse.read = true
81
+ // The whole object was asked for: every key counts as read.
82
+ markRead(options.settingsUse, READ_ALL)
83
+ }
84
+ return options.settings?.values ?? {}
85
+ }
86
+
87
+ /** One setting by its dotted path, for example `limits.maxIterations`; undefined when not stated. */
88
+ export function evalSetting(path: string): unknown {
89
+ const options = currentEvalRunOptions()
90
+ let at: unknown = options.settings?.values ?? {}
91
+ if (options.settingsUse) {
92
+ options.settingsUse.read = true
93
+ markRead(options.settingsUse, path)
94
+ }
95
+ for (const part of path.split('.')) {
96
+ if (typeof at !== 'object' || at === null || Array.isArray(at)) return undefined
97
+ at = (at as Record<string, unknown>)[part]
98
+ }
99
+ return at
100
+ }
@@ -2,11 +2,14 @@ import { UNKNOWN } from './disclosure.js'
2
2
  import type { RunMode } from './disclosure.js'
3
3
  import {
4
4
  type RunStats,
5
+ clarifyDeclared,
5
6
  describeIntervals,
6
7
  describeSplits,
7
8
  groupRuns,
8
9
  statsOver,
9
10
  } from './report-stats.js'
11
+ import type { SettingsSnapshot } from './settings.js'
12
+ import type { SplitFilter } from './split.js'
10
13
  import type { ExperimentReport } from './types.js'
11
14
 
12
15
  /** What produced a whole run, across every suite in it. */
@@ -23,6 +26,10 @@ export interface RunDisclosure {
23
26
  readonly runs: number
24
27
  /** `mixed` when suites that used a model differ in kind; a suite with no model at all does not count. */
25
28
  readonly mode: RunMode | 'mixed'
29
+ /** The settings the run was given. Absent from a run written before reports named them. */
30
+ readonly settings?: SettingsSnapshot
31
+ /** Which tasks ran. Absent from a run written before there were splits. */
32
+ readonly split?: SplitFilter
26
33
  }
27
34
 
28
35
  /** The numbers for every case of every suite taken together. */
@@ -40,6 +47,8 @@ export function summarizeRun(
40
47
  commit: string
41
48
  generatedAt: string
42
49
  sdkVersion: string
50
+ settings?: SettingsSnapshot
51
+ split?: SplitFilter
43
52
  },
44
53
  ): RunSummary {
45
54
  // A case is named by its suite and its id: two suites may reuse a name.
@@ -74,6 +83,8 @@ export function summarizeRun(
74
83
  cases: stats.cases,
75
84
  runs: stats.runs,
76
85
  mode,
86
+ ...(context.settings ? { settings: context.settings } : {}),
87
+ ...(context.split ? { split: context.split } : {}),
77
88
  },
78
89
  }
79
90
  }
@@ -96,7 +107,14 @@ export function formatRunSummary(summary: RunSummary): string {
96
107
  ` reliability across repeats: ${r.passedEveryRepeat} of ${r.cases} cases passed in every one of ${d.repeats} repeats${r.fraction === null ? '' : ` (${(r.fraction * 100).toFixed(1)}%)`}`,
97
108
  )
98
109
  }
99
- for (const line of describeSplits(summary.splits)) lines.push(` ${line}`)
110
+ for (const line of describeSplits(summary.splits)) {
111
+ if (d.split === 'held-out' && line.startsWith('no held-out cases')) continue
112
+ lines.push(` ${d.split ? clarifyDeclared(line) : line}`)
113
+ }
114
+ if (d.settings) {
115
+ lines.push(` settings: "${d.settings.name}", sha256 ${d.settings.digest.slice(0, 12)}`)
116
+ }
117
+ if (d.split) lines.push(` split: ${d.split}`)
100
118
  lines.push(
101
119
  ` produced by: namzu eval ${d.harnessVersion}, sdk ${d.sdkVersion}, commit ${d.commit}, ${d.generatedAt}, ${d.mode}`,
102
120
  )
@@ -0,0 +1,225 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { EvalUsageError } from './bootstrap.js'
3
+
4
+ /**
5
+ * The settings an eval run ran under, as a named, canonical, hashed record.
6
+ *
7
+ * Two reports of one suite say little about a harness setting unless each says
8
+ * exactly which settings it ran under. The snapshot is that statement: a name a
9
+ * person chose (or `default`), a digest of the values, and the values. The
10
+ * digest is taken over the values alone, in a canonical form, so it is the same
11
+ * whatever order the keys were written in and whatever the snapshot is called.
12
+ *
13
+ * Secrets never enter one. {@link buildSettingsSnapshot} refuses a value that
14
+ * names a credential or looks like one, so a report written from a snapshot
15
+ * cannot carry a key even if a caller passed it by mistake.
16
+ */
17
+ export interface SettingsSnapshot {
18
+ /** What the person called it; the file's name when it came from a file. */
19
+ readonly name: string
20
+ /** SHA-256 of the canonical JSON of {@link values}, in hex. */
21
+ readonly digest: string
22
+ /** How the digest was made, so a later version can change it without a silent mismatch. */
23
+ readonly algorithm: typeof SETTINGS_DIGEST_ALGORITHM
24
+ /** The settings that differ from the defaults: whatever was stated. Empty for `default`. */
25
+ readonly values: Readonly<Record<string, unknown>>
26
+ }
27
+
28
+ export const SETTINGS_DIGEST_ALGORITHM = 'sha256-canonical-json-1'
29
+
30
+ /** The name of the snapshot of a run that was given no settings. */
31
+ export const DEFAULT_SETTINGS_NAME = 'default'
32
+
33
+ /** What a suite that read the settings says about it, written into its report. */
34
+ export interface ReportSettings extends SettingsSnapshot {
35
+ /**
36
+ * Whether the suite asked for the settings while it ran. A suite that never
37
+ * does cannot have been shaped by them, so a difference between two snapshots
38
+ * says nothing about its numbers.
39
+ */
40
+ readonly read: boolean
41
+ /**
42
+ * The dotted paths the suite asked for, or `*` when it asked for the whole
43
+ * object. Absent from a report that predates it, which is read as every key.
44
+ */
45
+ readonly readKeys?: readonly string[]
46
+ }
47
+
48
+ function isRecord(value: unknown): value is Record<string, unknown> {
49
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
50
+ }
51
+
52
+ /**
53
+ * Canonical JSON: keys sorted at every level, no whitespace, array order kept.
54
+ * A value JSON cannot carry (`undefined` inside an array, a non-finite number,
55
+ * a function) is refused, because a digest over a value that cannot be written
56
+ * back would name something nobody can reproduce. An `undefined` object field
57
+ * is the same as an absent one and is dropped.
58
+ */
59
+ export function canonicalJson(value: unknown): string {
60
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') {
61
+ return JSON.stringify(value)
62
+ }
63
+ if (typeof value === 'number') {
64
+ if (!Number.isFinite(value)) {
65
+ throw new EvalUsageError(`a setting must be a finite number; received ${String(value)}`)
66
+ }
67
+ return JSON.stringify(value)
68
+ }
69
+ if (Array.isArray(value)) {
70
+ return `[${value
71
+ .map((item) => {
72
+ if (item === undefined) throw new EvalUsageError('a setting list cannot hold undefined')
73
+ return canonicalJson(item)
74
+ })
75
+ .join(',')}]`
76
+ }
77
+ if (isRecord(value)) {
78
+ const parts: string[] = []
79
+ for (const key of Object.keys(value).sort()) {
80
+ const item = value[key]
81
+ if (item === undefined) continue
82
+ parts.push(`${JSON.stringify(key)}:${canonicalJson(item)}`)
83
+ }
84
+ return `{${parts.join(',')}}`
85
+ }
86
+ throw new EvalUsageError(`a setting must be plain JSON; received ${typeof value}`)
87
+ }
88
+
89
+ /** Names that hold a credential. `maxResponseTokens` and `tokenBudget` are not among them. */
90
+ const SECRET_KEY =
91
+ /^(?:token|secret|password|passwd|credentials?|authorization|cookie|bearer)$|api[-_]?key|private[-_]?key|secret|passw(?:or)?d|(?:access|auth|refresh|bearer|session|id)[-_]?token|client[-_]?secret/i
92
+
93
+ /** Shapes of the keys and tokens providers hand out. */
94
+ const SECRET_VALUE = [
95
+ // A password written into a URL: scheme://user:password@host
96
+ /[A-Za-z][A-Za-z0-9+.-]*:\/\/[^/\s:@]+:[^/\s@]+@/,
97
+ /\bsk-[A-Za-z0-9_-]{16,}/,
98
+ /\b(?:ghp|gho|ghu|ghs|ghr|github_pat)_[A-Za-z0-9_]{20,}/,
99
+ /\bxox[abprs]-[A-Za-z0-9-]{10,}/,
100
+ /\bAKIA[0-9A-Z]{16}\b/,
101
+ /\bAIza[0-9A-Za-z_-]{30,}/,
102
+ /\bBearer\s+[A-Za-z0-9._~+/=-]{16,}/i,
103
+ /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/,
104
+ /-----BEGIN [A-Z ]*PRIVATE KEY-----/,
105
+ ]
106
+
107
+ /**
108
+ * The path of the first thing in `values` that is, or names, a credential, or
109
+ * undefined when there is none. The path never includes the secret itself.
110
+ */
111
+ export function findSecretIn(values: unknown, path = ''): string | undefined {
112
+ if (typeof values === 'string') {
113
+ return SECRET_VALUE.some((pattern) => pattern.test(values)) ? path || '(value)' : undefined
114
+ }
115
+ if (Array.isArray(values)) {
116
+ for (const [index, item] of values.entries()) {
117
+ const hit = findSecretIn(item, `${path}[${index}]`)
118
+ if (hit !== undefined) return hit
119
+ }
120
+ return undefined
121
+ }
122
+ if (isRecord(values)) {
123
+ for (const key of Object.keys(values).sort()) {
124
+ const here = path === '' ? key : `${path}.${key}`
125
+ // A setting that names the environment variable holding a credential
126
+ // (`apiKeyEnv`) holds a name, not a secret, but is still refused: the
127
+ // snapshot has no business carrying where a credential lives.
128
+ if (SECRET_KEY.test(key)) return here
129
+ const hit = findSecretIn(values[key], here)
130
+ if (hit !== undefined) return hit
131
+ }
132
+ }
133
+ return undefined
134
+ }
135
+
136
+ /** A snapshot name is plain: it is printed in a comparison and used as a file label. */
137
+ export function validateSettingsName(name: string): string {
138
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(name)) {
139
+ throw new EvalUsageError(
140
+ `a settings name is 1 to 64 letters, digits, dots, dashes or underscores, starting with a letter or digit; received ${JSON.stringify(name)}`,
141
+ )
142
+ }
143
+ return name
144
+ }
145
+
146
+ /**
147
+ * Build a snapshot. Throws an {@link EvalUsageError} naming the path of a
148
+ * secret, a value JSON cannot carry, or a name that is not plain. A snapshot
149
+ * called `default` must have no values: `default` is the name of "no settings
150
+ * stated", and a snapshot with values under it would say the opposite.
151
+ */
152
+ export function buildSettingsSnapshot(
153
+ name: string,
154
+ values: Readonly<Record<string, unknown>> = {},
155
+ ): SettingsSnapshot {
156
+ validateSettingsName(name)
157
+ if (!isRecord(values)) throw new EvalUsageError('settings must be an object of settings')
158
+ const secret = findSecretIn(values)
159
+ if (secret !== undefined) {
160
+ throw new EvalUsageError(
161
+ `settings "${secret}" is, or names, a credential. A credential never goes into an eval settings snapshot, because the snapshot is written into the report.`,
162
+ )
163
+ }
164
+ const canonical = canonicalJson(values)
165
+ if (name === DEFAULT_SETTINGS_NAME && canonical !== '{}') {
166
+ throw new EvalUsageError(
167
+ `the name "${DEFAULT_SETTINGS_NAME}" is for a run with no settings stated; give these settings another name`,
168
+ )
169
+ }
170
+ return {
171
+ name,
172
+ digest: createHash('sha256').update(canonical).digest('hex'),
173
+ algorithm: SETTINGS_DIGEST_ALGORITHM,
174
+ // A copy through the canonical form, so what is stored is what was hashed.
175
+ values: JSON.parse(canonical) as Record<string, unknown>,
176
+ }
177
+ }
178
+
179
+ /** The snapshot of a run given no settings. */
180
+ export function defaultSettingsSnapshot(): SettingsSnapshot {
181
+ return buildSettingsSnapshot(DEFAULT_SETTINGS_NAME, {})
182
+ }
183
+
184
+ export interface SettingDifference {
185
+ /** Dotted path of the setting; a list is one value. */
186
+ readonly key: string
187
+ /** Absent on the side that does not state it. */
188
+ readonly a?: unknown
189
+ readonly b?: unknown
190
+ }
191
+
192
+ function leaves(value: unknown, path: string, into: Map<string, unknown>): void {
193
+ if (isRecord(value) && Object.keys(value).length > 0) {
194
+ for (const key of Object.keys(value))
195
+ leaves(value[key], path === '' ? key : `${path}.${key}`, into)
196
+ return
197
+ }
198
+ into.set(path, value)
199
+ }
200
+
201
+ /** What differs between two snapshots' values, key by key, sorted by key. */
202
+ export function diffSettings(
203
+ a: Readonly<Record<string, unknown>>,
204
+ b: Readonly<Record<string, unknown>>,
205
+ ): SettingDifference[] {
206
+ const left = new Map<string, unknown>()
207
+ const right = new Map<string, unknown>()
208
+ leaves(a, '', left)
209
+ leaves(b, '', right)
210
+ left.delete('')
211
+ right.delete('')
212
+ const keys = [...new Set([...left.keys(), ...right.keys()])].sort()
213
+ const out: SettingDifference[] = []
214
+ for (const key of keys) {
215
+ const inA = left.has(key)
216
+ const inB = right.has(key)
217
+ if (inA && inB && canonicalJson(left.get(key)) === canonicalJson(right.get(key))) continue
218
+ out.push({
219
+ key,
220
+ ...(inA ? { a: left.get(key) } : {}),
221
+ ...(inB ? { b: right.get(key) } : {}),
222
+ })
223
+ }
224
+ return out
225
+ }
@@ -0,0 +1,83 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { EvalUsageError } from './bootstrap.js'
3
+ import type { EvalSplit } from './types.js'
4
+
5
+ /**
6
+ * Which tasks a harness setting may be chosen on, and which it is judged on.
7
+ *
8
+ * A setting tuned against some tasks and then judged on the same tasks has been
9
+ * shown to fit them, and nothing more. Every task belongs to one of two splits:
10
+ * `tune`, the tasks to choose settings on, and `held-out`, the tasks to judge
11
+ * the choice on. The split of a task is a function of its identity and a fixed
12
+ * seed, so the same task is in the same split on every machine, in every run,
13
+ * whoever runs it. A suite may state a task's split itself, and that wins.
14
+ */
15
+ export type TaskSplit = 'tune' | 'held-out'
16
+
17
+ /** What `namzu eval --split` selects. */
18
+ export type SplitFilter = TaskSplit | 'all'
19
+
20
+ export const SPLIT_FILTERS: readonly SplitFilter[] = ['tune', 'held-out', 'all']
21
+
22
+ /** The seed of the assignment. Fixed in the kernel and written into every report. */
23
+ export const TASK_SPLIT_SEED = 'namzu-eval-split-1'
24
+
25
+ /** The share of tasks assigned to `held-out`, written into every report. */
26
+ export const HELD_OUT_FRACTION = 0.5
27
+
28
+ export const TASK_SPLIT_ALGORITHM =
29
+ 'sha256(seed, suite, task) as a fraction; held-out when below the share'
30
+
31
+ /** The id of a task: its suite and its case name, which is unique within the suite. */
32
+ export function taskId(suite: string, name: string): string {
33
+ return `${suite}/${name}`
34
+ }
35
+
36
+ /** The split a seeded hash assigns to a task, whatever a suite declares. */
37
+ export function hashedSplit(suite: string, name: string): TaskSplit {
38
+ const digest = createHash('sha256')
39
+ .update(`${TASK_SPLIT_SEED}\u0000${suite}\u0000${name}`)
40
+ .digest()
41
+ // Six bytes: 48 bits, exact in a double.
42
+ const fraction = digest.readUIntBE(0, 6) / 2 ** 48
43
+ return fraction < HELD_OUT_FRACTION ? 'held-out' : 'tune'
44
+ }
45
+
46
+ /**
47
+ * The split of a task. A declared split wins; `development`, the name a case
48
+ * declares for the tasks a harness was shaped against, is `tune`.
49
+ */
50
+ export function assignSplit(
51
+ suite: string,
52
+ name: string,
53
+ declared?: EvalSplit,
54
+ ): { split: TaskSplit; declared: boolean } {
55
+ if (declared === 'held-out') return { split: 'held-out', declared: true }
56
+ if (declared === 'development') return { split: 'tune', declared: true }
57
+ return { split: hashedSplit(suite, name), declared: false }
58
+ }
59
+
60
+ export function validateSplitFilter(value: string | undefined): SplitFilter {
61
+ if (value === undefined) return 'all'
62
+ if (!SPLIT_FILTERS.includes(value as SplitFilter)) {
63
+ throw new EvalUsageError(
64
+ `split must be "tune", "held-out" or "all"; received ${JSON.stringify(value)}`,
65
+ )
66
+ }
67
+ return value as SplitFilter
68
+ }
69
+
70
+ /** The tasks a suite ran, and how they were assigned. Written into the suite's report. */
71
+ export interface ReportTaskSplit {
72
+ /** What the run asked for. */
73
+ readonly requested: SplitFilter
74
+ readonly seed: typeof TASK_SPLIT_SEED
75
+ /** The share of tasks assigned to `held-out` when a suite does not say. */
76
+ readonly heldOutFraction: number
77
+ /** The tasks that ran, in the suite's order, each with its split. */
78
+ readonly tasks: readonly {
79
+ readonly id: string
80
+ readonly split: TaskSplit
81
+ readonly declared: boolean
82
+ }[]
83
+ }
package/src/eval/types.ts CHANGED
@@ -3,6 +3,8 @@ import type { StepResult } from '../types/session/step.js'
3
3
  import type { CaseIntervals } from './bootstrap.js'
4
4
  import type { ReportDisclosure } from './disclosure.js'
5
5
  import type { RepeatReliability, SplitSummary } from './report-stats.js'
6
+ import type { ReportSettings } from './settings.js'
7
+ import type { ReportTaskSplit } from './split.js'
6
8
  import type { ScoreUncertainty } from './uncertainty.js'
7
9
 
8
10
  /**
@@ -239,6 +241,16 @@ export interface ExperimentReport {
239
241
  splits?: Partial<Record<EvalSplit | 'unassigned', SplitSummary>>
240
242
  /** What produced this report. */
241
243
  disclosure?: ReportDisclosure
244
+ /**
245
+ * The settings snapshot the suite ran under: name, digest, values, and
246
+ * whether the suite read them. Absent from a report that predates it.
247
+ */
248
+ settings?: ReportSettings
249
+ /**
250
+ * Which split of the tasks ran, how each task was assigned, and the ids that
251
+ * ran. Absent from a report that predates it.
252
+ */
253
+ taskSplit?: ReportTaskSplit
242
254
  }
243
255
 
244
256
  /** How the repeats of one case went. */
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process'
2
2
  import { existsSync } from 'node:fs'
3
3
  import { resolve } from 'node:path'
4
4
  import { killTree } from '../process/kill-tree.js'
5
+ import { withSessionChildMarker } from '../process/session-child.js'
5
6
  import type { LocalExecutionContextConfig } from '../types/connector/index.js'
6
7
  import type {
7
8
  CommandExecutor,
@@ -161,7 +162,7 @@ export class LocalExecutionContext extends BaseExecutionContext implements Comma
161
162
  }
162
163
 
163
164
  const cwd = options?.cwd ? resolve(this.cwd, options.cwd) : this.cwd
164
- const env = { ...process.env, ...this.envVars, ...options?.env }
165
+ const env = withSessionChildMarker({ ...process.env, ...this.envVars, ...options?.env })
165
166
  const timeoutMs = options?.timeoutMs ?? LOCAL_COMMAND_DEFAULT_TIMEOUT_MS
166
167
  if (!Number.isInteger(timeoutMs) || timeoutMs < 0) {
167
168
  throw new RangeError(