@reicek/neataptic-ts 0.1.25 → 0.1.26

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 (210) hide show
  1. package/.github/copilot-instructions.md +11 -0
  2. package/.github/skills/trace-analyzer-extension/SKILL.md +3 -3
  3. package/.github/skills/trace-analyzer-extension/assets/extension-checklist.md +1 -1
  4. package/.github/skills/trace-analyzer-extension/references/analyzer-extension-workflow.md +1 -1
  5. package/.github/skills/trace-audit-reporting/SKILL.md +3 -3
  6. package/.github/skills/trace-audit-reporting/references/trace-analysis-workflow.md +1 -1
  7. package/package.json +19 -13
  8. package/plans/Flappy_Bird_Folder_Documentation_Pass.md +4 -4
  9. package/plans/README.md +24 -0
  10. package/plans/Roadmap.md +62 -40
  11. package/plans/analyze-trace-solid-split.plans.md +66 -0
  12. package/plans/architecture-solid-split.plans.md +9 -15
  13. package/plans/asciiMaze-typescript-repair.plans.md +1 -1
  14. package/plans/generate-docs-solid-split.plans.md +87 -0
  15. package/plans/methods-docs.plans.md +25 -1
  16. package/plans/methods-solid-split.plans.md +14 -14
  17. package/plans/neat-docs.plans.md +9 -1
  18. package/plans/neat-test-surface-repair.plans.md +1 -1
  19. package/plans/render-docs-html-solid-split.plans.md +68 -0
  20. package/plans/src-no-explicit-any-cleanup.plans.md +1 -1
  21. package/plans/utils-docs.plans.md +6 -1
  22. package/scripts/analyze-trace/analyze-trace.analysis.ts +479 -0
  23. package/scripts/analyze-trace/analyze-trace.constants.ts +35 -0
  24. package/scripts/analyze-trace/analyze-trace.io.ts +69 -0
  25. package/scripts/analyze-trace/analyze-trace.report.ts +100 -0
  26. package/scripts/analyze-trace/analyze-trace.shared.ts +116 -0
  27. package/scripts/analyze-trace/analyze-trace.ts +45 -0
  28. package/scripts/analyze-trace/analyze-trace.types.ts +72 -0
  29. package/scripts/assets/theme.css +80 -23
  30. package/scripts/copy-examples.ts +239 -0
  31. package/scripts/export-onnx.ts +223 -0
  32. package/scripts/generate-bench-tables.ts +378 -37
  33. package/scripts/generate-docs/generate-docs.constants.ts +107 -0
  34. package/scripts/generate-docs/generate-docs.order.ts +355 -0
  35. package/scripts/generate-docs/generate-docs.state.ts +31 -0
  36. package/scripts/generate-docs/generate-docs.targets.ts +165 -0
  37. package/scripts/generate-docs/generate-docs.ts +63 -0
  38. package/scripts/generate-docs/generate-docs.types.ts +112 -0
  39. package/scripts/generate-docs/output/generate-docs.output.folder-index.utils.ts +167 -0
  40. package/scripts/generate-docs/output/generate-docs.output.ordering.utils.ts +353 -0
  41. package/scripts/generate-docs/output/generate-docs.output.readme.utils.ts +420 -0
  42. package/scripts/generate-docs/output/generate-docs.output.ts +123 -0
  43. package/scripts/generate-docs/output/generate-docs.output.warnings.utils.ts +219 -0
  44. package/scripts/generate-docs/symbols/generate-docs.symbols.collection.utils.ts +365 -0
  45. package/scripts/generate-docs/symbols/generate-docs.symbols.jsdoc.utils.ts +373 -0
  46. package/scripts/generate-docs/symbols/generate-docs.symbols.normalize.utils.ts +155 -0
  47. package/scripts/generate-docs/symbols/generate-docs.symbols.render.utils.ts +149 -0
  48. package/scripts/generate-docs/symbols/generate-docs.symbols.signature.utils.ts +289 -0
  49. package/scripts/generate-docs/symbols/generate-docs.symbols.ts +11 -0
  50. package/scripts/mermaid-cli.mjs +102 -22
  51. package/scripts/mermaid-cli.ts +736 -0
  52. package/scripts/render-docs-html/render-docs-html.assets.ts +54 -0
  53. package/scripts/render-docs-html/render-docs-html.mermaid.ts +245 -0
  54. package/scripts/{render-docs-html.sidebar.ts → render-docs-html/render-docs-html.navigation.ts} +141 -144
  55. package/scripts/render-docs-html/render-docs-html.pages.ts +333 -0
  56. package/scripts/render-docs-html/render-docs-html.shared.ts +333 -0
  57. package/scripts/render-docs-html/render-docs-html.types.ts +42 -0
  58. package/scripts/render-docs-html.ts +23 -587
  59. package/scripts/run-docs.ts +238 -0
  60. package/scripts/write-dist-docs-pkg.ts +40 -0
  61. package/src/README.md +75 -75
  62. package/src/architecture/connection/README.md +5 -5
  63. package/src/architecture/layer/README.md +508 -508
  64. package/src/architecture/network/README.md +1458 -1458
  65. package/src/architecture/network/activate/README.md +694 -694
  66. package/src/architecture/network/bootstrap/README.md +77 -77
  67. package/src/architecture/network/connect/README.md +74 -74
  68. package/src/architecture/network/deterministic/README.md +135 -135
  69. package/src/architecture/network/evolve/README.md +364 -364
  70. package/src/architecture/network/gating/README.md +130 -130
  71. package/src/architecture/network/genetic/README.md +399 -399
  72. package/src/architecture/network/mutate/README.md +897 -897
  73. package/src/architecture/network/onnx/README.md +720 -720
  74. package/src/architecture/network/onnx/export/README.md +728 -728
  75. package/src/architecture/network/onnx/export/layers/README.md +450 -450
  76. package/src/architecture/network/onnx/import/README.md +618 -618
  77. package/src/architecture/network/onnx/schema/README.md +32 -32
  78. package/src/architecture/network/prune/README.md +245 -245
  79. package/src/architecture/network/remove/README.md +135 -135
  80. package/src/architecture/network/runtime/README.md +106 -106
  81. package/src/architecture/network/serialize/README.md +542 -542
  82. package/src/architecture/network/slab/README.md +608 -608
  83. package/src/architecture/network/standalone/README.md +212 -212
  84. package/src/architecture/network/stats/README.md +84 -84
  85. package/src/architecture/network/topology/README.md +465 -465
  86. package/src/architecture/network/training/README.md +200 -200
  87. package/src/architecture/node/README.md +5 -5
  88. package/src/architecture/nodePool/README.md +14 -14
  89. package/src/methods/README.md +99 -99
  90. package/src/methods/activation/README.md +189 -189
  91. package/src/methods/cost/README.md +131 -131
  92. package/src/methods/rate/README.md +86 -86
  93. package/src/multithreading/README.md +77 -77
  94. package/src/multithreading/workers/browser/README.md +8 -8
  95. package/src/multithreading/workers/node/README.md +8 -8
  96. package/src/neat/README.md +148 -148
  97. package/src/neat/adaptive/README.md +120 -120
  98. package/src/neat/adaptive/acceptance/README.md +40 -40
  99. package/src/neat/adaptive/complexity/README.md +137 -137
  100. package/src/neat/adaptive/core/README.md +197 -197
  101. package/src/neat/adaptive/lineage/README.md +90 -90
  102. package/src/neat/adaptive/mutation/README.md +284 -284
  103. package/src/neat/compat/README.md +43 -43
  104. package/src/neat/compat/core/README.md +90 -90
  105. package/src/neat/diversity/README.md +35 -35
  106. package/src/neat/diversity/core/README.md +88 -88
  107. package/src/neat/evaluate/README.md +85 -85
  108. package/src/neat/evaluate/auto-distance/README.md +75 -75
  109. package/src/neat/evaluate/entropy-compat/README.md +37 -37
  110. package/src/neat/evaluate/entropy-sharing/README.md +43 -43
  111. package/src/neat/evaluate/fitness/README.md +23 -23
  112. package/src/neat/evaluate/novelty/README.md +120 -120
  113. package/src/neat/evaluate/objectives/README.md +17 -17
  114. package/src/neat/evaluate/shared/README.md +94 -94
  115. package/src/neat/evolve/README.md +96 -96
  116. package/src/neat/evolve/adaptive/README.md +60 -60
  117. package/src/neat/evolve/objectives/README.md +63 -63
  118. package/src/neat/evolve/offspring/README.md +56 -56
  119. package/src/neat/evolve/population/README.md +171 -171
  120. package/src/neat/evolve/runtime/README.md +79 -79
  121. package/src/neat/evolve/speciation/README.md +74 -74
  122. package/src/neat/evolve/warnings/README.md +10 -10
  123. package/src/neat/export/README.md +114 -114
  124. package/src/neat/helpers/README.md +50 -50
  125. package/src/neat/init/README.md +9 -9
  126. package/src/neat/lineage/core/README.md +101 -101
  127. package/src/neat/multiobjective/category/README.md +74 -74
  128. package/src/neat/multiobjective/crowding/README.md +272 -272
  129. package/src/neat/multiobjective/dominance/README.md +171 -171
  130. package/src/neat/multiobjective/fronts/README.md +68 -68
  131. package/src/neat/multiobjective/metrics/README.md +43 -43
  132. package/src/neat/multiobjective/objectives/README.md +31 -31
  133. package/src/neat/multiobjective/shared/README.md +27 -27
  134. package/src/neat/mutation/README.md +97 -97
  135. package/src/neat/mutation/add-conn/README.md +115 -115
  136. package/src/neat/mutation/add-node/README.md +126 -126
  137. package/src/neat/mutation/flow/README.md +149 -149
  138. package/src/neat/mutation/repair/README.md +185 -185
  139. package/src/neat/mutation/select/README.md +117 -117
  140. package/src/neat/mutation/shared/README.md +32 -32
  141. package/src/neat/objectives/README.md +25 -25
  142. package/src/neat/objectives/core/README.md +67 -67
  143. package/src/neat/pruning/README.md +40 -40
  144. package/src/neat/pruning/core/README.md +171 -171
  145. package/src/neat/pruning/facade/README.md +32 -32
  146. package/src/neat/rng/README.md +104 -104
  147. package/src/neat/rng/core/README.md +137 -137
  148. package/src/neat/rng/facade/README.md +50 -50
  149. package/src/neat/selection/README.md +111 -111
  150. package/src/neat/selection/core/README.md +227 -227
  151. package/src/neat/selection/facade/README.md +61 -61
  152. package/src/neat/shared/README.md +163 -163
  153. package/src/neat/speciation/README.md +31 -31
  154. package/src/neat/speciation/threshold/README.md +35 -35
  155. package/src/neat/species/README.md +25 -25
  156. package/src/neat/species/core/README.md +20 -20
  157. package/src/neat/species/core/shared/README.md +18 -18
  158. package/src/neat/species/history/context/README.md +22 -22
  159. package/src/neat/telemetry/accessors/README.md +58 -58
  160. package/src/neat/telemetry/exports/README.md +233 -233
  161. package/src/neat/telemetry/facade/README.md +252 -252
  162. package/src/neat/telemetry/facade/archive/README.md +57 -57
  163. package/src/neat/telemetry/facade/buffer/README.md +43 -43
  164. package/src/neat/telemetry/facade/lineage/README.md +12 -12
  165. package/src/neat/telemetry/facade/objectives/README.md +44 -44
  166. package/src/neat/telemetry/facade/runtime/README.md +26 -26
  167. package/src/neat/telemetry/facade/species/README.md +27 -27
  168. package/src/neat/telemetry/metrics/README.md +696 -696
  169. package/src/neat/telemetry/recorder/README.md +57 -57
  170. package/src/neat/telemetry/types/README.md +32 -32
  171. package/src/neat/topology-intent/README.md +75 -75
  172. package/src/utils/README.md +193 -193
  173. package/test/examples/asciiMaze/browser-entry/README.md +92 -92
  174. package/test/examples/asciiMaze/dashboardManager/README.md +109 -109
  175. package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +28 -28
  176. package/test/examples/asciiMaze/evolutionEngine/README.md +1527 -1527
  177. package/test/examples/asciiMaze/mazeMovement/README.md +105 -105
  178. package/test/examples/asciiMaze/mazeMovement/finalization/README.md +16 -16
  179. package/test/examples/asciiMaze/mazeMovement/policy/README.md +57 -57
  180. package/test/examples/asciiMaze/mazeMovement/runtime/README.md +52 -52
  181. package/test/examples/asciiMaze/mazeMovement/shaping/README.md +46 -46
  182. package/test/examples/flappy_bird/browser-entry/README.md +508 -508
  183. package/test/examples/flappy_bird/browser-entry/host/README.md +101 -101
  184. package/test/examples/flappy_bird/browser-entry/host/resize/README.md +144 -144
  185. package/test/examples/flappy_bird/browser-entry/network-view/README.md +194 -194
  186. package/test/examples/flappy_bird/browser-entry/playback/README.md +278 -278
  187. package/test/examples/flappy_bird/browser-entry/playback/background/README.md +129 -129
  188. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +502 -502
  189. package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +139 -139
  190. package/test/examples/flappy_bird/browser-entry/playback/snapshot/README.md +10 -10
  191. package/test/examples/flappy_bird/browser-entry/playback/trail/README.md +43 -43
  192. package/test/examples/flappy_bird/browser-entry/playback/worker-channel/README.md +30 -30
  193. package/test/examples/flappy_bird/browser-entry/runtime/README.md +59 -59
  194. package/test/examples/flappy_bird/browser-entry/visualization/README.md +276 -276
  195. package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +16 -16
  196. package/test/examples/flappy_bird/constants/README.md +1070 -1070
  197. package/test/examples/flappy_bird/environment/README.md +22 -22
  198. package/test/examples/flappy_bird/evaluation/README.md +32 -32
  199. package/test/examples/flappy_bird/evaluation/rollout/README.md +141 -141
  200. package/test/examples/flappy_bird/flappy-evolution-worker/README.md +425 -425
  201. package/test/examples/flappy_bird/simulation-shared/README.md +170 -170
  202. package/test/examples/flappy_bird/simulation-shared/observation/README.md +109 -109
  203. package/test/examples/flappy_bird/trainer/README.md +325 -325
  204. package/test/examples/flappy_bird/trainer/evaluation/README.md +74 -74
  205. package/scripts/analyze-trace.ts +0 -590
  206. package/scripts/copy-examples.mjs +0 -114
  207. package/scripts/export-onnx.mjs +0 -86
  208. package/scripts/generate-bench-tables.mjs +0 -182
  209. package/scripts/generate-docs.ts +0 -2900
  210. package/scripts/write-dist-docs-pkg.mjs +0 -16
