pub struct Task {
pub name: String,
pub description: String,
pub lang: String,
pub script: String,
pub opts: Vec<String>,
pub env: Vec<(String, String)>,
pub args: Vec<Arg>,
pub requires: Vec<String>,
pub agent_allow: bool,
}Expand description
One task: a named script with its interpreter and metadata.
Fields§
§name: StringThe heading text (the command name).
description: StringProse in the task body that is not a recognized Key: value line.
lang: StringThe fenced block’s info-string language (sh, zsh, python, …); empty
means an unlabeled fence (treated as sh).
script: StringThe script (the fenced block’s contents), verbatim.
opts: Vec<String>Opts: carries per-task boolean flags, space-separated. The only flag
today is inherit-cwd: run the task in the directory mdtask was invoked
from, rather than the default (the directory of the task file that defines
it). Use it for a task that operates on a path relative to where you are (a
carry-around task such as pdf a-note.md). An unrecognized flag is recorded
as a warning and otherwise ignored. See TaskFile::invocation.
env: Vec<(String, String)>Env: adds extra environment for this task.
args: Vec<Arg>Args: declares positional arguments in just’s syntax. A bare name is
required, name='default' is optional, and a trailing *name is variadic
(it collects the rest, space-joined). Each one is substituted as
{{ name }} in the script and also exported as $name. Note that
{{ name }} is raw text substitution, spliced in before the interpreter
parses the script, so {{ name }} is NOT injection-safe for untrusted values
in any language. The safe form is to read the value from the environment,
never to template it: "$name" in a shell, os.environ["name"] in Python,
process.env.name in Node, and so on. Reserve {{ }} for developer-authored
templates.
requires: Vec<String>Requires: names the tasks this one depends on. mdtask-core does not run
them (execution stays the caller’s), but dependency_order resolves the
transitive run order (deps first, cycle and typo detected) so a caller can
run each in turn. The mdtask CLI does exactly that.
agent_allow: boolAgent: allow opts a task in to being listed and run by an MCP or agent
surface. It is advisory data: nothing in mdtask-core’s execution path
checks it. A caller exposing tasks to an agent must filter with
TaskFile::agent_tasks (off by default), which is the enforcement point.
The flag alone enforces nothing.
Implementations§
Source§impl Task
impl Task
Sourcepub fn inherits_cwd(&self) -> bool
pub fn inherits_cwd(&self) -> bool
Whether this task opted into Opts: inherit-cwd: run it in the invocation
directory rather than the default (the task file’s own directory).
Sourcepub fn script_arg_templates(&self) -> Vec<&str>
pub fn script_arg_templates(&self) -> Vec<&str>
The declared argument names this task interpolates into its script via
{{ arg }} (raw text substitution, spliced in before the interpreter parses
the script). Because it is not quoted, each of these is an injection point
for an untrusted argument value, in any language. A surface that runs a task
with caller-controlled argument values (an agent/MCP surface) should refuse
a task that has any; the author should read the value from the environment
instead ("$arg", os.environ["arg"], …). Empty for a task that reads its
args from the environment, the safe form. See TaskFile::invocation.