ShtukbaseStandard

Code: the Unix philosophy

code-unix · version 0.1.0
Code5 norms2 checks

The Unix philosophy (McIlroy, 1978; Raymond, "The Art of Unix Programming", 2003): one program, one job, text as the interface, composition, silence on success, loud failure, policy apart from mechanism; two heuristics and three judges.

About the package

The school. A program is small and busy with one job. Big things are assembled from small ones, joined by plain text: the output of one is the input of another. When there is nothing to say, the program is silent; when it cannot do its job, it refuses at once and loudly.

The authors. Douglas McIlroy; Eric Raymond. Source: M. D. McIlroy, E. N. Pinson, B. A. Tague, "UNIX Time-Sharing System: Foreword", Bell System Technical Journal, 1978; Eric S. Raymond, "The Art of Unix Programming", Addison-Wesley, 2003 (the rules of modularity, composition, separation, silence, repair). The norms below retell the ideas in our own words; they are not quotes.

When to take it. Command-line utilities, scripts, services, libraries called from other programs; agents' tools.

When not to take it. Interactive applications with windows: they have their own school of interface; the rule of silence for them is not about stdout.

Norms

NormWhat holdsLevelEnforcer
UNX-R01One program, one jobSHOULDjudge judges/one-thing.md
UNX-R02Silence on successSHOULDcheck silent-library
UNX-R03Failure is loudSHOULDcheck swallowed-errors
UNX-R04Text as the interface, honest exit codesSHOULDjudge judges/text-interface.md
UNX-R05Policy apart from mechanismMAYjudge judges/policy-mechanism.md

All norms are in observe mode: the checks print findings and pass, the judges are a procedure for the reviewer. A check you trust on your code is moved by the owner to mode: enforce in the norm's page, and then a finding fails shtuk check.

How to connect

shtuk install <path>/apps/standard/packages/code-unix --dir <project>
shtuk check --dir <project>
shtuk run code-unix review                 # a prompt for the reviewer over the uncommitted change
shtuk run code-unix review --diff main..HEAD
shtuk run code-unix review src/a.ts src/b.py

The package requires norms-core and code-lib (the shared code-parsing library and shared settings). It is installed on top of Basic.

Settings

Which code to read is the shared page /norms/code.md of the code-lib package: roots (roots), exclusions (exclude), languages, whether to read tests. This package's thresholds are the page /norms/code/code-unix.md:

KeyDefaultWhat it means
rustLetUnderscorefalsecount let _ = call(); in Rust as a swallowed error (UNX-R03)
strictPassfalsealso count except SpecificError: pass in Python (UNX-R03)

The same page has its own exclude list (path masks from the project root). One place is released by the comment code-allow: <check name> on its line or the line above.

Honestly about the checks

The checks are rough heuristics: regular expressions and bracket parsing for TypeScript/JavaScript, Python and Rust, with no parsers and no dependencies. They err both ways, which is why they stand in observe. The meaning of a norm is held by the judge; the heuristic only shows where to look. 2 checks, 3 judges.

Norms 5

IDNormLevelModeEnforcer
UNX-R01
A program, a command or a module does one job, which is described by one phrase without "and"; a new job is a new program or command, not a flag on the old one.
SHOULD observes
judge
UNX-R02
Library code prints nothing to stdout; the program's entry point prints, and only what was asked for.
SHOULD observes
sensor
UNX-R03
An error is not swallowed silently: an empty catch, except Exception: pass, Err(_) => {} are allowed only with a comment saying why it can be forgotten.
SHOULD observes
sensor
UNX-R04
A program's output is fit to be the input of another: data goes to stdout line by line or as JSON on a flag, messages and trouble go to stderr; exit code 0 only on success.
SHOULD observes
judge
UNX-R05
What to do (rules, thresholds, choices) is written apart from how to do it (the mechanism): in settings, in data or in a separate module.
MAY observes
judge

"Blocks": the enforcer stops a violation. "Observes": it only notes it. Level MUST means required; SHOULD means yes by default.

Actions 3

NameWhat it doesFileWhen
silent-librarySilence on success
norm UNX-R02
checks/silent_library.ts
check
swallowed-errorsFailure is loud
norm UNX-R03
checks/swallowed_errors.ts
check
reviewA prompt for a reviewing agent over the package norms: by diff or by filesactions/review.ts
shtuk run

shtuk check runs the checks; shtuk run code-unix <name> runs any action. "After install" actions run by themselves only if the package comes from a trusted source.

Pages 6

They go into the project at these paths.

Package files 7

They go into .shtukbase/packages/code-unix/; actions run from there.