Programs
With exec:<program> in its manifest, a plugin can run that program and no other:
const dir = await this.app.files.temp()
await this.app.files.write(`${dir}/book.html`, book.html)
const res = await this.app.exec.run('pandoc', ['book.html', '-o', 'book.odt'], { cwd: dir, timeout: 120_000 })
if (res.code !== 0) throw new Error(res.stderr || 'Pandoc failed')
const odt = await this.app.files.read(`${dir}/book.odt`)This is how it runs:
- The program: Bläck Studio finds it by name on the PATH, as the system would. A path isn't accepted. If the program isn't installed, you get an error that says so.
- Arguments: they go to the program as you give them, with no shell.
$HOME,;,|and*are just characters. input: goes to the program's standard input.cwd: a folder the writer chose for the plugin, or the plugin's temporary folder (the default).- Time and output: Bläck Studio stops the program after
timeout(a minute unless you set it, ten at most;timedOuttells you this happened), and at 50 MB of output. Anything the program started is stopped with it. - Its environment: only what a program needs to find its way:
PATH,HOME, the language and the like. It doesn't get Bläck Studio's own environment, which may hold keys and tokens. - The result:
code,stdoutas bytes (text()for text),stderrandtimedOut.
When the writer allows a program, they trust the plugin with whatever that program can be made to do with the arguments the plugin gives it. Pandoc converts documents, but it also runs Lua filters it's given, and git runs hooks. That's why every exec: permission comes with a warning, and a shell, Python or Node with a stronger one. Ask only for the programs you need, and say in your description what you run them for.