Skip to content

Read what a command line writes: invocations and authorship checks - #4

Open
devmaxxx wants to merge 2 commits into
mainfrom
feat/authorship-guards
Open

devmaxxx wants to merge 2 commits into
mainfrom
feat/authorship-guards

Conversation

@devmaxxx

Copy link
Copy Markdown
Owner

Summary

  • invocations(cmd, command) lists every command a line certainly runs. For each one it gives the words as the shell passes them, with wrappers removed, and the stdin it reads from a here-document or here-string. A word that is one whole $(cat <<'EOF' … EOF) resolves to the here-document text.
  • Authorship checks in src/authorship.ts:
    • authoredMessages reads commit text from -m, -F - and --trailer, and gh pr title, body and body-file text.
    • branchNames covers checkout -b, switch -c, branch, branch -m and worktree add.
    • aiSignatures, isConventionalCommit, isConventionalBranch, COMMIT_TYPES and BRANCH_TYPES hold the rules.
    • authorshipViolations combines all of the above. It ports the authorship-conventions logic from the bond plugin's hooks.
  • Reader: each here-document body is now attached to the command it feeds, and each $(…) leaves an index to its source. deniedBy, runsCommand and commandSegments behave as before (all 477 existing tests pass unchanged).
  • Docs: README API sections, an authorship hook recipe, and a CHANGELOG entry.

Note: this branch is based on docs/awesome-readme, so it also carries 0c6a747 chore: rename package and repository to shell-guards. That commit was pushed after #3 merged and never reached main.

Known gaps (found in review, not fixed here):

  • $'…' ANSI-C words are read as expansions, so a message spelled that way is not checked.
  • Only git commit and gh pr … are read. git tag -m, git merge -m and gh issue comment are not.
  • Stdin ignores redirection order (for example a here-string followed by < file).
  • Typed Merge … and fixup! … subjects pass the Conventional Commit check.

Test plan

  • pnpm test: 525 passed
  • pnpm typecheck, pnpm lint and publint are clean
  • /code-review high --fix: 10 findings, 5 fixed (signature glued to its flag, partial -m subject, prose false positive, unescaped custom types, README recipe that could fail open), 5 left as the gaps above

The shell-command-guard name was never published to npm, so the
package moves to the shorter shell-guards with nothing to deprecate.
Repository links follow the GitHub rename; GitHub redirects the old URLs.
shell-guards could tell whether a line runs `git commit`, but a caller
that wanted to check the message still had to dig it out of the raw
text with regexes, which miss `env`/`bash -c` wrappers and misread a
heredoc that merely prints the words. The authorship-conventions hooks
in bond did exactly that.

The reader now keeps what it used to throw away: each here-document body
is attached to the command it feeds, and each $(…) leaves an index to
its source after its EXP marker. On top of that, `invocations(cmd,
command)` lists every command a line certainly runs with its words as
the shell passes them and its here-document or here-string stdin; a
word that is one whole `$(cat <<'EOF' … EOF)` resolves to the body.

`src/authorship.ts` builds the policy on it: `authoredMessages` reads
commit `-m`/`-F -`/`--trailer` and `gh pr` title/body text,
`branchNames` reads every way git creates or renames a branch, and
`authorshipViolations` reports AI signatures, non-Conventional commit
subjects and non-Conventional branch names. What the line does not show
(an editor, an expansion) is not a violation; message files are read
only through a caller-supplied `readFile`.

deniedBy, runsCommand and commandSegments behave as before; the markers
never leave the module.

Verified: pnpm test (525 passed), pnpm typecheck, pnpm lint, publint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant