packet
jagt render, and the layers of the packet text.jagt render saves .agents/log/packets/<nonce>.json in the shared log
folder, the log folder of the main checkout. A hook later finds the nonce
in the result of the fresh agent, and reads this file for the target, the
input tree and the worktree.
const LOG_DIR
pub const LOG_DIR: &str = ".agents/log";The log folder of a checkout, relative to its top folder.
const PACKETS_DIR
pub const PACKETS_DIR: &str = "packets";The folder of the packet files, inside the log folder.
const NONCE_BYTES
pub const NONCE_BYTES: usize = 16;The number of random bytes in a nonce. The nonce is their hex form.
const PACKET_FILE_VERSION
pub const PACKET_FILE_VERSION: u32 = 1;The version of the form of the packet file.
struct PacketRecord
pub struct PacketRecordThe saved facts of one packet, as packets/<nonce>.json holds them.
| Field | Type | Description |
|---|---|---|
version |
u32 | The version of this form, now 1. |
nonce |
String | The random value that the packet text and the result both hold. |
target |
String | The target of the packet, for example review. |
input_tree |
String | The worktree tree when the packet was made, as a git tree hash. |
worktree |
String | The absolute path of the worktree in which jagt render ran. |
packet_sha256 |
String | The SHA-256 of the packet text, the exact bytes on stdout, in hex. |
Implements Debug, Clone, PartialEq, Eq, Serialize, Deserialize<'de>.
struct GitContext
pub struct GitContextThe git facts that jagt render needs, found from the current folder.
| Field | Type | Description |
|---|---|---|
worktree |
PathBuf | The top folder of the current worktree. |
main_checkout |
PathBuf | The checkout whose log folder jagt saves in: the main checkout, or the current worktree when the shared git folder is not named .git. |
Implements Debug, Clone, PartialEq, Eq.
GitContext::discover
pub fn discover(cwd: &Path) -> Result<Option<Self>>Find the worktree and the main checkout from cwd.
It gives None outside a git worktree, for example in a temporary
folder or inside .git, and when git cannot start. It fails when the main
repository is bare, because a bare repository has no log folder, and when
a later git call fails.
| Parameter | Type | Description |
|---|---|---|
cwd |
&Path | the folder to start from, which jagt render takes as the current folder |
| returns | Result<Option<Self>> | The worktree and the main checkout, or None outside a git worktree. |
fn project_root
pub fn project_root(cwd: &Path) -> PathBufFind the folder that jagt reads the project config and the layers from: the top of the git
worktree that holds cwd, or cwd itself outside a worktree or when git cannot start.
| Parameter | Type | Description |
|---|---|---|
cwd |
&Path | the folder that jagt runs in |
| returns | PathBuf | The project root. |
fn worktree_tree
pub fn worktree_tree(worktree: &Path, scratch_name: &str) -> Result<String>Compute the worktree tree: the index with every change in the worktree,
staged or not, plus the untracked files that are not ignored. A file that
the index holds stays in the tree, also when .gitignore names it. The
commit gates compute the tree the same way. So a commit of all the changes
has this tree, if no entry is assume-unchanged or skip-worktree.
It works on a copy of the index and a temporary object store, so the real
index does not change and .git/objects gets no new object. Git can still
update the time of an object that exists there:
cp -p <index> <tmp>/index # keeps the time of the index
GIT_INDEX_FILE=<tmp>/index GIT_OBJECT_DIRECTORY=<tmp>/objects \
GIT_ALTERNATE_OBJECT_DIRECTORIES=<objects> \
git -c core.splitIndex=false add -A -- :/
... git -c core.splitIndex=false write-treeThe copy keeps the time of the real index. Git compares the time of each
file with it, so a file that changed in the same second as the index is
still read again. jagt starts from git read-tree HEAD instead of the copy
when there is no index, or when an entry of the index is assume-unchanged
or skip-worktree, because git add does not see a change in such a file.
Before the first commit, it then starts from an empty index.
core.splitIndex=false keeps git from writing a shared index file into
the git folder for the copy.
It fails when the folder of the temporary index exists already, or when git fails.
| Parameter | Type | Description |
|---|---|---|
worktree |
&Path | the top folder of the worktree |
scratch_name |
&str | the end of the name of the temporary folder, jagt-index-<name>; jagt render gives the nonce |
| returns | Result<String> | The hash of the tree, as git write-tree prints it, with no newline. |
const LOCAL_ENV_VARS
pub const LOCAL_ENV_VARS: [&str; 21] = [
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
"GIT_CONFIG",
"GIT_CONFIG_PARAMETERS",
"GIT_CONFIG_COUNT",
"GIT_OBJECT_DIRECTORY",
"GIT_DIR",
"GIT_WORK_TREE",
"GIT_IMPLICIT_WORK_TREE",
"GIT_GRAFT_FILE",
"GIT_INDEX_FILE",
"GIT_NO_REPLACE_OBJECTS",
"GIT_REPLACE_REF_BASE",
"GIT_PREFIX",
"GIT_INTERNAL_SUPER_PREFIX",
"GIT_SHALLOW_FILE",
"GIT_COMMON_DIR",
"GIT_NAMESPACE",
"GIT_LITERAL_PATHSPECS",
"GIT_GLOB_PATHSPECS",
"GIT_NOGLOB_PATHSPECS",
"GIT_ICASE_PATHSPECS",
];The variables that git rev-parse --local-env-vars lists in git 2.54,
two more that change where git looks, GIT_INTERNAL_SUPER_PREFIX and
GIT_NAMESPACE, and the four that change how git reads a pathspec, such
as :/.
fn new_nonce
pub fn new_nonce() -> Result<String>Draw a new random nonce: 16 bytes from the system, in lowercase hex.
The first digit is always a letter from a to f. A YAML reader then
always reads the nonce as a string, never as a number such as 123e45.
jagt draws again until the first digit is a letter. It fails when the
system gives no random bytes.
| Parameter | Type | Description |
|---|---|---|
| returns | Result<String> | The nonce, 32 lowercase hex digits. |
fn is_nonce
pub fn is_nonce(value: &str) -> boolSay whether value has the form of a nonce: 32 lowercase hex digits, of
which the first is a letter from a to f.
| Parameter | Type | Description |
|---|---|---|
value |
&str | the text to check |
| returns | bool | True when value is a nonce. |
fn sha256_hex
pub fn sha256_hex(text: &str) -> StringHash a text with SHA-256.
| Parameter | Type | Description |
|---|---|---|
text |
&str | the text, hashed as its UTF-8 bytes |
| returns | String | The hash, 64 lowercase hex digits. |
fn save_record
pub fn save_record(log_dir: &Path, record: &PacketRecord) -> Result<PathBuf>Save record as <log_dir>/packets/<nonce>.json.
It makes .agents, the log folder and the packets folder when they are
missing. Where the log folder or the packets folder has no .gitignore
yet, it writes one that holds *, as jlog does, so git never sees the
packets. An existing .gitignore is kept as it is.
It never replaces a file: a packet file with the same name stops the
render. It also fails when the nonce of record is not a nonce, and when
one of the folders is a symlink or not a folder.
| Parameter | Type | Description |
|---|---|---|
log_dir |
&Path | the log folder, .agents/log of a checkout |
record |
&PacketRecord | the facts of the packet |
| returns | Result<PathBuf> | The path of the new packet file. |
fn remove_record
pub fn remove_record(path: &Path) -> Result<()>Remove the packet file path that save_record wrote, as after a
broken pipe. On Unix, it goes through the same folder handles, so a folder
that is now a symlink cannot point the removal elsewhere.
| Parameter | Type | Description |
|---|---|---|
path |
&Path | the path that [save_record] returned |
| returns | Result<()> | Ok(()) when the file is gone, or the error. |
struct Layer
pub struct LayerOne layer of the packet text: where it came from, and its text.
| Field | Type | Description |
|---|---|---|
label |
String | A label for the provenance, for example language layer: .agents/targets/python/docs.md. |
text |
String | The text of the layer. |
fn read_layers
pub fn read_layers(root: &Path, target: &str) -> Result<Vec<Layer>>Read the language layers and the repository text of target from the
checkout at root:
.agents/targets/<language>/<target>.md, for each language in theprofileslist of.agents/stack.json, in the order of that list;.agents/targets/<target>.md.
A missing file is not an error, and neither is a missing stack.json.
A file of blank lines adds no layer. It fails on a bad stack.json, and
on a layer file whose real path leads outside .agents/targets.
| Parameter | Type | Description |
|---|---|---|
root |
&Path | the top folder of the checkout |
target |
&str | the Just target |
| returns | Result<Vec<Layer>> | The layers in that order, each with its label for the provenance. |
fn stack_languages
pub fn stack_languages(root: &Path) -> Result<Vec<String>>Read the languages of the stack: the profiles list of .agents/stack.json.
Each name must be a plain folder name, so a name such as .. cannot send
the read out of .agents/targets.
A missing file, a missing profiles and profiles: null give no
languages. It fails when the file is not JSON, when profiles is not a
list of names, and when the real path of the file is not
.agents/stack.json of the checkout.
| Parameter | Type | Description |
|---|---|---|
root |
&Path | the top folder of the checkout |
| returns | Result<Vec<String>> | The names, in the order of the list, with each name once. |
fn check_config_prompt_path
pub fn check_config_prompt_path(cwd: &Path, path: &str) -> Result<()>Check the prompt path that a config file names, before jagt reads it.
A config file comes with the repository, so its prompt must not put any
file into the packet. A missing file is left for the read to report. Each of
these refuses the file:
- its real path is outside the real path of
cwd; - a part of its path is
.git; - on Unix, the file has more than one hard link, so it may be a file outside;
- a repository between the file and
cwdignores the file, such as an ignored.env. jagt asks each repository from the folder of the file up tocwd, so a submodule and the repository around it both answer; - a folder above the file holds a
.gitentry, and the repository nearest the file gives no clear answer, for example when git cannot start; - no folder above the file holds a
.gitentry, and a part of its path starts with., other than the folders.agentsand.jagt.
| Parameter | Type | Description |
|---|---|---|
cwd |
&Path | the project root, from [project_root], against which a relative path is read |
path |
&str | the prompt path from the config |
| returns | Result<()> | Ok(()), or a render error that says why jagt does not read the file. |
fn join_layers
pub fn join_layers(layers: &[Layer]) -> StringJoin the layers in order, with one blank line between two layers. The blank lines and the line break at the end of each layer are dropped, but the spaces and tabs at the end of its last line are kept.
| Parameter | Type | Description |
|---|---|---|
layers |
&[Layer] | the layers, in the order of the join |
| returns | String | The joined text, with no newline at its end. It is empty when there are no layers. |