Repository navigation
chore: update copier template to v0.7.0 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
egparedes
wants to merge
4
commits into
main
Choose a base branch
from
ao/ulv-5/copier-v0.7.0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e942012
chore: update copier template to v0.7.0
egparedes 65e0911
chore: address code-review findings on template update
egparedes 0031146
chore: port harness hardening and process-memory records from the ulv…
egparedes a4ccc39
fix: address review threads - fail-open Stop gate, architect edit:ask
egparedes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,72 @@ | ||
| #!/usr/bin/env sh | ||
| # block-destructive.sh — canonical destructive-command matcher. | ||
| # | ||
| # Reads candidate command text on stdin; exits 2 if it matches a forbidden | ||
| # pattern, 0 otherwise. This is the single source of truth for the deny-list. | ||
| # Reads candidate command text on stdin; exits 2 (with a reason on stderr) if | ||
| # it matches a forbidden pattern, 0 otherwise. This is the single source of | ||
| # truth for the deny-list. | ||
| # | ||
| # Consumers: | ||
| # - Claude Code: the PreToolUse(Bash) hook in .claude/settings.json pipes the | ||
| # tool input here. | ||
| # - OpenCode: cannot call a script, so the deny globs in | ||
| # .opencode/opencode.jsonc restate these patterns by hand — keep in sync. | ||
| # Those globs are plain substring matches and cannot express the quoting | ||
| # and command-position rules below, so OpenCode over-blocks where this | ||
| # script does not. | ||
| # | ||
| # See .agents/README.md for the single-source-of-truth rationale. | ||
| grep -qE 'rm -rf|push --force|reset --hard|DROP TABLE' && exit 2 || exit 0 | ||
| # | ||
| # DIVERGES FROM THE COPIER TEMPLATE. Upstream matches the raw command text | ||
| # with one substring `grep -qE`, which denies any command that merely *quotes* | ||
| # a pattern — enough to block a `rg` search of this file or a PR description | ||
| # explaining it. Behaviour here is pinned by tests/test_harness_config.py; on | ||
| # `copier update`, keep this version and reject the upstream hunk. Like | ||
| # upstream, the deny decision stays on POSIX `grep -qE`: `grep -o` is a | ||
| # non-POSIX extension that suppresses stdout on binary-classified input, so | ||
| # using the extracted match as the decision would fail open. | ||
|
|
||
| cmd=$(cat) | ||
| [ -n "$cmd" ] || exit 0 | ||
|
|
||
| # Shell-syntax patterns are matched against text with quoted spans removed, so | ||
| # a command that merely *names* a dangerous form — `rg "rm -rf" .agents/`, | ||
| # `git log --grep="reset --hard"`, a heredoc documenting the deny-list — is not | ||
| # blocked. Only an unquoted occurrence is shell the caller is about to run. | ||
| bare=$(printf '%s' "$cmd" | sed -e "s/'[^']*'/''/g" -e 's/"[^"]*"/""/g') | ||
|
|
||
| deny() { | ||
| printf 'block-destructive: refusing this command — %s.\n' "$1" >&2 | ||
| printf 'block-destructive: %s\n' "$cmd" >&2 | ||
| printf 'block-destructive: see .agents/hooks/block-destructive.sh for the deny-list.\n' >&2 | ||
| exit 2 | ||
| } | ||
|
|
||
| # A command position: start of input, or after a separator that begins a new | ||
| # command. Keeps `rm` as an argument (`git log -- rm`) from matching. | ||
| POS='(^|[;&|(]|\$\()[[:space:]]*(sudo[[:space:]]+)?' | ||
|
|
||
| # Recursive *and* forced delete, in the spellings that actually occur: | ||
| # combined (-rf, -fr, -rvf), separate (-r -f, -f -r), and long-form. | ||
| match() { printf '%s' "$bare" | grep -qE "$1"; } | ||
|
|
||
| match "${POS}rm[[:space:]]+(-[A-Za-z]+[[:space:]]+)*-[A-Za-z]*([rR][A-Za-z]*[fF]|[fF][A-Za-z]*[rR])" || | ||
| match "${POS}rm[[:space:]]+(-[A-Za-z]*[rR][A-Za-z]*[[:space:]]+)+(-[A-Za-z]*[fF])" || | ||
| match "${POS}rm[[:space:]]+(-[A-Za-z]*[fF][A-Za-z]*[[:space:]]+)+(-[A-Za-z]*[rR])" || | ||
| match "${POS}rm([[:space:]]+--(recursive|force))+[[:space:]]+--(recursive|force)" && | ||
| deny 'a recursive forced delete' | ||
|
|
||
| # `[^;&|()]*` spans git's own options (`git -C /repo push …`) without running | ||
| # past the end of the command. `--force([^-]|$)` leaves --force-with-lease, | ||
| # the reviewable form, allowed. | ||
| match "${POS}git[[:space:]]+([^;&|()]*[[:space:]]+)?push[[:space:]]+[^;&|()]*--force([^-]|\$)" && | ||
| deny 'a force push (use --force-with-lease on your own branch, deliberately)' | ||
|
|
||
| match "${POS}git[[:space:]]+([^;&|()]*[[:space:]]+)?reset[[:space:]]+[^;&|()]*--hard" && | ||
| deny 'a hard reset (it discards uncommitted work irreversibly)' | ||
|
|
||
| # SQL, unlike the above, is normally *inside* quotes (`psql -c "DROP TABLE x"`), | ||
| # so this one is matched against the raw text. | ||
| printf '%s' "$cmd" | grep -qiE 'DROP[[:space:]]+(TABLE|DATABASE|SCHEMA)' && | ||
| deny 'a destructive SQL statement' | ||
|
|
||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/usr/bin/env sh | ||
| # hook-input.sh — canonical reader for agent-hook JSON payloads. | ||
| # | ||
| # Usage: hook-input.sh <dot.path> (stdin: the hook's JSON payload) | ||
| # e.g. hook-input.sh .tool_input.command | ||
| # | ||
| # Prints the field's value on stdout, identically under either backend: | ||
| # '' for null/absent (including a path through a non-object), 'true'/'false' | ||
| # for booleans, raw text for strings, compact JSON for objects/arrays. | ||
| # (Known residual divergence: non-canonical numeric literals like 1.5e3 may | ||
| # render differently per backend; all current consumers read strings/booleans.) | ||
| # | ||
| # Exit codes: 0 read OK; 3 no working JSON parser on PATH; 4 empty or | ||
| # unparseable payload (both backends reject a payload that is not exactly | ||
| # one JSON document). Callers branch on the distinction to pick their own | ||
| # failure posture and message. | ||
| # | ||
| # Parses with jq when available, falling back to python3. Both backends are | ||
| # probed by *running* them, not `command -v` alone — a broken jq install | ||
| # (stub, wrong arch) must fall through to python3, and stock macOS ships a | ||
| # /usr/bin/python3 stub that passes `command -v` but fails until the Xcode | ||
| # Command Line Tools are installed. | ||
| # | ||
| # Consumers: | ||
| # - Claude Code: the PostToolUse, PreToolUse, and Stop hooks in | ||
| # .claude/settings.json read their payloads through this script. | ||
| # | ||
| # See .agents/README.md for the single-source-of-truth rationale. | ||
|
|
||
| payload=$(cat) | ||
| if [ -z "$payload" ]; then | ||
| echo 'hook-input.sh: empty hook payload on stdin.' >&2 | ||
| exit 4 | ||
| fi | ||
|
|
||
| if printf '{}' | jq . >/dev/null 2>&1; then | ||
| out=$(printf '%s' "$payload" | jq -rcn --arg p "$1" ' | ||
| [inputs] as $docs | ||
| | if ($docs | length) != 1 then error("expected exactly one JSON document") else $docs[0] end | ||
| | ($p | split(".") | map(select(length > 0))) as $parts | ||
| | (try getpath($parts) catch null) | ||
| | if . == null then "" elif type == "boolean" then tostring else . end | ||
| ' 2>/dev/null) || { | ||
| echo 'hook-input.sh: cannot parse the hook payload as JSON.' >&2 | ||
| exit 4 | ||
| } | ||
| printf '%s\n' "$out" | ||
| exit 0 | ||
| fi | ||
|
|
||
| if python3 -c '' >/dev/null 2>&1; then | ||
| printf '%s' "$payload" | python3 -c ' | ||
| import json, sys | ||
| try: | ||
| v = json.load(sys.stdin) | ||
| except ValueError: | ||
| print("hook-input.sh: cannot parse the hook payload as JSON.", file=sys.stderr) | ||
| sys.exit(4) | ||
| for p in [p for p in sys.argv[1].split(".") if p]: | ||
| v = v.get(p) if isinstance(v, dict) else None | ||
| if v is None: | ||
| print("") | ||
| elif v is True or v is False: | ||
| print(str(v).lower()) | ||
| elif isinstance(v, (dict, list)): | ||
| print(json.dumps(v, separators=(",", ":"))) | ||
| else: | ||
| print(v) | ||
| ' "$1" | ||
| exit $? | ||
| fi | ||
|
|
||
| echo 'hook-input.sh: no working JSON parser (jq or python3) on PATH; cannot read the hook input. Install jq (apt-get install jq / brew install jq).' >&2 | ||
| exit 3 | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[code-review:xhigh] jq/python3 output differs for objects and numbers (CONFIRMED)
jq -r without -c pretty-prints objects/arrays while the python3 fallback prints compact json.dumps; JSON 1.5e3 prints '1500' (jq) vs '1500.0' (python). Violates the header's 'identically under either backend' contract. Harmless for today's string-only consumers, but any future non-string consumer behaves differently depending on whether jq is installed.