@@ -52,101 +52,94 @@ flowchart LR
52
52
 
53
53
  ## neat/telemetry/exports/telemetry.exports.ts
54
54
 
55
- ### exportTelemetryJSONL
55
+ ### buildSpeciesHistoryCsv
56
56
 
57
57
  ```ts
58
- exportTelemetryJSONL(): string
58
+ buildSpeciesHistoryCsv(
59
+ recentHistory: SpeciesHistoryEntry[],
60
+ headers: string[],
61
+ ): string
59
62
  ```
60
63
 
61
- Serialize telemetry as JSON Lines for stream-friendly log exports.
62
-
63
- JSONL keeps the export path almost lossless: each telemetry entry is emitted
64
- as one JSON object on one line, which makes the format easy to append to a
65
- file, stream through command-line tools, or reload in notebook code without
66
- flattening nested structures first.
64
+ Build the full CSV string for species history entries.
67
65
 
68
- Parameters:
69
- - `this` - - Neat instance exposing the internal telemetry buffer.
66
+ Species history exports are row-expanded: each generation snapshot can produce
67
+ multiple rows, one for each species stat recorded inside that generation. The
68
+ helper therefore writes a single shared header line and then flattens the
69
+ nested history structure into one CSV row per species snapshot.
70
70
 
71
- Returns: JSONL payload with one telemetry object per line.
71
+ The important teaching point is that species history is not a one-row-per-
72
+ generation export. A generation can contain several contemporaneous species,
73
+ so the serializer preserves that multiplicity instead of forcing species data
74
+ into one over-packed cell.
72
75
 
