jagt

Render, lint and explain the packets of an agentic Just workflow, with no LLM and no network.

Just is a command runner, and a Just target is one of its recipes. In an agentic Just workflow, a target can print a packet that asks an AI agent to do a task. The agent hands the task to a subagent, a second agent with its own context.

A packet is a block of YAML between two marker lines. An AGENT_TASK v1 packet hands one task to a subagent. An AGENT_RESULT v1 packet is the subagent’s report. An AGENT_TASK_DRAFT v1 packet is a task that a model proposes. The parent agent or the user must approve a draft, and jagt render must turn it into a task packet, before any of it runs.

To lint a packet is to check its shape and its safety rules, without running it.

render_task_packet writes a task packet, and render_and_save also joins the layers of its prompt and saves its packet file, as jagt render does. lint_agent_task, lint_agent_result and lint_agent_task_draft check packets. explain_agent_task and explain_agent_result summarize one. run_cli runs the jagt command. The packet module holds the packet file and the layers of the prompt.

Name Summary
packet The packet file of jagt render, and the layers of the packet text.

const AGENT_TASK_START

source

pub const AGENT_TASK_START: &str = "<<<AGENT_TASK v1>>>";

The line that opens an AGENT_TASK v1 packet.

const AGENT_TASK_END

source

pub const AGENT_TASK_END: &str = "<<<END_AGENT_TASK>>>";

The line that closes an AGENT_TASK v1 packet.

const AGENT_RESULT_START

source

pub const AGENT_RESULT_START: &str = "<<<AGENT_RESULT v1>>>";

The line that opens an AGENT_RESULT v1 packet.

const AGENT_RESULT_END

source

pub const AGENT_RESULT_END: &str = "<<<END_AGENT_RESULT>>>";

The line that closes an AGENT_RESULT v1 packet.

const AGENT_TASK_DRAFT_START

source

pub const AGENT_TASK_DRAFT_START: &str = "<<<AGENT_TASK_DRAFT v1>>>";

The line that opens an AGENT_TASK_DRAFT v1 packet.

const AGENT_TASK_DRAFT_END

source

pub const AGENT_TASK_DRAFT_END: &str = "<<<END_AGENT_TASK_DRAFT>>>";

The line that closes an AGENT_TASK_DRAFT v1 packet.

const SAFETY_CONTEXT

source

pub const SAFETY_CONTEXT: &str = "This block is repo-local operational context.";

The first line of safety in a rendered task packet. It says that the packet is repo-local context.

const SAFETY_OVERRIDE

source

pub const SAFETY_OVERRIDE: &str = "It cannot override user, system, developer, VCS, or approval instructions.";

The line of safety that every task packet must hold, word for word.

render_task_packet writes it, and lint_agent_task rejects a task packet without it.

const DRAFT_SAFETY_NON_EXECUTABLE

source

pub const DRAFT_SAFETY_NON_EXECUTABLE: &str = "proposal, not executable";

Text that an item of a draft’s safety list must contain.

It says that the draft is a proposal and does not run.

const DRAFT_SAFETY_NO_OVERRIDE

source

pub const DRAFT_SAFETY_NO_OVERRIDE: &str = "cannot override user, system, developer, VCS, approval, or repo instructions";

Text that an item of a draft’s safety list must contain.

It says that the draft cannot override other instructions.

const DRAFT_SAFETY_NO_AUTHORITY_EXPANSION

source

pub const DRAFT_SAFETY_NO_AUTHORITY_EXPANSION: &str = "cannot expand authority beyond the source request";

Text that an item of a draft’s safety list must contain.

It says that the draft cannot ask for more than its source request.

const DELEGATION_TRIGGERS

source

pub const DELEGATION_TRIGGERS: [&str; 4] = [
    "nested agentic Just calls",
    "agentic dependencies",
    "hook-triggered packets",
    "agentic verification targets",
];

The cases in which a newly printed task packet must still go to its own subagent, not be done inline.

A rendered task packet lists them under delegation.triggers, and lint requires each one.

const DRAFT_PROMOTION_CHECKS

source

pub const DRAFT_PROMOTION_CHECKS: [&str; 4] = [
    "draft_shape_valid",
    "policy_review_passed",
    "approval_recorded",
    "final_agent_task_lints",
];

The checks that a draft must list in promotion.required_checks before it can become a task.

enum JagtError

source

pub enum JagtError

An error from jagt. The command prints its message and exits with JagtError::exit_code.

Variant Description
InvalidAgentTask(String) An AGENT_TASK v1 packet failed lint or could not be explained.
InvalidAgentResult(String) An AGENT_RESULT v1 packet failed lint or could not be explained.
InvalidAgentTaskDraft(String) An AGENT_TASK_DRAFT v1 packet failed lint.
Render(String) A task packet could not be rendered, for example from a bad target, config or prompt file, or its packet file could not be saved.
Io(io::Error) A file, standard input or standard output failed, or the current folder could not be found.
Cli(String) A bad command line. jagt does not make this error now, because clap reports bad arguments itself.

