self-evolve-framework 1.6.0 → 1.6.1

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 (301) hide show
  1. package/README.md +33 -23
  2. package/bin/cli.js +24 -67
  3. package/package.json +1 -1
  4. package/template/rules/knowledge/README.md +56 -0
  5. package/template/rules/knowledge/ant-design-vue.mdc +54 -0
  6. package/template/rules/knowledge/general.mdc +56 -0
  7. package/template/rules/knowledge/rust.mdc +55 -0
  8. package/template/rules/knowledge/shadcn-svelte.mdc +64 -0
  9. package/template/rules/knowledge/svelte.mdc +135 -0
  10. package/template/rules/knowledge/tailwind.mdc +66 -0
  11. package/template/rules/knowledge/tauri.mdc +65 -0
  12. package/template/rules/knowledge/typescript.mdc +41 -0
  13. package/template/rules/knowledge/vue.mdc +48 -0
  14. package/template/rules/ponytail.mdc +23 -98
  15. package/template/rules/self-evolve.mdc +24 -0
  16. package/template/skills/impeccable/SKILL.md +47 -174
  17. package/template/skills/skillopt-sleep/SKILL.md +32 -88
  18. package/template/skills/impeccable/agents/impeccable_asset_producer.toml +0 -92
  19. package/template/skills/impeccable/agents/impeccable_manual_edit_applier.toml +0 -95
  20. package/template/skills/impeccable/agents/openai.yaml +0 -4
  21. package/template/skills/impeccable/reference/adapt.md +0 -311
  22. package/template/skills/impeccable/reference/animate.md +0 -201
  23. package/template/skills/impeccable/reference/audit.md +0 -133
  24. package/template/skills/impeccable/reference/bolder.md +0 -113
  25. package/template/skills/impeccable/reference/brand.md +0 -108
  26. package/template/skills/impeccable/reference/clarify.md +0 -288
  27. package/template/skills/impeccable/reference/codex.md +0 -105
  28. package/template/skills/impeccable/reference/colorize.md +0 -257
  29. package/template/skills/impeccable/reference/craft.md +0 -123
  30. package/template/skills/impeccable/reference/critique.md +0 -790
  31. package/template/skills/impeccable/reference/delight.md +0 -302
  32. package/template/skills/impeccable/reference/distill.md +0 -111
  33. package/template/skills/impeccable/reference/document.md +0 -429
  34. package/template/skills/impeccable/reference/extract.md +0 -69
  35. package/template/skills/impeccable/reference/harden.md +0 -347
  36. package/template/skills/impeccable/reference/hooks.md +0 -90
  37. package/template/skills/impeccable/reference/init.md +0 -172
  38. package/template/skills/impeccable/reference/interaction-design.md +0 -189
  39. package/template/skills/impeccable/reference/layout.md +0 -161
  40. package/template/skills/impeccable/reference/live.md +0 -720
  41. package/template/skills/impeccable/reference/onboard.md +0 -234
  42. package/template/skills/impeccable/reference/optimize.md +0 -258
  43. package/template/skills/impeccable/reference/overdrive.md +0 -130
  44. package/template/skills/impeccable/reference/polish.md +0 -241
  45. package/template/skills/impeccable/reference/product.md +0 -60
  46. package/template/skills/impeccable/reference/quieter.md +0 -99
  47. package/template/skills/impeccable/reference/shape.md +0 -165
  48. package/template/skills/impeccable/reference/typeset.md +0 -279
  49. package/template/skills/impeccable/scripts/command-metadata.json +0 -94
  50. package/template/skills/impeccable/scripts/context-signals.mjs +0 -225
  51. package/template/skills/impeccable/scripts/context.mjs +0 -961
  52. package/template/skills/impeccable/scripts/critique-storage.mjs +0 -242
  53. package/template/skills/impeccable/scripts/detect-csp.mjs +0 -198
  54. package/template/skills/impeccable/scripts/detect.mjs +0 -21
  55. package/template/skills/impeccable/scripts/detector/browser/injected/index.mjs +0 -1937
  56. package/template/skills/impeccable/scripts/detector/cli/main.mjs +0 -290
  57. package/template/skills/impeccable/scripts/detector/design-system.mjs +0 -750
  58. package/template/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +0 -5138
  59. package/template/skills/impeccable/scripts/detector/detect-antipatterns.mjs +0 -50
  60. package/template/skills/impeccable/scripts/detector/engines/browser/detect-url.mjs +0 -277
  61. package/template/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +0 -568
  62. package/template/skills/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +0 -1015
  63. package/template/skills/impeccable/scripts/detector/engines/static-html/detect-html.mjs +0 -234
  64. package/template/skills/impeccable/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -189
  65. package/template/skills/impeccable/scripts/detector/findings.mjs +0 -12
  66. package/template/skills/impeccable/scripts/detector/node/file-system.mjs +0 -198
  67. package/template/skills/impeccable/scripts/detector/profile/profiler.mjs +0 -166
  68. package/template/skills/impeccable/scripts/detector/registry/antipatterns.mjs +0 -448
  69. package/template/skills/impeccable/scripts/detector/rules/checks.mjs +0 -2671
  70. package/template/skills/impeccable/scripts/detector/shared/color.mjs +0 -124
  71. package/template/skills/impeccable/scripts/detector/shared/constants.mjs +0 -101
  72. package/template/skills/impeccable/scripts/detector/shared/inline-ignores.mjs +0 -148
  73. package/template/skills/impeccable/scripts/detector/shared/page.mjs +0 -7
  74. package/template/skills/impeccable/scripts/hook-admin.mjs +0 -661
  75. package/template/skills/impeccable/scripts/hook-before-edit.mjs +0 -476
  76. package/template/skills/impeccable/scripts/hook-lib.mjs +0 -1632
  77. package/template/skills/impeccable/scripts/hook.mjs +0 -61
  78. package/template/skills/impeccable/scripts/lib/design-parser.mjs +0 -842
  79. package/template/skills/impeccable/scripts/lib/impeccable-config.mjs +0 -638
  80. package/template/skills/impeccable/scripts/lib/impeccable-paths.mjs +0 -128
  81. package/template/skills/impeccable/scripts/lib/is-generated.mjs +0 -69
  82. package/template/skills/impeccable/scripts/lib/target-args.mjs +0 -42
  83. package/template/skills/impeccable/scripts/live/browser-script-parts.mjs +0 -49
  84. package/template/skills/impeccable/scripts/live/completion.mjs +0 -19
  85. package/template/skills/impeccable/scripts/live/event-validation.mjs +0 -137
  86. package/template/skills/impeccable/scripts/live/insert-ui.mjs +0 -458
  87. package/template/skills/impeccable/scripts/live/manual-apply.mjs +0 -939
  88. package/template/skills/impeccable/scripts/live/manual-edit-routes.mjs +0 -357
  89. package/template/skills/impeccable/scripts/live/manual-edits-buffer.mjs +0 -152
  90. package/template/skills/impeccable/scripts/live/session-store.mjs +0 -289
  91. package/template/skills/impeccable/scripts/live/svelte-component.mjs +0 -826
  92. package/template/skills/impeccable/scripts/live/sveltekit-adapter.mjs +0 -274
  93. package/template/skills/impeccable/scripts/live/ui-core.mjs +0 -180
  94. package/template/skills/impeccable/scripts/live/vocabulary.mjs +0 -36
  95. package/template/skills/impeccable/scripts/live-accept.mjs +0 -812
  96. package/template/skills/impeccable/scripts/live-browser-dom.js +0 -146
  97. package/template/skills/impeccable/scripts/live-browser-session.js +0 -123
  98. package/template/skills/impeccable/scripts/live-browser.js +0 -11173
  99. package/template/skills/impeccable/scripts/live-commit-manual-edits.mjs +0 -1241
  100. package/template/skills/impeccable/scripts/live-complete.mjs +0 -75
  101. package/template/skills/impeccable/scripts/live-copy-edit-agent.mjs +0 -683
  102. package/template/skills/impeccable/scripts/live-discard-manual-edits.mjs +0 -51
  103. package/template/skills/impeccable/scripts/live-inject.mjs +0 -583
  104. package/template/skills/impeccable/scripts/live-insert.mjs +0 -272
  105. package/template/skills/impeccable/scripts/live-manual-edit-evidence.mjs +0 -363
  106. package/template/skills/impeccable/scripts/live-poll.mjs +0 -384
  107. package/template/skills/impeccable/scripts/live-resume.mjs +0 -94
  108. package/template/skills/impeccable/scripts/live-server.mjs +0 -1135
  109. package/template/skills/impeccable/scripts/live-status.mjs +0 -61
  110. package/template/skills/impeccable/scripts/live-target.mjs +0 -30
  111. package/template/skills/impeccable/scripts/live-wrap.mjs +0 -894
  112. package/template/skills/impeccable/scripts/live.mjs +0 -297
  113. package/template/skills/impeccable/scripts/modern-screenshot.umd.js +0 -14
  114. package/template/skills/impeccable/scripts/palette.mjs +0 -633
  115. package/template/skills/impeccable/scripts/pin.mjs +0 -214
  116. package/template/skills/skillopt-sleep/configs/_base_/default.yaml +0 -103
  117. package/template/skills/skillopt-sleep/configs/alfworld/default.yaml +0 -29
  118. package/template/skills/skillopt-sleep/configs/docvqa/default.yaml +0 -28
  119. package/template/skills/skillopt-sleep/configs/features/soft_gate.yaml +0 -47
  120. package/template/skills/skillopt-sleep/configs/livemathematicianbench/default.yaml +0 -22
  121. package/template/skills/skillopt-sleep/configs/officeqa/default.yaml +0 -34
  122. package/template/skills/skillopt-sleep/configs/searchqa/default.yaml +0 -32
  123. package/template/skills/skillopt-sleep/configs/spreadsheetbench/default.yaml +0 -34
  124. package/template/skills/skillopt-sleep/scripts/framework/skillopt/__init__.py +0 -28
  125. package/template/skills/skillopt-sleep/scripts/framework/skillopt/config.py +0 -282
  126. package/template/skills/skillopt-sleep/scripts/framework/skillopt/datasets/__init__.py +0 -7
  127. package/template/skills/skillopt-sleep/scripts/framework/skillopt/datasets/base.py +0 -512
  128. package/template/skills/skillopt-sleep/scripts/framework/skillopt/engine/__init__.py +0 -9
  129. package/template/skills/skillopt-sleep/scripts/framework/skillopt/engine/trainer.py +0 -2379
  130. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/__init__.py +0 -1
  131. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/README.md +0 -43
  132. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/config_template.yaml +0 -55
  133. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/env_template.py +0 -151
  134. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/loader_template.py +0 -87
  135. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/__init__.py +0 -5
  136. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/adapter.py +0 -428
  137. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/dataloader.py +0 -123
  138. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/analyst_error.md +0 -55
  139. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/analyst_success.md +0 -33
  140. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/rollout_no_history.md +0 -8
  141. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/rollout_with_history.md +0 -9
  142. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/rollout_with_memory.md +0 -16
  143. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/reflect.py +0 -4
  144. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/rollout.py +0 -366
  145. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/skills/initial.md +0 -45
  146. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/__init__.py +0 -9
  147. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/alfworld_envs.py +0 -221
  148. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/alfworld_projection.py +0 -60
  149. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/alfworld_prompts.py +0 -8
  150. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/config_tw.yaml +0 -145
  151. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/env_base.py +0 -84
  152. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/env_manager.py +0 -139
  153. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/memory.py +0 -87
  154. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/base.py +0 -329
  155. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/__init__.py +0 -1
  156. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/adapter.py +0 -90
  157. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/dataloader.py +0 -61
  158. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/evaluator.py +0 -113
  159. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/prompts/analyst_error.md +0 -35
  160. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/prompts/analyst_success.md +0 -24
  161. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/prompts/rollout_system.md +0 -12
  162. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/rollout.py +0 -391
  163. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/skills/initial.md +0 -11
  164. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/__init__.py +0 -1
  165. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/adapter.py +0 -129
  166. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/dataloader.py +0 -308
  167. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/evaluator.py +0 -62
  168. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/prompts/analyst_error.md +0 -37
  169. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/prompts/analyst_success.md +0 -25
  170. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/prompts/rollout_system.md +0 -12
  171. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/reflect.py +0 -4
  172. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/rollout.py +0 -434
  173. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/skills/initial.md +0 -16
  174. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/__init__.py +0 -1
  175. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/adapter.py +0 -112
  176. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/dataloader.py +0 -71
  177. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/evaluator.py +0 -46
  178. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/prompts/analyst_error.md +0 -37
  179. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/prompts/analyst_success.md +0 -25
  180. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/prompts/rollout_system.md +0 -15
  181. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/rollout.py +0 -799
  182. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/skills/initial.md +0 -15
  183. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/tool_runtime.py +0 -552
  184. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/__init__.py +0 -1
  185. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/adapter.py +0 -96
  186. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/dataloader.py +0 -42
  187. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/evaluator.py +0 -100
  188. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/prompts/analyst_error.md +0 -46
  189. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/prompts/analyst_success.md +0 -32
  190. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/prompts/rollout_system.md +0 -13
  191. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/reflect.py +0 -4
  192. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/rollout.py +0 -494
  193. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/skills/initial.md +0 -3
  194. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/__init__.py +0 -5
  195. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/adapter.py +0 -159
  196. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/codegen_agent.py +0 -731
  197. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/dataloader.py +0 -37
  198. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/evaluator.py +0 -158
  199. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/executor.py +0 -67
  200. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/analyst_error.md +0 -46
  201. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/analyst_success.md +0 -32
  202. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/codegen_system.md +0 -1
  203. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/critical_rules.md +0 -9
  204. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/react_system.md +0 -21
  205. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/react_agent.py +0 -395
  206. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/reflect.py +0 -4
  207. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/rollout.py +0 -979
  208. package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/skills/initial.md +0 -56
  209. package/template/skills/skillopt-sleep/scripts/framework/skillopt/evaluation/__init__.py +0 -13
  210. package/template/skills/skillopt-sleep/scripts/framework/skillopt/evaluation/gate.py +0 -148
  211. package/template/skills/skillopt-sleep/scripts/framework/skillopt/gradient/__init__.py +0 -15
  212. package/template/skills/skillopt-sleep/scripts/framework/skillopt/gradient/aggregate.py +0 -253
  213. package/template/skills/skillopt-sleep/scripts/framework/skillopt/gradient/reflect.py +0 -635
  214. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/__init__.py +0 -514
  215. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/azure_openai.py +0 -915
  216. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/backend_config.py +0 -185
  217. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/claude_backend.py +0 -371
  218. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/codex_backend.py +0 -666
  219. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/codex_harness.py +0 -1057
  220. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/common.py +0 -229
  221. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/minimax_backend.py +0 -277
  222. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/qwen_backend.py +0 -456
  223. package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/router.py +0 -236
  224. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/__init__.py +0 -15
  225. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/appendix.py +0 -156
  226. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/clip.py +0 -109
  227. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/lr_autonomous.py +0 -108
  228. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/meta_skill.py +0 -79
  229. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/rewrite.py +0 -59
  230. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/scheduler.py +0 -127
  231. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/select.py +0 -4
  232. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/skill.py +0 -201
  233. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/skill_aware.py +0 -206
  234. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/slow_update.py +0 -396
  235. package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/update_modes.py +0 -135
  236. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/__init__.py +0 -63
  237. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_error.md +0 -41
  238. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_error_full_rewrite.md +0 -32
  239. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_error_rewrite.md +0 -44
  240. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_success.md +0 -36
  241. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_success_full_rewrite.md +0 -30
  242. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_success_rewrite.md +0 -33
  243. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/lr_autonomous.md +0 -20
  244. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_failure.md +0 -30
  245. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_failure_full_rewrite.md +0 -28
  246. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_failure_rewrite.md +0 -26
  247. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_final.md +0 -33
  248. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_final_full_rewrite.md +0 -28
  249. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_final_rewrite.md +0 -25
  250. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_success.md +0 -28
  251. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_success_full_rewrite.md +0 -28
  252. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_success_rewrite.md +0 -25
  253. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/meta_skill.md +0 -40
  254. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/ranking.md +0 -20
  255. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/ranking_rewrite.md +0 -15
  256. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/rewrite_skill.md +0 -25
  257. package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/slow_update.md +0 -60
  258. package/template/skills/skillopt-sleep/scripts/framework/skillopt/scheduler/__init__.py +0 -8
  259. package/template/skills/skillopt-sleep/scripts/framework/skillopt/types.py +0 -306
  260. package/template/skills/skillopt-sleep/scripts/framework/skillopt/utils/__init__.py +0 -4
  261. package/template/skills/skillopt-sleep/scripts/framework/skillopt/utils/json_utils.py +0 -172
  262. package/template/skills/skillopt-sleep/scripts/framework/skillopt/utils/scoring.py +0 -28
  263. package/template/skills/skillopt-sleep/scripts/python/__init__.py +0 -20
  264. package/template/skills/skillopt-sleep/scripts/python/__main__.py +0 -343
  265. package/template/skills/skillopt-sleep/scripts/python/backend.py +0 -1371
  266. package/template/skills/skillopt-sleep/scripts/python/budget.py +0 -75
  267. package/template/skills/skillopt-sleep/scripts/python/config.py +0 -162
  268. package/template/skills/skillopt-sleep/scripts/python/consolidate.py +0 -238
  269. package/template/skills/skillopt-sleep/scripts/python/cycle.py +0 -291
  270. package/template/skills/skillopt-sleep/scripts/python/dream.py +0 -138
  271. package/template/skills/skillopt-sleep/scripts/python/experiments/__init__.py +0 -1
  272. package/template/skills/skillopt-sleep/scripts/python/experiments/gbrain_bench.py +0 -119
  273. package/template/skills/skillopt-sleep/scripts/python/experiments/personas.py +0 -86
  274. package/template/skills/skillopt-sleep/scripts/python/experiments/report.py +0 -132
  275. package/template/skills/skillopt-sleep/scripts/python/experiments/run_experiment.py +0 -178
  276. package/template/skills/skillopt-sleep/scripts/python/experiments/run_gbrain.py +0 -209
  277. package/template/skills/skillopt-sleep/scripts/python/experiments/run_transfer.py +0 -155
  278. package/template/skills/skillopt-sleep/scripts/python/experiments/sweep.py +0 -164
  279. package/template/skills/skillopt-sleep/scripts/python/gate.py +0 -50
  280. package/template/skills/skillopt-sleep/scripts/python/harvest.py +0 -304
  281. package/template/skills/skillopt-sleep/scripts/python/harvest_codex.py +0 -253
  282. package/template/skills/skillopt-sleep/scripts/python/harvest_sources.py +0 -41
  283. package/template/skills/skillopt-sleep/scripts/python/judges.py +0 -84
  284. package/template/skills/skillopt-sleep/scripts/python/llm_miner.py +0 -134
  285. package/template/skills/skillopt-sleep/scripts/python/memory.py +0 -129
  286. package/template/skills/skillopt-sleep/scripts/python/mine.py +0 -312
  287. package/template/skills/skillopt-sleep/scripts/python/replay.py +0 -146
  288. package/template/skills/skillopt-sleep/scripts/python/rollout.py +0 -153
  289. package/template/skills/skillopt-sleep/scripts/python/scheduler.py +0 -138
  290. package/template/skills/skillopt-sleep/scripts/python/slow_update.py +0 -142
  291. package/template/skills/skillopt-sleep/scripts/python/staging.py +0 -103
  292. package/template/skills/skillopt-sleep/scripts/python/state.py +0 -96
  293. package/template/skills/skillopt-sleep/scripts/python/tasks_file.py +0 -81
  294. package/template/skills/skillopt-sleep/scripts/python/types.py +0 -146
  295. package/template/skills/skillopt-sleep/scripts/shell/__init__.py +0 -0
  296. package/template/skills/skillopt-sleep/scripts/shell/eval_only.py +0 -466
  297. package/template/skills/skillopt-sleep/scripts/shell/materialize_searchqa.py +0 -148
  298. package/template/skills/skillopt-sleep/scripts/shell/run_alfworld.sh +0 -60
  299. package/template/skills/skillopt-sleep/scripts/shell/run_searchqa.sh +0 -40
  300. package/template/skills/skillopt-sleep/scripts/shell/run_spreadsheetbench.sh +0 -39
  301. package/template/skills/skillopt-sleep/scripts/shell/train.py +0 -556
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * CLI helper: discard pending manual edits from the buffer without applying.
4
- *
5
- * Reads .impeccable/live/pending-manual-edits.json, drops entries, writes back.
6
- * No source-file writes. Use this when the user wants to throw away unsaved
7
- * manual edits.
8
- *
9
- * Trigger: only when the user explicitly asks the AI to discard / throw away /
10
- * clear pending manual edits.
11
- *
12
- * Usage:
13
- * node live-discard-manual-edits.mjs # discard all pending
14
- * node live-discard-manual-edits.mjs --page-url=/ # discard only entries for "/"
15
- *
16
- * Output JSON: { discarded: N, entries: [...discardedEntries], totalCount: N }
17
- */
18
-
19
- import { readBuffer, removeEntries, truncateBuffer } from './live/manual-edits-buffer.mjs';
20
-
21
- function argVal(args, name) {
22
- const prefix = name + '=';
23
- for (const a of args) {
24
- if (a === name) return true;
25
- if (a.startsWith(prefix)) return a.slice(prefix.length);
26
- }
27
- return null;
28
- }
29
-
30
- const args = process.argv.slice(2);
31
- if (args.includes('--help') || args.includes('-h')) {
32
- console.log('Usage: node live-discard-manual-edits.mjs [--page-url=<url>]');
33
- process.exit(0);
34
- }
35
-
36
- const pageUrlFilter = argVal(args, '--page-url');
37
- const cwd = process.cwd();
38
-
39
- let discarded;
40
- let entries;
41
- const buffer = readBuffer(cwd);
42
- if (pageUrlFilter) {
43
- entries = buffer.entries.filter((entry) => entry.pageUrl === pageUrlFilter);
44
- discarded = removeEntries(cwd, (entry) => entry.pageUrl === pageUrlFilter);
45
- } else {
46
- entries = buffer.entries;
47
- discarded = truncateBuffer(cwd);
48
- }
49
-
50
- const remaining = readBuffer(cwd).entries.reduce((n, e) => n + e.ops.length, 0);
51
- console.log(JSON.stringify({ discarded, entries, totalCount: remaining }));
@@ -1,583 +0,0 @@
1
- /**
2
- * CLI helper: insert/remove the live variant mode script tag in the project's
3
- * main HTML entry point.
4
- *
5
- * On first live run, the agent generates `.impeccable/live/config.json`
6
- * with the project's insertion target (framework-specific). On
7
- * every subsequent run, this script handles insert/remove deterministically
8
- * with zero LLM involvement.
9
- *
10
- * Usage:
11
- * node live-inject.mjs --port PORT # Insert the live script tag
12
- * node live-inject.mjs --remove # Remove the live script tag
13
- * node live-inject.mjs --check # Check whether live config exists
14
- */
15
-
16
- import fs from 'node:fs';
17
- import path from 'node:path';
18
- import { fileURLToPath } from 'node:url';
19
- import { resolveLiveConfigPath } from './lib/impeccable-paths.mjs';
20
- import {
21
- applySvelteKitLiveAdapter,
22
- detectSvelteKitProject,
23
- removeSvelteKitLiveAdapter,
24
- } from './live/sveltekit-adapter.mjs';
25
-
26
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
27
- const CONFIG_PATH = resolveLiveConfigPath({ cwd: process.cwd(), scriptsDir: __dirname });
28
- const MARKER_OPEN_TEXT = 'impeccable-live-start';
29
- const MARKER_CLOSE_TEXT = 'impeccable-live-end';
30
- const IGNORE_MARKER_OPEN = '# impeccable-live-ignore-start';
31
- const IGNORE_MARKER_CLOSE = '# impeccable-live-ignore-end';
32
-
33
- export const LIVE_IGNORE_PATTERNS = Object.freeze([
34
- '.impeccable/hook.cache.json',
35
- '.impeccable/hook.pending.json',
36
- '.impeccable/config.local.json',
37
- '.impeccable/live/server.json',
38
- '.impeccable/live/sessions/',
39
- '.impeccable/live/previews/',
40
- '.impeccable/live/annotations/',
41
- '.impeccable/live/cache/',
42
- '.impeccable/live/manual-edit-apply-transaction.json',
43
- '.impeccable/live/manual-edit-events.jsonl',
44
- '.impeccable/live/manual-edit-evidence/',
45
- '.impeccable/live/pending-manual-edits.json',
46
- '.impeccable/live/deferred-svelte-component-accepts.json',
47
- '.impeccable-live.json',
48
- '.impeccable-live/',
49
- 'node_modules/.impeccable-live/',
50
- 'src/lib/impeccable/ImpeccableLiveRoot.svelte',
51
- 'src/lib/impeccable/__runtime.js',
52
- 'src/lib/impeccable/[0-9a-f]*/',
53
- ]);
54
-
55
- /**
56
- * Hard-excluded directory patterns. These are NEVER user-facing pages and
57
- * matching them would silently inject tracking scripts into third-party
58
- * code. The user cannot turn these off via config — they are the floor.
59
- */
60
- const HARD_EXCLUDES = [
61
- '**/node_modules/**',
62
- '**/.git/**',
63
- ];
64
-
65
- export async function injectCli() {
66
- const args = process.argv.slice(2);
67
-
68
- if (args.includes('--help') || args.includes('-h')) {
69
- console.log(`Usage: node live-inject.mjs [options]
70
-
71
- Insert or remove the live mode script tag in the project's HTML entry point.
72
- Reads configuration from .impeccable/live/config.json.
73
-
74
- Modes:
75
- --port PORT Insert script tag pointing at http://localhost:PORT/live.js
76
- --remove Remove the script tag (if present)
77
- --check Print whether .impeccable/live/config.json exists and its content
78
-
79
- Output (JSON):
80
- { ok, file, inserted|removed, config? }`);
81
- process.exit(0);
82
- }
83
-
84
- if (args.includes('--check')) {
85
- if (!fs.existsSync(CONFIG_PATH)) {
86
- console.log(JSON.stringify({ ok: false, error: 'config_missing', path: CONFIG_PATH }));
87
- process.exit(0);
88
- }
89
- let cfg;
90
- try {
91
- cfg = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
92
- } catch (err) {
93
- console.log(JSON.stringify({ ok: false, error: 'config_invalid', message: err.message, path: CONFIG_PATH }));
94
- return;
95
- }
96
- try {
97
- validateConfig(cfg);
98
- } catch (err) {
99
- console.log(JSON.stringify({ ok: false, error: 'config_invalid', message: err.message, path: CONFIG_PATH }));
100
- return;
101
- }
102
- console.log(JSON.stringify({ ok: true, config: cfg, path: CONFIG_PATH }));
103
- return;
104
- }
105
-
106
- // Load config
107
- if (!fs.existsSync(CONFIG_PATH)) {
108
- console.error(JSON.stringify({ ok: false, error: 'config_missing', path: CONFIG_PATH }));
109
- process.exit(1);
110
- }
111
- const config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
112
- validateConfig(config);
113
-
114
- const resolvedFiles = resolveFiles(process.cwd(), config);
115
- const svelteKit = detectSvelteKitProject(process.cwd(), config);
116
-
117
- if (args.includes('--remove')) {
118
- if (svelteKit) {
119
- const adapterResult = removeSvelteKitLiveAdapter({ cwd: process.cwd(), config });
120
- console.log(JSON.stringify({ ok: true, adapter: 'sveltekit', results: [adapterResult] }));
121
- return;
122
- }
123
- const results = resolvedFiles.map((relFile) => {
124
- const absFile = path.resolve(process.cwd(), relFile);
125
- if (!fs.existsSync(absFile)) return { file: relFile, error: 'file_not_found' };
126
- const content = fs.readFileSync(absFile, 'utf-8');
127
- const detagged = removeTag(content, config.commentSyntax);
128
- const updated = revertCspMeta(detagged);
129
- if (updated === content) return { file: relFile, removed: false, note: 'no tag present' };
130
- fs.writeFileSync(absFile, updated, 'utf-8');
131
- return {
132
- file: relFile,
133
- removed: detagged !== content,
134
- cspReverted: updated !== detagged,
135
- };
136
- });
137
- console.log(JSON.stringify({ ok: true, results }));
138
- return;
139
- }
140
-
141
- // Insert mode — need --port
142
- const portIdx = args.indexOf('--port');
143
- const port = portIdx !== -1 ? parseInt(args[portIdx + 1], 10) : NaN;
144
- if (!Number.isFinite(port)) {
145
- console.error(JSON.stringify({ ok: false, error: 'missing_port' }));
146
- process.exit(1);
147
- }
148
- const gitIgnore = ensureLiveGitIgnores(process.cwd());
149
-
150
- if (svelteKit) {
151
- const adapterResult = applySvelteKitLiveAdapter({ cwd: process.cwd(), port, config });
152
- console.log(JSON.stringify({ ok: true, port, adapter: 'sveltekit', gitIgnore, results: [adapterResult] }));
153
- return;
154
- }
155
-
156
- const results = resolvedFiles.map((relFile) => {
157
- const absFile = path.resolve(process.cwd(), relFile);
158
- if (!fs.existsSync(absFile)) return { file: relFile, error: 'file_not_found' };
159
- const content = fs.readFileSync(absFile, 'utf-8');
160
- const withoutOld = revertCspMeta(removeTag(content, config.commentSyntax));
161
- const withTag = insertTag(withoutOld, config, port, relFile);
162
- if (withTag === withoutOld) {
163
- return { file: relFile, error: 'insertion_point_not_found', anchor: config.insertBefore || config.insertAfter };
164
- }
165
- const updated = patchCspMeta(withTag, port);
166
- fs.writeFileSync(absFile, updated, 'utf-8');
167
- return {
168
- file: relFile,
169
- inserted: true,
170
- cspPatched: updated !== withTag,
171
- };
172
- });
173
- const anyInserted = results.some((r) => r.inserted);
174
- console.log(JSON.stringify({ ok: anyInserted, port, gitIgnore, results }));
175
- if (!anyInserted) process.exit(1);
176
- }
177
-
178
- export function ensureLiveGitIgnores(cwd = process.cwd()) {
179
- const target = resolveIgnoreTarget(cwd);
180
- const existing = fs.existsSync(target.path) ? fs.readFileSync(target.path, 'utf-8') : '';
181
- const block = [
182
- IGNORE_MARKER_OPEN,
183
- ...LIVE_IGNORE_PATTERNS,
184
- IGNORE_MARKER_CLOSE,
185
- ].join('\n');
186
- const markerRe = new RegExp(`${escapeRegExp(IGNORE_MARKER_OPEN)}[\\s\\S]*?${escapeRegExp(IGNORE_MARKER_CLOSE)}`);
187
-
188
- let updated;
189
- if (markerRe.test(existing)) {
190
- updated = existing.replace(markerRe, block);
191
- } else {
192
- const prefix = existing.length === 0 ? '' : existing.endsWith('\n') ? existing : existing + '\n';
193
- updated = `${prefix}${prefix.endsWith('\n\n') || prefix === '' ? '' : '\n'}${block}\n`;
194
- }
195
-
196
- if (updated !== existing) {
197
- fs.mkdirSync(path.dirname(target.path), { recursive: true });
198
- fs.writeFileSync(target.path, updated, 'utf-8');
199
- }
200
-
201
- return {
202
- file: path.relative(cwd, target.path).split(path.sep).join('/'),
203
- mode: target.mode,
204
- changed: updated !== existing,
205
- patterns: [...LIVE_IGNORE_PATTERNS],
206
- };
207
- }
208
-
209
- function resolveIgnoreTarget(cwd) {
210
- const gitExcludePath = resolveGitInfoExcludePath(cwd);
211
- if (gitExcludePath) {
212
- return { path: gitExcludePath, mode: 'git-info-exclude' };
213
- }
214
- return { path: path.join(cwd, '.gitignore'), mode: 'gitignore' };
215
- }
216
-
217
- function resolveGitInfoExcludePath(cwd) {
218
- const dotGit = path.join(cwd, '.git');
219
- if (!fs.existsSync(dotGit)) return null;
220
-
221
- const stat = fs.statSync(dotGit);
222
- if (stat.isDirectory()) return path.join(dotGit, 'info', 'exclude');
223
- if (!stat.isFile()) return null;
224
-
225
- const body = fs.readFileSync(dotGit, 'utf-8').trim();
226
- const match = body.match(/^gitdir:\s*(.+)$/i);
227
- if (!match) return null;
228
- const gitDir = path.isAbsolute(match[1]) ? match[1] : path.resolve(cwd, match[1]);
229
- return path.join(gitDir, 'info', 'exclude');
230
- }
231
-
232
- function escapeRegExp(value) {
233
- return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
234
- }
235
-
236
- /**
237
- * Expand config.files (which may contain glob patterns) into a literal list
238
- * of existing file paths relative to rootDir. Literal entries pass through;
239
- * glob patterns are expanded via fs.globSync. HARD_EXCLUDES and config.exclude
240
- * are applied as filters. Duplicates are removed. Order is preserved by
241
- * first appearance.
242
- */
243
- export function resolveFiles(rootDir, config) {
244
- const patterns = config.files;
245
- const userExcludes = Array.isArray(config.exclude) ? config.exclude : [];
246
- const allExcludes = [...HARD_EXCLUDES, ...userExcludes];
247
- const excludeRegexes = allExcludes.map(globToRegex);
248
-
249
- const isExcluded = (relPath) => excludeRegexes.some((re) => re.test(relPath));
250
- const isGlob = (s) => /[*?[]/.test(s);
251
-
252
- const seen = new Set();
253
- const out = [];
254
- for (const pat of patterns) {
255
- if (!isGlob(pat)) {
256
- // Literal path — include even if it doesn't exist yet; the caller
257
- // reports file_not_found per-entry. Exclude list doesn't apply to
258
- // explicit literal entries (user named it on purpose).
259
- if (!seen.has(pat)) {
260
- seen.add(pat);
261
- out.push(pat);
262
- }
263
- continue;
264
- }
265
- let matches;
266
- try {
267
- matches = fs.globSync(pat, { cwd: rootDir, withFileTypes: true });
268
- } catch {
269
- continue;
270
- }
271
- for (const ent of matches) {
272
- if (!ent.isFile || !ent.isFile()) continue;
273
- const abs = path.join(ent.parentPath || ent.path || rootDir, ent.name);
274
- const rel = path.relative(rootDir, abs).split(path.sep).join('/');
275
- if (isExcluded(rel)) continue;
276
- if (seen.has(rel)) continue;
277
- seen.add(rel);
278
- out.push(rel);
279
- }
280
- }
281
- return out;
282
- }
283
-
284
- /**
285
- * Convert a glob pattern to a RegExp. Supports:
286
- * ** → any number of path segments (including zero)
287
- * * → any chars except `/`
288
- * ? → any single char except `/`
289
- * Paths are normalized to forward slashes before matching.
290
- */
291
- function globToRegex(pattern) {
292
- let re = '';
293
- let i = 0;
294
- while (i < pattern.length) {
295
- const c = pattern[i];
296
- if (c === '*') {
297
- if (pattern[i + 1] === '*') {
298
- // ** — any number of segments, including zero. Handle the common
299
- // **/ and /** forms so `a/**/b` matches `a/b` as well as `a/x/y/b`.
300
- if (pattern[i + 2] === '/') {
301
- re += '(?:.*/)?';
302
- i += 3;
303
- } else {
304
- re += '.*';
305
- i += 2;
306
- }
307
- } else {
308
- re += '[^/]*';
309
- i += 1;
310
- }
311
- } else if (c === '?') {
312
- re += '[^/]';
313
- i += 1;
314
- } else if (/[.+^${}()|[\]\\]/.test(c)) {
315
- re += '\\' + c;
316
- i += 1;
317
- } else {
318
- re += c;
319
- i += 1;
320
- }
321
- }
322
- return new RegExp('^' + re + '$');
323
- }
324
-
325
- // ---------------------------------------------------------------------------
326
- // Core operations
327
- // ---------------------------------------------------------------------------
328
-
329
- function validateConfig(cfg) {
330
- if (!cfg || typeof cfg !== 'object') throw new Error('config.json must be an object');
331
- if (!Array.isArray(cfg.files) || cfg.files.length === 0) {
332
- throw new Error('config.files (non-empty string array) required');
333
- }
334
- if (!cfg.files.every((f) => typeof f === 'string' && f.length > 0)) {
335
- throw new Error('config.files must contain only non-empty strings');
336
- }
337
- if (cfg.exclude !== undefined) {
338
- if (!Array.isArray(cfg.exclude)) {
339
- throw new Error('config.exclude, if present, must be a string array');
340
- }
341
- if (!cfg.exclude.every((f) => typeof f === 'string' && f.length > 0)) {
342
- throw new Error('config.exclude must contain only non-empty strings');
343
- }
344
- }
345
- if (typeof cfg.insertBefore !== 'string' && typeof cfg.insertAfter !== 'string') {
346
- throw new Error('config.insertBefore or config.insertAfter (string) required');
347
- }
348
- if (cfg.commentSyntax !== 'html' && cfg.commentSyntax !== 'jsx') {
349
- throw new Error("config.commentSyntax must be 'html' or 'jsx'");
350
- }
351
- if (cfg.cspChecked !== undefined && typeof cfg.cspChecked !== 'boolean') {
352
- throw new Error("config.cspChecked, if present, must be a boolean");
353
- }
354
- }
355
-
356
- function commentOpen(syntax) { return syntax === 'jsx' ? '{/*' : '<!--'; }
357
- function commentClose(syntax) { return syntax === 'jsx' ? '*/}' : '-->'; }
358
-
359
- function buildTagBlock(syntax, port, filePath) {
360
- const open = commentOpen(syntax);
361
- const close = commentClose(syntax);
362
- // Astro processes <script> tags by default and rewrites src to its own
363
- // bundled URL. is:inline opts out so the literal external src survives.
364
- const isAstro = typeof filePath === 'string' && filePath.endsWith('.astro');
365
- const scriptAttrs = isAstro ? 'is:inline ' : '';
366
- return (
367
- open + ' ' + MARKER_OPEN_TEXT + ' ' + close + '\n' +
368
- '<script ' + scriptAttrs + 'src="http://localhost:' + port + '/live.js"></script>\n' +
369
- open + ' ' + MARKER_CLOSE_TEXT + ' ' + close + '\n'
370
- );
371
- }
372
-
373
- function detectLineEnding(content) {
374
- if (content.includes('\r\n')) return '\r\n';
375
- if (content.includes('\r')) return '\r';
376
- return '\n';
377
- }
378
-
379
- function normalizeLineEndings(content, lineEnding) {
380
- return lineEnding === '\n' ? content : content.replace(/\n/g, lineEnding);
381
- }
382
-
383
- function readLineEndingAt(content, index) {
384
- if (content[index] === '\r' && content[index + 1] === '\n') return '\r\n';
385
- if (content[index] === '\n') return '\n';
386
- if (content[index] === '\r') return '\r';
387
- return '';
388
- }
389
-
390
- function insertTag(content, config, port, filePath) {
391
- const lineEnding = detectLineEnding(content);
392
- const block = normalizeLineEndings(buildTagBlock(config.commentSyntax, port, filePath), lineEnding);
393
- // insertBefore: match the LAST occurrence. Anchors like `</body>` naturally
394
- // belong at the end, and the same literal can appear earlier in code blocks
395
- // within rendered documentation pages.
396
- if (config.insertBefore) {
397
- const idx = content.lastIndexOf(config.insertBefore);
398
- if (idx === -1) return content;
399
- return content.slice(0, idx) + block + content.slice(idx);
400
- }
401
- // insertAfter: match the FIRST occurrence — typical anchors like `<head>` or
402
- // `<body>` open near the top of the document.
403
- const idx = content.indexOf(config.insertAfter);
404
- if (idx === -1) return content;
405
- const after = idx + config.insertAfter.length;
406
- // Preserve an existing trailing newline if the anchor already has one.
407
- // Slice the remainder from the original anchor offset, not prefix.length:
408
- // in the no-newline case prefix is one char longer than the anchor (the
409
- // appended '\n'), so slicing by prefix.length would drop the first real
410
- // character after the anchor (#227).
411
- const existingNewline = readLineEndingAt(content, after);
412
- const prefix = content.slice(0, after) + (existingNewline || lineEnding);
413
- const rest = content.slice(after + existingNewline.length);
414
- return prefix + block + rest;
415
- }
416
-
417
- /**
418
- * Remove the live script block. Matches either HTML or JSX comment markers
419
- * regardless of config (so stale tags from a wrong config can still be cleaned).
420
- *
421
- * Indent-preserving: captures any whitespace immediately preceding the opener
422
- * marker and re-emits it in place of the removed block. `insertTag` inserted
423
- * the block *after* the original line's indent and *before* the anchor (e.g.
424
- * `</body>`), which moved the indent onto the opener line and left the anchor
425
- * unindented. Replacing the whole block (plus its trailing newline) with just
426
- * the captured indent hands the indent back to the anchor that follows.
427
- */
428
- function removeTag(content, _syntax) {
429
- const patterns = [
430
- /([ \t]*)<!--\s*impeccable-live-start\s*-->[\s\S]*?<!--\s*impeccable-live-end\s*-->([ \t]*(?:\r\n|\n|\r|$)?)/,
431
- /([ \t]*)\{\/\*\s*impeccable-live-start\s*\*\/\}[\s\S]*?\{\/\*\s*impeccable-live-end\s*\*\/\}([ \t]*(?:\r\n|\n|\r|$)?)/,
432
- ];
433
- for (const pat of patterns) {
434
- let changed = false;
435
- let next = content;
436
- do {
437
- content = next;
438
- next = content.replace(pat, (_match, leadingIndent, trailing = '') => {
439
- if (/[\r\n]/.test(trailing)) return leadingIndent;
440
- return leadingIndent || trailing || '';
441
- });
442
- if (next !== content) changed = true;
443
- } while (next !== content);
444
- if (changed) return next;
445
- }
446
- return content;
447
- }
448
-
449
- // ---------------------------------------------------------------------------
450
- // Content-Security-Policy meta-tag patcher
451
- //
452
- // When the user's HTML carries `<meta http-equiv="Content-Security-Policy">`,
453
- // the cross-origin load of /live.js (and the SSE/POST connection back to
454
- // localhost:PORT) is blocked unless the CSP explicitly allows that origin.
455
- //
456
- // On insert: append `http://localhost:PORT` to `script-src` and `connect-src`,
457
- // and stash the original `content` value in a `data-impeccable-csp-original`
458
- // attribute (base64) so revert is exact.
459
- //
460
- // On remove: detect the marker attribute, decode it, restore the original
461
- // content value verbatim, drop the marker.
462
- //
463
- // Header-based CSP (Next.js headers, Nuxt routeRules, SvelteKit kit.csp,
464
- // shared helpers) is NOT patched here — those need framework-specific config
465
- // edits and are handled via the existing detect-csp.mjs reference output.
466
- // Only the in-source meta-tag form gets the auto-patch.
467
- // ---------------------------------------------------------------------------
468
-
469
- const CSP_MARKER_ATTR = 'data-impeccable-csp-original';
470
-
471
- function findCspMetaTags(content) {
472
- const out = [];
473
- const tagRe = /<meta\s+([^>]*?)\/?>/gis;
474
- let m;
475
- while ((m = tagRe.exec(content)) !== null) {
476
- const attrs = m[1];
477
- if (!/(http-equiv|httpEquiv)\s*=\s*(['"])Content-Security-Policy\2/i.test(attrs)) continue;
478
- out.push({ start: m.index, end: m.index + m[0].length, full: m[0], attrs });
479
- }
480
- return out;
481
- }
482
-
483
- function getAttr(attrs, name) {
484
- const re = new RegExp(`\\b${name}\\s*=\\s*(['"])([\\s\\S]*?)\\1`, 'i');
485
- const m = attrs.match(re);
486
- return m ? { quote: m[1], value: m[2], full: m[0] } : null;
487
- }
488
-
489
- function appendOriginToDirective(csp, directive, origin) {
490
- const re = new RegExp(`(^|;)(\\s*)(${directive})\\s+([^;]*)`, 'i');
491
- const m = csp.match(re);
492
- if (m) {
493
- const tokens = m[4].trim().split(/\s+/);
494
- if (tokens.includes(origin)) return csp;
495
- return csp.replace(re, `${m[1]}${m[2]}${m[3]} ${[...tokens, origin].join(' ')}`);
496
- }
497
- // Directive missing — add it. Use 'self' + origin so we don't inadvertently
498
- // narrow the policy compared to the default-src fallback (most users with
499
- // an explicit CSP have 'self' there).
500
- return csp.trim().replace(/;?\s*$/, '') + `; ${directive} 'self' ${origin}`;
501
- }
502
-
503
- export function patchCspMeta(content, port) {
504
- const tags = findCspMetaTags(content);
505
- if (tags.length === 0) return content;
506
- const origin = `http://localhost:${port}`;
507
-
508
- // Walk last-to-first so prior splices don't invalidate later indices.
509
- let result = content;
510
- for (let i = tags.length - 1; i >= 0; i--) {
511
- const tag = tags[i];
512
- const attrs = tag.attrs;
513
- if (getAttr(attrs, CSP_MARKER_ATTR)) continue; // already patched
514
- const contentAttr = getAttr(attrs, 'content');
515
- if (!contentAttr) continue;
516
-
517
- const original = contentAttr.value;
518
- let patched = original;
519
- patched = appendOriginToDirective(patched, 'script-src', origin);
520
- patched = appendOriginToDirective(patched, 'connect-src', origin);
521
- // The shader overlay during 'generating' creates a screenshot via
522
- // URL.createObjectURL, producing a `blob:` URL — img-src 'self' rejects
523
- // those. Add `blob:` so the overlay doesn't throw a CSP violation.
524
- patched = appendOriginToDirective(patched, 'img-src', 'blob:');
525
- if (patched === original) continue;
526
-
527
- const newContentAttr = `content=${contentAttr.quote}${patched}${contentAttr.quote}`;
528
- const marker = `${CSP_MARKER_ATTR}="${Buffer.from(original, 'utf-8').toString('base64')}"`;
529
- // The tagRe captures any whitespace between the last attribute and the
530
- // closing `/>` as part of `attrs`. Naively appending ` ${marker}` after
531
- // a replace would land it BEFORE that trailing space, leaving a double
532
- // space inside attrs and clobbering the space before `/>`. Split off
533
- // the trailing whitespace, splice the marker into the attribute body,
534
- // and re-append the original trailing whitespace so a self-closing
535
- // `<meta … />` round-trips byte-for-byte.
536
- const trailingWs = (attrs.match(/[ \t]*$/) || [''])[0];
537
- const attrsBody = attrs.slice(0, attrs.length - trailingWs.length);
538
- const newAttrs = attrsBody.replace(contentAttr.full, newContentAttr) + ' ' + marker + trailingWs;
539
- const newTag = tag.full.replace(attrs, newAttrs);
540
-
541
- result = result.slice(0, tag.start) + newTag + result.slice(tag.end);
542
- }
543
- return result;
544
- }
545
-
546
- export function revertCspMeta(content) {
547
- const tags = findCspMetaTags(content);
548
- if (tags.length === 0) return content;
549
-
550
- let result = content;
551
- for (let i = tags.length - 1; i >= 0; i--) {
552
- const tag = tags[i];
553
- const origAttr = getAttr(tag.attrs, CSP_MARKER_ATTR);
554
- if (!origAttr) continue;
555
- const contentAttr = getAttr(tag.attrs, 'content');
556
- if (!contentAttr) continue;
557
-
558
- let originalValue;
559
- try { originalValue = Buffer.from(origAttr.value, 'base64').toString('utf-8'); }
560
- catch { continue; }
561
-
562
- const newContentAttr = `content=${contentAttr.quote}${originalValue}${contentAttr.quote}`;
563
- let newAttrs = tag.attrs.replace(contentAttr.full, newContentAttr);
564
- // Drop the marker attribute and any single space immediately preceding it.
565
- newAttrs = newAttrs.replace(new RegExp(`\\s*${origAttr.full}`), '');
566
- const newTag = tag.full.replace(tag.attrs, newAttrs);
567
-
568
- result = result.slice(0, tag.start) + newTag + result.slice(tag.end);
569
- }
570
- return result;
571
- }
572
-
573
- // ---------------------------------------------------------------------------
574
- // Auto-execute
575
- // ---------------------------------------------------------------------------
576
-
577
- const _running = process.argv[1];
578
- if (_running?.endsWith('live-inject.mjs') || _running?.endsWith('live-inject.mjs/')) {
579
- injectCli();
580
- }
581
-
582
- export { insertTag, removeTag, validateConfig, buildTagBlock };
583
- // patchCspMeta + revertCspMeta are exported above where they're defined.