73
- Example:
76
+ Parameters:
77
+ - `recentHistory` - - History entries to export.
78
+ - `headers` - - Ordered headers for the export window.
74
79
 
75
- ```ts
76
- const jsonl = exportTelemetryJSONL.call(neat);
77
- console.log(jsonl.split('\n').length);
78
- ```
80
+ Returns: Complete CSV payload.
79
81
 
80
- ### exportTelemetryCSV
82
+ ### buildTelemetryHeaders
81
83
 
82
84
  ```ts
83
- exportTelemetryCSV(
84
- maxEntries: number,
85
- ): string
85
+ buildTelemetryHeaders(
86
+ info: TelemetryHeaderInfo,
87
+ ): string[]
86
88
  ```
87
89
 
88
- Export recent telemetry entries to a CSV string.
89
-
90
- This is the human-scanning export path. Instead of preserving the exact
91
- object graph like JSONL does, it discovers a stable column set across the
92
- sampled window and then flattens grouped metrics into prefixed columns.
90
+ Build the ordered header list for telemetry CSV output.
93
91
 
94
- Flattening rules:
95
- - nested `complexity`, `perf`, `lineage`, and selected `diversity` fields
96
- become `group.key` columns,
97
- - optional arrays and maps are serialized as JSON cells only when present in
98
- the sampled window,
99
- - the most recent `maxEntries` records are exported to keep output bounded.
92
+ Once discovery is complete, this helper turns the collected key sets into the
93
+ final column order. Group prefixes such as `complexity.` and `perf.` preserve
94
+ meaning after flattening so spreadsheet readers can still tell which runtime
95
+ family a value came from.
100
96
 
