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