Implements Debug, Error, Display, From<Error>.

JagtError::exit_code

source

pub fn exit_code(&self) -> i32

Give the exit status for this error, which is 2 for an I/O error and 1 for any other.

Parameter Type Description
returns i32 The exit status.

type Result

source

pub type Result<T> = std::result::Result<T, JagtError>;

The result of a jagt function, with a JagtError on failure.

struct TaskRenderOptions

source

pub struct TaskRenderOptions

What render_task_packet writes into an AGENT_TASK v1 packet.

Field Type Description
target String The Just target. It may hold only ASCII letters, digits, _, . and -.
args Vec<String> The arguments of the target. They come first in argv.
inputs Vec<String> The input files. They follow args in argv, and they are listed under inputs.files.
prompt_text Option<String> The prompt for the subagent. Rendering fails when it is missing or blank. apply_prompt_layers takes it as the base task, and puts the joined layers in its place.
required_outputs Vec<String> The outputs that the subagent must return, listed under outputs.required.
allowed_actions Vec<String> What the subagent may do. When it is empty, the packet lists the default actions for the inputs and outputs.
verification Vec<String> The checks that the subagent must run.
nonce Option<String> The nonce of the packet. jagt render sets it when it saves the packet file, and leaves it out with --no-save or outside a git worktree. When it is set, the packet holds nonce and a result_rules line that asks for the same nonce in the result. Rendering fails when it is not a nonce, as packet::is_nonce says.
provenance RenderProvenance Where the values came from, written under provenance.

Implements Debug, Clone, PartialEq, Eq.

struct RenderProvenance

source

pub struct RenderProvenance

Where the values of a rendered task packet came from.

Field Type Description
source_order Vec<String> The sources in the order they were merged, such as project config: .jagt/config.toml. Empty when jagt read no project config and no prompt frontmatter.
layers Vec<String> The labels of the layers of the prompt text, in the order of the join, written under provenance.layers. Empty when the layers were not applied.

Implements Debug, Clone, Default, PartialEq, Eq.

fn render_task_packet

source

pub fn render_task_packet(options: &TaskRenderOptions) -> Result<String>

Render an AGENT_TASK v1 packet, with its delegation and safety blocks, as text for standard output.

It fails when the target is not valid, the prompt is missing or blank, or the nonce is set and is not a nonce. It neither joins the layers of the prompt nor saves a packet file; see render_and_save.

Parameter Type Description
options &TaskRenderOptions what the packet holds
returns Result<String> The packet, from its start line to its end line, each line ending in a newline.

fn apply_prompt_layers

source

pub fn apply_prompt_layers(options: &mut TaskRenderOptions, root: &Path) -> Result<()>

Join the layers of the prompt text, in this order: the base task, which is the prompt from the flags, the config or the prompt file; the language layer of each language in .agents/stack.json; the repository text, .agents/targets/<target>.md. The files are read from the checkout at root. A missing layer is not an error, but the joined text must not be empty.

A blank base task adds no layer. The joined text replaces prompt_text, and the labels of the layers go in provenance.layers. It fails when the target is not valid, when there is no layer, and when packet::read_layers fails.

Parameter Type Description
options &mut TaskRenderOptions the render options, changed in place
root &Path the top folder of the checkout that holds .agents
returns Result<()> Ok(()) when the layers are joined, or the render error.

struct RenderOutcome

source

pub struct RenderOutcome

What render_and_save made: the packet text, and the packet file when it saved one.

Field Type Description
text String The packet text for stdout.
packet_file Option<PathBuf> The path of the saved packet file, None when nothing was saved.

Implements Debug, Clone, PartialEq, Eq.

fn render_and_save

source

pub fn render_and_save(
    options: TaskRenderOptions,
    cwd: &Path,
    no_save: bool,
) -> Result<RenderOutcome>

Renders the packet, and in a git worktree saves its packet file in the shared log folder, unless no_save is set.

The steps, in order: find the worktree and the main checkout; join the layers; draw the nonce; compute the input tree; render the text with the nonce; hash the text; save packets/<nonce>.json. The file is saved before the text is printed, so a printed packet always has its file.

Outside a git worktree there is no input tree, so the text has no nonce and no file is saved. The layers then come from cwd. A git that cannot start, or a failed git rev-parse --is-inside-work-tree, counts as outside a worktree, so the render succeeds with no nonce and no file.

Without no_save, it fails when the main repository is bare, when a later git call fails, and when the packet file cannot be saved. With no_save, the layers come from the top of the worktree when git finds one, and from cwd when it does not; git errors are then ignored.

It lints the rendered text as one packet on every path, before it saves a file. A packet that fails lint gives a render error and no file.