101
- Use this path when the reader question is comparative rather than archival:
102
- you want to sort, filter, chart, or diff recent runtime behavior in a tool
103
- that understands rows and columns better than nested objects.
97
+ The output order is intentionally grouped rather than purely alphabetical. It
98
+ keeps top-level run facts first, then nested metric families, then sparse
99
+ optional payload columns that behave more like attachments.
104
100
 
105
101
  Parameters:
106
- - `this` - - Neat instance exposing the internal telemetry buffer.
107
- - `maxEntries` - - Maximum number of recent telemetry rows to include.
102
+ - `info` - - Collected header discovery state.
108
103
 
109
- Returns: CSV string containing headers plus one row per exported entry.
104
+ Returns: Ordered header names used for serialization.
110
105
 
111
- Example:
106
+ ### collectTelemetryHeaderInfo
112
107
 
113
108
  ```ts
114
- const csv = exportTelemetryCSV.call(neat, 50);
115
- console.log(csv.split('\n')[0]);
109
+ collectTelemetryHeaderInfo(
110
+ entries: TelemetryEntry[],
111
+ ): TelemetryHeaderInfo
116
112
  ```
117
113
 
118
- ### exportSpeciesHistoryCSV
114
+ Collect header metadata from the sampled telemetry entries.
119
115
 
120
- ```ts
121
- exportSpeciesHistoryCSV(
122
- maxEntries: number,
123
- ): string
124
- ```
116
+ This is the discovery pass that makes CSV exports deterministic. Instead of
117
+ assuming every telemetry entry has the same shape, the helper scans the
118
+ window first and records which base fields, grouped metrics, and optional
119
+ columns actually appear anywhere in the sample.
125
120
 
126
- Export species history snapshots to CSV.
121
+ Conceptually, this is where an irregular event stream becomes a table plan.
122
+ The rest of the CSV path is simpler because this helper commits to one export
123
+ shape before row serialization starts.
127
124
 
128
- The exporter preserves runtime-added species stat fields by discovering the
129
- union of keys across the requested history window. When history has not been
130
- recorded yet but live species data exists, the helper synthesizes a minimal
131
- snapshot so early-run CSV exports remain deterministic.
125
+ Parameters:
126
+ - `entries` - - Telemetry entries included in the export window.
132
127
 
133
- This is the most timeline-oriented export in the chapter. Instead of one row
134
- per telemetry entry, it expands each generation snapshot into one row per
135
- species so a reader can inspect turnover, stagnation, and size changes with
136
- ordinary tabular tools.
128
+ Returns: Flattened header discovery state.
137
129
 
138
- Parameters:
139
- - `this` - - Neat instance exposing species history and optional live species.
140
- - `maxEntries` - - Maximum number of recent history snapshots to include.
130
+ ### DEFAULT_SPECIES_BEST_SCORE
141
131
 
