logancyang / obsidian-copilot

THE Copilot in Obsidian
GNU Affero General Public License v3.0
2.73k stars 189 forks source link

Optionally execute code in LLM output #637

Open logancyang opened 3 weeks ago

logancyang commented 3 weeks ago

Obsidian auto-executes code blocks for certain languages such as Mermaid. If you have a plugin like dataview, dataview and dataviewjs code are executed automatically too. Since LLM output is rendered with Obsidian's markdown renderer, they get auto execution too.

This is good and bad:

A better approach is to not execute the code blocks in the LLM output first, but leave a button for the user to trigger the run manually.

Discussion

2 sides of the argument:


There's a case where a user has a JS auto-execution plugin, and the JS in LLM output gets auto-executed. This can be dangerous! There should be an option to "run" in LLM output.

https://x.com/4confusedemoji/status/1833709872057057607

taygetea commented 2 weeks ago

Ah, yeah. Hi, that's me. This is what I settled on for the moment, but Obsidian makes it extremely annoying to remove the outer block if there's more than one. Screenshot_20240917-213059.png

The most straightforward way to do this as a plugin I can think of is to force replace the codeblockprocessor string with 'markdown' and inject a button that'll swap them out and rerun it.

Something like this appears to do everything you would need. [https://github.com/mugiwara85/CodeblockCustomizer]()