skillfit 0.0.0-stage → 0.8.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 (371) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +226 -2
  3. package/README.zh-CN.md +224 -0
  4. package/benches/README.md +172 -0
  5. package/benches/code-review/bench.json +57 -0
  6. package/benches/code-review/fixtures/explain-x1/.skillfit-mock.json +10 -0
  7. package/benches/code-review/fixtures/explain-x1/SPEC.md +16 -0
  8. package/benches/code-review/fixtures/explain-x1/src/compact.js +18 -0
  9. package/benches/code-review/fixtures/explain-x1/tests/compact.test.js +18 -0
  10. package/benches/code-review/fixtures/review-r1/.skillfit-mock.json +10 -0
  11. package/benches/code-review/fixtures/review-r1/CHANGES.diff +42 -0
  12. package/benches/code-review/fixtures/review-r1/SPEC.md +16 -0
  13. package/benches/code-review/fixtures/review-r1/src/errors.js +7 -0
  14. package/benches/code-review/fixtures/review-r1/src/money.js +3 -0
  15. package/benches/code-review/fixtures/review-r1/src/order.js +13 -0
  16. package/benches/code-review/fixtures/review-r1/tests/order.test.js +17 -0
  17. package/benches/code-review/fixtures/review-r2/.skillfit-mock.json +10 -0
  18. package/benches/code-review/fixtures/review-r2/CHANGES.diff +81 -0
  19. package/benches/code-review/fixtures/review-r2/SPEC.md +25 -0
  20. package/benches/code-review/fixtures/review-r2/src/errors.js +7 -0
  21. package/benches/code-review/fixtures/review-r2/src/invoice.js +9 -0
  22. package/benches/code-review/fixtures/review-r2/src/money.js +3 -0
  23. package/benches/code-review/fixtures/review-r2/tests/invoice.test.js +13 -0
  24. package/benches/code-review/fixtures/review-r3/.skillfit-mock.json +10 -0
  25. package/benches/code-review/fixtures/review-r3/CHANGES.diff +76 -0
  26. package/benches/code-review/fixtures/review-r3/SPEC.md +24 -0
  27. package/benches/code-review/fixtures/review-r3/src/errors.js +7 -0
  28. package/benches/code-review/fixtures/review-r3/src/money.js +3 -0
  29. package/benches/code-review/fixtures/review-r3/src/pricing.js +20 -0
  30. package/benches/code-review/fixtures/review-r3/tests/pricing.test.js +15 -0
  31. package/benches/code-review/fixtures/summarize-s1/.skillfit-mock.json +16 -0
  32. package/benches/code-review/fixtures/summarize-s1/CHANGES.diff +27 -0
  33. package/benches/code-review/fixtures/summarize-s1/SPEC.md +15 -0
  34. package/benches/code-review/fixtures/summarize-s1/src/discount.js +20 -0
  35. package/benches/code-review/fixtures/summarize-s1/src/errors.js +7 -0
  36. package/benches/code-review/fixtures/summarize-s1/src/money.js +7 -0
  37. package/benches/code-review/ground-truth/oracle-r1.mjs +21 -0
  38. package/benches/code-review/ground-truth/oracle-r2.mjs +21 -0
  39. package/benches/code-review/ground-truth/oracle-r3.mjs +20 -0
  40. package/benches/code-review/ground-truth/oracle-summarize-s1.mjs +21 -0
  41. package/benches/code-review/ground-truth/oracle-x1.mjs +18 -0
  42. package/benches/code-review/ground-truth/r1.md +22 -0
  43. package/benches/code-review/ground-truth/r2.md +21 -0
  44. package/benches/code-review/ground-truth/r3.md +18 -0
  45. package/benches/code-review/ground-truth/summarize-s1.md +26 -0
  46. package/benches/code-review/ground-truth/x1.md +7 -0
  47. package/benches/code-review/prompts/explain-x1.md +5 -0
  48. package/benches/code-review/prompts/explain-x1.trigger.md +5 -0
  49. package/benches/code-review/prompts/review-r1.md +7 -0
  50. package/benches/code-review/prompts/review-r1.trigger.md +7 -0
  51. package/benches/code-review/prompts/review-r2.md +7 -0
  52. package/benches/code-review/prompts/review-r2.trigger.md +7 -0
  53. package/benches/code-review/prompts/review-r3.md +7 -0
  54. package/benches/code-review/prompts/review-r3.trigger.md +7 -0
  55. package/benches/code-review/prompts/summarize-s1.md +9 -0
  56. package/benches/code-review/prompts/summarize-s1.trigger.md +9 -0
  57. package/benches/code-review/verifiers/explain-x1.mjs +30 -0
  58. package/benches/code-review/verifiers/review-r2.mjs +66 -0
  59. package/benches/code-review/verifiers/review-r3.mjs +60 -0
  60. package/benches/code-review/verifiers/seeded-bugs.mjs +74 -0
  61. package/benches/code-review/verifiers/summarize-s1.mjs +80 -0
  62. package/benches/contrib/README.md +42 -0
  63. package/benches/contrib/oss-lru-cache/README.md +24 -0
  64. package/benches/contrib/oss-lru-cache/bench.json +37 -0
  65. package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/LICENSE +15 -0
  66. package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/README.md +3 -0
  67. package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/index.js +1044 -0
  68. package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/package.json +11 -0
  69. package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/runtime.mjs +22 -0
  70. package/benches/contrib/oss-lru-cache/fixtures/fetch-abort/test.mjs +11 -0
  71. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/LICENSE.md +55 -0
  72. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/README.md +3 -0
  73. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/package.json +11 -0
  74. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/runtime.mjs +22 -0
  75. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/diagnostics-channel-browser.ts +11 -0
  76. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/diagnostics-channel-cjs.cts +11 -0
  77. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/diagnostics-channel-esm.mts +29 -0
  78. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/diagnostics-channel-node.ts +7 -0
  79. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/diagnostics-channel.ts +6 -0
  80. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/index.ts +3148 -0
  81. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/src/perf.ts +17 -0
  82. package/benches/contrib/oss-lru-cache/fixtures/fetch-lifecycle/test.mjs +11 -0
  83. package/benches/contrib/oss-lru-cache/fixtures/fetch-size/LICENSE +15 -0
  84. package/benches/contrib/oss-lru-cache/fixtures/fetch-size/README.md +3 -0
  85. package/benches/contrib/oss-lru-cache/fixtures/fetch-size/index.js +1028 -0
  86. package/benches/contrib/oss-lru-cache/fixtures/fetch-size/package.json +11 -0
  87. package/benches/contrib/oss-lru-cache/fixtures/fetch-size/runtime.mjs +22 -0
  88. package/benches/contrib/oss-lru-cache/fixtures/fetch-size/test.mjs +11 -0
  89. package/benches/contrib/oss-lru-cache/ground-truth/fetch-abort/LICENSE +15 -0
  90. package/benches/contrib/oss-lru-cache/ground-truth/fetch-abort/index.js +1053 -0
  91. package/benches/contrib/oss-lru-cache/ground-truth/fetch-abort.md +11 -0
  92. package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/LICENSE.md +55 -0
  93. package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/diagnostics-channel-browser.ts +11 -0
  94. package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/diagnostics-channel-cjs.cts +11 -0
  95. package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/diagnostics-channel-esm.mts +29 -0
  96. package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/diagnostics-channel-node.ts +7 -0
  97. package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/diagnostics-channel.ts +6 -0
  98. package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/index.ts +3174 -0
  99. package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle/src/perf.ts +17 -0
  100. package/benches/contrib/oss-lru-cache/ground-truth/fetch-lifecycle.md +11 -0
  101. package/benches/contrib/oss-lru-cache/ground-truth/fetch-size/LICENSE +15 -0
  102. package/benches/contrib/oss-lru-cache/ground-truth/fetch-size/index.js +1028 -0
  103. package/benches/contrib/oss-lru-cache/ground-truth/fetch-size.md +11 -0
  104. package/benches/contrib/oss-lru-cache/ground-truth/oracle-fetch-abort.mjs +8 -0
  105. package/benches/contrib/oss-lru-cache/ground-truth/oracle-fetch-lifecycle.mjs +7 -0
  106. package/benches/contrib/oss-lru-cache/ground-truth/oracle-fetch-size.mjs +7 -0
  107. package/benches/contrib/oss-lru-cache/ground-truth/oracle.mjs +9 -0
  108. package/benches/contrib/oss-lru-cache/prompts/fetch-abort.md +5 -0
  109. package/benches/contrib/oss-lru-cache/prompts/fetch-lifecycle.md +5 -0
  110. package/benches/contrib/oss-lru-cache/prompts/fetch-size.md +5 -0
  111. package/benches/contrib/oss-lru-cache/provenance.json +62 -0
  112. package/benches/contrib/oss-lru-cache/runtime.mjs +22 -0
  113. package/benches/contrib/oss-lru-cache/verifiers/cases.mjs +74 -0
  114. package/benches/contrib/oss-lru-cache/verifiers/fetch-abort.mjs +3 -0
  115. package/benches/contrib/oss-lru-cache/verifiers/fetch-lifecycle.mjs +3 -0
  116. package/benches/contrib/oss-lru-cache/verifiers/fetch-size.mjs +3 -0
  117. package/benches/contrib/oss-lru-cache/verifiers/probe.mjs +14 -0
  118. package/benches/contrib/oss-lru-cache/verifiers/shared.mjs +130 -0
  119. package/benches/contrib/oss-lru-cache/verifiers/test-reporter.mjs +29 -0
  120. package/benches/contrib/oss-mcp-use-utf8/LICENSE.upstream +21 -0
  121. package/benches/contrib/oss-mcp-use-utf8/README.md +56 -0
  122. package/benches/contrib/oss-mcp-use-utf8/bench.json +16 -0
  123. package/benches/contrib/oss-mcp-use-utf8/fixtures/view-utf8/LICENSE +21 -0
  124. package/benches/contrib/oss-mcp-use-utf8/fixtures/view-utf8/package.json +3 -0
  125. package/benches/contrib/oss-mcp-use-utf8/fixtures/view-utf8/src/ext-apps-bridge.js +3 -0
  126. package/benches/contrib/oss-mcp-use-utf8/fixtures/view-utf8/src/resolve-view-resource.ts +96 -0
  127. package/benches/contrib/oss-mcp-use-utf8/fixtures/view-utf8/test/basic.test.mjs +13 -0
  128. package/benches/contrib/oss-mcp-use-utf8/ground-truth/README.md +5 -0
  129. package/benches/contrib/oss-mcp-use-utf8/ground-truth/oracle-view-utf8.mjs +11 -0
  130. package/benches/contrib/oss-mcp-use-utf8/ground-truth/solutions/view-utf8/src/resolve-view-resource.ts +96 -0
  131. package/benches/contrib/oss-mcp-use-utf8/ground-truth/solutions/view-utf8/test/utf8.regression.test.mjs +14 -0
  132. package/benches/contrib/oss-mcp-use-utf8/prompts/view-utf8.md +8 -0
  133. package/benches/contrib/oss-mcp-use-utf8/verifiers/view-utf8.mjs +120 -0
  134. package/benches/contrib/waza-behavior/LICENSE.upstream +21 -0
  135. package/benches/contrib/waza-behavior/README.md +31 -0
  136. package/benches/contrib/waza-behavior/bench.json +10 -0
  137. package/benches/contrib/waza-behavior/fixtures/explicit-hold/README.md +1 -0
  138. package/benches/contrib/waza-behavior/fixtures/explicit-hold/notes.txt +1 -0
  139. package/benches/contrib/waza-behavior/fixtures/receipt-current/README.md +1 -0
  140. package/benches/contrib/waza-behavior/fixtures/receipt-current/docs/guide.md +2 -0
  141. package/benches/contrib/waza-behavior/fixtures/receipt-current/notes.txt +1 -0
  142. package/benches/contrib/waza-behavior/fixtures/receipt-current/scripts/check-links.mjs +16 -0
  143. package/benches/contrib/waza-behavior/fixtures/receipt-current/validation-receipt.json +10 -0
  144. package/benches/contrib/waza-behavior/fixtures/receipt-stale/README.md +1 -0
  145. package/benches/contrib/waza-behavior/fixtures/receipt-stale/docs/guide.md +3 -0
  146. package/benches/contrib/waza-behavior/fixtures/receipt-stale/notes.txt +1 -0
  147. package/benches/contrib/waza-behavior/fixtures/receipt-stale/scripts/check-links.mjs +16 -0
  148. package/benches/contrib/waza-behavior/fixtures/receipt-stale/validation-receipt.json +10 -0
  149. package/benches/contrib/waza-behavior/ground-truth/oracle.mjs +24 -0
  150. package/benches/contrib/waza-behavior/prompts/explicit-hold.md +1 -0
  151. package/benches/contrib/waza-behavior/prompts/receipt-current.md +1 -0
  152. package/benches/contrib/waza-behavior/prompts/receipt-stale.md +1 -0
  153. package/benches/contrib/waza-behavior/verifiers/behavior.mjs +59 -0
  154. package/benches/debugging/bench.json +93 -0
  155. package/benches/debugging/fixtures/async-queue/src/task-queue.mjs +50 -0
  156. package/benches/debugging/fixtures/async-queue/test/basic.test.mjs +18 -0
  157. package/benches/debugging/fixtures/chunked-decoder/src/frame-decoder.mjs +39 -0
  158. package/benches/debugging/fixtures/chunked-decoder/test/basic.test.mjs +17 -0
  159. package/benches/debugging/fixtures/debug-redaction/src/debug-redaction.mjs +33 -0
  160. package/benches/debugging/fixtures/debug-redaction/test/basic.test.mjs +26 -0
  161. package/benches/debugging/fixtures/document-queue/.skillfit-mock.json +16 -0
  162. package/benches/debugging/fixtures/document-queue/src/task-queue.mjs +52 -0
  163. package/benches/debugging/fixtures/document-queue/test/basic.test.mjs +23 -0
  164. package/benches/debugging/fixtures/explain-cache/.skillfit-mock.json +16 -0
  165. package/benches/debugging/fixtures/explain-cache/src/ttl-cache.mjs +31 -0
  166. package/benches/debugging/fixtures/explain-cache/test/basic.test.mjs +28 -0
  167. package/benches/debugging/fixtures/feat-slug/test/slug.test.mjs +15 -0
  168. package/benches/debugging/fixtures/range-parser/src/range-parser.mjs +9 -0
  169. package/benches/debugging/fixtures/range-parser/test/basic.test.mjs +8 -0
  170. package/benches/debugging/fixtures/ttl-cache/src/ttl-cache.mjs +30 -0
  171. package/benches/debugging/fixtures/ttl-cache/test/basic.test.mjs +11 -0
  172. package/benches/debugging/ground-truth/async-queue.md +81 -0
  173. package/benches/debugging/ground-truth/chunked-decoder.md +91 -0
  174. package/benches/debugging/ground-truth/debug-redaction.md +113 -0
  175. package/benches/debugging/ground-truth/document-queue.md +24 -0
  176. package/benches/debugging/ground-truth/explain-cache.md +22 -0
  177. package/benches/debugging/ground-truth/feat-slug.md +45 -0
  178. package/benches/debugging/ground-truth/oracle-async-queue.mjs +14 -0
  179. package/benches/debugging/ground-truth/oracle-chunked-decoder.mjs +14 -0
  180. package/benches/debugging/ground-truth/oracle-debug-redaction.mjs +30 -0
  181. package/benches/debugging/ground-truth/oracle-document-queue.mjs +27 -0
  182. package/benches/debugging/ground-truth/oracle-explain-cache.mjs +28 -0
  183. package/benches/debugging/ground-truth/oracle-feat-slug.mjs +13 -0
  184. package/benches/debugging/ground-truth/oracle-range-parser.mjs +14 -0
  185. package/benches/debugging/ground-truth/oracle-ttl-cache.mjs +14 -0
  186. package/benches/debugging/ground-truth/range-parser.md +121 -0
  187. package/benches/debugging/ground-truth/solutions/async-queue/src/task-queue.mjs +52 -0
  188. package/benches/debugging/ground-truth/solutions/chunked-decoder/src/frame-decoder.mjs +50 -0
  189. package/benches/debugging/ground-truth/solutions/debug-redaction/src/debug-redaction.mjs +27 -0
  190. package/benches/debugging/ground-truth/solutions/debug-redaction/test/debug-leak.regression.test.mjs +27 -0
  191. package/benches/debugging/ground-truth/solutions/feat-slug/src/slug.mjs +6 -0
  192. package/benches/debugging/ground-truth/solutions/range-parser/src/range-parser.mjs +34 -0
  193. package/benches/debugging/ground-truth/solutions/range-parser/test/basic.test.mjs +26 -0
  194. package/benches/debugging/ground-truth/solutions/ttl-cache/src/ttl-cache.mjs +31 -0
  195. package/benches/debugging/ground-truth/ttl-cache.md +69 -0
  196. package/benches/debugging/prompts/async-queue.md +13 -0
  197. package/benches/debugging/prompts/async-queue.trigger.md +13 -0
  198. package/benches/debugging/prompts/chunked-decoder.md +13 -0
  199. package/benches/debugging/prompts/chunked-decoder.trigger.md +13 -0
  200. package/benches/debugging/prompts/debug-redaction.md +23 -0
  201. package/benches/debugging/prompts/debug-redaction.trigger.md +23 -0
  202. package/benches/debugging/prompts/document-queue.md +10 -0
  203. package/benches/debugging/prompts/document-queue.trigger.md +10 -0
  204. package/benches/debugging/prompts/explain-cache.md +10 -0
  205. package/benches/debugging/prompts/explain-cache.trigger.md +10 -0
  206. package/benches/debugging/prompts/feat-slug.md +3 -0
  207. package/benches/debugging/prompts/feat-slug.trigger.md +5 -0
  208. package/benches/debugging/prompts/range-parser.md +15 -0
  209. package/benches/debugging/prompts/range-parser.trigger.md +15 -0
  210. package/benches/debugging/prompts/ttl-cache.md +18 -0
  211. package/benches/debugging/prompts/ttl-cache.trigger.md +18 -0
  212. package/benches/debugging/verifiers/async-queue.mjs +221 -0
  213. package/benches/debugging/verifiers/chunked-decoder.mjs +208 -0
  214. package/benches/debugging/verifiers/debug-redaction.mjs +283 -0
  215. package/benches/debugging/verifiers/document-queue.mjs +52 -0
  216. package/benches/debugging/verifiers/explain-cache.mjs +62 -0
  217. package/benches/debugging/verifiers/feat-slug.mjs +127 -0
  218. package/benches/debugging/verifiers/range-parser.mjs +146 -0
  219. package/benches/debugging/verifiers/ttl-cache.mjs +111 -0
  220. package/dist/agents.js +26 -0
  221. package/dist/cli.js +310 -0
  222. package/dist/cli.test.js +76 -0
  223. package/dist/commands/bench.js +1035 -0
  224. package/dist/commands/bench.test.js +1061 -0
  225. package/dist/commands/bundle.js +334 -0
  226. package/dist/commands/bundle.test.js +142 -0
  227. package/dist/commands/confirm.js +39 -0
  228. package/dist/commands/doctor.js +399 -0
  229. package/dist/commands/doctor.test.js +280 -0
  230. package/dist/commands/eval-report.js +485 -0
  231. package/dist/commands/eval-report.test.js +306 -0
  232. package/dist/commands/eval.js +391 -0
  233. package/dist/commands/eval.test.js +446 -0
  234. package/dist/commands/install.js +653 -0
  235. package/dist/commands/install.test.js +555 -0
  236. package/dist/commands/mcp.js +20 -0
  237. package/dist/commands/report.js +78 -0
  238. package/dist/commands/report.test.js +110 -0
  239. package/dist/commands/setup.js +95 -0
  240. package/dist/commands/setup.test.js +150 -0
  241. package/dist/commands/upstream.js +210 -0
  242. package/dist/commands/upstream.test.js +139 -0
  243. package/dist/docs.test.js +154 -0
  244. package/dist/frontmatter.js +53 -0
  245. package/dist/frontmatter.test.js +49 -0
  246. package/dist/harness/bench.js +134 -0
  247. package/dist/harness/bench.test.js +109 -0
  248. package/dist/harness/bundle.js +46 -0
  249. package/dist/harness/bundle.test.js +71 -0
  250. package/dist/harness/constants.js +2 -0
  251. package/dist/harness/executors/api.js +68 -0
  252. package/dist/harness/executors/api.test.js +75 -0
  253. package/dist/harness/executors/cli.js +348 -0
  254. package/dist/harness/executors/cli.test.js +402 -0
  255. package/dist/harness/executors/mock.js +34 -0
  256. package/dist/harness/executors/mock.test.js +43 -0
  257. package/dist/harness/experiment-session.js +345 -0
  258. package/dist/harness/experiment-session.test.js +223 -0
  259. package/dist/harness/hash.js +29 -0
  260. package/dist/harness/installed-skill.js +78 -0
  261. package/dist/harness/installed-skill.test.js +162 -0
  262. package/dist/harness/judge.js +108 -0
  263. package/dist/harness/judge.test.js +181 -0
  264. package/dist/harness/kill-tree.js +43 -0
  265. package/dist/harness/kimi-usage.js +94 -0
  266. package/dist/harness/kimi-usage.test.js +62 -0
  267. package/dist/harness/oss-lru-cache.test.js +79 -0
  268. package/dist/harness/oss-regression-witness.test.js +89 -0
  269. package/dist/harness/prompt.js +57 -0
  270. package/dist/harness/prompt.test.js +48 -0
  271. package/dist/harness/receipts.js +297 -0
  272. package/dist/harness/receipts.test.js +148 -0
  273. package/dist/harness/report.js +225 -0
  274. package/dist/harness/report.test.js +297 -0
  275. package/dist/harness/runner.js +629 -0
  276. package/dist/harness/runner.test.js +555 -0
  277. package/dist/harness/stats.js +93 -0
  278. package/dist/harness/stats.test.js +124 -0
  279. package/dist/harness/target.js +90 -0
  280. package/dist/harness/target.test.js +60 -0
  281. package/dist/harness/trigger.js +368 -0
  282. package/dist/harness/trigger.test.js +249 -0
  283. package/dist/harness/types.js +1 -0
  284. package/dist/harness/verifier-summary.js +59 -0
  285. package/dist/harness/verifier-summary.test.js +99 -0
  286. package/dist/harness/waza-behavior.test.js +139 -0
  287. package/dist/invocation.js +21 -0
  288. package/dist/matrix/agents.json +200 -0
  289. package/dist/matrix/agents.schema.json +152 -0
  290. package/dist/mcp/probe.js +317 -0
  291. package/dist/mcp/probe.test.js +87 -0
  292. package/dist/version.js +4 -0
  293. package/docs/assets/skillfit-flow.en.svg +47 -0
  294. package/docs/assets/skillfit-flow.zh-CN.svg +47 -0
  295. package/docs/assets/skillfit-mark.svg +9 -0
  296. package/docs/audit-2026-09-24-triage.md +231 -0
  297. package/docs/audit-2026-09-24.md +876 -0
  298. package/docs/bench-authoring.md +407 -0
  299. package/docs/codex-upstream-audit.md +41 -0
  300. package/docs/config-experiments.md +119 -0
  301. package/docs/examples/bench-check.yml +32 -0
  302. package/docs/examples/eval-manifest.synthetic.json +61 -0
  303. package/docs/experiment-workflow.md +15 -0
  304. package/docs/first-real-eval.md +90 -0
  305. package/docs/growth-roadmap-2026-10.md +100 -0
  306. package/docs/installed-skill-evaluation.md +77 -0
  307. package/docs/metrics.md +318 -0
  308. package/docs/oss-task-evaluation.md +139 -0
  309. package/docs/plans/2026-10-01-oss-task-evaluation.md +73 -0
  310. package/docs/plans/2026-10-09-experiment-workflow.md +18 -0
  311. package/docs/plans/2026-10-09-grader-calibration-audit.md +13 -0
  312. package/docs/plans/2026-10-09-waza-resource-evaluation.md +46 -0
  313. package/docs/portable-codex.md +31 -0
  314. package/docs/reproducible-offline-example.md +29 -0
  315. package/docs/selectable-codex.md +41 -0
  316. package/docs/sharing-results.md +53 -0
  317. package/evidence/2026-07-skill-baseline.md +34 -0
  318. package/evidence/2026-09-22-codex-trigger-capture.md +36 -0
  319. package/evidence/2026-09-bench-calibration.md +46 -0
  320. package/evidence/2026-09-debugging-bench-exploratory.md +55 -0
  321. package/evidence/2026-09-debugging-hardening.md +42 -0
  322. package/evidence/2026-09-ocr-vs-code-review.md +31 -0
  323. package/evidence/2026-09-trigger-snapshot-correction.md +48 -0
  324. package/evidence/2026-10-01-codex-diagnosing-bugs-pilot.md +58 -0
  325. package/evidence/2026-10-01-oss-case-selection.md +42 -0
  326. package/evidence/2026-10-01-oss-workspace-smoke.md +110 -0
  327. package/evidence/README.md +47 -0
  328. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/README.md +27 -0
  329. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/artifact-index.json +118 -0
  330. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/output.md +5 -0
  331. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/prompt.txt +14 -0
  332. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/result.json +65 -0
  333. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/verifier.txt +2 -0
  334. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/LICENSE +21 -0
  335. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/package.json +3 -0
  336. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/src/ext-apps-bridge.js +3 -0
  337. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/src/resolve-view-resource.ts +100 -0
  338. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/test/basic.test.mjs +13 -0
  339. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/baseline/workspace/test/resolve-view-resource.test.mjs +102 -0
  340. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/manifest.json +206 -0
  341. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/original-console.txt +44 -0
  342. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/report.md +67 -0
  343. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/output.md +5 -0
  344. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/prompt.txt +163 -0
  345. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/result.json +65 -0
  346. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/verifier.txt +2 -0
  347. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/LICENSE +21 -0
  348. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/package.json +3 -0
  349. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/src/ext-apps-bridge.js +3 -0
  350. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/src/resolve-view-resource.ts +100 -0
  351. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/test/basic.test.mjs +13 -0
  352. package/evidence/artifacts/2026-10-01-oss-workspace-smoke/treatment/workspace/test/resolve-view-resource.test.mjs +136 -0
  353. package/evidence/inputs/README.md +15 -0
  354. package/evidence/inputs/diagnosing-bugs/LICENSE +21 -0
  355. package/evidence/inputs/diagnosing-bugs/SKILL.md +138 -0
  356. package/evidence/inputs/diagnosing-bugs/agents/openai.yaml +3 -0
  357. package/evidence/inputs/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
  358. package/evidence/plans/2026-10-01-oss-workspace-smoke.json +29 -0
  359. package/package.json +47 -4
  360. package/profiles/codex-curated/catalog.json +28 -0
  361. package/profiles/codex-curated/profile.json +282 -0
  362. package/profiles/codex-curated/rules/global.md +12 -0
  363. package/profiles/codex-curated/skills/autonomous-iteration/SKILL.md +75 -0
  364. package/profiles/codex-curated/skills/autonomous-iteration/agents/openai.yaml +4 -0
  365. package/profiles/codex-curated/skills/vibe-coding/SKILL.md +45 -0
  366. package/profiles/codex-curated/skills/vibe-coding/agents/openai.yaml +4 -0
  367. package/profiles/codex-upstream-sources.json +2980 -0
  368. package/profiles/recommended/profile.json +12 -0
  369. package/profiles/recommended/rules/core-workflow.md +41 -0
  370. package/profiles/recommended/skills/commit-message/SKILL.md +18 -0
  371. package/skills/skillfit/SKILL.md +60 -0