142
- Returns: CSV payload describing one species row per generation snapshot.
132
+ Default fallback best score when a synthesized history row lacks a score.
143
133
 
144
- Example:
134
+ This preserves a numeric best-score column even when the runtime only has a
135
+ minimally reconstructed species snapshot.
145
136
 
146
- ```ts
147
- const csv = exportSpeciesHistoryCSV.call(neat, 25);
148
- console.log(csv.split('\n').slice(0, 2).join('\n'));
149
- ```
137
+ ### DEFAULT_SPECIES_HISTORY_GENERATION
138
+
139
+ Default fallback generation used when backfilling an early species snapshot.
140
+
141
+ The synthetic row still prefers the controller's live generation when it is
142
+ available. This constant is the final floor for partially initialized hosts.
150
143
 
151
144
  ### DEFAULT_SPECIES_HISTORY_MAX_ENTRIES
152
145
 
@@ -167,6 +160,14 @@ Default fallback species id when a synthesized history row lacks an id.
167
160
  This only appears in the synthetic early-history path where live species
168
161
  exist but a formal history snapshot has not been archived yet.
169
162
 
163
+ ### DEFAULT_SPECIES_LAST_IMPROVED
164
+
165
+ Default fallback last-improved generation when a synthesized row lacks one.
166
+
167
+ A neutral default keeps the CSV shape deterministic without pretending the
168
+ exporter knows more improvement history than the controller has actually
169
+ recorded.
170
+
170
171
  ### DEFAULT_SPECIES_SIZE
171
172
 
172
173
  Default fallback species size when a synthesized history row lacks a size.
@@ -175,84 +176,101 @@ The exporter prefers an explicit neutral size over leaving the cell absent so
175
176
  spreadsheets and notebooks can still treat the backfilled row as a stable
176
177
  member of the same column contract.
177
178
 
178
- ### DEFAULT_SPECIES_BEST_SCORE
179
-
180
- Default fallback best score when a synthesized history row lacks a score.
181
-
182
- This preserves a numeric best-score column even when the runtime only has a
183
- minimally reconstructed species snapshot.
184
-
185
- ### DEFAULT_SPECIES_LAST_IMPROVED
179
+ ### exportSpeciesHistoryCSV
186
180
 
187
- Default fallback last-improved generation when a synthesized row lacks one.
181
+ ```ts
182
+ exportSpeciesHistoryCSV(
183
+ maxEntries: number,
184
+ ): string
185
+ ```
188
186
 
189
- A neutral default keeps the CSV shape deterministic without pretending the
190
- exporter knows more improvement history than the controller has actually
191
- recorded.
187
+ Export species history snapshots to CSV.
192
188
 
193
- ### DEFAULT_SPECIES_HISTORY_GENERATION
189
+ The exporter preserves runtime-added species stat fields by discovering the
190
+ union of keys across the requested history window. When history has not been
191
+ recorded yet but live species data exists, the helper synthesizes a minimal
192
+ snapshot so early-run CSV exports remain deterministic.
194
193
 
195
- Default fallback generation used when backfilling an early species snapshot.
194
+ This is the most timeline-oriented export in the chapter. Instead of one row
195
+ per telemetry entry, it expands each generation snapshot into one row per
196
+ species so a reader can inspect turnover, stagnation, and size changes with
197
+ ordinary tabular tools.
196
198
 
197
- The synthetic row still prefers the controller's live generation when it is
198
- available. This constant is the final floor for partially initialized hosts.
199
+ Parameters:
200
+ - `this` - - Neat instance exposing species history and optional live species.
201
+ - `maxEntries` - - Maximum number of recent history snapshots to include.
199
202
 
200
- ### TelemetryHeaderInfo
203
+ Returns: CSV payload describing one species row per generation snapshot.
201
204
 
202
- Shape describing collected telemetry header discovery info.
205
+ Example:
203
206
 
204
- Think of this as the temporary export blueprint for one CSV window. Before a
205
- telemetry entry can be flattened into cells, the exporter needs to know which
206
- top-level fields exist, which nested metric groups need prefixed columns, and
207
- which optional arrays or maps appeared anywhere in the sampled window.
207
+ ```ts
208
+ const csv = exportSpeciesHistoryCSV.call(neat, 25);
209
+ console.log(csv.split('\n').slice(0, 2).join('\n'));
210
+ ```
208
211
 
209
- ### collectTelemetryHeaderInfo
212
+ ### exportTelemetryCSV
210
213
 
211
214
  ```ts
212
- collectTelemetryHeaderInfo(
213
- entries: TelemetryEntry[],
214
- ): TelemetryHeaderInfo
215
+ exportTelemetryCSV(
216
+ maxEntries: number,
217
+ ): string
215
218
  ```
216
219
 
217
- Collect header metadata from the sampled telemetry entries.
220
+ Export recent telemetry entries to a CSV string.
218
221
 
219
- This is the discovery pass that makes CSV exports deterministic. Instead of
220
- assuming every telemetry entry has the same shape, the helper scans the
221
- window first and records which base fields, grouped metrics, and optional
222
- columns actually appear anywhere in the sample.
222
+ This is the human-scanning export path. Instead of preserving the exact
223
+ object graph like JSONL does, it discovers a stable column set across the
224
+ sampled window and then flattens grouped metrics into prefixed columns.
223
225
 
