sera-code 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (456) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE-SERA.md +25 -0
  3. package/README.md +27 -2
  4. package/THIRD_PARTY_NOTICES.md +68 -0
  5. package/bin/sera.mjs +137 -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-6JXVX6Q2.js +2 -0
  15. package/dist/bundle/chunks/chunk-6QGV3IWD.js +6 -0
  16. package/dist/bundle/chunks/chunk-7CBJINYJ.js +20 -0
  17. package/dist/bundle/chunks/chunk-7DDKXS2Q.js +2 -0
  18. package/dist/bundle/chunks/chunk-7RZ5BS7U.js +2 -0
  19. package/dist/bundle/chunks/chunk-7ZC4UXSL.js +2 -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-GUGC72EB.js +1222 -0
  26. package/dist/bundle/chunks/chunk-HODJBMOY.js +9 -0
  27. package/dist/bundle/chunks/chunk-HQBQWHLD.js +7 -0
  28. package/dist/bundle/chunks/chunk-HQJBN2MC.js +2 -0
  29. package/dist/bundle/chunks/chunk-JXWJOIH4.js +2 -0
  30. package/dist/bundle/chunks/chunk-KXU77PUU.js +4 -0
  31. package/dist/bundle/chunks/chunk-L2ZPNLYD.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-I5QRIHN6.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 +190 -0
  181. package/lib/provider.js +52 -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 +2416 -0
  383. package/sera-core/src/fs-tools.ts +444 -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/no-progress.ts +177 -0
  412. package/sera-core/src/notebook-tool.ts +179 -0
  413. package/sera-core/src/ofis.ts +473 -0
  414. package/sera-core/src/path-guard.ts +139 -0
  415. package/sera-core/src/permission-bridge.ts +228 -0
  416. package/sera-core/src/policy-chain.ts +122 -0
  417. package/sera-core/src/pricing.ts +71 -0
  418. package/sera-core/src/proc.ts +149 -0
  419. package/sera-core/src/rea.ts +188 -0
  420. package/sera-core/src/repo-map.ts +230 -0
  421. package/sera-core/src/research.ts +347 -0
  422. package/sera-core/src/rules-memory.ts +227 -0
  423. package/sera-core/src/sandbox.ts +445 -0
  424. package/sera-core/src/server-error.ts +78 -0
  425. package/sera-core/src/skills.ts +268 -0
  426. package/sera-core/src/snapshot.ts +143 -0
  427. package/sera-core/src/spec-gate.ts +112 -0
  428. package/sera-core/src/subagent.ts +261 -0
  429. package/sera-core/src/teslim.ts +120 -0
  430. package/sera-core/src/test-fix.ts +184 -0
  431. package/sera-core/src/todo-question.ts +163 -0
  432. package/sera-core/src/turn-snapshots.ts +126 -0
  433. package/sera-core/src/tuval/arac.ts +338 -0
  434. package/sera-core/src/tuval/arsiv.ts +106 -0
  435. package/sera-core/src/tuval/belge.ts +216 -0
  436. package/sera-core/src/tuval/birlestir.ts +282 -0
  437. package/sera-core/src/tuval/disa.ts +235 -0
  438. package/sera-core/src/tuval/editor.ts +583 -0
  439. package/sera-core/src/tuval/film-cekirdek.ts +170 -0
  440. package/sera-core/src/tuval/film-disa.ts +188 -0
  441. package/sera-core/src/tuval/film-oynatici.ts +307 -0
  442. package/sera-core/src/tuval/kimlik.ts +156 -0
  443. package/sera-core/src/tuval/pano.ts +763 -0
  444. package/sera-core/src/tuval/proje.ts +728 -0
  445. package/sera-core/src/tuval/sistem-cekirdek.ts +167 -0
  446. package/sera-core/src/tuval/sistem.ts +328 -0
  447. package/sera-core/src/tuval/sunucu.ts +413 -0
  448. package/sera-core/src/tuval/uretim.ts +24 -0
  449. package/sera-core/src/tuval/veri-cekirdek.ts +477 -0
  450. package/sera-core/src/tuval/xlsx.ts +215 -0
  451. package/sera-core/src/tuval/zip.ts +163 -0
  452. package/sera-core/src/untrusted.ts +201 -0
  453. package/sera-core/src/video-edit-tool.ts +411 -0
  454. package/sera-core/src/video-tool.ts +217 -0
  455. package/sera-core/src/web-tools.ts +257 -0
  456. package/sera-core/src/zk.ts +104 -0
