JetBrains Open-Sources KotlinLLM: Smart Macros That Generate Kotlin Source Code at Runtime and Hot-Reload It Through JDI
https://www.marktechpost.com/2026/07/31/jetbrains-research-open-sources-kotlinllm-intellij-plugin-kotlin-runtime-llm/📌 【JetBrains Research 開源】KotlinLLM:透過 Smart Macros 與 JDI 實現程式碼即時生成與熱重載
TL;DR:KotlinLLM 是一個實驗性 IntelliJ IDEA 插件,利用 Smart macros 在執行期生成 Kotlin 程式碼並透過 JDI 進行熱重載。
JetBrains Research 近期開源了 KotlinLLM,這是一個針對 Kotlin/JVM 專案開發的實驗性研究原型(Research Prototype)。它引入了一種稱為「Smart macros」的新語言特性,讓開發者能在執行期生成程式碼,並在邏輯不符時自動修正。
🧩 Smart macros:將函式呼叫轉化為生成的程式碼
KotlinLLM 的核心概念是 Smart macro,它本質上是一個普通的 Kotlin 函式呼叫,但其函式體是由 LLM 生成的程式碼。目前提供的公開 API 非常精簡:
asLlm<F, T>(from, hint):將輸入類型 F 轉換為目標類型 T(例如 data class、enum、list 或基本型別)。mockLlm<T>():為介面 T 生成一個具備狀態的實作,其行為會根據被呼叫的方法而變化。
🚀 九步執行迴圈:如何實現自動修正與熱重載
當專案透過 KotlinLLM 的執行設定啟動時,插件會執行以下流程:
- 掃描專案中的
asLlm與mockLlm呼叫。 - 更新生成的 bootstrap/provider/parser/mock 檔案。
- 在 JDI(Java Debug Interface)環境下啟動執行設定。
- 在生成的 regenerate hooks 上註冊斷點。
- 若生成的邏輯與執行期場景不符,執行流程會觸發 hook。
- 插件從暫停的 frame 中擷取執行期數值與型別資訊。
- LLM Agent 根據資訊提交程式碼更新。
- 插件編譯新程式碼並透過 JDI 重新定義(redefine)已載入的類別。
- 重新嘗試原始呼叫。
📊 實驗數據:高成功率與極低的執行開銷
在一個適配過的 Spring Petclinic Kotlin 專案測試中(包含 18 個 asLlm 呼叫點):
- 成功率:24 個應用場景皆在 Smart macro 演化後成功完成,熱重載成功率達 100%。
- 效能影響:編譯與重新定義過程僅增加約 1% 的總執行時間開銷。
- 其他應用:在一個名為「GitHub Beginner Issue Radar」的合成實驗中,透過解析 20 個儲存庫與 3 萬多個 issue,在初學者標籤的檢索上達到了約 0.89 的召回率(recall)。
💡 並非生產環境工具,但輸出結果可部署
儘管 JetBrains 將其標記為實驗性插件,但其產出的行為(behavior)是可部署的。一旦行為生成完成,目標專案可以編譯並執行該行為,而不需要針對相同場景再次請求 LLM。開發者交付的是純粹的 Kotlin 程式碼,而非模型依賴。
⚠️ 使用限制與環境需求
- 需要 IntelliJ IDEA 2025.2.x 版本。
- 需要 JDK 21。
- 需要在目標專案的
.kotlinllm檔案中設定 OpenAI API key。
🎯 實務啟示
對於開發者而言,這提供了一種在開發早期快速模擬複雜邏輯或處理未知輸入的方式。透過將 LLM 的生成能力與 JVM 的動態特性結合,開發者可以在不重啟應用程式的情況下,直接在執行期「修復」生成的邏輯。
🔗 來源
- 標題:JetBrains Open-Sources KotlinLLM: Smart Macros That Generate Kotlin Source Code at Runtime and Hot-Reload It Through JDI
- 作者/機構:Michal Sutter @ MarkTechPost
- 連結:https://www.marktechpost.com/2026/07/31/jetbrains-research-open-sources-kotlinllm-intellij-plugin-kotlin-runtime-llm/
#Kotlin #JetBrains #LLM #IntelliJ #JVM #SmartMacros #OpenSource #SoftwareEngineering #HotReload #MachineLearning
原始資料 MarkTechPost · 收集於 2026-08-01
摘要原文
JetBrains Research Open-Sources KotlinLLM. KotlinLLM is an IntelliJ IDEA plugin for Kotlin/JVM projects that adds a language feature called Smart macros . A Smart macro is a regular Kotlin function call whose body is generated Kotlin code. The public API is deliberately small. asLlm<F, T>(from, hint) converts an input of type F into a typed value T, such as a data class, enum, list, or primitive. mockLlm<T>() generates a stateful implementation of an interface T, whose behavior depends on which methods are called on it. When a project launches through the KotlinLLM run configuration, the plugin scans for asLlm and mockLlm calls, updates generated bootstrap/provider/parser/mock files, launches the run configuration under JDI, and registers breakpoints on generated regenerate hooks. If generated logic does not match a runtime scenario, execution reaches a hook. The plugin captures runtime values and type information from the suspended frame, the LLM agent submits a code update, and the plugin compiles it and redefines the loaded class before retrying the original call. KotlinLLM targets Kotlin/JVM specifically because the runtime evolution loop depends on JVM class redefinition through JDI. The embed below walks the macro API, animates the nine-step runtime loop, and models why covered scenarios stop costing inference calls. On an adapted Spring Petclinic Kotlin project with 18 asLlm call sites, 24 of 24 application scenarios completed after Smart macro evolution, with a 100% hot-reload success rate and compilation/redefinition adding roughly 1% of total runtime overhead. A synthetic “GitHub Beginner Issue Radar” parsed real issue data across 20 repositories and 30k+ issues, reaching about 0.89 recall on ground-truth beginner labels. The plugin requires IntelliJ IDEA 2025.2.x, JDK 21, and an OpenAI API key stored in the target project’s .kotlinllm file via Tools > KotlinLLM Settings . It is released under the Apache License 2.0, with runnable examples, the thesis write-up , and the KotlinConf 2026 talk recording in the repository . Not as a production runtime, at least not yet. JetBrains labels KotlinLLM a research prototype , and it is described it as an experimental IntelliJ IDEA plugin. The plugin is experimental, but its output is deployable . Once behavior has been generated, the target project can compile and run that behavior without another LLM request for the same scenario. You ship plain Kotlin, not a model dependency. Sources: JetBrains Research blog , the kotlinllm-plugin README , and InfoWorld The post JetBrains Open-Sources KotlinLLM: Smart Macros That Generate Kotlin Source Code at Runtime and Hot-Reload It Through JDI appeared first on MarkTechPost .
由 tencent/hy3:free 自動生成