224
- Conceptually, this is where an irregular event stream becomes a table plan.
225
- The rest of the CSV path is simpler because this helper commits to one export
226
- shape before row serialization starts.
226
+ Flattening rules:
227
+ - nested `complexity`, `perf`, `lineage`, and selected `diversity` fields
228
+ become `group.key` columns,
229
+ - optional arrays and maps are serialized as JSON cells only when present in
230
+ the sampled window,
231
+ - the most recent `maxEntries` records are exported to keep output bounded.
232
+
233
+ Use this path when the reader question is comparative rather than archival:
234
+ you want to sort, filter, chart, or diff recent runtime behavior in a tool
235
+ that understands rows and columns better than nested objects.
227
236
 
228
237
  Parameters:
229
- - `entries` - - Telemetry entries included in the export window.
238
+ - `this` - - Neat instance exposing the internal telemetry buffer.
239
+ - `maxEntries` - - Maximum number of recent telemetry rows to include.
230
240
 
231
- Returns: Flattened header discovery state.
241
+ Returns: CSV string containing headers plus one row per exported entry.
232
242
 
233
- ### buildTelemetryHeaders
243
+ Example:
234
244
 
235
245
  ```ts
236
- buildTelemetryHeaders(
237
- info: TelemetryHeaderInfo,
238
- ): string[]
246
+ const csv = exportTelemetryCSV.call(neat, 50);
247
+ console.log(csv.split('\n')[0]);
239
248
  ```
240
249
 
241
- Build the ordered header list for telemetry CSV output.
250
+ ### exportTelemetryJSONL
242
251
 
243
- Once discovery is complete, this helper turns the collected key sets into the
244
- final column order. Group prefixes such as `complexity.` and `perf.` preserve
245
- meaning after flattening so spreadsheet readers can still tell which runtime
246
- family a value came from.
252
+ ```ts
253
+ exportTelemetryJSONL(): string
254
+ ```
247
255
 
248
- The output order is intentionally grouped rather than purely alphabetical. It
249
- keeps top-level run facts first, then nested metric families, then sparse
250
- optional payload columns that behave more like attachments.
256
+ Serialize telemetry as JSON Lines for stream-friendly log exports.
257
+
258
+ JSONL keeps the export path almost lossless: each telemetry entry is emitted
259
+ as one JSON object on one line, which makes the format easy to append to a
260
+ file, stream through command-line tools, or reload in notebook code without
261
+ flattening nested structures first.
251
262
 
252
263
  Parameters:
253
- - `info` - - Collected header discovery state.
264
+ - `this` - - Neat instance exposing the internal telemetry buffer.
254
265
 
255
- Returns: Ordered header names used for serialization.
266
+ Returns: JSONL payload with one telemetry object per line.
267
+
268
+ Example:
269
+
270
+ ```ts
271
+ const jsonl = exportTelemetryJSONL.call(neat);
272
+ console.log(jsonl.split('\n').length);
273
+ ```
256
274
 
257
275
  ### serializeTelemetryEntry
258
276
 
@@ -281,32 +299,14 @@ Parameters:
281
299
 
282
300
  Returns: CSV row string.
283
301
 
284
- ### buildSpeciesHistoryCsv
285
-
286
- ```ts
287
- buildSpeciesHistoryCsv(
288
- recentHistory: SpeciesHistoryEntry[],
289
- headers: string[],
290
- ): string
291
- ```
292
-
293
- Build the full CSV string for species history entries.
294
-
295
- Species history exports are row-expanded: each generation snapshot can produce
296
- multiple rows, one for each species stat recorded inside that generation. The
297
- helper therefore writes a single shared header line and then flattens the
298
- nested history structure into one CSV row per species snapshot.
299
-
300
- The important teaching point is that species history is not a one-row-per-
301
- generation export. A generation can contain several contemporaneous species,
302
- so the serializer preserves that multiplicity instead of forcing species data
303
- into one over-packed cell.
302
+ ### TelemetryHeaderInfo
304
303
 
305
- Parameters:
306
- - `recentHistory` - - History entries to export.
307
- - `headers` - - Ordered headers for the export window.
304
+ Shape describing collected telemetry header discovery info.
308
305
 
309
- Returns: Complete CSV payload.
306
+ Think of this as the temporary export blueprint for one CSV window. Before a
307
+ telemetry entry can be flattened into cells, the exporter needs to know which
308
+ top-level fields exist, which nested metric groups need prefixed columns, and
309
+ which optional arrays or maps appeared anywhere in the sampled window.
310
310
 
311
311
  ## neat/telemetry/exports/telemetry.exports.utils.ts
312
312
 
@@ -324,6 +324,39 @@ functions first answer the low-level questions: which columns exist in this
324
324
  window, which optional structures actually appeared, which species-history
325
325
  fields must be backfilled, and how should one value become one safe CSV cell.
326
326
 
