sera-code 0.0.0-stage → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (457) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE-SERA.md +33 -0
  3. package/README.md +27 -2
  4. package/THIRD_PARTY_NOTICES.md +68 -0
  5. package/bin/sera.mjs +145 -0
  6. package/dist/bundle/chunks/anthropic-messages-RD7GXOQL.js +6 -0
  7. package/dist/bundle/chunks/anthropic.js +75 -0
  8. package/dist/bundle/chunks/azure-openai-responses-CJT3KTVK.js +2 -0
  9. package/dist/bundle/chunks/bedrock-converse-stream.js +89 -0
  10. package/dist/bundle/chunks/chunk-46WGNYIE.js +82 -0
  11. package/dist/bundle/chunks/chunk-4UNN5OGR.js +4 -0
  12. package/dist/bundle/chunks/chunk-53H5DPHA.js +16 -0
  13. package/dist/bundle/chunks/chunk-5AGIVGSV.js +6 -0
  14. package/dist/bundle/chunks/chunk-6QGV3IWD.js +6 -0
  15. package/dist/bundle/chunks/chunk-7CBJINYJ.js +20 -0
  16. package/dist/bundle/chunks/chunk-7DDKXS2Q.js +2 -0
  17. package/dist/bundle/chunks/chunk-7RZ5BS7U.js +2 -0
  18. package/dist/bundle/chunks/chunk-7ZC4UXSL.js +2 -0
  19. package/dist/bundle/chunks/chunk-AZC5WTED.js +1222 -0
  20. package/dist/bundle/chunks/chunk-BPHHHEET.js +9 -0
  21. package/dist/bundle/chunks/chunk-BSS6T6KQ.js +2 -0
  22. package/dist/bundle/chunks/chunk-CF5GWZHW.js +31 -0
  23. package/dist/bundle/chunks/chunk-EDSQGWII.js +44 -0
  24. package/dist/bundle/chunks/chunk-FFMDRXC4.js +10 -0
  25. package/dist/bundle/chunks/chunk-HODJBMOY.js +9 -0
  26. package/dist/bundle/chunks/chunk-HQBQWHLD.js +7 -0
  27. package/dist/bundle/chunks/chunk-HQJBN2MC.js +2 -0
  28. package/dist/bundle/chunks/chunk-JXWJOIH4.js +2 -0
  29. package/dist/bundle/chunks/chunk-KXU77PUU.js +4 -0
  30. package/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
  31. package/dist/bundle/chunks/chunk-LOMPDCMP.js +2 -0
  32. package/dist/bundle/chunks/chunk-LPXNMA2W.js +2 -0
  33. package/dist/bundle/chunks/chunk-LVVZS2NO.js +12 -0
  34. package/dist/bundle/chunks/chunk-M3LEVT3X.js +2 -0
  35. package/dist/bundle/chunks/chunk-P7FPUEYA.js +2 -0
  36. package/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
  37. package/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
  38. package/dist/bundle/chunks/chunk-PMRZO46Y.js +2 -0
  39. package/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
  40. package/dist/bundle/chunks/chunk-QTM7S6TH.js +2 -0
  41. package/dist/bundle/chunks/chunk-RDZVAGPR.js +2 -0
  42. package/dist/bundle/chunks/chunk-TLNP2BSO.js +2 -0
  43. package/dist/bundle/chunks/chunk-TMKHGABX.js +2 -0
  44. package/dist/bundle/chunks/chunk-TMTOQ7H7.js +2 -0
  45. package/dist/bundle/chunks/chunk-UKVNB6C4.js +2 -0
  46. package/dist/bundle/chunks/chunk-USJZMAIR.js +2 -0
  47. package/dist/bundle/chunks/chunk-UTB4DTYQ.js +2 -0
  48. package/dist/bundle/chunks/chunk-ZLAHUYDW.js +131 -0
  49. package/dist/bundle/chunks/chunk-ZNCN2NGY.js +60 -0
  50. package/dist/bundle/chunks/cli-MML2DU4A.js +51 -0
  51. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-QPZQRBK5.js +2 -0
  52. package/dist/bundle/chunks/codemode-worker.js +478 -0
  53. package/dist/bundle/chunks/dist-ZNZCJI7B.js +7 -0
  54. package/dist/bundle/chunks/easter-egg-3d-VOETWRJO.js +2 -0
  55. package/dist/bundle/chunks/execute-HXDNZ26B.js +505 -0
  56. package/dist/bundle/chunks/github-copilot.js +2 -0
  57. package/dist/bundle/chunks/google-generative-ai-SJXMIEPZ.js +2 -0
  58. package/dist/bundle/chunks/google-vertex-VSXQ3BDH.js +2 -0
  59. package/dist/bundle/chunks/https-proxy-agent-LVOO5TPL.js +13 -0
  60. package/dist/bundle/chunks/image-resize-worker.js +2 -0
  61. package/dist/bundle/chunks/jiti-loader-GL4HJFAD.js +21 -0
  62. package/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +2 -0
  63. package/dist/bundle/chunks/kimi-coding.js +2 -0
  64. package/dist/bundle/chunks/lib-4AVRLBHM.js +9 -0
  65. package/dist/bundle/chunks/llama-cpp-classify-4KFSGAMH.js +22 -0
  66. package/dist/bundle/chunks/meta.js +2 -0
  67. package/dist/bundle/chunks/mistral-conversations-JYWDZV2K.js +5 -0
  68. package/dist/bundle/chunks/multipart-parser-FMGQ7342.js +3 -0
  69. package/dist/bundle/chunks/node-AUOGOBCN.js +2 -0
  70. package/dist/bundle/chunks/node-KCMANYC2.js +16 -0
  71. package/dist/bundle/chunks/openai-chatgpt.js +75 -0
  72. package/dist/bundle/chunks/openai-codex-responses-OQV5DCFA.js +10 -0
  73. package/dist/bundle/chunks/openai-codex.js +75 -0
  74. package/dist/bundle/chunks/openai-completions-RFDJM2W5.js +7 -0
  75. package/dist/bundle/chunks/openai-decisions-O6PHBSCB.js +5 -0
  76. package/dist/bundle/chunks/openai-responses-LVNAPALQ.js +4 -0
  77. package/dist/bundle/chunks/openrouter-images-4WG6OOLH.js +2 -0
  78. package/dist/bundle/chunks/openrouter.js +75 -0
  79. package/dist/bundle/chunks/pdfjs-BETXZQ7A.js +108 -0
  80. package/dist/bundle/chunks/pdfjs-decoders-37HBPYHX.js +2 -0
  81. package/dist/bundle/chunks/pdfjs-jbig2-MH7WRXUP.js +2 -0
  82. package/dist/bundle/chunks/pdfjs-jbig2_nowasm_fallback-UVK7AQLA.js +2 -0
  83. package/dist/bundle/chunks/pdfjs-openjpeg-TC2QHC4G.js +2 -0
  84. package/dist/bundle/chunks/pdfjs-openjpeg_nowasm_fallback-ZC2FTHCZ.js +3 -0
  85. package/dist/bundle/chunks/pi-messages-EZXKVRR6.js +8 -0
  86. package/dist/bundle/chunks/radius.js +75 -0
  87. package/dist/bundle/chunks/runtime-JAH75CB5.js +2 -0
  88. package/dist/bundle/chunks/src-QKGKDFSU.js +4 -0
  89. package/dist/bundle/chunks/typesafe-system-one-X3JT6ECA.js +2 -0
  90. package/dist/bundle/chunks/virtual-modules-Z2V3PTLI.js +2 -0
  91. package/dist/bundle/chunks/xai.js +2 -0
  92. package/dist/bundle/cli-runtime.js +3 -0
  93. package/dist/bundle/cli.js +5 -0
  94. package/dist/bundle/index.js +2 -0
  95. package/dist/bundle/rpc-entry.js +3 -0
  96. package/dist/core/export-html/ansi-to-html.d.ts +22 -0
  97. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
  98. package/dist/core/export-html/ansi-to-html.js +249 -0
  99. package/dist/core/export-html/ansi-to-html.js.map +1 -0
  100. package/dist/core/export-html/index.d.ts +37 -0
  101. package/dist/core/export-html/index.d.ts.map +1 -0
  102. package/dist/core/export-html/index.js +228 -0
  103. package/dist/core/export-html/index.js.map +1 -0
  104. package/dist/core/export-html/template.css +1085 -0
  105. package/dist/core/export-html/template.html +56 -0
  106. package/dist/core/export-html/template.js +2044 -0
  107. package/dist/core/export-html/tool-renderer.d.ts +34 -0
  108. package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
  109. package/dist/core/export-html/tool-renderer.js +110 -0
  110. package/dist/core/export-html/tool-renderer.js.map +1 -0
  111. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  112. package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
  113. package/dist/core/export-html/vendor/marked.min.js +79 -0
  114. package/dist/modes/interactive/assets/clankolas.png +0 -0
  115. package/dist/modes/interactive/theme/dark.json +81 -0
  116. package/dist/modes/interactive/theme/light.json +81 -0
  117. package/dist/modes/interactive/theme/system-theme.d.ts +55 -0
  118. package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -0
  119. package/dist/modes/interactive/theme/system-theme.js +546 -0
  120. package/dist/modes/interactive/theme/system-theme.js.map +1 -0
  121. package/dist/modes/interactive/theme/theme-controller.d.ts +81 -0
  122. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -0
  123. package/dist/modes/interactive/theme/theme-controller.js +210 -0
  124. package/dist/modes/interactive/theme/theme-controller.js.map +1 -0
  125. package/dist/modes/interactive/theme/theme-schema.d.ts +28 -0
  126. package/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -0
  127. package/dist/modes/interactive/theme/theme-schema.js +105 -0
  128. package/dist/modes/interactive/theme/theme-schema.js.map +1 -0
  129. package/dist/modes/interactive/theme/theme-tokens.d.ts +257 -0
  130. package/dist/modes/interactive/theme/theme-tokens.d.ts.map +1 -0
  131. package/dist/modes/interactive/theme/theme-tokens.js +94 -0
  132. package/dist/modes/interactive/theme/theme-tokens.js.map +1 -0
  133. package/dist/modes/interactive/theme/theme.d.ts +155 -0
  134. package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
  135. package/dist/modes/interactive/theme/theme.js +905 -0
  136. package/dist/modes/interactive/theme/theme.js.map +1 -0
  137. package/docs/cli-integration.md +106 -0
  138. package/docs/cli.md +333 -0
  139. package/docs/codemode.md +230 -0
  140. package/docs/compaction.md +463 -0
  141. package/docs/configuration.md +47 -0
  142. package/docs/containerization.md +183 -0
  143. package/docs/custom-provider.md +227 -0
  144. package/docs/docs.json +220 -0
  145. package/docs/environment-variables.md +102 -0
  146. package/docs/extensions.md +400 -0
  147. package/docs/how-pi-works.md +49 -0
  148. package/docs/index.md +39 -0
  149. package/docs/json.md +226 -0
  150. package/docs/keybindings.md +195 -0
  151. package/docs/llama-cpp.md +121 -0
  152. package/docs/mcp.md +272 -0
  153. package/docs/message-types.md +279 -0
  154. package/docs/models-configuration.md +196 -0
  155. package/docs/models.md +225 -0
  156. package/docs/nvidia-rtx-llama-cpp.md +96 -0
  157. package/docs/packages.md +131 -0
  158. package/docs/prompt-templates.md +59 -0
  159. package/docs/providers.md +247 -0
  160. package/docs/quickstart.md +136 -0
  161. package/docs/rpc-commands.md +860 -0
  162. package/docs/rpc-extension-ui.md +200 -0
  163. package/docs/rpc.md +193 -0
  164. package/docs/sdk.md +147 -0
  165. package/docs/security.md +99 -0
  166. package/docs/session-format.md +293 -0
  167. package/docs/sessions.md +66 -0
  168. package/docs/settings.md +172 -0
  169. package/docs/shell-aliases.md +93 -0
  170. package/docs/skills.md +93 -0
  171. package/docs/slash-commands.md +61 -0
  172. package/docs/terminal-setup.md +233 -0
  173. package/docs/termux.md +117 -0
  174. package/docs/themes.md +138 -0
  175. package/docs/tmux.md +55 -0
  176. package/docs/tui.md +195 -0
  177. package/docs/usage.md +94 -0
  178. package/docs/virtual-models.md +114 -0
  179. package/docs/windows.md +81 -0
  180. package/lib/auth.js +377 -0
  181. package/lib/provider.js +71 -0
  182. package/package.json +43 -5
  183. package/sera-core/skills/apple-tasarim/SKILL.md +48 -0
  184. package/sera-core/skills/apple-tasarim/referanslar/apple-hig.md +55 -0
  185. package/sera-core/skills/belge-yarat/SKILL.md +64 -0
  186. package/sera-core/skills/belge-yarat/referanslar/belge-yazim.md +60 -0
  187. package/sera-core/skills/derin-arastirma/SKILL.md +52 -0
  188. package/sera-core/skills/derin-arastirma/referanslar/arastirma-yontem.md +50 -0
  189. package/sera-core/skills/dusunme-dogrulama/SKILL.md +59 -0
  190. package/sera-core/skills/dusunme-dogrulama/referanslar/dusunme-kontrol.md +54 -0
  191. package/sera-core/skills/film-stilleri/SKILL.md +51 -0
  192. package/sera-core/skills/hyperframes/LICENSE-UPSTREAM +190 -0
  193. package/sera-core/skills/hyperframes/SKILL.md +79 -0
  194. package/sera-core/skills/hyperframes/assets/frame-presets/biennale-yellow/FRAME.md +289 -0
  195. package/sera-core/skills/hyperframes/assets/frame-presets/blockframe/FRAME.md +275 -0
  196. package/sera-core/skills/hyperframes/assets/frame-presets/blue-professional/FRAME.md +307 -0
  197. package/sera-core/skills/hyperframes/assets/frame-presets/bold-poster/FRAME.md +275 -0
  198. package/sera-core/skills/hyperframes/assets/frame-presets/broadside/FRAME.md +284 -0
  199. package/sera-core/skills/hyperframes/assets/frame-presets/capsule/FRAME.md +284 -0
  200. package/sera-core/skills/hyperframes/assets/frame-presets/cartesian/FRAME.md +278 -0
  201. package/sera-core/skills/hyperframes/assets/frame-presets/cobalt-grid/FRAME.md +265 -0
  202. package/sera-core/skills/hyperframes/assets/frame-presets/code-editorial/FRAME.md +277 -0
  203. package/sera-core/skills/hyperframes/assets/frame-presets/coral/FRAME.md +314 -0
  204. package/sera-core/skills/hyperframes/assets/frame-presets/creative-mode/FRAME.md +333 -0
  205. package/sera-core/skills/hyperframes/assets/frame-presets/daisy-days/FRAME.md +274 -0
  206. package/sera-core/skills/hyperframes/assets/frame-presets/editorial-forest/FRAME.md +265 -0
  207. package/sera-core/skills/hyperframes/references/captions.md +46 -0
  208. package/sera-core/skills/hyperframes/references/film.md +48 -0
  209. package/sera-core/skills/hyperframes/references/format.md +159 -0
  210. package/sera-core/skills/hyperframes/references/look.md +69 -0
  211. package/sera-core/skills/hyperframes/references/motion.md +95 -0
  212. package/sera-core/skills/hyperframes/references/overlays.md +39 -0
  213. package/sera-core/skills/hyperframes/references/path-tracing.md +36 -0
  214. package/sera-core/skills/hyperframes/references/plugin-installation.md +42 -0
  215. package/sera-core/skills/hyperframes/references/review.md +51 -0
  216. package/sera-core/skills/hyperframes/references/runtimes.md +69 -0
  217. package/sera-core/skills/hyperframes/references/skill-lifecycle.md +54 -0
  218. package/sera-core/skills/hyperframes/references/sound.md +43 -0
  219. package/sera-core/skills/hyperframes/references/spec.md +76 -0
  220. package/sera-core/skills/hyperframes/references/story.md +103 -0
  221. package/sera-core/skills/hyperframes/references/storyboard-format.md +107 -0
  222. package/sera-core/skills/hyperframes/references/storyboard.md +36 -0
  223. package/sera-core/skills/hyperframes/references/types/3d.md +25 -0
  224. package/sera-core/skills/hyperframes/references/types/character.md +20 -0
  225. package/sera-core/skills/hyperframes/references/types/data.md +19 -0
  226. package/sera-core/skills/hyperframes/references/types/explainer.md +34 -0
  227. package/sera-core/skills/hyperframes/references/types/launch.md +41 -0
  228. package/sera-core/skills/hyperframes/references/types/music.md +24 -0
  229. package/sera-core/skills/hyperframes/references/types/vertical.md +23 -0
  230. package/sera-core/skills/hyperframes-cli/LICENSE-UPSTREAM +190 -0
  231. package/sera-core/skills/hyperframes-cli/SKILL.md +99 -0
  232. package/sera-core/skills/hyperframes-cli/references/beats.md +17 -0
  233. package/sera-core/skills/hyperframes-cli/references/compare-and-batch.md +105 -0
  234. package/sera-core/skills/hyperframes-cli/references/conventions.md +16 -0
  235. package/sera-core/skills/hyperframes-cli/references/doctor-browser.md +80 -0
  236. package/sera-core/skills/hyperframes-cli/references/feedback.md +14 -0
  237. package/sera-core/skills/hyperframes-cli/references/init-and-scaffold.md +75 -0
  238. package/sera-core/skills/hyperframes-cli/references/lint-validate-inspect.md +164 -0
  239. package/sera-core/skills/hyperframes-cli/references/preview-render.md +204 -0
  240. package/sera-core/skills/hyperframes-cli/references/upgrade-info-misc.md +134 -0
  241. package/sera-core/skills/impeccable/LICENSE-UPSTREAM +191 -0
  242. package/sera-core/skills/impeccable/NOTICE-UPSTREAM.md +11 -0
  243. package/sera-core/skills/impeccable/SKILL.md +89 -0
  244. package/sera-core/skills/impeccable/reference/adapt.md +318 -0
  245. package/sera-core/skills/impeccable/reference/adapt.native.md +58 -0
  246. package/sera-core/skills/impeccable/reference/android.md +46 -0
  247. package/sera-core/skills/impeccable/reference/animate.md +89 -0
  248. package/sera-core/skills/impeccable/reference/audit.md +139 -0
  249. package/sera-core/skills/impeccable/reference/audit.native.md +139 -0
  250. package/sera-core/skills/impeccable/reference/bolder.md +33 -0
  251. package/sera-core/skills/impeccable/reference/clarify.md +94 -0
  252. package/sera-core/skills/impeccable/reference/colorize.md +86 -0
  253. package/sera-core/skills/impeccable/reference/component-review.md +63 -0
  254. package/sera-core/skills/impeccable/reference/craft-floor.md +44 -0
  255. package/sera-core/skills/impeccable/reference/craft.md +5 -0
  256. package/sera-core/skills/impeccable/reference/critique.md +819 -0
  257. package/sera-core/skills/impeccable/reference/degraded/asset-producer.md +42 -0
  258. package/sera-core/skills/impeccable/reference/degraded/documenter.md +24 -0
  259. package/sera-core/skills/impeccable/reference/degraded/finish-reviewer.md +38 -0
  260. package/sera-core/skills/impeccable/reference/degraded/manual-edit-applier.md +93 -0
  261. package/sera-core/skills/impeccable/reference/delight.md +70 -0
  262. package/sera-core/skills/impeccable/reference/distill.md +111 -0
  263. package/sera-core/skills/impeccable/reference/doctor.md +54 -0
  264. package/sera-core/skills/impeccable/reference/document.md +416 -0
  265. package/sera-core/skills/impeccable/reference/extract.md +69 -0
  266. package/sera-core/skills/impeccable/reference/generate.md +101 -0
  267. package/sera-core/skills/impeccable/reference/harden.md +362 -0
  268. package/sera-core/skills/impeccable/reference/hooks.md +120 -0
  269. package/sera-core/skills/impeccable/reference/init.md +133 -0
  270. package/sera-core/skills/impeccable/reference/ios.md +51 -0
  271. package/sera-core/skills/impeccable/reference/layout.md +84 -0
  272. package/sera-core/skills/impeccable/reference/live-setup.md +104 -0
  273. package/sera-core/skills/impeccable/reference/live.md +327 -0
  274. package/sera-core/skills/impeccable/reference/mode-operate.md +21 -0
  275. package/sera-core/skills/impeccable/reference/mode-persuade.md +19 -0
  276. package/sera-core/skills/impeccable/reference/mode-read.md +21 -0
  277. package/sera-core/skills/impeccable/reference/new-work.md +152 -0
  278. package/sera-core/skills/impeccable/reference/onboard.md +234 -0
  279. package/sera-core/skills/impeccable/reference/operate.md +61 -0
  280. package/sera-core/skills/impeccable/reference/optimize.md +257 -0
  281. package/sera-core/skills/impeccable/reference/overdrive.md +127 -0
  282. package/sera-core/skills/impeccable/reference/polish.md +105 -0
  283. package/sera-core/skills/impeccable/reference/quieter.md +99 -0
  284. package/sera-core/skills/impeccable/reference/region-map.md +26 -0
  285. package/sera-core/skills/impeccable/reference/routing.md +24 -0
  286. package/sera-core/skills/impeccable/reference/shape.md +59 -0
  287. package/sera-core/skills/impeccable/reference/typeset.md +90 -0
  288. package/sera-core/skills/impeccable/reference/visualize.md +47 -0
  289. package/sera-core/skills/oyun-yarat/SKILL.md +106 -0
  290. package/sera-core/skills/oyun-yarat/referanslar/3b-yaris.md +74 -0
  291. package/sera-core/skills/oyun-yarat/referanslar/kaplay.md +99 -0
  292. package/sera-core/skills/oyun-yarat/referanslar/oyun-desenleri.md +73 -0
  293. package/sera-core/skills/oyun-yarat/sablonlar/kaplay-2d.html +164 -0
  294. package/sera-core/skills/oyun-yarat/sablonlar/three-yaris.html +149 -0
  295. package/sera-core/skills/oyun-yarat/sablonlar/tuval-minimal.html +77 -0
  296. package/sera-core/skills/receiving-code-review/LICENSE-UPSTREAM +21 -0
  297. package/sera-core/skills/receiving-code-review/SKILL.md +205 -0
  298. package/sera-core/skills/refero-design/LICENSE-UPSTREAM +21 -0
  299. package/sera-core/skills/refero-design/SKILL.md +534 -0
  300. package/sera-core/skills/refero-design/references/anti-ai-slop.md +292 -0
  301. package/sera-core/skills/refero-design/references/color.md +563 -0
  302. package/sera-core/skills/refero-design/references/copywriting.md +222 -0
  303. package/sera-core/skills/refero-design/references/craft-details.md +525 -0
  304. package/sera-core/skills/refero-design/references/example-workflow.md +264 -0
  305. package/sera-core/skills/refero-design/references/icons.md +166 -0
  306. package/sera-core/skills/refero-design/references/mcp-tools.md +258 -0
  307. package/sera-core/skills/refero-design/references/motion.md +504 -0
  308. package/sera-core/skills/refero-design/references/typography.md +737 -0
  309. package/sera-core/skills/refero-design/references/visual-workflow.md +105 -0
  310. package/sera-core/skills/requesting-code-review/LICENSE-UPSTREAM +21 -0
  311. package/sera-core/skills/requesting-code-review/SKILL.md +95 -0
  312. package/sera-core/skills/requesting-code-review/code-reviewer.md +198 -0
  313. package/sera-core/skills/reverse-engineer-anything/DISCLAIMER.md +136 -0
  314. package/sera-core/skills/reverse-engineer-anything/LICENSE-REA-MIT +21 -0
  315. package/sera-core/skills/reverse-engineer-anything/SKILL.md +363 -0
  316. package/sera-core/skills/reverse-engineer-anything/THIRD_PARTY_NOTICES.md +135 -0
  317. package/sera-core/skills/reverse-engineer-anything/references/android-applications.md +36 -0
  318. package/sera-core/skills/reverse-engineer-anything/references/connection-and-recovery.md +127 -0
  319. package/sera-core/skills/reverse-engineer-anything/references/evidence-workflows.md +71 -0
  320. package/sera-core/skills/reverse-engineer-anything/references/javascript-applications.md +218 -0
  321. package/sera-core/skills/reverse-engineer-anything/references/native-and-artifacts.md +297 -0
  322. package/sera-core/skills/reverse-engineer-anything/references/runtime-observation.md +78 -0
  323. package/sera-core/skills/seo-audit/LICENSE-UPSTREAM +21 -0
  324. package/sera-core/skills/seo-audit/SKILL.md +210 -0
  325. package/sera-core/skills/sera-guvenlik-denetim/SKILL.md +44 -0
  326. package/sera-core/skills/sera-guvenlik-denetim/referanslar/guvenlik-listesi.md +33 -0
  327. package/sera-core/skills/sera-hata-ayikla/SKILL.md +27 -0
  328. package/sera-core/skills/sera-hata-ayikla/referanslar/hata-ayiklama.md +37 -0
  329. package/sera-core/skills/sera-kod-inceleme/SKILL.md +44 -0
  330. package/sera-core/skills/sera-kod-inceleme/referanslar/inceleme-listesi.md +62 -0
  331. package/sera-core/skills/sera-ofis-dosya/SKILL.md +27 -0
  332. package/sera-core/skills/sera-ofis-dosya/referanslar/ofis-dosya.md +93 -0
  333. package/sera-core/skills/sera-research/SKILL.md +90 -0
  334. package/sera-core/skills/sera-tasarim/SKILL.md +149 -0
  335. package/sera-core/skills/sera-teslim-sozlesmesi/SKILL.md +592 -0
  336. package/sera-core/skills/sera-test-yaz/SKILL.md +26 -0
  337. package/sera-core/skills/sera-test-yaz/referanslar/test-yazimi.md +35 -0
  338. package/sera-core/skills/sera-veri-gorsel/SKILL.md +65 -0
  339. package/sera-core/skills/sera-web-test/SKILL.md +26 -0
  340. package/sera-core/skills/sera-web-test/referanslar/web-test.md +44 -0
  341. package/sera-core/skills/sera-zamanli-gorev/SKILL.md +22 -0
  342. package/sera-core/skills/sera-zamanli-gorev/referanslar/zamanli-gorev.md +58 -0
  343. package/sera-core/skills/systematic-debugging/LICENSE-UPSTREAM +21 -0
  344. package/sera-core/skills/systematic-debugging/SKILL.md +283 -0
  345. package/sera-core/skills/systematic-debugging/condition-based-waiting.md +115 -0
  346. package/sera-core/skills/systematic-debugging/defense-in-depth.md +122 -0
  347. package/sera-core/skills/systematic-debugging/root-cause-tracing.md +169 -0
  348. package/sera-core/skills/test-driven-development/LICENSE-UPSTREAM +21 -0
  349. package/sera-core/skills/test-driven-development/SKILL.md +330 -0
  350. package/sera-core/skills/test-driven-development/writing-good-tests.md +198 -0
  351. package/sera-core/skills/ticaret-icerik/SKILL.md +49 -0
  352. package/sera-core/skills/ticaret-icerik/referanslar/ticaret-icerik.md +54 -0
  353. package/sera-core/skills/uygulama-yarat/SKILL.md +95 -0
  354. package/sera-core/skills/uygulama-yarat/referanslar/uygulama-desenleri.md +63 -0
  355. package/sera-core/skills/uygulama-yarat/sablonlar/uygulama-tek-dosya.html +121 -0
  356. package/sera-core/skills/uyumluluk-denetim/SKILL.md +56 -0
  357. package/sera-core/skills/uyumluluk-denetim/referanslar/mevzuat-tablosu.md +65 -0
  358. package/sera-core/skills/veri-analizi/SKILL.md +54 -0
  359. package/sera-core/skills/veri-analizi/referanslar/veri-analizi-yontem.md +49 -0
  360. package/sera-core/skills/veri-analizi/sablonlar/profil.mjs +79 -0
  361. package/sera-core/skills/video-duzen/SKILL.md +50 -0
  362. package/sera-core/skills/video-duzen/referanslar/video-duzen.md +100 -0
  363. package/sera-core/skills/web-yayin-listesi/SKILL.md +115 -0
  364. package/sera-core/skills/writing-plans/LICENSE-UPSTREAM +21 -0
  365. package/sera-core/skills/writing-plans/SKILL.md +204 -0
  366. package/sera-core/src/action-nudge.ts +200 -0
  367. package/sera-core/src/agent-mode.ts +143 -0
  368. package/sera-core/src/agents.ts +185 -0
  369. package/sera-core/src/app-master.ts +275 -0
  370. package/sera-core/src/app-verify.ts +551 -0
  371. package/sera-core/src/approval.ts +131 -0
  372. package/sera-core/src/budget.ts +136 -0
  373. package/sera-core/src/command-policy.ts +808 -0
  374. package/sera-core/src/config.ts +135 -0
  375. package/sera-core/src/context-diet.ts +272 -0
  376. package/sera-core/src/device-id.ts +48 -0
  377. package/sera-core/src/dogal-arac.ts +203 -0
  378. package/sera-core/src/dogal-niyet.ts +173 -0
  379. package/sera-core/src/egress-allow.ts +52 -0
  380. package/sera-core/src/export.ts +124 -0
  381. package/sera-core/src/exposure.ts +8 -0
  382. package/sera-core/src/extension.ts +2410 -0
  383. package/sera-core/src/fs-tools.ts +448 -0
  384. package/sera-core/src/generated/build-rules.ts +26 -0
  385. package/sera-core/src/generated/zero-knowledge.ts +170 -0
  386. package/sera-core/src/github-agent-command.ts +133 -0
  387. package/sera-core/src/github-agent-engine.ts +198 -0
  388. package/sera-core/src/github-agent-schedule.ts +180 -0
  389. package/sera-core/src/github-agent.ts +669 -0
  390. package/sera-core/src/github-ajan-akis.ts +193 -0
  391. package/sera-core/src/github-ajan-gercek.ts +102 -0
  392. package/sera-core/src/github-tick.ts +78 -0
  393. package/sera-core/src/github-yedek.ts +269 -0
  394. package/sera-core/src/goal.ts +119 -0
  395. package/sera-core/src/handoff.ts +132 -0
  396. package/sera-core/src/hooks.ts +284 -0
  397. package/sera-core/src/image-tool.ts +118 -0
  398. package/sera-core/src/intake-brief.ts +82 -0
  399. package/sera-core/src/intake-core.ts +1152 -0
  400. package/sera-core/src/intake-hook.ts +88 -0
  401. package/sera-core/src/ios-build-tool.ts +134 -0
  402. package/sera-core/src/lazy-capability.ts +125 -0
  403. package/sera-core/src/lazy-mcp.ts +300 -0
  404. package/sera-core/src/limit-command.ts +51 -0
  405. package/sera-core/src/loop-brake.ts +129 -0
  406. package/sera-core/src/lsp.ts +618 -0
  407. package/sera-core/src/mcp-bridge.ts +159 -0
  408. package/sera-core/src/mcp-pin.ts +105 -0
  409. package/sera-core/src/mcp-ssrf.ts +124 -0
  410. package/sera-core/src/message-cap.ts +45 -0
  411. package/sera-core/src/model-list.ts +108 -0
  412. package/sera-core/src/no-progress.ts +177 -0
  413. package/sera-core/src/notebook-tool.ts +179 -0
  414. package/sera-core/src/ofis.ts +473 -0
  415. package/sera-core/src/path-guard.ts +139 -0
  416. package/sera-core/src/permission-bridge.ts +228 -0
  417. package/sera-core/src/policy-chain.ts +122 -0
  418. package/sera-core/src/pricing.ts +71 -0
  419. package/sera-core/src/proc.ts +149 -0
  420. package/sera-core/src/rea.ts +188 -0
  421. package/sera-core/src/repo-map.ts +230 -0
  422. package/sera-core/src/research.ts +347 -0
  423. package/sera-core/src/rules-memory.ts +227 -0
  424. package/sera-core/src/sandbox.ts +476 -0
  425. package/sera-core/src/server-error.ts +78 -0
  426. package/sera-core/src/skills.ts +268 -0
  427. package/sera-core/src/snapshot.ts +143 -0
  428. package/sera-core/src/spec-gate.ts +112 -0
  429. package/sera-core/src/subagent.ts +261 -0
  430. package/sera-core/src/teslim.ts +121 -0
  431. package/sera-core/src/test-fix.ts +184 -0
  432. package/sera-core/src/todo-question.ts +163 -0
  433. package/sera-core/src/turn-snapshots.ts +126 -0
  434. package/sera-core/src/tuval/arac.ts +338 -0
  435. package/sera-core/src/tuval/arsiv.ts +106 -0
  436. package/sera-core/src/tuval/belge.ts +216 -0
  437. package/sera-core/src/tuval/birlestir.ts +282 -0
  438. package/sera-core/src/tuval/disa.ts +235 -0
  439. package/sera-core/src/tuval/editor.ts +583 -0
  440. package/sera-core/src/tuval/film-cekirdek.ts +170 -0
  441. package/sera-core/src/tuval/film-disa.ts +188 -0
  442. package/sera-core/src/tuval/film-oynatici.ts +307 -0
  443. package/sera-core/src/tuval/kimlik.ts +156 -0
  444. package/sera-core/src/tuval/pano.ts +763 -0
  445. package/sera-core/src/tuval/proje.ts +728 -0
  446. package/sera-core/src/tuval/sistem-cekirdek.ts +167 -0
  447. package/sera-core/src/tuval/sistem.ts +328 -0
  448. package/sera-core/src/tuval/sunucu.ts +413 -0
  449. package/sera-core/src/tuval/uretim.ts +24 -0
  450. package/sera-core/src/tuval/veri-cekirdek.ts +477 -0
  451. package/sera-core/src/tuval/xlsx.ts +215 -0
  452. package/sera-core/src/tuval/zip.ts +163 -0
  453. package/sera-core/src/untrusted.ts +201 -0
  454. package/sera-core/src/video-edit-tool.ts +411 -0
  455. package/sera-core/src/video-tool.ts +217 -0
  456. package/sera-core/src/web-tools.ts +257 -0
  457. package/sera-core/src/zk.ts +104 -0
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Hedef modu (/goal — Dalga 2, rakip matris madde 2/8; rakip: Codex goal, Qwen /goal, Cursor uzun ömürlü hedef).
3
+ * Kullanıcı bir hedef koyar; ajan her turun sonunda (agent_end) hedefe ulaşana ya da BÜTÇE/YİNELEME tavanına kadar
4
+ * kendi kendine devam eder (followUp ile bir sonraki turu tetikler). Model hedefi bitirince `goal_done` aracını çağırır.
5
+ *
6
+ * GÜVENLİK (sahip "güvenli" + anayasa bütçe ilkesi): otonom devam ÇOK KATMANLI tavanla sınırlıdır —
7
+ * 1) sert yineleme tavanı (HARD_MAX_ITER), 2) tur bütçesi (maxTurns, varsayılan DEFAULT_MAX_TURNS),
8
+ * 3) USD bütçesi (maxUsd, isteğe bağlı), 4) mevcut BudgetGovernor + global kesici arkada. Hedef yoksa mod KAPALI.
9
+ * Bu modül SAFtır (I/O yok); karar mantığı burada test edilir, bağlama (komut/olay/araç) extension.ts'te.
10
+ */
11
+
12
+ /** Hiçbir ayar sonsuz döngüye izin vermez: yineleme her durumda bununla sınırlanır. */
13
+ export const HARD_MAX_ITER = 25;
14
+ /** maxTurns verilmezse uygulanan varsayılan tur bütçesi (hedef başından itibaren delta). */
15
+ export const DEFAULT_MAX_TURNS = 10;
16
+
17
+ export interface GoalState {
18
+ text: string;
19
+ /** Hedef kurulduğundaki governor değerleri (delta bütçe bunlara göre ölçülür). */
20
+ startUsd: number;
21
+ startTurns: number;
22
+ /** Hedef başından itibaren izin verilen tur/USD artışı. */
23
+ maxTurns: number;
24
+ maxUsd?: number;
25
+ /** Otonom devam yineleme sayacı ve sert tavanı. */
26
+ iterations: number;
27
+ maxIterations: number;
28
+ done: boolean;
29
+ }
30
+
31
+ export interface GoalParse {
32
+ /** /goal dur|stop|off|iptal */
33
+ stop?: boolean;
34
+ /** Hedef metni (yoksa komut geçersiz: kullanım göster). */
35
+ text?: string;
36
+ maxTurns?: number;
37
+ maxUsd?: number;
38
+ maxIterations?: number;
39
+ }
40
+
41
+ const num = (s: string | undefined): number | undefined => {
42
+ if (!s) return undefined;
43
+ const n = Number(s);
44
+ return Number.isFinite(n) && n > 0 ? n : undefined;
45
+ };
46
+
47
+ /** `/goal <hedef> [--turns N] [--usd X] [--iter N]` ya da `/goal dur|stop|off|iptal`. */
48
+ export function parseGoalCommand(args: string): GoalParse {
49
+ const raw = args.trim();
50
+ if (/^(dur|durdur|stop|off|iptal|kapat)$/i.test(raw)) return { stop: true };
51
+ let maxTurns: number | undefined;
52
+ let maxUsd: number | undefined;
53
+ let maxIterations: number | undefined;
54
+ const rest = raw
55
+ .replace(/--turns?\s+(\S+)/i, (_m, v) => {
56
+ maxTurns = num(v);
57
+ return "";
58
+ })
59
+ .replace(/--usd\s+(\S+)/i, (_m, v) => {
60
+ maxUsd = num(v);
61
+ return "";
62
+ })
63
+ .replace(/--iter(?:ations?)?\s+(\S+)/i, (_m, v) => {
64
+ maxIterations = num(v);
65
+ return "";
66
+ })
67
+ .replace(/\s+/g, " ")
68
+ .trim();
69
+ return { text: rest || undefined, maxTurns, maxUsd, maxIterations };
70
+ }
71
+
72
+ /** Parse sonucundan yeni hedef durumu (governor başlangıç değerleriyle). Sert tavan her zaman uygulanır. */
73
+ export function newGoal(p: GoalParse, start: { usd: number; turns: number }): GoalState {
74
+ const maxIterations = Math.min(p.maxIterations ?? DEFAULT_MAX_TURNS, HARD_MAX_ITER);
75
+ return {
76
+ text: p.text ?? "",
77
+ startUsd: start.usd,
78
+ startTurns: start.turns,
79
+ maxTurns: p.maxTurns ?? DEFAULT_MAX_TURNS,
80
+ maxUsd: p.maxUsd,
81
+ iterations: 0,
82
+ maxIterations,
83
+ done: false,
84
+ };
85
+ }
86
+
87
+ export interface ContinueDecision {
88
+ cont: boolean;
89
+ /** Durma gerekçesi (cont=false iken). */
90
+ reason?: string;
91
+ }
92
+
93
+ /**
94
+ * Bir turun bitişinde otonom devam edilmeli mi? Sıra önemli: önce bitiş, sonra sert yineleme, sonra tur, sonra USD.
95
+ * Tüm tavanlar DELTA (hedef başından itibaren). Herhangi biri aşıldıysa durur.
96
+ */
97
+ export function shouldContinue(state: GoalState, spent: { usd: number; turns: number }): ContinueDecision {
98
+ if (state.done) return { cont: false, reason: "hedefe ulaşıldı" };
99
+ if (state.iterations >= state.maxIterations)
100
+ return { cont: false, reason: `yineleme sınırı (${state.maxIterations}) doldu` };
101
+ if (spent.turns - state.startTurns >= state.maxTurns)
102
+ return { cont: false, reason: `tur bütçesi (${state.maxTurns}) doldu` };
103
+ if (state.maxUsd !== undefined && spent.usd - state.startUsd >= state.maxUsd)
104
+ return { cont: false, reason: `USD bütçesi ($${state.maxUsd}) doldu` };
105
+ return { cont: true };
106
+ }
107
+
108
+ /** Modeli hedefe doğru bir sonraki somut adıma iten followUp metni; bittiyse goal_done çağırmasını söyler. */
109
+ export function goalNudge(state: GoalState): string {
110
+ return (
111
+ `[Sera hedef modu] Aktif hedef: "${state.text}". ` +
112
+ `Hedefe henüz ulaşılmadıysa bir SONRAKİ somut adımı uygula ve kanıtla. ` +
113
+ `Hedef tamamsa \`goal_done\` aracını kısa bir özetle çağır, başka hiçbir şey yapma. ` +
114
+ `(yineleme ${state.iterations}/${state.maxIterations}, tur bütçesi ${state.maxTurns})`
115
+ );
116
+ }
117
+
118
+ /** Kullanım metni (geçersiz /goal çağrısında). */
119
+ export const GOAL_USAGE = "Kullanım: /goal <hedef> [--turns N] [--usd X] [--iter N] · durdurmak için: /goal dur";
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Devret (/devret): oturumu yeni bir oturuma tasimak icin MODEL CAGRISI YAPMADAN devir metni uretir.
3
+ * Kaynak yalniz oturum kaydi: son ozet (compaction), ilk/son kullanici istegi, son asistan cevabi,
4
+ * degistirilen/okunan dosyalar, acik isler (sera-todo kaydi varsa) ve son anlik kopya (sera-snapshot).
5
+ * Baslik ayni kaynaktan turetilir (yeni hedef > ozetin Goal satiri > ilk istek).
6
+ */
7
+
8
+ import { SNAPSHOT_ENTRY, type TurnSnapshot } from "./turn-snapshots.ts";
9
+
10
+ export const HANDOFF_COMMAND = "sera-handoff";
11
+ /** Komut sonucu bu onekle bildirim (notify) olarak doner; Sera Code adaptoru bekler ve okur. */
12
+ export const HANDOFF_NOTIFY_PREFIX = "sera-handoff:";
13
+ /** Ileride todo araci (D1-8) bu kayit adiyla yazar: { items: [{ text, done }] }. */
14
+ export const TODO_ENTRY = "sera-todo";
15
+
16
+ export interface HandoffEntry {
17
+ id?: string;
18
+ type: string;
19
+ customType?: string;
20
+ data?: unknown;
21
+ summary?: string;
22
+ message?: { role?: string; content?: unknown };
23
+ }
24
+
25
+ export interface Handoff {
26
+ title: string;
27
+ text: string;
28
+ files: string[];
29
+ snapshot?: string;
30
+ }
31
+
32
+ const MAX_TITLE = 50;
33
+
34
+ /** Tek satir, bosluklar sade, kelime sinirinda en fazla 50 karakter. Slash komutu baslik olmaz. */
35
+ export function deriveTitle(text: string): string {
36
+ const line =
37
+ text
38
+ .split("\n")
39
+ .map((l) => l.replace(/^[#>*\-\s]+/, "").trim())
40
+ .find((l) => l && !l.startsWith("/")) ?? "";
41
+ const flat = line.replace(/\s+/g, " ").trim();
42
+ if (flat.length <= MAX_TITLE) return flat;
43
+ const cut = flat.slice(0, MAX_TITLE);
44
+ const sp = cut.lastIndexOf(" ");
45
+ return `${(sp >= 25 ? cut.slice(0, sp) : cut).trimEnd()}…`;
46
+ }
47
+
48
+ function textOf(content: unknown): string {
49
+ if (typeof content === "string") return content;
50
+ if (!Array.isArray(content)) return "";
51
+ return content
52
+ .filter((c): c is { type: string; text: string } => c?.type === "text" && typeof c.text === "string")
53
+ .map((c) => c.text)
54
+ .join("\n");
55
+ }
56
+
57
+ function clip(s: string, n: number): string {
58
+ const t = s.trim();
59
+ return t.length <= n ? t : `${t.slice(0, n).trimEnd()}…`;
60
+ }
61
+
62
+ /** Ozet metninden "## Goal" (ya da "## Hedef") bolumunun ilk satiri. */
63
+ function summaryGoal(summary: string): string | undefined {
64
+ const m = /^##\s*(?:Goal|Hedef)\s*\n+([^\n]+)/im.exec(summary);
65
+ return m?.[1]?.trim() || undefined;
66
+ }
67
+
68
+ export function buildHandoff(branch: HandoffEntry[], goal = ""): Handoff | undefined {
69
+ const users: string[] = [];
70
+ let lastAssistant = "";
71
+ let summary: string | undefined;
72
+ const edited: string[] = [];
73
+ const read: string[] = [];
74
+ let todos: { text: string; done?: boolean }[] | undefined;
75
+ let snapshot: string | undefined;
76
+ const add = (list: string[], p: unknown) => {
77
+ if (typeof p === "string" && p && !list.includes(p)) list.push(p);
78
+ };
79
+ for (const e of branch) {
80
+ if (e.type === "compaction" && typeof e.summary === "string") summary = e.summary;
81
+ else if (e.type === "custom" && e.customType === SNAPSHOT_ENTRY) snapshot = (e.data as TurnSnapshot)?.after;
82
+ else if (e.type === "custom" && e.customType === TODO_ENTRY) {
83
+ const items = (e.data as { items?: unknown })?.items;
84
+ if (Array.isArray(items)) todos = items.filter((i) => typeof i?.text === "string");
85
+ } else if (e.type === "message" && e.message) {
86
+ const { role, content } = e.message;
87
+ if (role === "user") {
88
+ const t = textOf(content).trim();
89
+ if (t && !t.startsWith("/")) users.push(t);
90
+ } else if (role === "assistant") {
91
+ const t = textOf(content).trim();
92
+ if (t) lastAssistant = t;
93
+ for (const c of Array.isArray(content) ? content : []) {
94
+ if (c?.type !== "toolCall") continue;
95
+ const a = (c.arguments ?? {}) as { path?: unknown; file_path?: unknown };
96
+ const p = a.path ?? a.file_path;
97
+ if (c.name === "edit" || c.name === "write" || c.name === "notebook_edit") add(edited, p);
98
+ else if (c.name === "read") add(read, p);
99
+ }
100
+ }
101
+ }
102
+ }
103
+ if (users.length === 0 && !summary) return undefined;
104
+
105
+ const g = goal.trim();
106
+ const first = users[0] ?? "";
107
+ const last = users.at(-1) ?? "";
108
+ const parts: string[] = ["Önceki oturumdan devralınan bağlam (otomatik devir notu):", ""];
109
+ if (summary) parts.push("## Önceki oturumun özeti", summary.trim(), "");
110
+ else if (first) parts.push("## İlk istek", clip(first, 800), "");
111
+ if (last && last !== first) parts.push("## Son istek", clip(last, 800), "");
112
+ if (lastAssistant) parts.push("## Son durum (asistanın son cevabı)", clip(lastAssistant, 1500), "");
113
+ const open = (todos ?? []).filter((t) => !t.done);
114
+ if (open.length) parts.push("## Açık işler", ...open.map((t) => `- [ ] ${t.text}`), "");
115
+ if (edited.length) parts.push("## Değiştirilen dosyalar", ...edited.slice(0, 30).map((f) => `- ${f}`), "");
116
+ const onlyRead = read.filter((f) => !edited.includes(f));
117
+ if (onlyRead.length) parts.push("## İncelenen dosyalar", ...onlyRead.slice(0, 20).map((f) => `- ${f}`), "");
118
+ if (snapshot) parts.push(`Son anlık kopya: ${snapshot.slice(0, 12)}`, "");
119
+ parts.push("## Yeni görev", g || "(Devam edilecek işi buraya yaz.)");
120
+
121
+ const title = deriveTitle(g || (summary && summaryGoal(summary)) || first) || "Devredilen oturum";
122
+ return { title, text: parts.join("\n"), files: edited, snapshot };
123
+ }
124
+
125
+ /**
126
+ * Fork (/fork — bağlam paylaşan alt ajan, Dalga 2 matris madde 1) istemi: alt ajanın görevini, ebeveyn oturumunun
127
+ * bağlam özetiyle (buildHandoff: önceki özet/son istekler/açık todo/dosyalar) önden tohumlar — böylece "ayrı bağlam"
128
+ * alt ajanın (task) aksine fork, ebeveynin ne yaptığını bilerek sürer. Özet üretilemezse (boş dal) yalnız görev döner.
129
+ */
130
+ export function buildForkPrompt(branch: HandoffEntry[], task: string): string {
131
+ return buildHandoff(branch, task)?.text ?? task;
132
+ }
@@ -0,0 +1,284 @@
1
+ /**
2
+ * Kancalar (hooks): kullanicinin/projenin tanimladigi komut ya da http uclari arac cagrisindan once (PreToolUse),
3
+ * sonra (PostToolUse) ve tur bitince (Stop) calisir.
4
+ *
5
+ * Dosyalar: ~/.sera/hooks.json (kullanici, her zaman) + <proje>/.sera/hooks.json (yalniz kullanici o proje icin
6
+ * `/guven` dediyse - ~/.sera/trusted-projects.json; indirilen yabanci bir depo bilgisayarinda komut calistiramasin).
7
+ *
8
+ * Bicim: { "PreToolUse": [{ "matcher": "bash|edit", "type": "command", "command": "...", "timeout": 10 }], ... }
9
+ * Girdi: kancaya JSON (stdin ya da http govdesi): { event, tool, input, result? }.
10
+ * Cikti: cikis kodu 2 = engelle (stderr gerekce); ya da JSON { "decision": "block", "reason": "..." } / { "note": "..." }.
11
+ * Kanca izin katmanini ASAMAZ: "allow" diye bir karar yok, zincir izin adimiyla devam eder.
12
+ * Kanca hatasi/zaman asimi ajani durdurmaz; yalniz uyari yazilir.
13
+ */
14
+
15
+ import { spawn } from "node:child_process";
16
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
17
+ import { dirname, resolve } from "node:path";
18
+
19
+ export const HOOK_EVENTS = ["PreToolUse", "PostToolUse", "Stop"] as const;
20
+ export type HookEvent = (typeof HOOK_EVENTS)[number];
21
+
22
+ export interface HookDef {
23
+ matcher?: string;
24
+ type: "command" | "http";
25
+ command?: string;
26
+ url?: string;
27
+ /** saniye; varsayilan 10, ust sinir 120 */
28
+ timeout?: number;
29
+ }
30
+
31
+ export type HookConfig = Record<HookEvent, HookDef[]>;
32
+
33
+ export interface HookOutcome {
34
+ block?: boolean;
35
+ reason?: string;
36
+ note?: string;
37
+ error?: string;
38
+ ms: number;
39
+ }
40
+
41
+ export interface HookPayload {
42
+ event: HookEvent;
43
+ tool?: string;
44
+ input?: unknown;
45
+ result?: string;
46
+ }
47
+
48
+ const emptyConfig = (): HookConfig => ({ PreToolUse: [], PostToolUse: [], Stop: [] });
49
+
50
+ /** Dosyalari okur, gecersiz girdileri Turkce hata ile atlar (hicbiri ajani durdurmaz). */
51
+ export function loadHooks(files: string[]): { config: HookConfig; errors: string[] } {
52
+ const config = emptyConfig();
53
+ const errors: string[] = [];
54
+ for (const file of files) {
55
+ if (!existsSync(file)) continue;
56
+ let raw: unknown;
57
+ try {
58
+ raw = JSON.parse(readFileSync(file, "utf8"));
59
+ } catch {
60
+ errors.push(`${file}: JSON okunamadi, kancalar atlandi.`);
61
+ continue;
62
+ }
63
+ if (!raw || typeof raw !== "object") continue;
64
+ for (const [ev, list] of Object.entries(raw as Record<string, unknown>)) {
65
+ if (!(HOOK_EVENTS as readonly string[]).includes(ev)) {
66
+ errors.push(`${file}: bilinmeyen kanca olayi "${ev}" atlandi.`);
67
+ continue;
68
+ }
69
+ for (const d of Array.isArray(list) ? list : []) {
70
+ const def = d as HookDef;
71
+ const ok =
72
+ (def?.type === "command" && typeof def.command === "string" && def.command.trim()) ||
73
+ (def?.type === "http" && typeof def.url === "string" && /^https?:\/\//.test(def.url));
74
+ if (!ok) {
75
+ errors.push(`${file}: ${ev} icinde gecersiz kanca atlandi.`);
76
+ continue;
77
+ }
78
+ if (def.matcher !== undefined) {
79
+ try {
80
+ new RegExp(def.matcher);
81
+ } catch {
82
+ errors.push(`${file}: gecersiz matcher "${def.matcher}" atlandi.`);
83
+ continue;
84
+ }
85
+ }
86
+ config[ev as HookEvent].push(def);
87
+ }
88
+ }
89
+ }
90
+ return { config, errors };
91
+ }
92
+
93
+ export function matches(def: HookDef, tool: string | undefined): boolean {
94
+ if (!def.matcher || def.matcher === "*" || tool === undefined) return true;
95
+ return new RegExp(`^(?:${def.matcher})$`).test(tool);
96
+ }
97
+
98
+ function timeoutMs(def: HookDef): number {
99
+ const s = typeof def.timeout === "number" && def.timeout > 0 ? Math.min(def.timeout, 120) : 10;
100
+ return s * 1000;
101
+ }
102
+
103
+ function parseOutput(text: string): Pick<HookOutcome, "block" | "reason" | "note"> {
104
+ const t = text.trim();
105
+ if (!t.startsWith("{")) return {};
106
+ try {
107
+ const j = JSON.parse(t) as { decision?: unknown; reason?: unknown; note?: unknown };
108
+ return {
109
+ block: j.decision === "block" || undefined,
110
+ reason: typeof j.reason === "string" ? j.reason : undefined,
111
+ note: typeof j.note === "string" ? j.note : undefined,
112
+ };
113
+ } catch {
114
+ return {};
115
+ }
116
+ }
117
+
118
+ /** Kabukla baslayan kancanin TUM surec agacini sonlandirir (Windows'ta p.kill yalniz cmd.exe'yi oldurur). */
119
+ export function killTree(p: ReturnType<typeof spawn>): Promise<void> {
120
+ return new Promise((done) => {
121
+ if (p.pid === undefined) return done();
122
+ try {
123
+ if (process.platform === "win32") {
124
+ const k = spawn("taskkill", ["/pid", String(p.pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" });
125
+ k.on("close", () => done());
126
+ k.on("error", () => {
127
+ p.kill("SIGKILL");
128
+ done();
129
+ });
130
+ return;
131
+ }
132
+ process.kill(-p.pid, "SIGKILL");
133
+ } catch {
134
+ p.kill("SIGKILL");
135
+ }
136
+ done();
137
+ });
138
+ }
139
+
140
+ function runCommand(def: HookDef, payload: HookPayload, cwd: string): Promise<HookOutcome> {
141
+ const t0 = Date.now();
142
+ return new Promise((resolve) => {
143
+ let out = "";
144
+ let err = "";
145
+ let done = false;
146
+ const finish = (o: Omit<HookOutcome, "ms">) => {
147
+ if (done) return;
148
+ done = true;
149
+ clearTimeout(timer);
150
+ resolve({ ...o, ms: Date.now() - t0 });
151
+ };
152
+ const p = spawn(def.command ?? "", {
153
+ cwd,
154
+ shell: true,
155
+ stdio: ["pipe", "pipe", "pipe"],
156
+ windowsHide: true,
157
+ detached: process.platform !== "win32", // posix: surec grubu -> killTree hepsini oldurur
158
+ });
159
+ let timedOut = false;
160
+ const timer = setTimeout(() => {
161
+ timedOut = true;
162
+ const msg = `kanca zaman asimina ugradi (${timeoutMs(def) / 1000} sn)`;
163
+ void killTree(p).then(() => finish({ error: msg }));
164
+ }, timeoutMs(def));
165
+ p.stdout.on("data", (c: Buffer) => {
166
+ out += c.toString();
167
+ });
168
+ p.stderr.on("data", (c: Buffer) => {
169
+ err += c.toString();
170
+ });
171
+ p.on("error", (e) => finish({ error: `kanca calistirilamadi: ${e.message}` }));
172
+ p.on("close", (code) => {
173
+ if (timedOut) return; // sonucu zaman asimi yolu (agac olduruldukten sonra) verir
174
+ if (code === 2) return finish({ block: true, reason: err.trim() || "Kanca bu islemi engelledi." });
175
+ if (code !== 0) return finish({ error: `kanca hata verdi (cikis ${code})` });
176
+ finish(parseOutput(out));
177
+ });
178
+ p.stdin.on("error", () => {});
179
+ p.stdin.end(JSON.stringify(payload));
180
+ });
181
+ }
182
+
183
+ async function runHttp(def: HookDef, payload: HookPayload): Promise<HookOutcome> {
184
+ const t0 = Date.now();
185
+ try {
186
+ const r = await fetch(def.url ?? "", {
187
+ method: "POST",
188
+ headers: { "content-type": "application/json" },
189
+ body: JSON.stringify(payload),
190
+ signal: AbortSignal.timeout(timeoutMs(def)),
191
+ });
192
+ if (!r.ok) return { error: `kanca http ${r.status}`, ms: Date.now() - t0 };
193
+ return { ...parseOutput(await r.text()), ms: Date.now() - t0 };
194
+ } catch (e) {
195
+ const timeout = e instanceof Error && (e.name === "TimeoutError" || e.name === "AbortError");
196
+ return { error: timeout ? "kanca zaman asimina ugradi" : "kanca adresine ulasilamadi", ms: Date.now() - t0 };
197
+ }
198
+ }
199
+
200
+ export function runHook(def: HookDef, payload: HookPayload, cwd: string): Promise<HookOutcome> {
201
+ return def.type === "http" ? runHttp(def, payload) : runCommand(def, payload, cwd);
202
+ }
203
+
204
+ export class HookRunner {
205
+ totalMs = 0;
206
+ runs = 0;
207
+ private readonly config: HookConfig;
208
+ private readonly cwd: string;
209
+ private readonly warn: (msg: string) => void;
210
+ constructor(config: HookConfig, cwd: string, warn: (msg: string) => void) {
211
+ this.config = config;
212
+ this.cwd = cwd;
213
+ this.warn = warn;
214
+ }
215
+
216
+ get empty(): boolean {
217
+ return HOOK_EVENTS.every((e) => this.config[e].length === 0);
218
+ }
219
+
220
+ private async run(event: HookEvent, payload: HookPayload): Promise<HookOutcome[]> {
221
+ const outs: HookOutcome[] = [];
222
+ for (const def of this.config[event]) {
223
+ if (!matches(def, payload.tool)) continue;
224
+ const o = await runHook(def, payload, this.cwd);
225
+ this.totalMs += o.ms;
226
+ this.runs++;
227
+ if (o.error) this.warn(`[Sera KANCA] ${event}: ${o.error}`);
228
+ outs.push(o);
229
+ if (o.block && event === "PreToolUse") break; // ilk engel kazanir
230
+ }
231
+ return outs;
232
+ }
233
+
234
+ /** Engel varsa gerekceyi doner; yoksa undefined (zincir izin adimiyla devam eder). */
235
+ async pre(tool: string, input: unknown): Promise<{ block: true; reason: string } | undefined> {
236
+ const b = (await this.run("PreToolUse", { event: "PreToolUse", tool, input })).find((o) => o.block);
237
+ return b ? { block: true, reason: b.reason ?? "Kanca bu islemi engelledi." } : undefined;
238
+ }
239
+
240
+ /** Kancalarin modele iletilecek notlari. */
241
+ async post(tool: string, input: unknown, result: string): Promise<string[]> {
242
+ const outs = await this.run("PostToolUse", {
243
+ event: "PostToolUse",
244
+ tool,
245
+ input,
246
+ result: result.slice(0, 20_000),
247
+ });
248
+ return outs.map((o) => o.note).filter((n): n is string => !!n);
249
+ }
250
+
251
+ async stop(): Promise<void> {
252
+ await this.run("Stop", { event: "Stop" });
253
+ }
254
+ }
255
+
256
+ /** Sera'nin kendi proje guven listesi (motorun guven kararindan bagimsiz, acik kullanici onayi). */
257
+ export class TrustStore {
258
+ readonly file: string;
259
+ constructor(file: string) {
260
+ this.file = file;
261
+ }
262
+ private key(dir: string): string {
263
+ const p = resolve(dir);
264
+ return process.platform === "win32" ? p.toLowerCase() : p;
265
+ }
266
+ private read(): string[] {
267
+ try {
268
+ const j = JSON.parse(readFileSync(this.file, "utf8"));
269
+ return Array.isArray(j) ? j.filter((x): x is string => typeof x === "string") : [];
270
+ } catch {
271
+ return [];
272
+ }
273
+ }
274
+ has(dir: string): boolean {
275
+ return this.read().includes(this.key(dir));
276
+ }
277
+ set(dir: string, trusted: boolean): void {
278
+ const k = this.key(dir);
279
+ const list = this.read().filter((x) => x !== k);
280
+ if (trusted) list.push(k);
281
+ mkdirSync(dirname(this.file), { recursive: true });
282
+ writeFileSync(this.file, `${JSON.stringify(list, null, 2)}\n`);
283
+ }
284
+ }
@@ -0,0 +1,118 @@
1
+ import { mkdirSync, writeFileSync } from "node:fs";
2
+ import { dirname, extname, isAbsolute, join, resolve } from "node:path";
3
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
+ import { Type } from "typebox";
5
+ import { deviceId } from "./device-id.ts";
6
+ import { rareExposure } from "./exposure.ts";
7
+ import { formatServerError, networkErrorText } from "./server-error.ts";
8
+
9
+ // `image` araci: metin -> gorsel uretimi (Grok Imagine). Web ile AYNI sunucu ucunu kullanir (sera-web/api/image.ts):
10
+ // kota (sayilar/plan sunucuda; GET /api/usage media), icerik guvenligi ve harcama kesici sunucuda; CLI yalniz cagirir (web = CLI esitligi).
11
+ // Gorsel diske kaydedilir, yol yazilir. Yeni modul yalniz arac cagrilinca is yapar (tembel yukleme ilkesi): kayit ucuzdur.
12
+
13
+ export interface ImageOpts {
14
+ baseUrl?: string;
15
+ token?: () => string | undefined;
16
+ fetch?: typeof fetch;
17
+ /** Cikti dizini (varsayilan: calisma dizini). */
18
+ outDir?: string;
19
+ now?: () => number;
20
+ }
21
+
22
+ export const IMAGE_ASPECTS = ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3"] as const;
23
+ const LOGIN_MSG = "Görsel üretmek için önce `sera login` ile giriş yapmalısın.";
24
+ const EXT: Record<string, string> = { "image/png": "png", "image/webp": "webp", "image/jpeg": "jpg" };
25
+ const OUT_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
26
+
27
+ /** Girdi denetimi (sunucu ile ayni sinirlar). Gecerliyse govde, degilse hata atar. */
28
+ export function buildImageBody(p: Record<string, any>): { prompt: string; aspect?: string } {
29
+ const prompt = typeof p.prompt === "string" ? p.prompt.trim() : "";
30
+ if (prompt.length < 3) throw new Error("Ne cizilecegini bir cumleyle yaz (prompt).");
31
+ if (prompt.length > 1500) throw new Error("prompt en fazla 1500 karakter.");
32
+ const aspect = p.aspect;
33
+ if (aspect !== undefined && !(IMAGE_ASPECTS as readonly string[]).includes(aspect))
34
+ throw new Error(`aspect gecersiz (${IMAGE_ASPECTS.join(", ")}).`);
35
+ return aspect === undefined ? { prompt } : { prompt, aspect };
36
+ }
37
+
38
+ export function registerImageTool(pi: ExtensionAPI, opts: ImageOpts = {}): void {
39
+ pi.registerTool({
40
+ name: "image",
41
+ exposure: rareExposure(),
42
+ label: "Gorsel uret",
43
+ description:
44
+ "Metinden gorsel uretir (Grok Imagine; web ile ayni kota; hak plana gore sunucuda belirlenir, kalan icin /limit). Gorseli diske kaydeder ve yolunu dondurur. Hak dolunca sunucu yenilenme tarihini bildirir. `sera login` gerekir. Cinsel/cocuk icerikli istekler reddedilir.",
45
+ promptSnippet: "Metinden gorsel uret (prompt, ops. aspect, ops. out) ve dosya yolunu yaz",
46
+ parameters: Type.Object({
47
+ prompt: Type.String({ description: "Gorselin tarifi (en fazla 1500 karakter)" }),
48
+ aspect: Type.Optional(Type.String({ description: IMAGE_ASPECTS.join(" | ") })),
49
+ out: Type.Optional(
50
+ Type.String({
51
+ description: "Kaydedilecek dosya yolu (.png/.jpg/.webp); bos ise sera-gorsel-<zaman>.<uzanti>",
52
+ }),
53
+ ),
54
+ }),
55
+ async execute(_id, params, signal) {
56
+ const doFetch = opts.fetch ?? fetch;
57
+ const base = (opts.baseUrl ?? process.env.SERA_WEB_URL ?? "https://ssera.online").replace(/\/+$/, "");
58
+ const p = params as Record<string, any>;
59
+ const body = buildImageBody(p);
60
+ const token = opts.token ? opts.token() : process.env.SERA_AUTH_TOKEN || undefined;
61
+ if (!token) throw new Error(LOGIN_MSG);
62
+
63
+ let res: Response;
64
+ try {
65
+ res = await doFetch(`${base}/api/image`, {
66
+ method: "POST",
67
+ headers: {
68
+ authorization: `Bearer ${token}`,
69
+ "x-sera-device": deviceId(),
70
+ "content-type": "application/json",
71
+ },
72
+ body: JSON.stringify(body),
73
+ signal,
74
+ });
75
+ } catch {
76
+ if (signal?.aborted) throw new Error("Görsel üretimi durduruldu.");
77
+ throw new Error(networkErrorText("Görsel"));
78
+ }
79
+ const j = (await res.json().catch(() => ({}))) as Record<string, any>;
80
+ if (!res.ok || typeof j.b64 !== "string") {
81
+ // Sunucunun Türkçe mesajı (hak durumu + yenilenme anı) aynen iletilir; yoksa duruma göre üç bilgi.
82
+ const status = res.ok ? 502 : res.status;
83
+ throw new Error(
84
+ formatServerError({
85
+ noun: "Görsel üretimi",
86
+ status,
87
+ body: j,
88
+ loginMsg: "Görsel üretmek için önce `sera login` ile giriş yapmalısın.",
89
+ }),
90
+ );
91
+ }
92
+
93
+ const mime = typeof j.mime === "string" ? j.mime : "image/jpeg";
94
+ const ext = EXT[mime] ?? "jpg";
95
+ let path: string;
96
+ if (typeof p.out === "string" && p.out.trim()) {
97
+ const want = resolve(opts.outDir ?? process.cwd(), p.out.trim());
98
+ path = OUT_EXTS.has(extname(want).toLowerCase()) ? want : `${want}.${ext}`;
99
+ } else {
100
+ const dir = opts.outDir ?? process.cwd();
101
+ path = join(isAbsolute(dir) ? dir : resolve(dir), `sera-gorsel-${(opts.now ?? Date.now)()}.${ext}`);
102
+ }
103
+ const bytes = Buffer.from(j.b64, "base64");
104
+ if (bytes.length < 100) throw new Error("Sunucu geçersiz görsel döndürdü. Tekrar dene.");
105
+ mkdirSync(dirname(path), { recursive: true });
106
+ writeFileSync(path, bytes);
107
+
108
+ const left =
109
+ typeof j.remaining === "number" && typeof j.limit === "number"
110
+ ? ` Bu ay kalan hak: ${j.remaining}/${j.limit} (yenilenme: ${j.resetLabel ?? "?"}).`
111
+ : "";
112
+ return {
113
+ content: [{ type: "text", text: `Gorsel kaydedildi: ${path} (${bytes.length} bayt).${left}` }],
114
+ details: { path, bytes: bytes.length, mime, remaining: j.remaining, limit: j.limit, resetAt: j.resetAt },
115
+ };
116
+ },
117
+ });
118
+ }