akm-cli 0.7.0 → 0.7.2

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 (332) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/{src/cli.js → cli.js} +22 -8
  3. package/dist/{src/commands → commands}/installed-stashes.js +1 -1
  4. package/dist/{src/commands → commands}/source-add.js +1 -1
  5. package/dist/{src/core → core}/common.js +16 -1
  6. package/dist/{src/core → core}/config.js +5 -2
  7. package/dist/{src/indexer → indexer}/db-search.js +16 -1
  8. package/dist/{src/indexer → indexer}/graph-extraction.js +5 -3
  9. package/dist/{src/indexer → indexer}/indexer.js +27 -11
  10. package/dist/{src/indexer → indexer}/memory-inference.js +47 -58
  11. package/dist/{src/indexer → indexer}/search-source.js +1 -1
  12. package/dist/{src/llm → llm}/client.js +61 -1
  13. package/dist/{src/llm → llm}/embedder.js +8 -5
  14. package/dist/{src/llm → llm}/embedders/local.js +8 -2
  15. package/dist/{src/llm → llm}/embedders/remote.js +4 -2
  16. package/dist/{src/llm → llm}/graph-extract.js +4 -4
  17. package/dist/llm/memory-infer.js +114 -0
  18. package/dist/{src/llm → llm}/metadata-enhance.js +2 -2
  19. package/dist/{src/output → output}/cli-hints.js +2 -0
  20. package/dist/{src/setup → setup}/setup.js +30 -20
  21. package/dist/sources/providers/website.js +27 -0
  22. package/dist/{src/sources/providers/website.js → sources/website-ingest.js} +38 -51
  23. package/docs/README.md +7 -0
  24. package/docs/migration/release-notes/0.7.0.md +14 -0
  25. package/package.json +11 -8
  26. package/dist/src/llm/memory-infer.js +0 -86
  27. package/dist/tests/add-website-source.test.js +0 -119
  28. package/dist/tests/agent/agent-config-loader.test.js +0 -70
  29. package/dist/tests/agent/agent-config.test.js +0 -221
  30. package/dist/tests/agent/agent-detect.test.js +0 -100
  31. package/dist/tests/agent/agent-spawn.test.js +0 -234
  32. package/dist/tests/agent-output.test.js +0 -186
  33. package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +0 -103
  34. package/dist/tests/architecture/agent-spawn-seam.test.js +0 -193
  35. package/dist/tests/architecture/llm-stateless-seam.test.js +0 -112
  36. package/dist/tests/asset-ref.test.js +0 -192
  37. package/dist/tests/asset-registry.test.js +0 -103
  38. package/dist/tests/asset-spec.test.js +0 -241
  39. package/dist/tests/bench/attribution.test.js +0 -996
  40. package/dist/tests/bench/cleanup-sigint.test.js +0 -83
  41. package/dist/tests/bench/cleanup.js +0 -234
  42. package/dist/tests/bench/cleanup.test.js +0 -166
  43. package/dist/tests/bench/cli.js +0 -1018
  44. package/dist/tests/bench/cli.test.js +0 -445
  45. package/dist/tests/bench/compare.test.js +0 -556
  46. package/dist/tests/bench/corpus.js +0 -317
  47. package/dist/tests/bench/corpus.test.js +0 -258
  48. package/dist/tests/bench/doctor.js +0 -525
  49. package/dist/tests/bench/driver.js +0 -401
  50. package/dist/tests/bench/driver.test.js +0 -584
  51. package/dist/tests/bench/environment.js +0 -233
  52. package/dist/tests/bench/environment.test.js +0 -199
  53. package/dist/tests/bench/evolve-metrics.js +0 -179
  54. package/dist/tests/bench/evolve-metrics.test.js +0 -187
  55. package/dist/tests/bench/evolve.js +0 -647
  56. package/dist/tests/bench/evolve.test.js +0 -624
  57. package/dist/tests/bench/failure-modes.test.js +0 -349
  58. package/dist/tests/bench/feedback-integrity.test.js +0 -457
  59. package/dist/tests/bench/leakage.test.js +0 -228
  60. package/dist/tests/bench/learning-curve.test.js +0 -134
  61. package/dist/tests/bench/metrics.js +0 -2395
  62. package/dist/tests/bench/metrics.test.js +0 -1150
  63. package/dist/tests/bench/no-os-tmpdir-invariant.test.js +0 -43
  64. package/dist/tests/bench/opencode-config.js +0 -194
  65. package/dist/tests/bench/opencode-config.test.js +0 -370
  66. package/dist/tests/bench/report.js +0 -1885
  67. package/dist/tests/bench/report.test.js +0 -1038
  68. package/dist/tests/bench/run-config.js +0 -355
  69. package/dist/tests/bench/run-config.test.js +0 -298
  70. package/dist/tests/bench/run-curate-test.js +0 -32
  71. package/dist/tests/bench/run-failing-tasks.js +0 -56
  72. package/dist/tests/bench/run-full-bench.js +0 -51
  73. package/dist/tests/bench/run-items36-targeted.js +0 -69
  74. package/dist/tests/bench/run-nano-quick.js +0 -42
  75. package/dist/tests/bench/run-waveg-targeted.js +0 -62
  76. package/dist/tests/bench/runner.js +0 -699
  77. package/dist/tests/bench/runner.test.js +0 -958
  78. package/dist/tests/bench/search-bridge.test.js +0 -331
  79. package/dist/tests/bench/tmp.js +0 -131
  80. package/dist/tests/bench/trajectory.js +0 -116
  81. package/dist/tests/bench/trajectory.test.js +0 -127
  82. package/dist/tests/bench/verifier.js +0 -114
  83. package/dist/tests/bench/verifier.test.js +0 -118
  84. package/dist/tests/bench/workflow-evaluator.js +0 -557
  85. package/dist/tests/bench/workflow-evaluator.test.js +0 -421
  86. package/dist/tests/bench/workflow-spec.js +0 -345
  87. package/dist/tests/bench/workflow-spec.test.js +0 -363
  88. package/dist/tests/bench/workflow-trace.js +0 -472
  89. package/dist/tests/bench/workflow-trace.test.js +0 -254
  90. package/dist/tests/benchmark-search-quality.js +0 -536
  91. package/dist/tests/benchmark-suite.js +0 -1441
  92. package/dist/tests/capture-cli.test.js +0 -112
  93. package/dist/tests/cli-errors.test.js +0 -204
  94. package/dist/tests/commands/events.test.js +0 -370
  95. package/dist/tests/commands/history.test.js +0 -418
  96. package/dist/tests/commands/import.test.js +0 -103
  97. package/dist/tests/commands/proposal-cli.test.js +0 -209
  98. package/dist/tests/commands/reflect-propose-cli.test.js +0 -333
  99. package/dist/tests/commands/remember.test.js +0 -97
  100. package/dist/tests/commands/scope-flags.test.js +0 -300
  101. package/dist/tests/commands/search.test.js +0 -537
  102. package/dist/tests/commands/show-indexer-parity.test.js +0 -117
  103. package/dist/tests/commands/show.test.js +0 -294
  104. package/dist/tests/common.test.js +0 -266
  105. package/dist/tests/completions.test.js +0 -142
  106. package/dist/tests/config-cli.test.js +0 -193
  107. package/dist/tests/config-llm-features.test.js +0 -139
  108. package/dist/tests/config.test.js +0 -569
  109. package/dist/tests/contracts/migration-baseline.test.js +0 -43
  110. package/dist/tests/contracts/reflect-propose-envelope.test.js +0 -139
  111. package/dist/tests/contracts/spec-helpers.js +0 -46
  112. package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +0 -228
  113. package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +0 -56
  114. package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +0 -34
  115. package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +0 -94
  116. package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +0 -39
  117. package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +0 -44
  118. package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +0 -47
  119. package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +0 -40
  120. package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +0 -58
  121. package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +0 -34
  122. package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +0 -75
  123. package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +0 -36
  124. package/dist/tests/core/write-source.test.js +0 -366
  125. package/dist/tests/curate-command.test.js +0 -87
  126. package/dist/tests/db-scoring.test.js +0 -201
  127. package/dist/tests/db.test.js +0 -654
  128. package/dist/tests/distill-cli-flag.test.js +0 -208
  129. package/dist/tests/distill.test.js +0 -515
  130. package/dist/tests/docker-install.test.js +0 -120
  131. package/dist/tests/e2e.test.js +0 -1419
  132. package/dist/tests/embedder.test.js +0 -340
  133. package/dist/tests/embedding-model-config.test.js +0 -379
  134. package/dist/tests/feedback-command.test.js +0 -172
  135. package/dist/tests/file-context.test.js +0 -552
  136. package/dist/tests/fixtures/scripts/git/summarize-diff.js +0 -9
  137. package/dist/tests/fixtures/scripts/lint/eslint-check.js +0 -7
  138. package/dist/tests/fixtures/stashes/load.js +0 -166
  139. package/dist/tests/fixtures/stashes/load.test.js +0 -97
  140. package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +0 -12
  141. package/dist/tests/frontmatter.test.js +0 -190
  142. package/dist/tests/fts-field-weighting.test.js +0 -254
  143. package/dist/tests/fuzzy-search.test.js +0 -230
  144. package/dist/tests/git-provider-clone.test.js +0 -45
  145. package/dist/tests/github.test.js +0 -161
  146. package/dist/tests/graph-boost-ranking.test.js +0 -305
  147. package/dist/tests/graph-extraction.test.js +0 -282
  148. package/dist/tests/helpers/usage-events.js +0 -8
  149. package/dist/tests/index-pass-llm.test.js +0 -161
  150. package/dist/tests/indexer.test.js +0 -570
  151. package/dist/tests/info-command.test.js +0 -166
  152. package/dist/tests/init.test.js +0 -69
  153. package/dist/tests/install-script.test.js +0 -246
  154. package/dist/tests/integration/agent-real-profile.test.js +0 -94
  155. package/dist/tests/issue-36-repro.test.js +0 -304
  156. package/dist/tests/issues-191-194.test.js +0 -160
  157. package/dist/tests/lesson-lint.test.js +0 -111
  158. package/dist/tests/llm-client.test.js +0 -115
  159. package/dist/tests/llm-feature-gate.test.js +0 -151
  160. package/dist/tests/llm.test.js +0 -139
  161. package/dist/tests/lockfile.test.js +0 -216
  162. package/dist/tests/manifest.test.js +0 -205
  163. package/dist/tests/markdown.test.js +0 -126
  164. package/dist/tests/matchers-unit.test.js +0 -189
  165. package/dist/tests/memory-inference.test.js +0 -299
  166. package/dist/tests/merge-scoring.test.js +0 -136
  167. package/dist/tests/metadata.test.js +0 -313
  168. package/dist/tests/migration-help.test.js +0 -89
  169. package/dist/tests/origin-resolve.test.js +0 -124
  170. package/dist/tests/output-baseline.test.js +0 -218
  171. package/dist/tests/output-shapes-unit.test.js +0 -478
  172. package/dist/tests/parallel-search.test.js +0 -272
  173. package/dist/tests/parameter-metadata.test.js +0 -365
  174. package/dist/tests/paths.test.js +0 -177
  175. package/dist/tests/progressive-disclosure.test.js +0 -280
  176. package/dist/tests/proposals.test.js +0 -279
  177. package/dist/tests/proposed-quality.test.js +0 -271
  178. package/dist/tests/provider-registry.test.js +0 -32
  179. package/dist/tests/ranking-regression.test.js +0 -548
  180. package/dist/tests/reflect-propose.test.js +0 -455
  181. package/dist/tests/registry-build-index.test.js +0 -394
  182. package/dist/tests/registry-cli.test.js +0 -290
  183. package/dist/tests/registry-index-v2.test.js +0 -430
  184. package/dist/tests/registry-install.test.js +0 -728
  185. package/dist/tests/registry-providers/parity.test.js +0 -189
  186. package/dist/tests/registry-providers/skills-sh.test.js +0 -309
  187. package/dist/tests/registry-providers/static-index.test.js +0 -238
  188. package/dist/tests/registry-resolve.test.js +0 -126
  189. package/dist/tests/registry-search.test.js +0 -923
  190. package/dist/tests/remember-frontmatter.test.js +0 -378
  191. package/dist/tests/remember-unit.test.js +0 -123
  192. package/dist/tests/ripgrep-install.test.js +0 -251
  193. package/dist/tests/ripgrep-resolve.test.js +0 -108
  194. package/dist/tests/ripgrep.test.js +0 -163
  195. package/dist/tests/save-command.test.js +0 -94
  196. package/dist/tests/save-trust-qa-fixes.test.js +0 -270
  197. package/dist/tests/scoring-pipeline.test.js +0 -648
  198. package/dist/tests/search-include-proposed-cli.test.js +0 -118
  199. package/dist/tests/self-update.test.js +0 -442
  200. package/dist/tests/semantic-search-e2e.test.js +0 -512
  201. package/dist/tests/semantic-status.test.js +0 -471
  202. package/dist/tests/setup-run.integration.js +0 -877
  203. package/dist/tests/setup-wizard.test.js +0 -198
  204. package/dist/tests/setup.test.js +0 -131
  205. package/dist/tests/source-add.test.js +0 -11
  206. package/dist/tests/source-clone.test.js +0 -254
  207. package/dist/tests/source-manage.test.js +0 -366
  208. package/dist/tests/source-providers/filesystem.test.js +0 -82
  209. package/dist/tests/source-providers/git.test.js +0 -252
  210. package/dist/tests/source-providers/website.test.js +0 -128
  211. package/dist/tests/source-qa-fixes.test.js +0 -286
  212. package/dist/tests/source-registry.test.js +0 -350
  213. package/dist/tests/source-resolve.test.js +0 -100
  214. package/dist/tests/source-source.test.js +0 -281
  215. package/dist/tests/source.test.js +0 -533
  216. package/dist/tests/tar-utils-scan.test.js +0 -73
  217. package/dist/tests/toggle-components.test.js +0 -73
  218. package/dist/tests/usage-telemetry.test.js +0 -265
  219. package/dist/tests/utility-scoring.test.js +0 -558
  220. package/dist/tests/vault-load-error.test.js +0 -78
  221. package/dist/tests/vault-qa-fixes.test.js +0 -194
  222. package/dist/tests/vault.test.js +0 -429
  223. package/dist/tests/vector-search.test.js +0 -608
  224. package/dist/tests/walker.test.js +0 -252
  225. package/dist/tests/wave2-cluster-bc.test.js +0 -228
  226. package/dist/tests/wave2-cluster-d.test.js +0 -180
  227. package/dist/tests/wave2-cluster-e.test.js +0 -179
  228. package/dist/tests/wiki-qa-fixes.test.js +0 -270
  229. package/dist/tests/wiki.test.js +0 -529
  230. package/dist/tests/workflow-cli.test.js +0 -271
  231. package/dist/tests/workflow-markdown.test.js +0 -171
  232. package/dist/tests/workflow-path-escape.test.js +0 -132
  233. package/dist/tests/workflow-qa-fixes.test.js +0 -395
  234. package/dist/tests/workflows/indexer-rejection.test.js +0 -213
  235. /package/dist/{src/commands → commands}/completions.js +0 -0
  236. /package/dist/{src/commands → commands}/config-cli.js +0 -0
  237. /package/dist/{src/commands → commands}/curate.js +0 -0
  238. /package/dist/{src/commands → commands}/distill.js +0 -0
  239. /package/dist/{src/commands → commands}/events.js +0 -0
  240. /package/dist/{src/commands → commands}/history.js +0 -0
  241. /package/dist/{src/commands → commands}/info.js +0 -0
  242. /package/dist/{src/commands → commands}/init.js +0 -0
  243. /package/dist/{src/commands → commands}/install-audit.js +0 -0
  244. /package/dist/{src/commands → commands}/migration-help.js +0 -0
  245. /package/dist/{src/commands → commands}/proposal.js +0 -0
  246. /package/dist/{src/commands → commands}/propose.js +0 -0
  247. /package/dist/{src/commands → commands}/reflect.js +0 -0
  248. /package/dist/{src/commands → commands}/registry-search.js +0 -0
  249. /package/dist/{src/commands → commands}/remember.js +0 -0
  250. /package/dist/{src/commands → commands}/search.js +0 -0
  251. /package/dist/{src/commands → commands}/self-update.js +0 -0
  252. /package/dist/{src/commands → commands}/show.js +0 -0
  253. /package/dist/{src/commands → commands}/source-clone.js +0 -0
  254. /package/dist/{src/commands → commands}/source-manage.js +0 -0
  255. /package/dist/{src/commands → commands}/vault.js +0 -0
  256. /package/dist/{src/core → core}/asset-ref.js +0 -0
  257. /package/dist/{src/core → core}/asset-registry.js +0 -0
  258. /package/dist/{src/core → core}/asset-spec.js +0 -0
  259. /package/dist/{src/core → core}/errors.js +0 -0
  260. /package/dist/{src/core → core}/events.js +0 -0
  261. /package/dist/{src/core → core}/frontmatter.js +0 -0
  262. /package/dist/{src/core → core}/lesson-lint.js +0 -0
  263. /package/dist/{src/core → core}/markdown.js +0 -0
  264. /package/dist/{src/core → core}/paths.js +0 -0
  265. /package/dist/{src/core → core}/proposals.js +0 -0
  266. /package/dist/{src/core → core}/warn.js +0 -0
  267. /package/dist/{src/core → core}/write-source.js +0 -0
  268. /package/dist/{src/indexer → indexer}/db.js +0 -0
  269. /package/dist/{src/indexer → indexer}/file-context.js +0 -0
  270. /package/dist/{src/indexer → indexer}/graph-boost.js +0 -0
  271. /package/dist/{src/indexer → indexer}/manifest.js +0 -0
  272. /package/dist/{src/indexer → indexer}/matchers.js +0 -0
  273. /package/dist/{src/indexer → indexer}/metadata.js +0 -0
  274. /package/dist/{src/indexer → indexer}/search-fields.js +0 -0
  275. /package/dist/{src/indexer → indexer}/semantic-status.js +0 -0
  276. /package/dist/{src/indexer → indexer}/usage-events.js +0 -0
  277. /package/dist/{src/indexer → indexer}/walker.js +0 -0
  278. /package/dist/{src/integrations → integrations}/agent/config.js +0 -0
  279. /package/dist/{src/integrations → integrations}/agent/detect.js +0 -0
  280. /package/dist/{src/integrations → integrations}/agent/index.js +0 -0
  281. /package/dist/{src/integrations → integrations}/agent/profiles.js +0 -0
  282. /package/dist/{src/integrations → integrations}/agent/prompts.js +0 -0
  283. /package/dist/{src/integrations → integrations}/agent/spawn.js +0 -0
  284. /package/dist/{src/integrations → integrations}/github.js +0 -0
  285. /package/dist/{src/integrations → integrations}/lockfile.js +0 -0
  286. /package/dist/{src/llm → llm}/embedders/cache.js +0 -0
  287. /package/dist/{src/llm → llm}/embedders/types.js +0 -0
  288. /package/dist/{src/llm → llm}/feature-gate.js +0 -0
  289. /package/dist/{src/llm → llm}/index-passes.js +0 -0
  290. /package/dist/{src/output → output}/context.js +0 -0
  291. /package/dist/{src/output → output}/renderers.js +0 -0
  292. /package/dist/{src/output → output}/shapes.js +0 -0
  293. /package/dist/{src/output → output}/text.js +0 -0
  294. /package/dist/{src/registry → registry}/build-index.js +0 -0
  295. /package/dist/{src/registry → registry}/create-provider-registry.js +0 -0
  296. /package/dist/{src/registry → registry}/factory.js +0 -0
  297. /package/dist/{src/registry → registry}/origin-resolve.js +0 -0
  298. /package/dist/{src/registry → registry}/providers/index.js +0 -0
  299. /package/dist/{src/registry → registry}/providers/skills-sh.js +0 -0
  300. /package/dist/{src/registry → registry}/providers/static-index.js +0 -0
  301. /package/dist/{src/registry → registry}/providers/types.js +0 -0
  302. /package/dist/{src/registry → registry}/resolve.js +0 -0
  303. /package/dist/{src/registry → registry}/types.js +0 -0
  304. /package/dist/{src/setup → setup}/detect.js +0 -0
  305. /package/dist/{src/setup → setup}/ripgrep-install.js +0 -0
  306. /package/dist/{src/setup → setup}/ripgrep-resolve.js +0 -0
  307. /package/dist/{src/setup → setup}/steps.js +0 -0
  308. /package/dist/{src/sources → sources}/include.js +0 -0
  309. /package/dist/{src/sources → sources}/provider-factory.js +0 -0
  310. /package/dist/{src/sources → sources}/provider.js +0 -0
  311. /package/dist/{src/sources → sources}/providers/filesystem.js +0 -0
  312. /package/dist/{src/sources → sources}/providers/git.js +0 -0
  313. /package/dist/{src/sources → sources}/providers/index.js +0 -0
  314. /package/dist/{src/sources → sources}/providers/install-types.js +0 -0
  315. /package/dist/{src/sources → sources}/providers/npm.js +0 -0
  316. /package/dist/{src/sources → sources}/providers/provider-utils.js +0 -0
  317. /package/dist/{src/sources → sources}/providers/sync-from-ref.js +0 -0
  318. /package/dist/{src/sources → sources}/providers/tar-utils.js +0 -0
  319. /package/dist/{src/sources → sources}/resolve.js +0 -0
  320. /package/dist/{src/sources → sources}/types.js +0 -0
  321. /package/dist/{src/templates → templates}/wiki-templates.js +0 -0
  322. /package/dist/{src/version.js → version.js} +0 -0
  323. /package/dist/{src/wiki → wiki}/wiki.js +0 -0
  324. /package/dist/{src/workflows → workflows}/authoring.js +0 -0
  325. /package/dist/{src/workflows → workflows}/cli.js +0 -0
  326. /package/dist/{src/workflows → workflows}/db.js +0 -0
  327. /package/dist/{src/workflows → workflows}/document-cache.js +0 -0
  328. /package/dist/{src/workflows → workflows}/parser.js +0 -0
  329. /package/dist/{src/workflows → workflows}/renderer.js +0 -0
  330. /package/dist/{src/workflows → workflows}/runs.js +0 -0
  331. /package/dist/{src/workflows → workflows}/schema.js +0 -0
  332. /package/dist/{src/workflows → workflows}/validator.js +0 -0