327
+ ### buildSpeciesHistoryStats
328
+
329
+ ```ts
330
+ buildSpeciesHistoryStats(
331
+ speciesList: SpeciesHistoryStat[],
332
+ defaultSpeciesId: number,
333
+ defaultSpeciesSize: number,
334
+ defaultBestScore: number,
335
+ defaultLastImproved: number,
336
+ ): SpeciesHistoryStat[]
337
+ ```
338
+
339
+ Normalize raw species records into exportable history stats.
340
+
341
+ Runtime species objects can arrive with slightly different shapes depending
342
+ on when they were recorded or which legacy path produced them. This helper
343
+ converts those permissive records into one compact export-ready model with
344
+ explicit fallbacks for id, size, score, and last-improved generation.
345
+
346
+ Parameters:
347
+ - `speciesList` - - Raw species records to normalize.
348
+ - `defaultSpeciesId` - - Default species id when missing.
349
+ - `defaultSpeciesSize` - - Default species size when missing.
350
+ - `defaultBestScore` - - Default best score when missing.
351
+ - `defaultLastImproved` - - Default last improved when missing.
352
+
353
+ Returns: Normalized stats for CSV export.
354
+
355
+ Example:
356
+
357
+ const stats = buildSpeciesHistoryStats(neat._species ?? [], -1, 0, 0, 0);
358
+ console.log(stats.length);
359
+
327
360
  ### collectBaseKeys
328
361
 
329
362
  ```ts
@@ -347,47 +380,47 @@ Parameters:
347
380
 
348
381
  Returns: void. Mutates `state.baseKeys`.
349
382
 
350
- ### collectGroupedMetricKeys
383
+ ### collectDiversityLineageMetrics
351
384
 
352
385
  ```ts
