ShtukbaseStandard

Code: shared library

code-lib · version 0.1.0
Code

The shared part of the code-norm packages: a rough dependency-free parse of TypeScript/JavaScript, Python and Rust, shared settings (which code to read), running checks in observe or enforce mode, and a prompt for a reviewing agent.

About the package

The package has no norms of its own. The code-norm packages need it; each of them is one school of thought:

  • code-refactoring: code smells after Martin Fowler;
  • code-deep-modules: deep modules after John Ousterhout;
  • code-pragmatic: the habits of the "pragmatic programmer" of Hunt and Thomas;
  • code-unix: the Unix philosophy: McIlroy, Raymond;
  • code-functional-core: a pure core and a thin shell: Bernhardt, Seemann.

The packages can be installed one by one or together. The schools disagree in places (Fowler likes short functions, Ousterhout likes deep modules): take the ones that suit the project.

What is inside

  • The page /norms/code.md: which code to read: roots, languages, tests, exclusions.
  • checks/lib/lex.ts: masks strings and comments, so that brackets and words inside them do not confuse the heuristics.
  • checks/lib/units.ts: functions, classes, imports, nesting depth; regular expressions and bracket parsing.
  • checks/lib/scan.ts: settings and the file list.
  • checks/lib/run.ts: running a check: it reads the norm's mode; with enforce a finding fails the check, with observe and warn it prints and passes. The comment code-allow: <check> releases one place.
  • checks/lib/review.ts: the reviewer's prompt: norms, judges, hints from the checks and the material itself.

The norm packages import the library by a neighboring path: ../../code-lib/checks/lib/… from .shtukbase/packages/<package>/checks/.

Review by an agent

shtuk run code-lib review                     # all installed code packages, the uncommitted change
shtuk run code-lib review --diff main..HEAD   # a range of commits
shtuk run code-lib review --staged            # what is in the index
shtuk run code-lib review src/a.ts src/lib    # whole files

The action prints a ready prompt and does not start an agent: pass it to your own harness (claude -p, codex exec and the like). The reviewer's answer is one line per norm: holds, violated (where and how to fix it) or not applicable.

Honestly about the parse

This is not a parser. The parse is rough: regular expressions and bracket counting over text where strings and comments are blanked out. A regular expression in JavaScript differs from division only by the word before it; a symbol and a lifetime in Rust are told apart by the following characters; expressions inside Python f-strings are not parsed. So all the code-norm checks stay in observe until the owner is sure they are not noisy on their code.

Actions 1

NameWhat it doesFileWhen
reviewA prompt for a reviewing agent over all installed code-norm packages: by diff or by filesactions/review.ts
shtuk run

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

Pages 1

They go into the project at these paths.

Package files 7

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