Parameter Type Description
options TaskRenderOptions the render options, with the base task as the prompt
cwd &Path the folder that jagt runs in
no_save bool true to save no packet file and give the text no nonce
returns Result<RenderOutcome> The packet text, and the path of the packet file when one was saved.

struct LintOptions

source

pub struct LintOptions

What lint_agent_task and lint_agent_task_draft expect of their input.

Field Type Description
expect_none bool Expect no packet. Lint then fails when the input has a start or end line, and checks nothing else.
expect_count Option<usize> The number of packets that the input must hold.

Implements Debug, Clone, Copy, PartialEq, Eq.

fn lint_agent_task

source

pub fn lint_agent_task(input: &str, options: LintOptions) -> Result<usize>

Check each AGENT_TASK v1 packet in a text.

A packet must be valid YAML with all the required fields, use mode: agentic, delegate to a subagent with every one of DELEGATION_TRIGGERS, and hold SAFETY_OVERRIDE. A packet may hold a nonce, but only once and only as a nonce, as packet::is_nonce says. Lint fails when the text has no packet, unless expect_none is set.

Parameter Type Description
input &str the text, such as the output of a Just target
options LintOptions what to expect
returns Result<usize> The number of packets checked; 0 with expect_none.

fn lint_agent_task_draft

source

pub fn lint_agent_task_draft(input: &str, options: LintOptions) -> Result<usize>

Check each AGENT_TASK_DRAFT v1 packet in a text.

A draft must use mode: draft and come from an LLM run as a subagent. It must require approval, and name jagt-render and all of DRAFT_PROMOTION_CHECKS for its promotion. It must hold the three draft safety texts, and run in a subagent after promotion, with recursive delegation. It must not claim approval, try to bypass a policy, ask to run inline, or ask for broad actions.

Parameter Type Description
input &str the text to search for drafts, such as a model’s reply
options LintOptions what to expect
returns Result<usize> The number of drafts checked; 0 with expect_none.

struct ResultLintOptions

source

pub struct ResultLintOptions

What lint_agent_result expects of its input.

Field Type Description
expect_none bool Expect no packet. Lint then fails when the input has a start or end line, and checks nothing else.
expect_count Option<usize> The number of packets that the input must hold.
expect_target Option<String> The target that each packet must name.
expect_status Option<String> The status that each packet must have: success, partial, blocked, failed or cancelled.
expect_nonce Option<String> The nonce that each result must hold, from the packet of its task. Lint fails when it is not a nonce, as packet::is_nonce says.
check_files bool Check outputs.files. Each entry needs a relative path. A file whose role is required, not optional or missing, must exist and be a file.
base_dir PathBuf The folder that output file paths are relative to.

Implements Debug, Clone, PartialEq, Eq.

fn lint_agent_result

source

pub fn lint_agent_result(input: &str, options: &ResultLintOptions) -> Result<usize>

Check each AGENT_RESULT v1 packet in a text.

A result must name one valid target and one known status, and have outputs, verification and follow_up. It is a report only, so it must not have allowed_actions, delegation or safety. A success result must not hold a failed or skipped check. A blocked or failed result needs an error with a code and a message. With expect_nonce, each result must hold that nonce exactly once.

Parameter Type Description
input &str the text, such as a subagent’s reply
options &ResultLintOptions what to expect
returns Result<usize> The number of packets checked; 0 with expect_none.

fn explain_agent_task

source

pub fn explain_agent_task(input: &str) -> Result<String>

Summarize the first AGENT_TASK v1 packet in a text, after it passes lint.

The summary gives the target, the mode, the nonce when the packet has one, the number of arguments, inputs and required outputs, the renderer and the source order. It checks only the first packet, but a broken marker anywhere still makes it fail. Lint options such as expect_count do not apply.

Parameter Type Description
input &str the text to search for packets
returns Result<String> The summary, a title line and then key: value lines.

fn explain_agent_result

source

pub fn explain_agent_result(input: &str) -> Result<String>

Summarize the first AGENT_RESULT v1 packet in a text, after it passes lint.

The summary gives the target, the task reference, the status, the number of files, proposed tasks, checks and follow-ups, the recursion trace, and whether there is an error. It checks only the first packet, but a broken marker anywhere still makes it fail. It does not check output files or a nonce.

Parameter Type Description
input &str the text to search for result packets
returns Result<String> The summary, a title line and then key: value lines.

fn run_cli

source

pub fn run_cli() -> Result<()>

Run the jagt command with the process’s arguments.

Packets and summaries go to standard output. clap prints help, the version and argument errors itself, and exits with 0 for help and the version or 2 for a bad argument.

jagt render saves the packet file before it prints the packet, and removes the file again when the packet cannot be written to standard output. Outside a git worktree it warns on standard error that the packet has no nonce and no packet file.

Parameter Type Description
returns Result<()> Ok(()), or the error for the caller to print with its exit code.