353
- collectGroupedMetricKeys(
386
+ collectDiversityLineageMetrics(
354
387
  entry: TelemetryEntry,
355
388
  state: TelemetryHeaderCollectionState,
356
389
  ): void
357
390
  ```
358
391
 
359
- Collect nested metric keys for grouped telemetry fields.
392
+ Collect curated diversity lineage metrics for stable CSV exports.
360
393
 
361
- Grouped telemetry objects such as `complexity`, `perf`, and `lineage` become
362
- prefixed CSV columns. This helper discovers those nested keys without mixing
363
- them into the base top-level header set.
394
+ Diversity objects can contain more information than the CSV surface needs.
395
+ This helper intentionally exports only the lineage-related diversity metrics
396
+ that are useful and stable enough to deserve fixed columns.
364
397
 
365
398
  Parameters:
366
399
  - `entry` - - Telemetry entry to inspect.
367
400
  - `state` - - Mutable header collection state.
368
401
 
369
- Returns: void. Mutates complexity/perf/lineage key sets.
402
+ Returns: void. Mutates diversity lineage key set.
370
403
 
371
- ### collectDiversityLineageMetrics
404
+ ### collectGroupedMetricKeys
372
405
 
373
406
  ```ts
374
- collectDiversityLineageMetrics(
407
+ collectGroupedMetricKeys(
375
408
  entry: TelemetryEntry,
376
409
  state: TelemetryHeaderCollectionState,
377
410
  ): void
378
411
  ```
379
412
 
380
- Collect curated diversity lineage metrics for stable CSV exports.
413
+ Collect nested metric keys for grouped telemetry fields.
381
414
 
382
- Diversity objects can contain more information than the CSV surface needs.
383
- This helper intentionally exports only the lineage-related diversity metrics
384
- that are useful and stable enough to deserve fixed columns.
415
+ Grouped telemetry objects such as `complexity`, `perf`, and `lineage` become
416
+ prefixed CSV columns. This helper discovers those nested keys without mixing
417
+ them into the base top-level header set.
385
418
 
386
419
  Parameters:
387
420
  - `entry` - - Telemetry entry to inspect.
388
421
  - `state` - - Mutable header collection state.
389
422
 
390
- Returns: void. Mutates diversity lineage key set.
423
+ Returns: void. Mutates complexity/perf/lineage key sets.
391
424
 
392
425
  ### collectOptionalColumnPresence
393
426
 
@@ -411,24 +444,26 @@ Parameters:
411
444
 
412
445
  Returns: void. Mutates optional-column flags.
413
446
 
414
- ### ensureSpeciesHistoryArray
447
+ ### collectSpeciesHistoryHeaders
415
448
 
416
449
  ```ts
417
- ensureSpeciesHistoryArray(
418
- neatInstance: NeatLike & { _speciesHistory?: SpeciesHistoryEntry[] | undefined; },
419
- ): SpeciesHistoryEntry[]
450
+ collectSpeciesHistoryHeaders(
451
+ history: SpeciesHistoryEntry[],
452
+ generationHeader: string,
453
+ ): string[]
420
454
  ```
421
455
 
422
- Ensure the species history array exists on the Neat instance.
456
+ Collect ordered header keys for species history CSV export.
423
457
 
424
- This helper gives the CSV path one stable backing array to work with, even in
425
- early or partially initialized controller states. It keeps later export code
426
- focused on serialization instead of defensive host checks.
458
+ Species history rows can grow new fields over time. This helper scans the
459
+ selected history window and builds the union of all encountered stat keys so
460
+ every emitted row follows one shared, predictable column order.
427
461
 
428
462
  Parameters:
429
- - `neatInstance` - - Neat instance holding species history.
463
+ - `history` - - Recent species history entries.
464
+ - `generationHeader` - - Header label for generation column.
430
465
 
431
- Returns: Species history backing array (ensured on instance).
466
+ Returns: Ordered header list for CSV output.
432
467
 
433
468
  ### ensureMinimalSpeciesSnapshot
434
469
 
@@ -467,85 +502,24 @@ Example:
467
502
  const history = ensureSpeciesHistoryArray(neat);
468
503
  ensureMinimalSpeciesSnapshot(neat, history, 0, -1, 0, 0, 0);
469
504
 
470
- ### collectSpeciesHistoryHeaders
471
-
472
- ```ts
473
- collectSpeciesHistoryHeaders(
474
- history: SpeciesHistoryEntry[],
475
- generationHeader: string,
476
- ): string[]
477
- ```
478
-
479
- Collect ordered header keys for species history CSV export.
480
-
481
- Species history rows can grow new fields over time. This helper scans the
482
- selected history window and builds the union of all encountered stat keys so
483
- every emitted row follows one shared, predictable column order.
484
-
485
- Parameters:
486
- - `history` - - Recent species history entries.
487
- - `generationHeader` - - Header label for generation column.
488
-
489
- Returns: Ordered header list for CSV output.
490
-
491
- ### buildSpeciesHistoryStats
492
-
493
- ```ts
494
- buildSpeciesHistoryStats(
495
- speciesList: SpeciesHistoryStat[],
496
- defaultSpeciesId: number,
497
- defaultSpeciesSize: number,
498
- defaultBestScore: number,
499
- defaultLastImproved: number,
500
- ): SpeciesHistoryStat[]
501
- ```
502
-
503
- Normalize raw species records into exportable history stats.
504
-
505
- Runtime species objects can arrive with slightly different shapes depending
506
- on when they were recorded or which legacy path produced them. This helper
507
- converts those permissive records into one compact export-ready model with
508
- explicit fallbacks for id, size, score, and last-improved generation.
509
-
510
- Parameters:
511
- - `speciesList` - - Raw species records to normalize.
512
- - `defaultSpeciesId` - - Default species id when missing.
513
- - `defaultSpeciesSize` - - Default species size when missing.
514
- - `defaultBestScore` - - Default best score when missing.
515
- - `defaultLastImproved` - - Default last improved when missing.
516
-
517
- Returns: Normalized stats for CSV export.
518
-
519
- Example:
520
-
521
- const stats = buildSpeciesHistoryStats(neat._species ?? [], -1, 0, 0, 0);
522
- console.log(stats.length);
523
-
524
- ### serializeSpeciesHistoryRow
505
+ ### ensureSpeciesHistoryArray
525
506
 
526
507
  ```ts
527
- serializeSpeciesHistoryRow(
528
- historyEntry: SpeciesHistoryEntry,
529
- speciesStat: SpeciesHistoryStat,
530
- orderedHeaders: string[],
531
- generationHeader: string,
532
- ): string
508
+ ensureSpeciesHistoryArray(
509
+ neatInstance: NeatLike & { _speciesHistory?: SpeciesHistoryEntry[] | undefined; },
510
+ ): SpeciesHistoryEntry[]
533
511
  ```
534
512
 
535
- Serialize one species history row using the provided headers.
513
+ Ensure the species history array exists on the Neat instance.
536
514
 
537
- Species history CSV output is built row by row from one generation snapshot
538
- plus one species stat record. This helper guarantees that each row follows
539
- the same previously collected header order, even when some species records
540
- omit optional fields.
515
+ This helper gives the CSV path one stable backing array to work with, even in
516
+ early or partially initialized controller states. It keeps later export code
517
+ focused on serialization instead of defensive host checks.
541
518
 
542
519
  Parameters:
543
- - `historyEntry` - - A single generation snapshot.
544
- - `speciesStat` - - A single species stat record for that generation.
545
- - `orderedHeaders` - - Ordered header list for stable CSV.
546
- - `generationHeader` - - Column header name for generation.
520
+ - `neatInstance` - - Neat instance holding species history.
547
521
 
548
- Returns: CSV row string matching the provided header order.
522
+ Returns: Species history backing array (ensured on instance).
549
523
 
550
524
  ### resolveSpeciesHistoryCellValue
551
525
 
@@ -591,6 +565,32 @@ Parameters:
591
565
 
592
566
  Returns: JSON string or empty string when JSON.stringify returns undefined.
593
567
 
568
+ ### serializeSpeciesHistoryRow
569
+
570
+ ```ts
571
+ serializeSpeciesHistoryRow(
572
+ historyEntry: SpeciesHistoryEntry,
573
+ speciesStat: SpeciesHistoryStat,
574
+ orderedHeaders: string[],
575
+ generationHeader: string,
576
+ ): string
577
+ ```
578
+
579
+ Serialize one species history row using the provided headers.
580
+
581
+ Species history CSV output is built row by row from one generation snapshot
582
+ plus one species stat record. This helper guarantees that each row follows
583
+ the same previously collected header order, even when some species records
584
+ omit optional fields.
585
+
586
+ Parameters:
587
+ - `historyEntry` - - A single generation snapshot.
588
+ - `speciesStat` - - A single species stat record for that generation.
589
+ - `orderedHeaders` - - Ordered header list for stable CSV.
590
+ - `generationHeader` - - Column header name for generation.
591
+
592
+ Returns: CSV row string matching the provided header order.
593
+
594
594
  ### TelemetryHeaderCollectionState
595
595
 
596
596
  Mutable state container used while collecting telemetry header metadata.