@@ -0,0 +1,88 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { mkdirSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import {
5
+ type BriefCall,
6
+ type BriefOptions,
7
+ briefEligible,
8
+ briefPrompt,
9
+ type IntakeOptions,
10
+ intakePrompt,
11
+ } from "./intake-core.ts";
12
+
13
+ // Sera Giris Alani (CLI yuzu): "input" olayinda uzun kullanici mesajini temizler; kirpilirsa orijinal diske birebir yazilir.
14
+
15
+ export interface IntakeInputEvent {
16
+ text: string;
17
+ source?: string;
18
+ }
19
+
20
+ /** Orijinali <dir>/<id>/prompt-orig.txt dosyasina yazar; basarisizsa undefined (=> kirpma yapilmaz). */
21
+ export function makeIntakeSaver(dir: string): (original: string) => string | undefined {
22
+ return (original) => {
23
+ try {
24
+ const sub = join(dir, `${Date.now().toString(36)}-${randomBytes(3).toString("hex")}`);
25
+ mkdirSync(sub, { recursive: true });
26
+ const p = join(sub, "prompt-orig.txt");
27
+ writeFileSync(p, original, "utf8");
28
+ return p.split(String.fromCharCode(92)).join("/");
29
+ } catch {
30
+ return undefined;
31
+ }
32
+ };
33
+ }
34
+
35
+ export type IntakeDecision = { action: "continue" } | { action: "transform"; text: string; notice: string };
36
+
37
+ export function runIntake(event: IntakeInputEvent, dir: string, opts?: IntakeOptions, enabled = true): IntakeDecision {
38
+ if (!enabled || event.source === "extension") return { action: "continue" };
39
+ const r = intakePrompt(event.text, opts, makeIntakeSaver(dir));
40
+ return r.changed ? { action: "transform", text: r.text, notice: r.notice } : { action: "continue" };
41
+ }
42
+
43
+ export interface BriefDeps {
44
+ call: BriefCall;
45
+ opts?: BriefOptions;
46
+ }
47
+
48
+ /**
49
+ * Katman A + B. A her zaman senkron calisir; uzun DUZ YAZI icin (kod/log degil, esik ustu) ayrica ucuz modelle yapilandirilmis
50
+ * brif denenir ve orijinal diske birebir saklanir (modele yol verilir). Kapsam kontrolu gecmezse / hata / zaman asimi / kill switch =>
51
+ * sessizce Katman A karari. Ek "Soyle anladim" satiri yalniz onarim/belirsizlikte bildirime eklenir.
52
+ */
53
+ export async function runIntakeBriefed(
54
+ event: IntakeInputEvent,
55
+ dir: string,
56
+ deps?: BriefDeps,
57
+ opts?: IntakeOptions,
58
+ enabled = true,
59
+ ): Promise<IntakeDecision> {
60
+ if (!enabled || event.source === "extension") return { action: "continue" };
61
+ const save = makeIntakeSaver(dir);
62
+ let ref: string | undefined;
63
+ let tried = false;
64
+ const saveOnce = (o: string): string | undefined => {
65
+ if (!tried) {
66
+ tried = true;
67
+ ref = save(o);
68
+ }
69
+ return ref;
70
+ };
71
+ const r = intakePrompt(event.text, opts, saveOnce);
72
+ const base: IntakeDecision = r.changed
73
+ ? { action: "transform", text: r.text, notice: r.notice }
74
+ : { action: "continue" };
75
+ try {
76
+ if (!deps || deps.opts?.enabled === false || !briefEligible(event.text, deps.opts).ok) return base;
77
+ const refPath = saveOnce(event.text);
78
+ if (!refPath) return base;
79
+ const b = await briefPrompt(event.text, r.changed ? r.text : event.text, refPath, deps.call, deps.opts);
80
+ if (!b.used) return base;
81
+ const notice =
82
+ `Uzun mesajini okudum (${event.text.length} karakter); yapilandirilmis brife cevirdim (${b.text.length} karakter), aslini sakladim: ${refPath}` +
83
+ (b.notice ? ` | ${b.notice}` : "");
84
+ return { action: "transform", text: b.text, notice };
85
+ } catch {
86
+ return base;
87
+ }
88
+ }
@@ -0,0 +1,134 @@
1
+ import { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
2
+ import { join, relative, resolve, sep } from "node:path";
3
+ import { gzipSync } from "node:zlib";
4
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
5
+ import { Type } from "typebox";
6
+ import { deviceId } from "./device-id.ts";
7
+ import { rareExposure } from "./exposure.ts";
8
+ import { networkErrorText } from "./server-error.ts";
9
+
10
+ // `ios_build` araci: iOS (Swift/SwiftUI) uygulamasini SUNUCUDA gercek iOS SDK ile derler. Web ajani ile AYNI servis
11
+ // (web: VDS icinden soket; CLI: ssera.online/api/ios-build → VDS sera-dl /ios-build → systemd sera-ios@: ag yok, 3G, 300 sn).
12
+ // Bilgisayarda Xcode/Mac GEREKMEZ. Tembel: semasi modele yalniz `tool_search` ile istenince gider.
13
+
14
+ export interface IosBuildOpts {
15
+ baseUrl?: string;
16
+ token?: () => string | undefined;
17
+ fetch?: typeof fetch;
18
+ cwd?: string;
19
+ }
20
+
21
+ const LOGIN_MSG = "iOS derlemesi için önce `sera login` ile giriş yapmalısın.";
22
+ const SKIP = new Set([".build", "xtool", ".bsp", ".git", "node_modules", ".swiftpm", "DerivedData"]);
23
+ export const IOS_MAX_BYTES = 8 * 1024 * 1024;
24
+
25
+ function octal(n: number, len: number): string {
26
+ return `${n.toString(8).padStart(len - 1, "0")}\0`;
27
+ }
28
+
29
+ /** Minimal ustar arsivi (yalniz duz dosyalar; yol <=100 bayt ya da ustar prefix ile <=255). Bagimliliksiz. */
30
+ export function tarFiles(files: { name: string; data: Buffer }[]): Buffer {
31
+ const blocks: Buffer[] = [];
32
+ for (const f of files) {
33
+ let name = f.name;
34
+ let prefix = "";
35
+ if (Buffer.byteLength(name) > 100) {
36
+ const cut = name.lastIndexOf("/", 154);
37
+ if (cut <= 0 || Buffer.byteLength(name.slice(cut + 1)) > 100) continue; // asiri uzun yol: atla
38
+ prefix = name.slice(0, cut);
39
+ name = name.slice(cut + 1);
40
+ }
41
+ const h = Buffer.alloc(512, 0);
42
+ h.write(name, 0, 100, "utf8");
43
+ h.write(octal(0o644, 8), 100, 8, "ascii");
44
+ h.write(octal(0, 8), 108, 8, "ascii");
45
+ h.write(octal(0, 8), 116, 8, "ascii");
46
+ h.write(octal(f.data.length, 12), 124, 12, "ascii");
47
+ h.write(octal(0, 12), 136, 12, "ascii");
48
+ h.write(" ", 148, 8, "ascii");
49
+ h.write("0", 156, 1, "ascii");
50
+ h.write("ustar\0", 257, 6, "ascii");
51
+ h.write("00", 263, 2, "ascii");
52
+ h.write(prefix, 345, 155, "utf8");
53
+ let sum = 0;
54
+ for (const b of h) sum += b;
55
+ h.write(`${octal(sum, 7)} `, 148, 8, "ascii");
56
+ blocks.push(h, f.data);
57
+ const pad = (512 - (f.data.length % 512)) % 512;
58
+ if (pad) blocks.push(Buffer.alloc(pad, 0));
59
+ }
60
+ blocks.push(Buffer.alloc(1024, 0));
61
+ return Buffer.concat(blocks);
62
+ }
63
+
64
+ /** Proje klasorunu tar.gz yapar (derleme ciktilari/sembolik baglar haric). */
65
+ export function packProject(root: string): Buffer {
66
+ const files: { name: string; data: Buffer }[] = [];
67
+ const walk = (dir: string) => {
68
+ for (const e of readdirSync(dir)) {
69
+ if (SKIP.has(e)) continue;
70
+ const p = join(dir, e);
71
+ const st = lstatSync(p);
72
+ if (st.isSymbolicLink()) continue;
73
+ if (st.isDirectory()) walk(p);
74
+ else if (st.isFile()) files.push({ name: relative(root, p).split(sep).join("/"), data: readFileSync(p) });
75
+ }
76
+ };
77
+ walk(root);
78
+ return gzipSync(tarFiles(files));
79
+ }
80
+
81
+ export function registerIosBuildTool(pi: ExtensionAPI, opts: IosBuildOpts = {}): void {
82
+ pi.registerTool({
83
+ name: "ios_build",
84
+ exposure: rareExposure(),
85
+ label: "iOS derle",
86
+ description:
87
+ "iOS uygulamasini (Swift/SwiftUI, SwiftPM) sunucuda gercek iOS SDK ile derler; Mac/Xcode gerekmez. Proje: Package.swift (TEK .library urunu + .target, executableTarget degil) + xtool.yml + Sources/<Ad>/*.swift (@main App). Hata varsa derleyici hatalarini dosya:satir:sutun ile dondurur; duzeltip tekrar cagir. EXIT=0 ve APP= satiri gormeden iOS isini bitti sayma. `sera login` gerekir.",
88
+ promptSnippet: "iOS (Swift) projesini sunucuda derle ve hatalari getir (path)",
89
+ parameters: Type.Object({
90
+ path: Type.Optional(
91
+ Type.String({ description: "Proje klasoru (Package.swift'in oldugu yer), varsayilan calisma dizini" }),
92
+ ),
93
+ }),
94
+ async execute(_id, params, signal) {
95
+ const cwd = opts.cwd ?? process.cwd();
96
+ const p = params as Record<string, any>;
97
+ const root = resolve(cwd, typeof p.path === "string" && p.path.trim() ? p.path.trim() : ".");
98
+ if (!existsSync(join(root, "Package.swift")))
99
+ throw new Error(
100
+ `Package.swift yok (${root}). Önce SwiftPM iOS projesi yaz: Package.swift + xtool.yml + Sources/<Ad>/*.swift`,
101
+ );
102
+ const token = opts.token ? opts.token() : process.env.SERA_AUTH_TOKEN || undefined;
103
+ if (!token) throw new Error(LOGIN_MSG);
104
+ const body = packProject(root);
105
+ if (body.length > IOS_MAX_BYTES)
106
+ throw new Error("Proje 8MB'tan büyük; görselleri/ikili dosyaları çıkarıp tekrar dene.");
107
+ const base = (opts.baseUrl ?? process.env.SERA_WEB_URL ?? "https://ssera.online").replace(/\/+$/, "");
108
+ let res: Response;
109
+ try {
110
+ res = await (opts.fetch ?? fetch)(`${base}/api/ios-build`, {
111
+ method: "POST",
112
+ headers: {
113
+ authorization: `Bearer ${token}`,
114
+ "x-sera-device": deviceId(),
115
+ "content-type": "application/gzip",
116
+ },
117
+ body: new Uint8Array(body),
118
+ signal,
119
+ });
120
+ } catch {
121
+ if (signal?.aborted) throw new Error("iOS derlemesi durduruldu.");
122
+ throw new Error(networkErrorText("iOS derlemesi"));
123
+ }
124
+ const text = (await res.text().catch(() => "")).slice(0, 20000);
125
+ if (res.status === 401) throw new Error(LOGIN_MSG);
126
+ const m = /^EXIT=(\d+)/m.exec(text);
127
+ const exit = m ? Number(m[1]) : res.ok ? -1 : res.status;
128
+ return {
129
+ content: [{ type: "text", text: text || `iOS derleme servisi boş yanıt verdi (HTTP ${res.status}).` }],
130
+ details: { exit, ok: exit === 0 && /^APP=/m.test(text), bytes: body.length },
131
+ };
132
+ },
133
+ });
134
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Ortak "tembel yetenek" yasam dongusu (SAHIP ILKESI: yalniz ihtiyac olani yukle, is bitince kapat):
3
+ * tanit (kisa giris noktasi baglamda) -> etkinlestir (ilk kullanimda) -> kullan -> bosta kapat.
4
+ * MCP sunuculari (lazy-mcp.ts) ve REA bunu kullanir; ileride yerlesik arac ve alt ajanlar da ayni cekirdegi kullanabilir.
5
+ */
6
+
7
+ export type LazyState = "off" | "starting" | "on" | "failed";
8
+
9
+ export interface LazyCapability<H> {
10
+ id: string;
11
+ /** Baglamda duran TEK satirlik tanitim (model bunu gorur; semalar/araclar gorunmez). */
12
+ summary: string;
13
+ /** Agir kaynagi baslatir (surec, baglanti ...). Yalniz ilk gercek kullanimda cagrilir. */
14
+ activate(): Promise<H>;
15
+ /** Kaynagi kapatir (bosta kalinca ya da elle). Hata atmamali. */
16
+ deactivate(handle: H): Promise<void> | void;
17
+ }
18
+
19
+ export interface LazyOptions {
20
+ /** Bosta kalma suresi (ms) sonra kapanir. 0 = hic kapanmaz. Varsayilan 10 dk. */
21
+ idleMs?: number;
22
+ onState?: (state: LazyState, id: string) => void;
23
+ }
24
+
25
+ export const DEFAULT_IDLE_MS = 10 * 60 * 1000;
26
+
27
+ export function idleFromEnv(env: Record<string, string | undefined> = process.env): number {
28
+ const raw = env.SERA_LAZY_IDLE_MS;
29
+ if (raw === undefined || raw === "") return DEFAULT_IDLE_MS;
30
+ const v = Number(raw);
31
+ return Number.isFinite(v) && v >= 0 ? v : DEFAULT_IDLE_MS;
32
+ }
33
+
34
+ export class LazyRuntime<H> {
35
+ private handle?: H;
36
+ private starting?: Promise<H>;
37
+ private busy = 0;
38
+ private timer?: ReturnType<typeof setTimeout>;
39
+ private _state: LazyState = "off";
40
+ /** Bu yasam dongusunde kac kez etkinlestirildi (test/olcum). */
41
+ activations = 0;
42
+
43
+ readonly cap: LazyCapability<H>;
44
+ private readonly opts: LazyOptions;
45
+
46
+ constructor(cap: LazyCapability<H>, opts: LazyOptions = {}) {
47
+ this.cap = cap;
48
+ this.opts = opts;
49
+ }
50
+
51
+ get state(): LazyState {
52
+ return this._state;
53
+ }
54
+
55
+ private set(s: LazyState): void {
56
+ if (this._state === s) return;
57
+ this._state = s;
58
+ this.opts.onState?.(s, this.cap.id);
59
+ }
60
+
61
+ private clearTimer(): void {
62
+ if (this.timer) clearTimeout(this.timer);
63
+ this.timer = undefined;
64
+ }
65
+
66
+ private arm(): void {
67
+ this.clearTimer();
68
+ const ms = this.opts.idleMs ?? DEFAULT_IDLE_MS;
69
+ if (!ms || this.busy > 0 || this._state !== "on") return;
70
+ this.timer = setTimeout(() => void this.stop(), ms);
71
+ this.timer.unref?.();
72
+ }
73
+
74
+ private async ensure(): Promise<H> {
75
+ if (this.handle !== undefined) return this.handle;
76
+ if (!this.starting) {
77
+ this.set("starting");
78
+ this.starting = this.cap
79
+ .activate()
80
+ .then((h) => {
81
+ this.handle = h;
82
+ this.activations++;
83
+ this.set("on");
84
+ return h;
85
+ })
86
+ .catch((e) => {
87
+ this.set("failed");
88
+ throw e;
89
+ })
90
+ .finally(() => {
91
+ this.starting = undefined;
92
+ });
93
+ }
94
+ return this.starting;
95
+ }
96
+
97
+ /** Gerekirse etkinlestirir, `fn`i calistirir, bitince bosta sayacini yeniden kurar. */
98
+ async use<T>(fn: (h: H) => Promise<T>): Promise<T> {
99
+ this.clearTimer();
100
+ this.busy++;
101
+ try {
102
+ return await fn(await this.ensure());
103
+ } finally {
104
+ this.busy--;
105
+ this.arm();
106
+ }
107
+ }
108
+
109
+ async stop(): Promise<void> {
110
+ this.clearTimer();
111
+ if (this.starting) {
112
+ try {
113
+ await this.starting;
114
+ } catch {}
115
+ }
116
+ const h = this.handle;
117
+ this.handle = undefined;
118
+ if (h !== undefined) {
119
+ try {
120
+ await this.cap.deactivate(h);
121
+ } catch {}
122
+ }
123
+ this.set("off");
124
+ }
125
+ }
@@ -0,0 +1,300 @@
1
+ /**
2
+ * Tembel (ertelenmis) MCP: sunucu surec olarak ACILISTA baslamaz, arac semalari modelin baglamina KONMAZ.
3
+ * Baglamda yalniz tek kucuk giris noktasi vardir: `mcp__<ad>__lazy` (kisa aciklama). Model/kullanici ihtiyac duyunca
4
+ * action=groups -> tools(group) -> schema(tool) -> call(tool,args)
5
+ * ile ilerler; sunucu ilk cagrida baslar, yalniz istenen arac listesi/semasi sonuc olarak gelir, bosta (10 dk) kapanir.
6
+ * Kucuk bir stdio JSON-RPC (MCP) istemcisi icerir; Pi'nin yerlesik MCP baglantisini kullanmaz (o acilista baglanir).
7
+ */
8
+
9
+ import { type ChildProcess, spawn } from "node:child_process";
10
+ import { type LazyCapability, type LazyOptions, LazyRuntime } from "./lazy-capability.ts";
11
+ import type { SeraMcpServer } from "./mcp-bridge.ts";
12
+ import { checkPins } from "./mcp-pin.ts";
13
+
14
+ export interface McpToolInfo {
15
+ name: string;
16
+ description?: string;
17
+ inputSchema?: unknown;
18
+ }
19
+
20
+ const PROTOCOL = "2025-06-18";
21
+ export const LAZY_SUFFIX = "lazy";
22
+ export const lazyToolName = (server: string): string => `mcp__${server}__${LAZY_SUFFIX}`;
23
+
24
+ /** Windows'ta .cmd/.bat kabuklari icin tirnaklama (kabuk yalniz yol icermeyen komutlarda kullanilir). */
25
+ function quoteWin(a: string): string {
26
+ return /^[\w@%+=:,./-]+$/.test(a) ? a : `"${a.replace(/"/g, '""')}"`;
27
+ }
28
+
29
+ export class StdioMcpClient {
30
+ private proc?: ChildProcess;
31
+ private buf = "";
32
+ private nextId = 1;
33
+ private pending = new Map<
34
+ number,
35
+ { resolve: (v: any) => void; reject: (e: Error) => void; timer: ReturnType<typeof setTimeout> }
36
+ >();
37
+ private closed = false;
38
+ exited = false;
39
+
40
+ private readonly spec: SeraMcpServer;
41
+ private readonly timeoutMs: number;
42
+
43
+ constructor(spec: SeraMcpServer, timeoutMs = 60_000) {
44
+ this.spec = spec;
45
+ this.timeoutMs = timeoutMs;
46
+ }
47
+
48
+ async start(): Promise<void> {
49
+ const { command, args = [], env, cwd } = this.spec;
50
+ const useShell = process.platform === "win32" && !/[\\/]/.test(command) && !/\.exe$/i.test(command);
51
+ const base = { cwd, env: { ...process.env, ...env }, windowsHide: true };
52
+ const p: ChildProcess = useShell
53
+ ? spawn([command, ...args].map(quoteWin).join(" "), { ...base, shell: true })
54
+ : spawn(command, args, base);
55
+ this.proc = p;
56
+ p.stdout!.setEncoding("utf8");
57
+ p.stdout!.on("data", (d: string) => this.onData(d));
58
+ p.stderr!.on("data", () => {}); // stderr atilir (baglami sisirmesin)
59
+ p.on("error", (e) => this.fail(e));
60
+ p.on("exit", () => {
61
+ this.exited = true;
62
+ this.fail(new Error("MCP sunucusu kapandi."));
63
+ });
64
+ await this.request("initialize", {
65
+ protocolVersion: PROTOCOL,
66
+ capabilities: {},
67
+ clientInfo: { name: "sera-lazy-mcp", version: "1" },
68
+ });
69
+ this.write({ jsonrpc: "2.0", method: "notifications/initialized" });
70
+ }
71
+
72
+ private fail(e: Error): void {
73
+ for (const [, p] of this.pending) {
74
+ clearTimeout(p.timer);
75
+ p.reject(e);
76
+ }
77
+ this.pending.clear();
78
+ }
79
+
80
+ private onData(d: string): void {
81
+ this.buf += d;
82
+ let i = this.buf.indexOf("\n");
83
+ while (i >= 0) {
84
+ const line = this.buf.slice(0, i).trim();
85
+ this.buf = this.buf.slice(i + 1);
86
+ i = this.buf.indexOf("\n");
87
+ if (!line) continue;
88
+ let m: any;
89
+ try {
90
+ m = JSON.parse(line);
91
+ } catch {
92
+ continue;
93
+ }
94
+ if (m.id !== undefined && m.method) {
95
+ this.write({ jsonrpc: "2.0", id: m.id, result: {} }); // sunucudan istek (ping vb.): bos yanit
96
+ } else if (m.id !== undefined && this.pending.has(m.id)) {
97
+ const p = this.pending.get(m.id)!;
98
+ this.pending.delete(m.id);
99
+ clearTimeout(p.timer);
100
+ if (m.error) p.reject(new Error(String(m.error.message ?? "MCP hatasi")));
101
+ else p.resolve(m.result ?? {});
102
+ }
103
+ }
104
+ }
105
+
106
+ private write(o: unknown): void {
107
+ this.proc?.stdin?.write(`${JSON.stringify(o)}\n`);
108
+ }
109
+
110
+ request(method: string, params?: unknown, timeoutMs = this.timeoutMs): Promise<any> {
111
+ if (this.closed || this.exited) return Promise.reject(new Error("MCP sunucusu kapali."));
112
+ const id = this.nextId++;
113
+ return new Promise((resolve, reject) => {
114
+ const timer = setTimeout(() => {
115
+ this.pending.delete(id);
116
+ reject(new Error(`MCP istegi zaman asimina ugradi (${method}).`));
117
+ }, timeoutMs);
118
+ timer.unref?.();
119
+ this.pending.set(id, { resolve, reject, timer });
120
+ this.write({ jsonrpc: "2.0", id, method, params });
121
+ });
122
+ }
123
+
124
+ async listTools(): Promise<McpToolInfo[]> {
125
+ const out: McpToolInfo[] = [];
126
+ let cursor: string | undefined;
127
+ for (let i = 0; i < 50; i++) {
128
+ const r = await this.request("tools/list", cursor ? { cursor } : {});
129
+ out.push(...(r.tools ?? []));
130
+ cursor = r.nextCursor;
131
+ if (!cursor) break;
132
+ }
133
+ return out;
134
+ }
135
+
136
+ callTool(name: string, args: unknown, timeoutMs = 300_000): Promise<any> {
137
+ return this.request("tools/call", { name, arguments: args ?? {} }, timeoutMs);
138
+ }
139
+
140
+ close(): void {
141
+ this.closed = true;
142
+ this.fail(new Error("MCP sunucusu kapatildi."));
143
+ try {
144
+ this.proc?.stdin?.end();
145
+ } catch {}
146
+ const p = this.proc;
147
+ if (p && !this.exited) {
148
+ if (process.platform === "win32" && p.pid) {
149
+ try {
150
+ spawn("taskkill", ["/pid", String(p.pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" }).unref();
151
+ } catch {}
152
+ } else p.kill();
153
+ }
154
+ }
155
+ }
156
+
157
+ export interface LazyMcpHandle {
158
+ client: StdioMcpClient;
159
+ tools: McpToolInfo[];
160
+ /** Arac tanimi sabitleme/injection uyarisi (groups/tools yanitinin basina eklenir). */
161
+ warning?: string;
162
+ }
163
+
164
+ export interface LazyMcpDef {
165
+ name: string;
166
+ spec: SeraMcpServer;
167
+ /** Modelin gordugu tek satirlik tanitim. */
168
+ summary?: string;
169
+ /** Arac adi -> grup adi. Verilmezse onekten ("inspect_x" -> "inspect"). */
170
+ groupOf?: (tool: string) => string;
171
+ /** Ek uyari (groups/tools yanitinin basina eklenir). */
172
+ notice?: string;
173
+ /** Etkinlesmeden once calisir; hata atarsa etkinlesme iptal (ornegin "kurulu degil"). */
174
+ preflight?: () => void | Promise<void>;
175
+ /** false: arac tanimi sabitleme kapali (yalniz Sera'nin kendi guvenilir sunuculari icin). */
176
+ pin?: boolean;
177
+ }
178
+
179
+ export const defaultGroupOf = (tool: string): string => tool.split(/[_.-]/)[0] || "diger";
180
+ const SCHEMA_CAP = 12_000;
181
+ const DESC_CAP = 110;
182
+
183
+ export interface LazyParams {
184
+ action?: string;
185
+ group?: string;
186
+ tool?: string;
187
+ args?: unknown;
188
+ }
189
+
190
+ export class LazyMcpRuntime {
191
+ readonly def: LazyMcpDef;
192
+ readonly rt: LazyRuntime<LazyMcpHandle>;
193
+
194
+ constructor(def: LazyMcpDef, rt: LazyRuntime<LazyMcpHandle>) {
195
+ this.def = def;
196
+ this.rt = rt;
197
+ }
198
+
199
+ get toolName(): string {
200
+ return lazyToolName(this.def.name);
201
+ }
202
+
203
+ /** Modelin baglaminda duran TEK aciklama (kisa). */
204
+ get description(): string {
205
+ return `${this.def.summary ?? `MCP sunucusu ${this.def.name}.`} Tembel: action=groups, tools(group), schema(tool), call(tool,args), stop.`;
206
+ }
207
+
208
+ private groupOf(t: string): string {
209
+ return (this.def.groupOf ?? defaultGroupOf)(t);
210
+ }
211
+
212
+ /** Ham eylem; hata atar. */
213
+ async run(p: LazyParams): Promise<string> {
214
+ const action = p.action ?? "groups";
215
+ if (action === "stop") {
216
+ await this.rt.stop();
217
+ return `${this.def.name} kapatildi (arac semalari bellekten cikti).`;
218
+ }
219
+ return this.rt.use(async ({ client, tools, warning }) => {
220
+ const pre = [this.def.notice, warning].filter(Boolean).join("\n");
221
+ const nl = pre ? `${pre}\n` : "";
222
+ if (action === "groups") {
223
+ const g = new Map<string, number>();
224
+ for (const t of tools) g.set(this.groupOf(t.name), (g.get(this.groupOf(t.name)) ?? 0) + 1);
225
+ return `${nl}${tools.length} arac, ${g.size} grup. tools(group) ile ac:\n${[...g].map(([k, n]) => `- ${k} (${n})`).join("\n")}`;
226
+ }
227
+ if (action === "tools") {
228
+ const sel = tools.filter((t) => !p.group || this.groupOf(t.name) === p.group);
229
+ if (!sel.length) throw new Error(`Grup bulunamadi: ${p.group ?? "(bos)"}. Once action=groups.`);
230
+ const list = sel
231
+ .map((t) => `- ${t.name}: ${(t.description ?? "").replace(/\s+/g, " ").slice(0, DESC_CAP)}`)
232
+ .join("\n");
233
+ return `${nl}${list}\nSema icin action=schema,tool=<ad>; cagri icin action=call.`;
234
+ }
235
+ if (action === "schema") {
236
+ const t = tools.find((x) => x.name === p.tool);
237
+ if (!t) throw new Error(`Arac bulunamadi: ${p.tool ?? "(bos)"}.`);
238
+ const s = JSON.stringify(t.inputSchema ?? {});
239
+ return s.length > SCHEMA_CAP
240
+ ? `${s.slice(0, SCHEMA_CAP)}... (kisaltildi, ${s.length} karakter; kalan alanlari deneyerek ogren)`
241
+ : s;
242
+ }
243
+ if (action === "call") {
244
+ if (!tools.some((x) => x.name === p.tool))
245
+ throw new Error(`Arac bulunamadi: ${p.tool ?? "(bos)"}.${warning ? ` ${warning}` : ""}`);
246
+ const r = await client.callTool(p.tool!, p.args ?? {});
247
+ const body = (r.content ?? []).map((c: any) => (c.type === "text" ? c.text : `[${c.type}]`)).join("\n");
248
+ if (r.isError) throw new Error(body || "Arac hata dondurdu.");
249
+ return body || JSON.stringify(r.structuredContent ?? {});
250
+ }
251
+ throw new Error(`Bilinmeyen eylem: ${action}. groups|tools|schema|call|stop.`);
252
+ });
253
+ }
254
+
255
+ async execute(p: LazyParams) {
256
+ return { content: [{ type: "text" as const, text: await this.run(p) }], details: {} };
257
+ }
258
+ }
259
+
260
+ export function makeLazyMcp(def: LazyMcpDef, opts: LazyOptions = {}): LazyMcpRuntime {
261
+ const cap: LazyCapability<LazyMcpHandle> = {
262
+ id: def.name,
263
+ summary: def.summary ?? `MCP sunucusu ${def.name} (tembel).`,
264
+ async activate() {
265
+ await def.preflight?.();
266
+ const client = new StdioMcpClient(def.spec, (def.spec.timeout ?? 60) * 1000);
267
+ try {
268
+ await client.start();
269
+ const listed = await client.listTools();
270
+ if (def.pin === false) return { client, tools: listed };
271
+ const r = checkPins(def.name, listed);
272
+ const warns = [
273
+ r.warning,
274
+ r.suspicious.length
275
+ ? `UYARI: '${def.name}' araç açıklamalarında şüpheli talimat kalıpları var (${r.suspicious.join(", ")}); açıklamalara güvenme.`
276
+ : undefined,
277
+ ].filter(Boolean) as string[];
278
+ if (r.warning) process.stderr.write(`[Sera MCP] ${r.warning}\n`);
279
+ return {
280
+ client,
281
+ tools: r.allowed as McpToolInfo[],
282
+ ...(warns.length ? { warning: warns.join("\n") } : {}),
283
+ };
284
+ } catch (e) {
285
+ client.close();
286
+ throw e;
287
+ }
288
+ },
289
+ deactivate: (h) => h.client.close(),
290
+ };
291
+ return new LazyMcpRuntime(def, new LazyRuntime(cap, opts));
292
+ }
293
+
294
+ /** Izin kapisi icin: kesif eylemleri (groups/tools/schema/stop) sorulmaz; call'da asil arac adi gecerlidir. */
295
+ export function lazyGateInfo(toolName: string, input: unknown): { discovery: boolean; tool?: string } | undefined {
296
+ if (!toolName.startsWith("mcp__") || !toolName.endsWith(`__${LAZY_SUFFIX}`)) return undefined;
297
+ const i = (input ?? {}) as { action?: unknown; tool?: unknown };
298
+ const action = typeof i.action === "string" ? i.action : "groups";
299
+ return { discovery: action !== "call", tool: typeof i.tool === "string" ? i.tool : undefined };
300
+ }