@@ -0,0 +1,1044 @@
1
+ const perf =
2
+ typeof performance === 'object' &&
3
+ performance &&
4
+ typeof performance.now === 'function'
5
+ ? performance
6
+ : Date
7
+
8
+ const hasAbortController = typeof AbortController === 'function'
9
+
10
+ // minimal backwards-compatibility polyfill
11
+ // this doesn't have nearly all the checks and whatnot that
12
+ // actual AbortController/Signal has, but it's enough for
13
+ // our purposes, and if used properly, behaves the same.
14
+ const AC = hasAbortController
15
+ ? AbortController
16
+ : class AbortController {
17
+ constructor() {
18
+ this.signal = new AS()
19
+ }
20
+ abort() {
21
+ this.signal.dispatchEvent({
22
+ type: 'abort',
23
+ target: this.signal,
24
+ })
25
+ }
26
+ }
27
+
28
+ const hasAbortSignal = typeof AbortSignal === 'function'
29
+ // Some polyfills put this on the AC class, not global
30
+ const hasACAbortSignal = typeof AC.AbortSignal === 'function'
31
+ const AS = hasAbortSignal
32
+ ? AbortSignal
33
+ : hasACAbortSignal
34
+ ? AC.AbortController
35
+ : class AbortSignal {
36
+ constructor() {
37
+ this.aborted = false
38
+ this._listeners = []
39
+ }
40
+ dispatchEvent(e) {
41
+ if (e.type === 'abort') {
42
+ this.aborted = true
43
+ this.onabort(e)
44
+ this._listeners.forEach(f => f(e), this)
45
+ }
46
+ }
47
+ onabort() {}
48
+ addEventListener(ev, fn) {
49
+ if (ev === 'abort') {
50
+ this._listeners.push(fn)
51
+ }
52
+ }
53
+ removeEventListener(ev, fn) {
54
+ if (ev === 'abort') {
55
+ this._listeners = this._listeners.filter(f => f !== fn)
56
+ }
57
+ }
58
+ }
59
+
60
+ const warned = new Set()
61
+ const deprecatedOption = (opt, instead) => {
62
+ const code = `LRU_CACHE_OPTION_${opt}`
63
+ if (shouldWarn(code)) {
64
+ warn(code, `${opt} option`, `options.${instead}`, LRUCache)
65
+ }
66
+ }
67
+ const deprecatedMethod = (method, instead) => {
68
+ const code = `LRU_CACHE_METHOD_${method}`
69
+ if (shouldWarn(code)) {
70
+ const { prototype } = LRUCache
71
+ const { get } = Object.getOwnPropertyDescriptor(prototype, method)
72
+ warn(code, `${method} method`, `cache.${instead}()`, get)
73
+ }
74
+ }
75
+ const deprecatedProperty = (field, instead) => {
76
+ const code = `LRU_CACHE_PROPERTY_${field}`
77
+ if (shouldWarn(code)) {
78
+ const { prototype } = LRUCache
79
+ const { get } = Object.getOwnPropertyDescriptor(prototype, field)
80
+ warn(code, `${field} property`, `cache.${instead}`, get)
81
+ }
82
+ }
83
+
84
+ const emitWarning = (...a) => {
85
+ typeof process === 'object' &&
86
+ process &&
87
+ typeof process.emitWarning === 'function'
88
+ ? process.emitWarning(...a)
89
+ : console.error(...a)
90
+ }
91
+
92
+ const shouldWarn = code => !warned.has(code)
93
+
94
+ const warn = (code, what, instead, fn) => {
95
+ warned.add(code)
96
+ const msg = `The ${what} is deprecated. Please use ${instead} instead.`
97
+ emitWarning(msg, 'DeprecationWarning', code, fn)
98
+ }
99
+
100
+ const isPosInt = n => n && n === Math.floor(n) && n > 0 && isFinite(n)
101
+
102
+ /* istanbul ignore next - This is a little bit ridiculous, tbh.
103
+ * The maximum array length is 2^32-1 or thereabouts on most JS impls.
104
+ * And well before that point, you're caching the entire world, I mean,
105
+ * that's ~32GB of just integers for the next/prev links, plus whatever
106
+ * else to hold that many keys and values. Just filling the memory with
107
+ * zeroes at init time is brutal when you get that big.
108
+ * But why not be complete?
109
+ * Maybe in the future, these limits will have expanded. */
110
+ const getUintArray = max =>
111
+ !isPosInt(max)
112
+ ? null
113
+ : max <= Math.pow(2, 8)
114
+ ? Uint8Array
115
+ : max <= Math.pow(2, 16)
116
+ ? Uint16Array
117
+ : max <= Math.pow(2, 32)
118
+ ? Uint32Array
119
+ : max <= Number.MAX_SAFE_INTEGER
120
+ ? ZeroArray
121
+ : null
122
+
123
+ class ZeroArray extends Array {
124
+ constructor(size) {
125
+ super(size)
126
+ this.fill(0)
127
+ }
128
+ }
129
+
130
+ class Stack {
131
+ constructor(max) {
132
+ if (max === 0) {
133
+ return []
134
+ }
135
+ const UintArray = getUintArray(max)
136
+ this.heap = new UintArray(max)
137
+ this.length = 0
138
+ }
139
+ push(n) {
140
+ this.heap[this.length++] = n
141
+ }
142
+ pop() {
143
+ return this.heap[--this.length]
144
+ }
145
+ }
146
+
147
+ class LRUCache {
148
+ constructor(options = {}) {
149
+ const {
150
+ max = 0,
151
+ ttl,
152
+ ttlResolution = 1,
153
+ ttlAutopurge,
154
+ updateAgeOnGet,
155
+ updateAgeOnHas,
156
+ allowStale,
157
+ dispose,
158
+ disposeAfter,
159
+ noDisposeOnSet,
160
+ noUpdateTTL,
161
+ maxSize = 0,
162
+ maxEntrySize = 0,
163
+ sizeCalculation,
164
+ fetchMethod,
165
+ fetchContext,
166
+ noDeleteOnFetchRejection,
167
+ noDeleteOnStaleGet,
168
+ allowStaleOnFetchRejection,
169
+ } = options
170
+
171
+ // deprecated options, don't trigger a warning for getting them if
172
+ // the thing being passed in is another LRUCache we're copying.
173
+ const { length, maxAge, stale } =
174
+ options instanceof LRUCache ? {} : options
175
+
176
+ if (max !== 0 && !isPosInt(max)) {
177
+ throw new TypeError('max option must be a nonnegative integer')
178
+ }
179
+
180
+ const UintArray = max ? getUintArray(max) : Array
181
+ if (!UintArray) {
182
+ throw new Error('invalid max value: ' + max)
183
+ }
184
+
185
+ this.max = max
186
+ this.maxSize = maxSize
187
+ this.maxEntrySize = maxEntrySize || this.maxSize
188
+ this.sizeCalculation = sizeCalculation || length
189
+ if (this.sizeCalculation) {
190
+ if (!this.maxSize && !this.maxEntrySize) {
191
+ throw new TypeError(
192
+ 'cannot set sizeCalculation without setting maxSize or maxEntrySize'
193
+ )
194
+ }
195
+ if (typeof this.sizeCalculation !== 'function') {
196
+ throw new TypeError('sizeCalculation set to non-function')
197
+ }
198
+ }
199
+
200
+ this.fetchMethod = fetchMethod || null
201
+ if (this.fetchMethod && typeof this.fetchMethod !== 'function') {
202
+ throw new TypeError(
203
+ 'fetchMethod must be a function if specified'
204
+ )
205
+ }
206
+
207
+ this.fetchContext = fetchContext
208
+ if (!this.fetchMethod && fetchContext !== undefined) {
209
+ throw new TypeError(
210
+ 'cannot set fetchContext without fetchMethod'
211
+ )
212
+ }
213
+
214
+ this.keyMap = new Map()
215
+ this.keyList = new Array(max).fill(null)
216
+ this.valList = new Array(max).fill(null)
217
+ this.next = new UintArray(max)
218
+ this.prev = new UintArray(max)
219
+ this.head = 0
220
+ this.tail = 0
221
+ this.free = new Stack(max)
222
+ this.initialFill = 1
223
+ this.size = 0
224
+
225
+ if (typeof dispose === 'function') {
226
+ this.dispose = dispose
227
+ }
228
+ if (typeof disposeAfter === 'function') {
229
+ this.disposeAfter = disposeAfter
230
+ this.disposed = []
231
+ } else {
232
+ this.disposeAfter = null
233
+ this.disposed = null
234
+ }
235
+ this.noDisposeOnSet = !!noDisposeOnSet
236
+ this.noUpdateTTL = !!noUpdateTTL
237
+ this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection
238
+ this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection
239
+
240
+ // NB: maxEntrySize is set to maxSize if it's set
241
+ if (this.maxEntrySize !== 0) {
242
+ if (this.maxSize !== 0) {
243
+ if (!isPosInt(this.maxSize)) {
244
+ throw new TypeError(
245
+ 'maxSize must be a positive integer if specified'
246
+ )
247
+ }
248
+ }
249
+ if (!isPosInt(this.maxEntrySize)) {
250
+ throw new TypeError(
251
+ 'maxEntrySize must be a positive integer if specified'
252
+ )
253
+ }
254
+ this.initializeSizeTracking()
255
+ }
256
+
257
+ this.allowStale = !!allowStale || !!stale
258
+ this.noDeleteOnStaleGet = !!noDeleteOnStaleGet
259
+ this.updateAgeOnGet = !!updateAgeOnGet
260
+ this.updateAgeOnHas = !!updateAgeOnHas
261
+ this.ttlResolution =
262
+ isPosInt(ttlResolution) || ttlResolution === 0
263
+ ? ttlResolution
264
+ : 1
265
+ this.ttlAutopurge = !!ttlAutopurge
266
+ this.ttl = ttl || maxAge || 0
267
+ if (this.ttl) {
268
+ if (!isPosInt(this.ttl)) {
269
+ throw new TypeError(
270
+ 'ttl must be a positive integer if specified'
271
+ )
272
+ }
273
+ this.initializeTTLTracking()
274
+ }
275
+
276
+ // do not allow completely unbounded caches
277
+ if (this.max === 0 && this.ttl === 0 && this.maxSize === 0) {
278
+ throw new TypeError(
279
+ 'At least one of max, maxSize, or ttl is required'
280
+ )
281
+ }
282
+ if (!this.ttlAutopurge && !this.max && !this.maxSize) {
283
+ const code = 'LRU_CACHE_UNBOUNDED'
284
+ if (shouldWarn(code)) {
285
+ warned.add(code)
286
+ const msg =
287
+ 'TTL caching without ttlAutopurge, max, or maxSize can ' +
288
+ 'result in unbounded memory consumption.'
289
+ emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache)
290
+ }
291
+ }
292
+
293
+ if (stale) {
294
+ deprecatedOption('stale', 'allowStale')
295
+ }
296
+ if (maxAge) {
297
+ deprecatedOption('maxAge', 'ttl')
298
+ }
299
+ if (length) {
300
+ deprecatedOption('length', 'sizeCalculation')
301
+ }
302
+ }
303
+
304
+ getRemainingTTL(key) {
305
+ return this.has(key, { updateAgeOnHas: false }) ? Infinity : 0
306
+ }
307
+
308
+ initializeTTLTracking() {
309
+ this.ttls = new ZeroArray(this.max)
310
+ this.starts = new ZeroArray(this.max)
311
+
312
+ this.setItemTTL = (index, ttl, start = perf.now()) => {
313
+ this.starts[index] = ttl !== 0 ? start : 0
314
+ this.ttls[index] = ttl
315
+ if (ttl !== 0 && this.ttlAutopurge) {
316
+ const t = setTimeout(() => {
317
+ if (this.isStale(index)) {
318
+ this.delete(this.keyList[index])
319
+ }
320
+ }, ttl + 1)
321
+ /* istanbul ignore else - unref() not supported on all platforms */
322
+ if (t.unref) {
323
+ t.unref()
324
+ }
325
+ }
326
+ }
327
+
328
+ this.updateItemAge = index => {
329
+ this.starts[index] = this.ttls[index] !== 0 ? perf.now() : 0
330
+ }
331
+
332
+ // debounce calls to perf.now() to 1s so we're not hitting
333
+ // that costly call repeatedly.
334
+ let cachedNow = 0
335
+ const getNow = () => {
336
+ const n = perf.now()
337
+ if (this.ttlResolution > 0) {
338
+ cachedNow = n
339
+ const t = setTimeout(
340
+ () => (cachedNow = 0),
341
+ this.ttlResolution
342
+ )
343
+ /* istanbul ignore else - not available on all platforms */
344
+ if (t.unref) {
345
+ t.unref()
346
+ }
347
+ }
348
+ return n
349
+ }
350
+
351
+ this.getRemainingTTL = key => {
352
+ const index = this.keyMap.get(key)
353
+ if (index === undefined) {
354
+ return 0
355
+ }
356
+ return this.ttls[index] === 0 || this.starts[index] === 0
357
+ ? Infinity
358
+ : this.starts[index] +
359
+ this.ttls[index] -
360
+ (cachedNow || getNow())
361
+ }
362
+
363
+ this.isStale = index => {
364
+ return (
365
+ this.ttls[index] !== 0 &&
366
+ this.starts[index] !== 0 &&
367
+ (cachedNow || getNow()) - this.starts[index] >
368
+ this.ttls[index]
369
+ )
370
+ }
371
+ }
372
+ updateItemAge(index) {}
373
+ setItemTTL(index, ttl, start) {}
374
+ isStale(index) {
375
+ return false
376
+ }
377
+
378
+ initializeSizeTracking() {
379
+ this.calculatedSize = 0
380
+ this.sizes = new ZeroArray(this.max)
381
+ this.removeItemSize = index => {
382
+ this.calculatedSize -= this.sizes[index]
383
+ this.sizes[index] = 0
384
+ }
385
+ this.requireSize = (k, v, size, sizeCalculation) => {
386
+ // provisionally accept background fetches.
387
+ // actual value size will be checked when they return.
388
+ if (this.isBackgroundFetch(v)) {
389
+ return 0
390
+ }
391
+ if (!isPosInt(size)) {
392
+ if (sizeCalculation) {
393
+ if (typeof sizeCalculation !== 'function') {
394
+ throw new TypeError('sizeCalculation must be a function')
395
+ }
396
+ size = sizeCalculation(v, k)
397
+ if (!isPosInt(size)) {
398
+ throw new TypeError(
399
+ 'sizeCalculation return invalid (expect positive integer)'
400
+ )
401
+ }
402
+ } else {
403
+ throw new TypeError(
404
+ 'invalid size value (must be positive integer). ' +
405
+ 'When maxSize or maxEntrySize is used, sizeCalculation or size ' +
406
+ 'must be set.'
407
+ )
408
+ }
409
+ }
410
+ return size
411
+ }
412
+ this.addItemSize = (index, size) => {
413
+ this.sizes[index] = size
414
+ if (this.maxSize) {
415
+ const maxSize = this.maxSize - this.sizes[index]
416
+ while (this.calculatedSize > maxSize) {
417
+ this.evict(true)
418
+ }
419
+ }
420
+ this.calculatedSize += this.sizes[index]
421
+ }
422
+ }
423
+ removeItemSize(index) {}
424
+ addItemSize(index, size) {}
425
+ requireSize(k, v, size, sizeCalculation) {
426
+ if (size || sizeCalculation) {
427
+ throw new TypeError(
428
+ 'cannot set size without setting maxSize or maxEntrySize on cache'
429
+ )
430
+ }
431
+ }
432
+
433
+ *indexes({ allowStale = this.allowStale } = {}) {
434
+ if (this.size) {
435
+ for (let i = this.tail; true; ) {
436
+ if (!this.isValidIndex(i)) {
437
+ break
438
+ }
439
+ if (allowStale || !this.isStale(i)) {
440
+ yield i
441
+ }
442
+ if (i === this.head) {
443
+ break
444
+ } else {
445
+ i = this.prev[i]
446
+ }
447
+ }
448
+ }
449
+ }
450
+
451
+ *rindexes({ allowStale = this.allowStale } = {}) {
452
+ if (this.size) {
453
+ for (let i = this.head; true; ) {
454
+ if (!this.isValidIndex(i)) {
455
+ break
456
+ }
457
+ if (allowStale || !this.isStale(i)) {
458
+ yield i
459
+ }
460
+ if (i === this.tail) {
461
+ break
462
+ } else {
463
+ i = this.next[i]
464
+ }
465
+ }
466
+ }
467
+ }
468
+
469
+ isValidIndex(index) {
470
+ return this.keyMap.get(this.keyList[index]) === index
471
+ }
472
+
473
+ *entries() {
474
+ for (const i of this.indexes()) {
475
+ if (!this.isBackgroundFetch(this.valList[i])) {
476
+ yield [this.keyList[i], this.valList[i]]
477
+ }
478
+ }
479
+ }
480
+ *rentries() {
481
+ for (const i of this.rindexes()) {
482
+ if (!this.isBackgroundFetch(this.valList[i])) {
483
+ yield [this.keyList[i], this.valList[i]]
484
+ }
485
+ }
486
+ }
487
+
488
+ *keys() {
489
+ for (const i of this.indexes()) {
490
+ if (!this.isBackgroundFetch(this.valList[i])) {
491
+ yield this.keyList[i]
492
+ }
493
+ }
494
+ }
495
+ *rkeys() {
496
+ for (const i of this.rindexes()) {
497
+ if (!this.isBackgroundFetch(this.valList[i])) {
498
+ yield this.keyList[i]
499
+ }
500
+ }
501
+ }
502
+
503
+ *values() {
504
+ for (const i of this.indexes()) {
505
+ if (!this.isBackgroundFetch(this.valList[i])) {
506
+ yield this.valList[i]
507
+ }
508
+ }
509
+ }
510
+ *rvalues() {
511
+ for (const i of this.rindexes()) {
512
+ if (!this.isBackgroundFetch(this.valList[i])) {
513
+ yield this.valList[i]
514
+ }
515
+ }
516
+ }
517
+
518
+ [Symbol.iterator]() {
519
+ return this.entries()
520
+ }
521
+
522
+ find(fn, getOptions = {}) {
523
+ for (const i of this.indexes()) {
524
+ if (fn(this.valList[i], this.keyList[i], this)) {
525
+ return this.get(this.keyList[i], getOptions)
526
+ }
527
+ }
528
+ }
529
+
530
+ forEach(fn, thisp = this) {
531
+ for (const i of this.indexes()) {
532
+ fn.call(thisp, this.valList[i], this.keyList[i], this)
533
+ }
534
+ }
535
+
536
+ rforEach(fn, thisp = this) {
537
+ for (const i of this.rindexes()) {
538
+ fn.call(thisp, this.valList[i], this.keyList[i], this)
539
+ }
540
+ }
541
+
542
+ get prune() {
543
+ deprecatedMethod('prune', 'purgeStale')
544
+ return this.purgeStale
545
+ }
546
+
547
+ purgeStale() {
548
+ let deleted = false
549
+ for (const i of this.rindexes({ allowStale: true })) {
550
+ if (this.isStale(i)) {
551
+ this.delete(this.keyList[i])
552
+ deleted = true
553
+ }
554
+ }
555
+ return deleted
556
+ }
557
+
558
+ dump() {
559
+ const arr = []
560
+ for (const i of this.indexes({ allowStale: true })) {
561
+ const key = this.keyList[i]
562
+ const v = this.valList[i]
563
+ const value = this.isBackgroundFetch(v)
564
+ ? v.__staleWhileFetching
565
+ : v
566
+ if (value === undefined) continue
567
+ const entry = { value }
568
+ if (this.ttls) {
569
+ entry.ttl = this.ttls[i]
570
+ // always dump the start relative to a portable timestamp
571
+ // it's ok for this to be a bit slow, it's a rare operation.
572
+ const age = perf.now() - this.starts[i]
573
+ entry.start = Math.floor(Date.now() - age)
574
+ }
575
+ if (this.sizes) {
576
+ entry.size = this.sizes[i]
577
+ }
578
+ arr.unshift([key, entry])
579
+ }
580
+ return arr
581
+ }
582
+
583
+ load(arr) {
584
+ this.clear()
585
+ for (const [key, entry] of arr) {
586
+ if (entry.start) {
587
+ // entry.start is a portable timestamp, but we may be using
588
+ // node's performance.now(), so calculate the offset.
589
+ // it's ok for this to be a bit slow, it's a rare operation.
590
+ const age = Date.now() - entry.start
591
+ entry.start = perf.now() - age
592
+ }
593
+ this.set(key, entry.value, entry)
594
+ }
595
+ }
596
+
597
+ dispose(v, k, reason) {}
598
+
599
+ set(
600
+ k,
601
+ v,
602
+ {
603
+ ttl = this.ttl,
604
+ start,
605
+ noDisposeOnSet = this.noDisposeOnSet,
606
+ size = 0,
607
+ sizeCalculation = this.sizeCalculation,
608
+ noUpdateTTL = this.noUpdateTTL,
609
+ } = {}
610
+ ) {
611
+ size = this.requireSize(k, v, size, sizeCalculation)
612
+ // if the item doesn't fit, don't do anything
613
+ // NB: maxEntrySize set to maxSize by default
614
+ if (this.maxEntrySize && size > this.maxEntrySize) {
615
+ // have to delete, in case a background fetch is there already.
616
+ // in non-async cases, this is a no-op
617
+ this.delete(k)
618
+ return this
619
+ }
620
+ let index = this.size === 0 ? undefined : this.keyMap.get(k)
621
+ if (index === undefined) {
622
+ // addition
623
+ index = this.newIndex()
624
+ this.keyList[index] = k
625
+ this.valList[index] = v
626
+ this.keyMap.set(k, index)
627
+ this.next[this.tail] = index
628
+ this.prev[index] = this.tail
629
+ this.tail = index
630
+ this.size++
631
+ this.addItemSize(index, size)
632
+ noUpdateTTL = false
633
+ } else {
634
+ // update
635
+ this.moveToTail(index)
636
+ const oldVal = this.valList[index]
637
+ if (v !== oldVal) {
638
+ if (this.isBackgroundFetch(oldVal)) {
639
+ oldVal.__abortController.abort()
640
+ } else {
641
+ if (!noDisposeOnSet) {
642
+ this.dispose(oldVal, k, 'set')
643
+ if (this.disposeAfter) {
644
+ this.disposed.push([oldVal, k, 'set'])
645
+ }
646
+ }
647
+ }
648
+ this.removeItemSize(index)
649
+ this.valList[index] = v
650
+ this.addItemSize(index, size)
651
+ }
652
+ }
653
+ if (ttl !== 0 && this.ttl === 0 && !this.ttls) {
654
+ this.initializeTTLTracking()
655
+ }
656
+ if (!noUpdateTTL) {
657
+ this.setItemTTL(index, ttl, start)
658
+ }
659
+ if (this.disposeAfter) {
660
+ while (this.disposed.length) {
661
+ this.disposeAfter(...this.disposed.shift())
662
+ }
663
+ }
664
+ return this
665
+ }
666
+
667
+ newIndex() {
668
+ if (this.size === 0) {
669
+ return this.tail
670
+ }
671
+ if (this.size === this.max && this.max !== 0) {
672
+ return this.evict(false)
673
+ }
674
+ if (this.free.length !== 0) {
675
+ return this.free.pop()
676
+ }
677
+ // initial fill, just keep writing down the list
678
+ return this.initialFill++
679
+ }
680
+
681
+ pop() {
682
+ if (this.size) {
683
+ const val = this.valList[this.head]
684
+ this.evict(true)
685
+ return val
686
+ }
687
+ }
688
+
689
+ evict(free) {
690
+ const head = this.head
691
+ const k = this.keyList[head]
692
+ const v = this.valList[head]
693
+ if (this.isBackgroundFetch(v)) {
694
+ v.__abortController.abort()
695
+ } else {
696
+ this.dispose(v, k, 'evict')
697
+ if (this.disposeAfter) {
698
+ this.disposed.push([v, k, 'evict'])
699
+ }
700
+ }
701
+ this.removeItemSize(head)
702
+ // if we aren't about to use the index, then null these out
703
+ if (free) {
704
+ this.keyList[head] = null
705
+ this.valList[head] = null
706
+ this.free.push(head)
707
+ }
708
+ this.head = this.next[head]
709
+ this.keyMap.delete(k)
710
+ this.size--
711
+ return head
712
+ }
713
+
714
+ has(k, { updateAgeOnHas = this.updateAgeOnHas } = {}) {
715
+ const index = this.keyMap.get(k)
716
+ if (index !== undefined) {
717
+ if (!this.isStale(index)) {
718
+ if (updateAgeOnHas) {
719
+ this.updateItemAge(index)
720
+ }
721
+ return true
722
+ }
723
+ }
724
+ return false
725
+ }
726
+
727
+ // like get(), but without any LRU updating or TTL expiration
728
+ peek(k, { allowStale = this.allowStale } = {}) {
729
+ const index = this.keyMap.get(k)
730
+ if (index !== undefined && (allowStale || !this.isStale(index))) {
731
+ const v = this.valList[index]
732
+ // either stale and allowed, or forcing a refresh of non-stale value
733
+ return this.isBackgroundFetch(v) ? v.__staleWhileFetching : v
734
+ }
735
+ }
736
+
737
+ backgroundFetch(k, index, options, context) {
738
+ const v = index === undefined ? undefined : this.valList[index]
739
+ if (this.isBackgroundFetch(v)) {
740
+ return v
741
+ }
742
+ const ac = new AC()
743
+ const fetchOpts = {
744
+ signal: ac.signal,
745
+ options,
746
+ context,
747
+ }
748
+ const cb = v => {
749
+ if (!ac.signal.aborted) {
750
+ this.set(k, v, fetchOpts.options)
751
+ }
752
+ return v
753
+ }
754
+ const eb = er => {
755
+ if (this.valList[index] === p) {
756
+ // if we allow stale on fetch rejections, then we need to ensure that
757
+ // the stale value is not removed from the cache when the fetch fails.
758
+ const noDelete =
759
+ options.noDeleteOnFetchRejection ||
760
+ options.allowStaleOnFetchRejection
761
+ const del = !noDelete || p.__staleWhileFetching === undefined
762
+ if (del) {
763
+ this.delete(k)
764
+ } else {
765
+ // still replace the *promise* with the stale value,
766
+ // since we are done with the promise at this point.
767
+ this.valList[index] = p.__staleWhileFetching
768
+ }
769
+ }
770
+ if (options.allowStaleOnFetchRejection) {
771
+ return p.__staleWhileFetching
772
+ } else if (p.__returned === p) {
773
+ throw er
774
+ }
775
+ }
776
+ const pcall = res => res(this.fetchMethod(k, v, fetchOpts))
777
+ const p = new Promise(pcall).then(cb, eb)
778
+ p.__abortController = ac
779
+ p.__staleWhileFetching = v
780
+ p.__returned = null
781
+ if (index === undefined) {
782
+ this.set(k, p, fetchOpts.options)
783
+ index = this.keyMap.get(k)
784
+ } else {
785
+ this.valList[index] = p
786
+ }
787
+ return p
788
+ }
789
+
790
+ isBackgroundFetch(p) {
791
+ return (
792
+ p &&
793
+ typeof p === 'object' &&
794
+ typeof p.then === 'function' &&
795
+ Object.prototype.hasOwnProperty.call(
796
+ p,
797
+ '__staleWhileFetching'
798
+ ) &&
799
+ Object.prototype.hasOwnProperty.call(p, '__returned') &&
800
+ (p.__returned === p || p.__returned === null)
801
+ )
802
+ }
803
+
804
+ // this takes the union of get() and set() opts, because it does both
805
+ async fetch(
806
+ k,
807
+ {
808
+ // get options
809
+ allowStale = this.allowStale,
810
+ updateAgeOnGet = this.updateAgeOnGet,
811
+ noDeleteOnStaleGet = this.noDeleteOnStaleGet,
812
+ // set options
813
+ ttl = this.ttl,
814
+ noDisposeOnSet = this.noDisposeOnSet,
815
+ size = 0,
816
+ sizeCalculation = this.sizeCalculation,
817
+ noUpdateTTL = this.noUpdateTTL,
818
+ // fetch exclusive options
819
+ noDeleteOnFetchRejection = this.noDeleteOnFetchRejection,
820
+ allowStaleOnFetchRejection = this.allowStaleOnFetchRejection,
821
+ fetchContext = this.fetchContext,
822
+ forceRefresh = false,
823
+ } = {}
824
+ ) {
825
+ if (!this.fetchMethod) {
826
+ return this.get(k, {
827
+ allowStale,
828
+ updateAgeOnGet,
829
+ noDeleteOnStaleGet,
830
+ })
831
+ }
832
+
833
+ const options = {
834
+ allowStale,
835
+ updateAgeOnGet,
836
+ noDeleteOnStaleGet,
837
+ ttl,
838
+ noDisposeOnSet,
839
+ size,
840
+ sizeCalculation,
841
+ noUpdateTTL,
842
+ noDeleteOnFetchRejection,
843
+ allowStaleOnFetchRejection,
844
+ }
845
+
846
+ let index = this.keyMap.get(k)
847
+ if (index === undefined) {
848
+ const p = this.backgroundFetch(k, index, options, fetchContext)
849
+ return (p.__returned = p)
850
+ } else {
851
+ // in cache, maybe already fetching
852
+ const v = this.valList[index]
853
+ if (this.isBackgroundFetch(v)) {
854
+ return allowStale && v.__staleWhileFetching !== undefined
855
+ ? v.__staleWhileFetching
856
+ : (v.__returned = v)
857
+ }
858
+
859
+ // if we force a refresh, that means do NOT serve the cached value,
860
+ // unless we are already in the process of refreshing the cache.
861
+ if (!forceRefresh && !this.isStale(index)) {
862
+ this.moveToTail(index)
863
+ if (updateAgeOnGet) {
864
+ this.updateItemAge(index)
865
+ }
866
+ return v
867
+ }
868
+
869
+ // ok, it is stale or a forced refresh, and not already fetching.
870
+ // refresh the cache.
871
+ const p = this.backgroundFetch(k, index, options, fetchContext)
872
+ return allowStale && p.__staleWhileFetching !== undefined
873
+ ? p.__staleWhileFetching
874
+ : (p.__returned = p)
875
+ }
876
+ }
877
+
878
+ get(
879
+ k,
880
+ {
881
+ allowStale = this.allowStale,
882
+ updateAgeOnGet = this.updateAgeOnGet,
883
+ noDeleteOnStaleGet = this.noDeleteOnStaleGet,
884
+ } = {}
885
+ ) {
886
+ const index = this.keyMap.get(k)
887
+ if (index !== undefined) {
888
+ const value = this.valList[index]
889
+ const fetching = this.isBackgroundFetch(value)
890
+ if (this.isStale(index)) {
891
+ // delete only if not an in-flight background fetch
892
+ if (!fetching) {
893
+ if (!noDeleteOnStaleGet) {
894
+ this.delete(k)
895
+ }
896
+ return allowStale ? value : undefined
897
+ } else {
898
+ return allowStale ? value.__staleWhileFetching : undefined
899
+ }
900
+ } else {
901
+ // if we're currently fetching it, we don't actually have it yet
902
+ // it's not stale, which means this isn't a staleWhileRefetching,
903
+ // so we just return undefined
904
+ if (fetching) {
905
+ return undefined
906
+ }
907
+ this.moveToTail(index)
908
+ if (updateAgeOnGet) {
909
+ this.updateItemAge(index)
910
+ }
911
+ return value
912
+ }
913
+ }
914
+ }
915
+
916
+ connect(p, n) {
917
+ this.prev[n] = p
918
+ this.next[p] = n
919
+ }
920
+
921
+ moveToTail(index) {
922
+ // if tail already, nothing to do
923
+ // if head, move head to next[index]
924
+ // else
925
+ // move next[prev[index]] to next[index] (head has no prev)
926
+ // move prev[next[index]] to prev[index]
927
+ // prev[index] = tail
928
+ // next[tail] = index
929
+ // tail = index
930
+ if (index !== this.tail) {
931
+ if (index === this.head) {
932
+ this.head = this.next[index]
933
+ } else {
934
+ this.connect(this.prev[index], this.next[index])
935
+ }
936
+ this.connect(this.tail, index)
937
+ this.tail = index
938
+ }
939
+ }
940
+
941
+ get del() {
942
+ deprecatedMethod('del', 'delete')
943
+ return this.delete
944
+ }
945
+
946
+ delete(k) {
947
+ let deleted = false
948
+ if (this.size !== 0) {
949
+ const index = this.keyMap.get(k)
950
+ if (index !== undefined) {
951
+ deleted = true
952
+ if (this.size === 1) {
953
+ this.clear()
954
+ } else {
955
+ this.removeItemSize(index)
956
+ const v = this.valList[index]
957
+ if (this.isBackgroundFetch(v)) {
958
+ v.__abortController.abort()
959
+ } else {
960
+ this.dispose(v, k, 'delete')
961
+ if (this.disposeAfter) {
962
+ this.disposed.push([v, k, 'delete'])
963
+ }
964
+ }
965
+ this.keyMap.delete(k)
966
+ this.keyList[index] = null
967
+ this.valList[index] = null
968
+ if (index === this.tail) {
969
+ this.tail = this.prev[index]
970
+ } else if (index === this.head) {
971
+ this.head = this.next[index]
972
+ } else {
973
+ this.next[this.prev[index]] = this.next[index]
974
+ this.prev[this.next[index]] = this.prev[index]
975
+ }
976
+ this.size--
977
+ this.free.push(index)
978
+ }
979
+ }
980
+ }
981
+ if (this.disposed) {
982
+ while (this.disposed.length) {
983
+ this.disposeAfter(...this.disposed.shift())
984
+ }
985
+ }
986
+ return deleted
987
+ }
988
+
989
+ clear() {
990
+ for (const index of this.rindexes({ allowStale: true })) {
991
+ const v = this.valList[index]
992
+ if (this.isBackgroundFetch(v)) {
993
+ v.__abortController.abort()
994
+ } else {
995
+ const k = this.keyList[index]
996
+ this.dispose(v, k, 'delete')
997
+ if (this.disposeAfter) {
998
+ this.disposed.push([v, k, 'delete'])
999
+ }
1000
+ }
1001
+ }
1002
+
1003
+ this.keyMap.clear()
1004
+ this.valList.fill(null)
1005
+ this.keyList.fill(null)
1006
+ if (this.ttls) {
1007
+ this.ttls.fill(0)
1008
+ this.starts.fill(0)
1009
+ }
1010
+ if (this.sizes) {
1011
+ this.sizes.fill(0)
1012
+ }
1013
+ this.head = 0
1014
+ this.tail = 0
1015
+ this.initialFill = 1
1016
+ this.free.length = 0
1017
+ this.calculatedSize = 0
1018
+ this.size = 0
1019
+ if (this.disposed) {
1020
+ while (this.disposed.length) {
1021
+ this.disposeAfter(...this.disposed.shift())
1022
+ }
1023
+ }
1024
+ }
1025
+
1026
+ get reset() {
1027
+ deprecatedMethod('reset', 'clear')
1028
+ return this.clear
1029
+ }
1030
+
1031
+ get length() {
1032
+ deprecatedProperty('length', 'size')
1033
+ return this.size
1034
+ }
1035
+
1036
+ static get AbortController() {
1037
+ return AC
1038
+ }
1039
+ static get AbortSignal() {
1040
+ return AS
1041
+ }
1042
+ }
1043
+
1044
+ module.exports = LRUCache