@@ -1,472 +0,0 @@
1
- /**
2
- * akm-bench workflow trace normalization (issue #254).
3
- *
4
- * Produces a single, normalized stream of `WorkflowTraceEvent`s from a finished
5
- * `RunResult` so downstream consumers (#256 evaluator, workflow-compliance
6
- * reports) have ONE place to ask "what did this agent actually do?" instead of
7
- * scraping `events.jsonl`, agent stdout, workspace diffs, and verifier output
8
- * independently.
9
- *
10
- * Inputs:
11
- * • `RunResult.events` — structured AKM events (preferred when present).
12
- * • Captured agent stdout / tool-call text (`agentStdout`).
13
- * • Verifier output already lives on the run (`verifierStdout`).
14
- * • Optional `workspaceWrites` — paths the harness observed touched. The
15
- * normalizer will pick the first one as `first_workspace_write`.
16
- * • Optional `harness` lifecycle markers (started/finished timestamps).
17
- *
18
- * Outputs a `WorkflowTraceResult` with a stable `schemaVersion: 1` field on the
19
- * envelope so #256 (workflow evaluator, Wave 3) can pin against this contract.
20
- *
21
- * Design rules:
22
- * • Pure: never mutates the input `RunResult` and never touches disk.
23
- * • Bounded: caps total event count and per-event byte size. A pathological
24
- * 1MiB stdout line CANNOT become a 1MiB event — see
25
- * `MAX_EVENT_COUNT` / `MAX_EVENT_BYTES`.
26
- * • Stable order: events sort by `(orderHint asc, sourceRank asc, originalIndex asc)`
27
- * so the same RunResult always normalizes to the same trace.
28
- * • Source attribution: every event carries a `source` so callers can tell
29
- * where evidence came from when reconstructing the run.
30
- *
31
- * NOT in scope: live tailing, persistence, evaluation. Those belong to #256.
32
- */
33
- /** Runtime set of all valid workflow trace event names. Single source of truth. */
34
- export const WORKFLOW_TRACE_EVENT_NAMES = new Set([
35
- "agent_started",
36
- "akm_search",
37
- "akm_show",
38
- "akm_feedback",
39
- "akm_reflect",
40
- "akm_distill",
41
- "akm_propose",
42
- "akm_proposal_accept",
43
- "akm_workflow_start",
44
- "akm_workflow_next",
45
- "akm_workflow_complete",
46
- "akm_workflow_finish",
47
- "workspace_read",
48
- "workspace_write",
49
- "first_workspace_write",
50
- "test_run",
51
- "verifier_run",
52
- "agent_finished",
53
- ]);
54
- /* ─── Caps (documented contract) ──────────────────────────────────────────── */
55
- /** Hard cap on total events per trace. Prevents a noisy run from OOM-ing the harness. */
56
- export const MAX_EVENT_COUNT = 4096;
57
- /**
58
- * Per-string-field byte cap. Applied to `query`, `assetRef`, `filePath`,
59
- * `command`, and each `args[]` / `resultRefs[]` element. A pathological 1MiB
60
- * stdout line cannot become a 1MiB event because every string we copy off it
61
- * passes through `clamp(...)`.
62
- */
63
- export const MAX_EVENT_BYTES = 4096;
64
- /**
65
- * Cap on bytes scanned from `agentStdout`. A runaway agent could emit GBs.
66
- * 16 MiB matches `EVENTS_READ_CAP_BYTES` / `VERIFIER_STDOUT_SCAN_CAP` so the
67
- * harness has a single mental model of "how much output we look at".
68
- */
69
- export const MAX_STDOUT_SCAN_BYTES = 16 * 1024 * 1024;
70
- const SOURCE_RANK = {
71
- akm_events: 0,
72
- harness: 1,
73
- filesystem_diff: 2,
74
- verifier: 3,
75
- agent_stdout: 4,
76
- };
77
- /**
78
- * Normalize a `RunResult` (plus optional sidecar inputs) into a stable
79
- * workflow trace. Pure function; never throws on malformed input — bad lines
80
- * are skipped and a warning is appended to `options.warnings` if provided.
81
- */
82
- export function normalizeRunToTrace(run, options = {}) {
83
- const seeds = [];
84
- let originalIndex = 0;
85
- // 1) Harness lifecycle (if supplied).
86
- if (options.harness?.agentStartedTs) {
87
- seeds.push({
88
- orderHint: options.harness.agentStartedTs,
89
- sourceRank: SOURCE_RANK.harness,
90
- originalIndex: originalIndex++,
91
- partial: makePartial(run, options, {
92
- type: "agent_started",
93
- ts: options.harness.agentStartedTs,
94
- source: "harness",
95
- }),
96
- });
97
- }
98
- // 2) AKM events.jsonl — preferred evidence for akm_search/show/feedback/etc.
99
- for (const ev of run.events ?? []) {
100
- const seed = fromAkmEvent(ev, run, options, originalIndex);
101
- if (seed) {
102
- seeds.push(seed);
103
- originalIndex += 1;
104
- }
105
- }
106
- // 3) Agent stdout — scan for `akm <verb>` invocations not already covered.
107
- const stdoutSeeds = fromAgentStdout(options.agentStdout, run, options, originalIndex);
108
- for (const seed of stdoutSeeds) {
109
- seeds.push(seed);
110
- originalIndex += 1;
111
- }
112
- // 4) Workspace writes — first becomes `first_workspace_write`.
113
- if (options.workspaceWrites && options.workspaceWrites.length > 0) {
114
- let isFirst = true;
115
- for (const filePath of options.workspaceWrites) {
116
- if (typeof filePath !== "string" || filePath.length === 0)
117
- continue;
118
- seeds.push({
119
- // Workspace writes have no native timestamp; place them after akm_events
120
- // by giving them a high lexical hint anchored to the run finish marker
121
- // when present, else a sentinel that sorts after ISO timestamps.
122
- orderHint: options.harness?.agentFinishedTs ?? "~workspace",
123
- sourceRank: SOURCE_RANK.filesystem_diff,
124
- originalIndex: originalIndex++,
125
- partial: (() => {
126
- const clampedFilePath = clamp(filePath);
127
- const partial = makePartial(run, options, {
128
- type: isFirst ? "first_workspace_write" : "workspace_write",
129
- source: "filesystem_diff",
130
- filePath: clampedFilePath.value,
131
- });
132
- if (clampedFilePath.truncated)
133
- partial.bytesTruncated = true;
134
- return partial;
135
- })(),
136
- });
137
- isFirst = false;
138
- }
139
- }
140
- // 5) Verifier — derive a single `verifier_run` event from the run envelope.
141
- if (run.verifierExitCode !== undefined && run.verifierExitCode !== null) {
142
- seeds.push({
143
- orderHint: options.harness?.agentFinishedTs ?? "~verifier",
144
- sourceRank: SOURCE_RANK.verifier,
145
- originalIndex: originalIndex++,
146
- partial: makePartial(run, options, {
147
- type: "verifier_run",
148
- source: "verifier",
149
- exitCode: run.verifierExitCode,
150
- }),
151
- });
152
- }
153
- // 6) Harness finish (if supplied).
154
- if (options.harness?.agentFinishedTs) {
155
- seeds.push({
156
- orderHint: `${options.harness.agentFinishedTs}~`,
157
- sourceRank: SOURCE_RANK.harness,
158
- originalIndex: originalIndex++,
159
- partial: makePartial(run, options, {
160
- type: "agent_finished",
161
- ts: options.harness.agentFinishedTs,
162
- source: "harness",
163
- exitCode: run.verifierExitCode,
164
- }),
165
- });
166
- }
167
- // Stable sort: orderHint, then sourceRank, then originalIndex.
168
- seeds.sort((a, b) => {
169
- if (a.orderHint < b.orderHint)
170
- return -1;
171
- if (a.orderHint > b.orderHint)
172
- return 1;
173
- if (a.sourceRank !== b.sourceRank)
174
- return a.sourceRank - b.sourceRank;
175
- return a.originalIndex - b.originalIndex;
176
- });
177
- // Cap event count.
178
- let truncated = false;
179
- let kept = seeds;
180
- if (seeds.length > MAX_EVENT_COUNT) {
181
- kept = seeds.slice(0, MAX_EVENT_COUNT);
182
- truncated = true;
183
- if (options.warnings) {
184
- options.warnings.push(`workflow trace truncated: ${seeds.length} events exceed ${MAX_EVENT_COUNT}-event cap; remainder dropped.`);
185
- }
186
- }
187
- const events = kept.map((seed, idx) => ({ id: idx, ...seed.partial }));
188
- return {
189
- schemaVersion: 1,
190
- taskId: run.taskId,
191
- arm: run.arm,
192
- seed: run.seed,
193
- events,
194
- truncated,
195
- };
196
- }
197
- /* ─── Source: AKM events.jsonl envelopes ──────────────────────────────────── */
198
- const AKM_EVENT_TYPE_MAP = {
199
- search: "akm_search",
200
- show: "akm_show",
201
- feedback: "akm_feedback",
202
- reflect_invoked: "akm_reflect",
203
- distill_invoked: "akm_distill",
204
- propose_invoked: "akm_propose",
205
- promoted: "akm_proposal_accept",
206
- workflow_started: "akm_workflow_start",
207
- workflow_step_completed: "akm_workflow_complete",
208
- workflow_finished: "akm_workflow_finish",
209
- };
210
- function fromAkmEvent(ev, run, options, originalIndex) {
211
- if (!ev || typeof ev !== "object")
212
- return null;
213
- const envelope = ev;
214
- const eventType = typeof envelope.eventType === "string" ? envelope.eventType : undefined;
215
- if (!eventType)
216
- return null;
217
- const traceType = AKM_EVENT_TYPE_MAP[eventType];
218
- if (!traceType)
219
- return null; // ignore non-workflow events (add/remove/update/etc.)
220
- const ts = typeof envelope.ts === "string" && envelope.ts.length > 0 ? envelope.ts : undefined;
221
- const ref = typeof envelope.ref === "string" ? envelope.ref : undefined;
222
- const meta = (envelope.metadata ?? undefined);
223
- const partial = makePartial(run, options, {
224
- type: traceType,
225
- source: "akm_events",
226
- ts,
227
- });
228
- let bytesTruncated = false;
229
- if (ref) {
230
- const clampedRef = clamp(ref);
231
- partial.assetRef = clampedRef.value;
232
- bytesTruncated ||= clampedRef.truncated;
233
- }
234
- // Pull useful structured fields off metadata when present. We deliberately
235
- // probe a small whitelist so a malicious agent can't smuggle arbitrary
236
- // payloads into the trace.
237
- if (meta && typeof meta === "object") {
238
- const q = meta.query;
239
- if (typeof q === "string") {
240
- const clampedQuery = clamp(q);
241
- partial.query = clampedQuery.value;
242
- bytesTruncated ||= clampedQuery.truncated;
243
- }
244
- const fp = meta.path ?? meta.filePath;
245
- if (typeof fp === "string") {
246
- const clampedFilePath = clamp(fp);
247
- partial.filePath = clampedFilePath.value;
248
- bytesTruncated ||= clampedFilePath.truncated;
249
- }
250
- const ec = meta.exitCode;
251
- if (typeof ec === "number" && Number.isFinite(ec))
252
- partial.exitCode = ec;
253
- const refs = meta.resultRefs;
254
- if (Array.isArray(refs)) {
255
- partial.resultRefs = refs
256
- .filter((r) => typeof r === "string")
257
- .map((r) => {
258
- const clampedRef = clamp(r);
259
- bytesTruncated ||= clampedRef.truncated;
260
- return clampedRef.value;
261
- });
262
- }
263
- }
264
- if (bytesTruncated)
265
- partial.bytesTruncated = true;
266
- return {
267
- orderHint: ts ?? "￿akm-events", // events without ts sort after timestamped ones
268
- sourceRank: SOURCE_RANK.akm_events,
269
- originalIndex,
270
- partial,
271
- };
272
- }
273
- function fromAgentStdout(stdoutRaw, run, options, startIndex) {
274
- if (!stdoutRaw)
275
- return [];
276
- const stdout = stdoutRaw.length > MAX_STDOUT_SCAN_BYTES ? stdoutRaw.slice(0, MAX_STDOUT_SCAN_BYTES) : stdoutRaw;
277
- if (stdout.length < stdoutRaw.length && options.warnings) {
278
- options.warnings.push(`workflow trace stdout truncated: ${stdoutRaw.length} chars exceeds ${MAX_STDOUT_SCAN_BYTES}-char cap; trace computed from the prefix.`);
279
- }
280
- const out = [];
281
- let idx = startIndex;
282
- // Match invocations like `akm search "query"`, `akm show skill:foo`, `akm feedback +1 skill:foo`.
283
- // We scan line-by-line so position in the stdout becomes a stable order hint.
284
- const lines = stdout.split("\n");
285
- for (let lineNo = 0; lineNo < lines.length; lineNo += 1) {
286
- const line = lines[lineNo];
287
- const match = parseAkmCli(line);
288
- if (!match)
289
- continue;
290
- const clampedCommand = clamp(match.command);
291
- let bytesTruncated = clampedCommand.truncated;
292
- const partial = makePartial(run, options, {
293
- type: match.type,
294
- source: "agent_stdout",
295
- command: clampedCommand.value,
296
- });
297
- if (match.assetRef) {
298
- const clampedRef = clamp(match.assetRef);
299
- partial.assetRef = clampedRef.value;
300
- bytesTruncated ||= clampedRef.truncated;
301
- }
302
- if (match.query) {
303
- const clampedQuery = clamp(match.query);
304
- partial.query = clampedQuery.value;
305
- bytesTruncated ||= clampedQuery.truncated;
306
- }
307
- if (match.args) {
308
- partial.args = match.args.map((arg) => {
309
- const clampedArg = clamp(arg);
310
- bytesTruncated ||= clampedArg.truncated;
311
- return clampedArg.value;
312
- });
313
- }
314
- if (bytesTruncated)
315
- partial.bytesTruncated = true;
316
- out.push({
317
- // Stdout has no native timestamp; lexically place after timestamped events
318
- // by using a leading `~` sentinel (sorts after all printable ASCII timestamps),
319
- // then stable-order by line number padded to 8 digits.
320
- orderHint: `~stdout-${String(lineNo).padStart(8, "0")}`,
321
- sourceRank: SOURCE_RANK.agent_stdout,
322
- originalIndex: idx,
323
- partial,
324
- });
325
- idx += 1;
326
- }
327
- return out;
328
- }
329
- /**
330
- * Recognise an `akm <verb> ...` invocation in a single line of agent output.
331
- * Returns null when the line does not look like an akm CLI call.
332
- *
333
- * Supported shapes:
334
- * • Bare CLI: `akm search "deploy docker"`
335
- * • Tool-call: `tool: akm show skill:foo`
336
- * • JSON-ish: `{"command":"akm","args":["search","deploy"]}`
337
- */
338
- function parseAkmCli(line) {
339
- if (!line || line.length === 0)
340
- return null;
341
- // Quick reject — every form contains the literal `akm` token.
342
- if (line.indexOf("akm") === -1)
343
- return null;
344
- // JSON tool-call form first (most specific).
345
- const jsonMatch = line.match(/"command"\s*:\s*"akm"\s*,\s*"args"\s*:\s*\[([^\]]*)\]/);
346
- if (jsonMatch) {
347
- const argList = jsonMatch[1]
348
- .split(",")
349
- .map((a) => a.trim().replace(/^"|"$/g, ""))
350
- .filter(Boolean);
351
- return classifyArgs("akm", argList);
352
- }
353
- // Bare CLI form: capture everything after `akm `.
354
- const bareMatch = line.match(/(?:^|[\s>`'"])akm\s+(\w[\w-]*)(?:\s+([^\n]*))?/);
355
- if (bareMatch) {
356
- const verb = bareMatch[1];
357
- const rest = (bareMatch[2] ?? "").trim();
358
- const args = tokenizeArgs(rest);
359
- return classifyArgs("akm", [verb, ...args]);
360
- }
361
- return null;
362
- }
363
- function classifyArgs(command, argv) {
364
- if (argv.length === 0)
365
- return null;
366
- const verb = argv[0];
367
- const rest = argv.slice(1);
368
- switch (verb) {
369
- case "search":
370
- return { type: "akm_search", command, args: argv, query: rest.join(" ") || undefined };
371
- case "show":
372
- return { type: "akm_show", command, args: argv, assetRef: rest[0] };
373
- case "feedback":
374
- return { type: "akm_feedback", command, args: argv, assetRef: rest.find((a) => a.includes(":")) };
375
- case "reflect":
376
- return { type: "akm_reflect", command, args: argv };
377
- case "distill":
378
- return { type: "akm_distill", command, args: argv };
379
- case "propose":
380
- return { type: "akm_propose", command, args: argv };
381
- case "workflow": {
382
- const sub = rest[0];
383
- if (sub === "start")
384
- return { type: "akm_workflow_start", command, args: argv, assetRef: rest[1] };
385
- if (sub === "next")
386
- return { type: "akm_workflow_next", command, args: argv, assetRef: rest[1] };
387
- if (sub === "complete")
388
- return { type: "akm_workflow_complete", command, args: argv };
389
- return null;
390
- }
391
- default:
392
- return null;
393
- }
394
- }
395
- /**
396
- * Cheap shell-like tokenizer. Handles double-quoted and single-quoted strings;
397
- * everything else splits on whitespace. Not a full POSIX parser — we only need
398
- * "good enough" for opencode's tool-call logging.
399
- */
400
- function tokenizeArgs(rest) {
401
- const out = [];
402
- let i = 0;
403
- while (i < rest.length) {
404
- while (i < rest.length && rest[i] === " ")
405
- i += 1;
406
- if (i >= rest.length)
407
- break;
408
- const ch = rest[i];
409
- if (ch === '"' || ch === "'") {
410
- const quote = ch;
411
- i += 1;
412
- const start = i;
413
- while (i < rest.length && rest[i] !== quote)
414
- i += 1;
415
- out.push(rest.slice(start, i));
416
- if (i < rest.length)
417
- i += 1;
418
- }
419
- else {
420
- const start = i;
421
- while (i < rest.length && rest[i] !== " ")
422
- i += 1;
423
- out.push(rest.slice(start, i));
424
- }
425
- }
426
- return out;
427
- }
428
- /* ─── Helpers ─────────────────────────────────────────────────────────────── */
429
- function makePartial(run, options, fields) {
430
- const base = {
431
- taskId: run.taskId,
432
- arm: run.arm,
433
- seed: run.seed,
434
- type: fields.type,
435
- source: fields.source,
436
- };
437
- if (options.runId)
438
- base.runId = options.runId;
439
- if (fields.ts !== undefined)
440
- base.ts = fields.ts;
441
- if (fields.command !== undefined)
442
- base.command = fields.command;
443
- if (fields.args !== undefined)
444
- base.args = fields.args;
445
- if (fields.assetRef !== undefined)
446
- base.assetRef = fields.assetRef;
447
- if (fields.query !== undefined)
448
- base.query = fields.query;
449
- if (fields.resultRefs !== undefined)
450
- base.resultRefs = fields.resultRefs;
451
- if (fields.filePath !== undefined)
452
- base.filePath = fields.filePath;
453
- if (fields.exitCode !== undefined)
454
- base.exitCode = fields.exitCode;
455
- return base;
456
- }
457
- /** Clamp a single string to MAX_EVENT_BYTES UTF-8 bytes without splitting code points. */
458
- function clamp(value) {
459
- if (Buffer.byteLength(value, "utf8") <= MAX_EVENT_BYTES) {
460
- return { value, truncated: false };
461
- }
462
- let out = "";
463
- let bytes = 0;
464
- for (const ch of value) {
465
- const nextBytes = Buffer.byteLength(ch, "utf8");
466
- if (bytes + nextBytes > MAX_EVENT_BYTES)
467
- break;
468
- out += ch;
469
- bytes += nextBytes;
470
- }
471
- return { value: out, truncated: true };
472
- }