Skip to Content

Level 0 in ten minutes

cores/examples/level0-script is a whole core in two files, explained.

cores/examples/level0-script is a whole core in two files. Here it is, explained.

A core is a folder. The app finds it by its manifest, pitafix-core.toml:

schema = 1
id = "level0-script"
name = "Level 0 example"
version = "0.1.0"
publisher = "pitafix"
level = 0

[app]
compatible = ">=0.1 <2"

[detect]                 # PitaFix evaluates this itself; no code of yours runs before trust
any_files = ["README.md", "README"]

[run]
command = ["./write-trace.sh"]

[permissions]            # shown to the person before they say yes
exec = ["sh", "shasum"]
network = "none"
writes = [".pitafix/traces"]
untrusted_project = "none"

And the program, write-trace.sh, which does the whole job:

#!/bin/sh
set -e
run="r_$(date +%s)"; out=".pitafix/traces/$run"; mkdir -p "$out/artifacts"
tree='{"schema":"pitafix.tree/1","w":390,"h":844,"root":{"name":"Home","bounds":{"x":0,"y":0,"w":390,"h":844}}}'
printf '%s\n' "$tree" > "$out/artifacts/0001.tree.json"
sha=$(shasum -a 256 "$out/artifacts/0001.tree.json" | cut -d' ' -f1)
{ printf '{"type":"meta","schema":"pitafix.trace/1","run":"%s","commit":"%s","dirty":false,"source":"test","dataSource":"fixture","proofLevel":"typed-only","core":{"id":"level0-script","version":"0.1.0"},"facets":{}}\n' "$run" "${PITAFIX_COMMIT:-unknown}"
  printf '{"type":"step","id":"st_1","seq":1,"status":"passed","action":{"kind":"launch","actor":"script"},"screen":{"name":"Home","identity":{"method":"manual","key":"Home"}},"artifacts":[{"kind":"tree","phase":"after","path":"artifacts/0001.tree.json","sha256":"%s"}]}\n' "$sha"
  printf '{"type":"end","status":"passed"}\n'; } > "$out/trace.ndjson"

That is the whole contract at level 0:

  1. Make a run folder under .pitafix/traces/<run>/. The name is yours; the script uses r_<unix time>.
  2. Write each artifact first, then the record that names it. Artifact paths are relative to the run folder, and each carries its file's SHA-256, so PitaFix can tell the file on disk is the one the record meant.
  3. Write trace.ndjson, one JSON object per line: a meta record first, then journey, step and attribution records in the order they happened, then an end record.

Run it against any repository to see it work:

pitafix core test cores/examples/level0-script --project /path/to/some/repo

cores/sample is the next one to read, and the one core the app ships. It is still a level 0 shell script, and its run has what the rest of this guide describes: three journeys in two sections, screenshots, trees whose nodes name a file and a line, attribution, and scenes that scroll under a header and over a bar that stays at the bottom. It captures one made-up project, cores/sample/project, a recipe book of six screens, and hands out pictures drawn ahead of time from that project's files (internal/samplecore draws them), so it refuses any other project. To see it in the app, copy cores/sample/project out, make it a git repository with one commit, and open the copy. To check it:

pitafix core test cores/sample --project /path/to/the/copy

core test runs the core in a throwaway copy of the project, validates every record and artifact against the schemas below, and reports what to fix. It is the fastest feedback loop there is for core work; run it after every change.

On this page