@bookedsolid/rea 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/commit-msg +10 -2
- package/agents/codex-adversarial.md +7 -2
- package/commands/codex-review.md +8 -4
- package/dist/cli/upgrade.js +16 -1
- package/dist/hooks/push-gate/codex-runner.js +18 -7
- package/dist/policy/loader.d.ts +8 -4
- package/dist/policy/loader.js +8 -4
- package/hooks/_lib/cmd-segments.sh +144 -20
- package/hooks/_lib/policy-read.sh +91 -3
- package/hooks/_lib/protected-paths.sh +78 -7
- package/hooks/attribution-advisory.sh +28 -3
- package/hooks/security-disclosure-gate.sh +17 -0
- package/package.json +1 -1
package/.husky/commit-msg
CHANGED
|
@@ -78,9 +78,17 @@ BLOCKED=0
|
|
|
78
78
|
MATCHES=""
|
|
79
79
|
|
|
80
80
|
# Pattern 1: Co-Authored-By with noreply@ email
|
|
81
|
-
|
|
81
|
+
# 0.18.0 helix-020 / discord-ops Round 10 #3 fix (G4.B):
|
|
82
|
+
# the pre-fix pattern `Co-Authored-By:.*noreply@` matched both AI-tool
|
|
83
|
+
# noreply addresses AND legitimate `<user>@users.noreply.github.com`
|
|
84
|
+
# collaborator credits — blocking honest co-author footers from human
|
|
85
|
+
# contributors. Refined to enumerate AI-tool noreply domains explicitly;
|
|
86
|
+
# Pattern 2 below catches Co-Authored-By with named tools regardless of
|
|
87
|
+
# email, so dropping users.noreply.github.com from this branch only
|
|
88
|
+
# relaxes the check for human collaborators — never for AI.
|
|
89
|
+
if grep -qiE 'Co-Authored-By:.*noreply@(anthropic\.com|openai\.com|github-copilot|github\.com|claude\.ai|chatgpt\.com|googlemail\.com|google\.com|cursor\.com|codeium\.com|tabnine\.com|amazon\.com|amazonaws\.com|amazon-q\.amazonaws\.com|cody\.dev|sourcegraph\.com)' "$COMMIT_MSG_FILE" 2>/dev/null; then
|
|
82
90
|
BLOCKED=1
|
|
83
|
-
MATCHES="${MATCHES}$(grep -niE 'Co-Authored-By:.*noreply@' "$COMMIT_MSG_FILE" 2>/dev/null)
|
|
91
|
+
MATCHES="${MATCHES}$(grep -niE 'Co-Authored-By:.*noreply@(anthropic\.com|openai\.com|github-copilot|github\.com|claude\.ai|chatgpt\.com|googlemail\.com|google\.com|cursor\.com|codeium\.com|tabnine\.com|amazon\.com|amazonaws\.com|amazon-q\.amazonaws\.com|cody\.dev|sourcegraph\.com)' "$COMMIT_MSG_FILE" 2>/dev/null)
|
|
84
92
|
"
|
|
85
93
|
fi
|
|
86
94
|
|
|
@@ -32,13 +32,18 @@ You may read additional files in the repo if needed for context, but do so read-
|
|
|
32
32
|
1. **Check HALT and policy** — read `.rea/policy.yaml`, check `.rea/HALT`. If frozen, stop immediately.
|
|
33
33
|
2. **Validate Codex availability** — if `/codex` is not installed, report and stop. Do not silently fall back to another reviewer.
|
|
34
34
|
3. **Prepare the Codex invocation** — construct the adversarial-review prompt with the diff, commit log, and any relevant context files.
|
|
35
|
-
4. **Invoke `/codex:adversarial-review`** —
|
|
35
|
+
4. **Invoke `/codex:adversarial-review --model gpt-5.4`** — pass the `--model` flag explicitly to pin the iron-gate model regardless of plugin defaults or `~/.codex/config.toml` resolution. The codex-companion script accepts `--model` (see `codex-companion.mjs:684`). This call flows through the REA middleware chain (audit → kill-switch → tier → policy → redact → injection → execute → result-size-cap).
|
|
36
36
|
|
|
37
37
|
**Model pinning (0.16.1+):** when the codex plugin's adversarial-review supports model overrides, request `gpt-5.4` with `model_reasoning_effort: high` to match the push-gate's iron-gate defaults. Pre-0.16.1, in-session adversarial reviews ran on whatever the plugin defaulted to (likely `codex-auto-review` at medium reasoning) — meaningfully WEAKER than the push-gate's `gpt-5.4` + `high`. This caused a "in-session review passes, push-gate review fails" pattern reported by helix across 014 / 015 / 016. If the plugin call accepts model parameters, pass them. If it does not, fall back to invoking `codex exec review --base <ref> --json --ephemeral -c model="gpt-5.4" -c model_reasoning_effort="high"` directly via `Bash` — same shape the push-gate uses (see `src/hooks/push-gate/codex-runner.ts::runCodexReview`). The cost of the stronger model is small relative to the cost of shipping a release with a P1 bypass that gets caught at consumer push time.
|
|
38
38
|
5. **Parse the Codex output** — extract structured findings.
|
|
39
39
|
6. **Classify findings** by category: security, correctness, edge cases, test gaps, API design, performance.
|
|
40
40
|
7. **Assign verdict**: `pass` (no material findings), `concerns` (findings worth addressing but not blocking), `blocking` (findings that must be fixed before merge).
|
|
41
|
-
8. **Emit an audit entry — REQUIRED** for every `/codex-review` invocation.
|
|
41
|
+
8. **Emit an audit entry — REQUIRED** for every `/codex-review` invocation. This is one of three identical contract checkpoints:
|
|
42
|
+
- The runtime always emits (`src/hooks/push-gate/index.ts` calls `appendAuditRecord` via `safeAppend` on every completed review — see `EVT_REVIEWED`).
|
|
43
|
+
- This agent always emits (this step).
|
|
44
|
+
- The `/codex-review` slash command's Step 3 verifies the entry exists and surfaces "review never happened" as a failure if it does not.
|
|
45
|
+
|
|
46
|
+
The pre-push gate does not consult audit records to decide pass/fail (post-0.11.0 the gate is stateless), but the audit record is still the operator's only forensic trail for an interactive review. Without it, "did this review actually happen" becomes unanswerable. Reconciled in 0.18.0 (helixir Finding #6 across cycles 1–7) so the three documents — `commands/codex-review.md`, `agents/codex-adversarial.md`, `src/hooks/push-gate/index.ts` — describe the same contract in identical wording. Append via the public `@bookedsolid/rea/audit` helper:
|
|
42
47
|
|
|
43
48
|
```ts
|
|
44
49
|
import { appendAuditRecord, CODEX_REVIEW_TOOL_NAME, CODEX_REVIEW_SERVER_NAME, Tier, InvocationStatus } from '@bookedsolid/rea/audit';
|
package/commands/codex-review.md
CHANGED
|
@@ -55,17 +55,21 @@ Invoke the `codex-adversarial` agent with:
|
|
|
55
55
|
|
|
56
56
|
The agent wraps `/codex:adversarial-review` and returns structured findings.
|
|
57
57
|
|
|
58
|
-
## Step 3 —
|
|
58
|
+
## Step 3 — Verify audit entry — REQUIRED
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
The `codex-adversarial` agent **MUST** emit an audit entry for every invocation. This is the same contract documented in `agents/codex-adversarial.md` Step 4 and matches the runtime behavior of `rea hook push-gate` (which always calls `appendAuditRecord` on a completed review — see `src/hooks/push-gate/index.ts`'s `EVT_REVIEWED` path).
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
Verify the entry was written:
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
65
|
tail -n 1 .rea/audit.jsonl
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
The expected entry has `tool_name: "codex.review"`, `server_name: "codex"`, and `metadata` containing `head_sha`, `target`, `finding_count`, and `verdict`. If the entry is missing, the review **did not complete its contract** — surface that to the user as a failure.
|
|
69
|
+
|
|
70
|
+
**Why audit emission is required even though the pre-push gate is stateless:** the 0.11.0 push-gate decides pass/fail on Codex's live verdict, not on a receipt in the audit log — but the audit record is still the operator's only forensic trail for an interactive `/codex-review` run. Without it, "did this review actually happen" becomes unanswerable, which is exactly the failure mode helixir flagged across rounds 65/66/73 in the 0.13–0.17 cycle. Runtime always emits; the agent always emits; the slash command verifies. Three checkpoints, one contract.
|
|
71
|
+
|
|
72
|
+
(Earlier docs in 0.15+ said this step was "optional"; that wording contradicted both the agent's Step 4 and the runtime behavior of `safeAppend` in `src/hooks/push-gate/index.ts`. Reconciled in 0.18.0 — helixir Finding #6 across cycles 1–7.)
|
|
69
73
|
|
|
70
74
|
## Step 4 — Report
|
|
71
75
|
|
package/dist/cli/upgrade.js
CHANGED
|
@@ -635,7 +635,22 @@ export async function runUpgrade(options = {}) {
|
|
|
635
635
|
}
|
|
636
636
|
const now = new Date().toISOString();
|
|
637
637
|
const installedAt = existingManifest?.installed_at ?? now;
|
|
638
|
-
|
|
638
|
+
// 0.18.0 helix-020 G6 fix: pre-fix the upgrade path read profile from
|
|
639
|
+
// the existing manifest only — and pre-0.2.0 manifests recorded
|
|
640
|
+
// `"unknown"` as a placeholder. Every subsequent `rea upgrade` then
|
|
641
|
+
// re-stamped `"unknown"` forever. Authoritative source for the
|
|
642
|
+
// profile is `.rea/policy.yaml`; the manifest is a derivative
|
|
643
|
+
// record. Read policy first; fall back to existing manifest only
|
|
644
|
+
// when policy load fails (covers the bootstrap case where the
|
|
645
|
+
// manifest exists but policy is malformed).
|
|
646
|
+
let profile;
|
|
647
|
+
try {
|
|
648
|
+
const livePolicy = loadPolicy(resolvedRoot);
|
|
649
|
+
profile = livePolicy.profile;
|
|
650
|
+
}
|
|
651
|
+
catch {
|
|
652
|
+
profile = existingManifest?.profile ?? 'unknown';
|
|
653
|
+
}
|
|
639
654
|
const freshManifest = {
|
|
640
655
|
version: getPkgVersion(),
|
|
641
656
|
profile,
|
|
@@ -136,18 +136,29 @@ function escapeTomlString(value) {
|
|
|
136
136
|
*/
|
|
137
137
|
export async function runCodexReview(options) {
|
|
138
138
|
const spawner = options.spawnImpl ?? spawn;
|
|
139
|
+
// 0.18.0 iron-gate runtime default: ALWAYS pass model + reasoning
|
|
140
|
+
// effort to codex. Pre-fix, undefined options fell back to codex's
|
|
141
|
+
// own default (`codex-auto-review` at medium reasoning), which
|
|
142
|
+
// bypassed the iron-gate intent and let weaker reviews ship. Now
|
|
143
|
+
// the runtime hardcodes `gpt-5.4` + `high` as the floor; policy
|
|
144
|
+
// can OVERRIDE to a different model/effort but cannot opt out into
|
|
145
|
+
// codex's defaults (config.toml or otherwise). The user's directive
|
|
146
|
+
// — "we want codex to be using its BEST. EVERY TIME" — is enforced
|
|
147
|
+
// here, not at the policy layer.
|
|
148
|
+
//
|
|
139
149
|
// Model + reasoning overrides go BEFORE the `exec` subcommand because
|
|
140
150
|
// `-c key=value` is a top-level codex CLI flag, not an `exec` flag.
|
|
141
151
|
// Codex's TOML parser interprets the value, so we wrap strings in TOML
|
|
142
152
|
// quotes — `-c model="gpt-5.4"` not `-c model=gpt-5.4` — to ensure the
|
|
143
153
|
// value lands as a string regardless of upstream parsing changes.
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
const effectiveModel = options.model !== undefined && options.model.length > 0 ? options.model : 'gpt-5.4';
|
|
155
|
+
const effectiveReasoning = options.reasoningEffort ?? 'high';
|
|
156
|
+
const overrideArgs = [
|
|
157
|
+
'-c',
|
|
158
|
+
`model="${escapeTomlString(effectiveModel)}"`,
|
|
159
|
+
'-c',
|
|
160
|
+
`model_reasoning_effort="${escapeTomlString(effectiveReasoning)}"`,
|
|
161
|
+
];
|
|
151
162
|
const baseArgs = [
|
|
152
163
|
...overrideArgs,
|
|
153
164
|
'exec',
|
package/dist/policy/loader.d.ts
CHANGED
|
@@ -48,10 +48,14 @@ declare const PolicySchema: z.ZodObject<{
|
|
|
48
48
|
*/
|
|
49
49
|
auto_narrow_threshold: z.ZodOptional<z.ZodNumber>;
|
|
50
50
|
/**
|
|
51
|
-
* Codex CLI model override (0.13.4
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
51
|
+
* Codex CLI model override (0.13.4+; runtime-default since 0.18.0).
|
|
52
|
+
* Pinned via `-c model="<name>"` on every `codex exec review`
|
|
53
|
+
* invocation. **0.18.0 iron-gate runtime default**: when unset, the
|
|
54
|
+
* runtime hardcodes `gpt-5.4` — codex's own default
|
|
55
|
+
* (`codex-auto-review` at medium) is no longer reachable through the
|
|
56
|
+
* rea push-gate. To select a different model, set this key
|
|
57
|
+
* explicitly. config.toml is consulted ONLY when the explicit value
|
|
58
|
+
* passed by rea is `undefined`, which the runtime never does.
|
|
55
59
|
*
|
|
56
60
|
* For serious adversarial review on consumer codebases (where verdict
|
|
57
61
|
* stability matters) the recommended setting is `gpt-5.4` with
|
package/dist/policy/loader.js
CHANGED
|
@@ -39,10 +39,14 @@ const ReviewPolicySchema = z
|
|
|
39
39
|
*/
|
|
40
40
|
auto_narrow_threshold: z.number().int().nonnegative().optional(),
|
|
41
41
|
/**
|
|
42
|
-
* Codex CLI model override (0.13.4
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
42
|
+
* Codex CLI model override (0.13.4+; runtime-default since 0.18.0).
|
|
43
|
+
* Pinned via `-c model="<name>"` on every `codex exec review`
|
|
44
|
+
* invocation. **0.18.0 iron-gate runtime default**: when unset, the
|
|
45
|
+
* runtime hardcodes `gpt-5.4` — codex's own default
|
|
46
|
+
* (`codex-auto-review` at medium) is no longer reachable through the
|
|
47
|
+
* rea push-gate. To select a different model, set this key
|
|
48
|
+
* explicitly. config.toml is consulted ONLY when the explicit value
|
|
49
|
+
* passed by rea is `undefined`, which the runtime never does.
|
|
46
50
|
*
|
|
47
51
|
* For serious adversarial review on consumer codebases (where verdict
|
|
48
52
|
* stability matters) the recommended setting is `gpt-5.4` with
|
|
@@ -73,6 +73,20 @@
|
|
|
73
73
|
# escapes (per POSIX). Multiple wrappers per command-line are handled
|
|
74
74
|
# (e.g. `foo; bash -c 'bar' && sh -c 'baz'` emits both `bar` and `baz`).
|
|
75
75
|
#
|
|
76
|
+
# 0.18.0 helix-020 G1.A fix: the unwrap pass scans a QUOTE-MASKED form
|
|
77
|
+
# of the input, not the raw input. Pre-fix, a quoted argument that
|
|
78
|
+
# MENTIONED a wrapper (e.g. `git commit -m "docs: mention bash -c 'npm
|
|
79
|
+
# install left-pad'"`) would emit a phantom inner-payload segment, and
|
|
80
|
+
# `dependency-audit-gate.sh` would block the innocent commit. The
|
|
81
|
+
# quote-mask layer (the same one `_rea_split_segments` uses) replaces
|
|
82
|
+
# all in-quote separators AND in-quote single/double quote characters
|
|
83
|
+
# with multi-byte sentinels — so the wrapper regex can no longer match
|
|
84
|
+
# inside an outer quoted span. The unwrapped payload itself is still
|
|
85
|
+
# emitted from the un-masked input by recomputing offsets back to the
|
|
86
|
+
# raw string, so escape semantics inside legitimate wrappers stay
|
|
87
|
+
# correct. We only need the mask to suppress matching; the captured
|
|
88
|
+
# payload is read off the original string.
|
|
89
|
+
#
|
|
76
90
|
# Limitation: ONE level of unwrapping. A wrapper inside a wrapper
|
|
77
91
|
# (`bash -c "bash -c 'innermost'"`) emits only the second-level payload
|
|
78
92
|
# (`bash -c 'innermost'`), not the third-level. This is enough for
|
|
@@ -81,32 +95,130 @@
|
|
|
81
95
|
_rea_unwrap_nested_shells() {
|
|
82
96
|
local cmd="$1"
|
|
83
97
|
printf '%s\n' "$cmd"
|
|
84
|
-
|
|
98
|
+
# Build a mask where in-quote `"` `'` `;` `&` `|` characters are
|
|
99
|
+
# replaced with multi-byte sentinels so the wrapper regex below
|
|
100
|
+
# cannot match wrapper syntax that lives inside outer quoted prose.
|
|
101
|
+
# We also mask the in-quote QUOTE characters themselves so the awk
|
|
102
|
+
# body's quote-state heuristic (which looks at the byte immediately
|
|
103
|
+
# after the matched wrapper-prefix region) cannot mistake an inner
|
|
104
|
+
# quote for a payload-opening quote. Sentinel bytes are aligned to
|
|
105
|
+
# be the same width as their original character (single-byte) so
|
|
106
|
+
# offsets into the raw string remain valid for payload extraction.
|
|
107
|
+
#
|
|
108
|
+
# Approach: rather than synthesize a per-byte sentinel of width 1,
|
|
109
|
+
# we run the awk wrapper-scan against a SEPARATE masked stream and
|
|
110
|
+
# then translate matched RSTART/RLENGTH offsets back to the original
|
|
111
|
+
# string. We do that by passing both strings into awk (raw via stdin,
|
|
112
|
+
# masked via -v MASKED) and tracking the same index across both —
|
|
113
|
+
# since the mask substitutes single bytes with single bytes only
|
|
114
|
+
# (placeholder bytes drawn from the C0 control-character range) the
|
|
115
|
+
# offsets line up.
|
|
116
|
+
#
|
|
117
|
+
# Placeholder bytes — chosen from the C0 control range so they
|
|
118
|
+
# cannot appear in real shell input under UTF-8 (NUL, BEL, VT, FF
|
|
119
|
+
# are reserved by some shells; we use SOH/STX/ETX/ENQ/ACK which are
|
|
120
|
+
# not assigned operational meaning by any shell we ship with).
|
|
121
|
+
# \x01 SOH — replaces in-quote `"`
|
|
122
|
+
# \x02 STX — replaces in-quote `'`
|
|
123
|
+
# \x03 ETX — replaces in-quote `;`
|
|
124
|
+
# \x05 ENQ — replaces in-quote `&`
|
|
125
|
+
# \x06 ACK — replaces in-quote `|`
|
|
126
|
+
local masked
|
|
127
|
+
masked=$(printf '%s' "$cmd" | awk '
|
|
128
|
+
{
|
|
129
|
+
line = $0
|
|
130
|
+
out = ""
|
|
131
|
+
i = 1
|
|
132
|
+
n = length(line)
|
|
133
|
+
mode = 0
|
|
134
|
+
while (i <= n) {
|
|
135
|
+
ch = substr(line, i, 1)
|
|
136
|
+
if (mode == 0) {
|
|
137
|
+
if (ch == "\"") { mode = 1; out = out ch; i++; continue }
|
|
138
|
+
if (ch == "'\''") { mode = 2; out = out ch; i++; continue }
|
|
139
|
+
out = out ch
|
|
140
|
+
i++
|
|
141
|
+
continue
|
|
142
|
+
}
|
|
143
|
+
if (mode == 2) {
|
|
144
|
+
if (ch == "'\''") { mode = 0; out = out "\002"; i++; continue }
|
|
145
|
+
if (ch == ";") { out = out "\003"; i++; continue }
|
|
146
|
+
if (ch == "&") { out = out "\005"; i++; continue }
|
|
147
|
+
if (ch == "|") { out = out "\006"; i++; continue }
|
|
148
|
+
if (ch == "\"") { out = out "\001"; i++; continue }
|
|
149
|
+
out = out ch
|
|
150
|
+
i++
|
|
151
|
+
continue
|
|
152
|
+
}
|
|
153
|
+
# mode == 1 (double-quoted)
|
|
154
|
+
if (ch == "\\" && i < n) {
|
|
155
|
+
# Preserve the escape pair literally — width preserved.
|
|
156
|
+
nxt = substr(line, i + 1, 1)
|
|
157
|
+
out = out ch nxt
|
|
158
|
+
i += 2
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
161
|
+
if (ch == "\"") { mode = 0; out = out "\001"; i++; continue }
|
|
162
|
+
if (ch == ";") { out = out "\003"; i++; continue }
|
|
163
|
+
if (ch == "&") { out = out "\005"; i++; continue }
|
|
164
|
+
if (ch == "|") { out = out "\006"; i++; continue }
|
|
165
|
+
if (ch == "'\''") { out = out "\002"; i++; continue }
|
|
166
|
+
out = out ch
|
|
167
|
+
i++
|
|
168
|
+
}
|
|
169
|
+
printf "%s", out
|
|
170
|
+
}')
|
|
171
|
+
# Pass both raw and masked into awk. Wrapper-regex matches against the
|
|
172
|
+
# masked form; payload extraction reads the raw form using the same
|
|
173
|
+
# offsets. Because the mask is byte-for-byte width-preserving, the
|
|
174
|
+
# same RSTART/RLENGTH applies to both.
|
|
175
|
+
printf '' | awk -v raw="$cmd" -v masked="$masked" '
|
|
85
176
|
BEGIN {
|
|
86
177
|
# Wrapper-prefix regex: shell-name + optional flag tokens + -c-style flag.
|
|
87
178
|
# Each flag token is `-` followed by 1+ letters and trailing space.
|
|
179
|
+
# NOTE: matches only OUTSIDE outer quoted spans because in-quote
|
|
180
|
+
# `"`, `'\''`, `;`, `&`, `|` are masked out in `masked`. The leading
|
|
181
|
+
# alternation `(^|[[:space:]&|;])` therefore cannot anchor on a
|
|
182
|
+
# masked separator, and the shell-name token itself can no longer
|
|
183
|
+
# appear adjacent to a masked quote-introducer.
|
|
88
184
|
WRAP = "(^|[[:space:]&|;])(bash|sh|zsh|dash|ksh)([[:space:]]+-[a-zA-Z]+)*[[:space:]]+-(c|lc|lic|ic|cl|cli|li|il)[[:space:]]+"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
185
|
+
# Track the cursor in BOTH raw and masked. Because the mask is
|
|
186
|
+
# byte-for-byte width-preserving, the same RSTART/RLENGTH applies
|
|
187
|
+
# to both — but each iteration of the loop must SLICE both strings
|
|
188
|
+
# by the same amount so subsequent matches see synchronized tails.
|
|
189
|
+
mrest = masked
|
|
190
|
+
rrest = raw
|
|
191
|
+
while (length(mrest) > 0) {
|
|
192
|
+
if (! match(mrest, WRAP)) break
|
|
193
|
+
# Tail begins immediately after the matched wrapper prefix in
|
|
194
|
+
# BOTH strings (offsets line up — mask is width-preserving).
|
|
195
|
+
mtail = substr(mrest, RSTART + RLENGTH)
|
|
196
|
+
rtail = substr(rrest, RSTART + RLENGTH)
|
|
197
|
+
# The wrapper-payload-introducing quote must be a REAL outer
|
|
198
|
+
# quote — i.e. not a masked in-quote sentinel. Probe the raw
|
|
199
|
+
# form for the introducer character, which the mask preserved
|
|
200
|
+
# verbatim only when it was an outer quote.
|
|
201
|
+
first = substr(rtail, 1, 1)
|
|
202
|
+
mfirst = substr(mtail, 1, 1)
|
|
203
|
+
if (first == "'\''" && mfirst == "'\''") {
|
|
204
|
+
# Single-quoted body: no escape semantics; runs to next `'\''`.
|
|
205
|
+
body = substr(rtail, 2)
|
|
206
|
+
mbody = substr(mtail, 2)
|
|
100
207
|
end = index(body, "'\''")
|
|
101
|
-
if (end == 0) {
|
|
208
|
+
if (end == 0) {
|
|
209
|
+
mrest = substr(mtail, 2)
|
|
210
|
+
rrest = substr(rtail, 2)
|
|
211
|
+
continue
|
|
212
|
+
}
|
|
102
213
|
payload = substr(body, 1, end - 1)
|
|
103
214
|
print payload
|
|
104
|
-
|
|
215
|
+
mrest = substr(mbody, end + 1)
|
|
216
|
+
rrest = substr(body, end + 1)
|
|
105
217
|
continue
|
|
106
218
|
}
|
|
107
|
-
if (first == "\"") {
|
|
219
|
+
if (first == "\"" && mfirst == "\"") {
|
|
108
220
|
# Double-quoted body: \" and \\ are literal escapes.
|
|
109
|
-
body = substr(
|
|
221
|
+
body = substr(rtail, 2)
|
|
110
222
|
n = length(body)
|
|
111
223
|
j = 1
|
|
112
224
|
out = ""
|
|
@@ -124,15 +236,27 @@ _rea_unwrap_nested_shells() {
|
|
|
124
236
|
out = out c
|
|
125
237
|
j++
|
|
126
238
|
}
|
|
127
|
-
if (closed == 0) {
|
|
239
|
+
if (closed == 0) {
|
|
240
|
+
mrest = substr(mtail, 2)
|
|
241
|
+
rrest = substr(rtail, 2)
|
|
242
|
+
continue
|
|
243
|
+
}
|
|
128
244
|
print out
|
|
129
|
-
|
|
245
|
+
# Skip past the opening `"` (1 byte) AND the closing `"` (1
|
|
246
|
+
# byte at body[closed], i.e. mtail[closed+1]). Cursor lands
|
|
247
|
+
# at mtail[closed+2].
|
|
248
|
+
mrest = substr(mtail, closed + 2)
|
|
249
|
+
rrest = substr(rtail, closed + 2)
|
|
130
250
|
continue
|
|
131
251
|
}
|
|
132
252
|
# Non-quoted argument — proceed past the matched prefix only.
|
|
133
|
-
|
|
253
|
+
mrest = mtail
|
|
254
|
+
rrest = rtail
|
|
134
255
|
}
|
|
135
|
-
}
|
|
256
|
+
}
|
|
257
|
+
# Empty action with no input rules — explicitly drive the loop from
|
|
258
|
+
# END so awk does not require any input records.
|
|
259
|
+
END {}'
|
|
136
260
|
}
|
|
137
261
|
|
|
138
262
|
# Split $1 on shell command separators. Emits one segment per line on
|
|
@@ -53,20 +53,80 @@ policy_bool_true() {
|
|
|
53
53
|
[[ "$value" == "true" ]]
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
# Read a list of scalars from a top-level sequence
|
|
56
|
+
# Read a list of scalars from a top-level sequence.
|
|
57
57
|
# Usage: mapfile -t patterns < <(policy_list "delegate_to_subagent")
|
|
58
|
-
#
|
|
58
|
+
#
|
|
59
|
+
# Recognized YAML forms:
|
|
60
|
+
#
|
|
61
|
+
# 1. Block sequence (the historical / canonical form):
|
|
62
|
+
# blocked_paths:
|
|
63
|
+
# - .env
|
|
64
|
+
# - .env.*
|
|
65
|
+
# - .rea/HALT
|
|
66
|
+
#
|
|
67
|
+
# 2. Empty inline array (since 0.1.x):
|
|
68
|
+
# blocked_paths: [] # → no entries (returns successfully)
|
|
69
|
+
#
|
|
70
|
+
# 3. Non-empty inline array (added 0.18.0 G1.B/G1.C):
|
|
71
|
+
# blocked_paths: [.env, .env.*, .rea/HALT]
|
|
72
|
+
#
|
|
73
|
+
# Inline arrays may span multiple lines:
|
|
74
|
+
#
|
|
75
|
+
# blocked_paths: [
|
|
76
|
+
# .env,
|
|
77
|
+
# .env.*,
|
|
78
|
+
# .rea/HALT
|
|
79
|
+
# ]
|
|
80
|
+
#
|
|
81
|
+
# Quoted entries (single or double quotes) are unquoted. Leading and
|
|
82
|
+
# trailing whitespace on each entry is trimmed. Empty entries (e.g. from
|
|
83
|
+
# a trailing `,`) are skipped silently.
|
|
84
|
+
#
|
|
85
|
+
# Pre-fix (G1.B/G1.C): the inline array form was VALID YAML but parsed
|
|
86
|
+
# to an empty list — silent bypass of `blocked-paths-bash-gate.sh` and
|
|
87
|
+
# silent ignore of `protected_writes` overrides. Fixed by extending the
|
|
88
|
+
# parser to recognize the inline form in addition to the block form.
|
|
89
|
+
#
|
|
90
|
+
# The block form is still preferred (sed-friendly, line-aligned diffs)
|
|
91
|
+
# but the inline form is now equally enforced.
|
|
59
92
|
policy_list() {
|
|
60
93
|
local key="$1"
|
|
61
94
|
local policy
|
|
62
95
|
policy=$(policy_path)
|
|
63
96
|
[[ -z "$policy" ]] && return 0
|
|
64
97
|
local in_block=0
|
|
98
|
+
local in_inline=0
|
|
99
|
+
local inline_buf=""
|
|
65
100
|
while IFS= read -r line; do
|
|
101
|
+
# Skip while we're collecting an inline-array body across lines.
|
|
102
|
+
if [[ $in_inline -eq 1 ]]; then
|
|
103
|
+
inline_buf="${inline_buf} ${line}"
|
|
104
|
+
# Detect the closing `]` (any position on the line).
|
|
105
|
+
if printf '%s' "$line" | grep -qE '\]'; then
|
|
106
|
+
_policy_emit_inline_array "$inline_buf"
|
|
107
|
+
return 0
|
|
108
|
+
fi
|
|
109
|
+
continue
|
|
110
|
+
fi
|
|
66
111
|
if printf '%s' "$line" | grep -qE "^[[:space:]]*${key}:"; then
|
|
67
|
-
|
|
112
|
+
# Empty inline `[]` — explicit empty list.
|
|
113
|
+
if printf '%s' "$line" | grep -qE "${key}:[[:space:]]*\[[[:space:]]*\]"; then
|
|
68
114
|
return 0
|
|
69
115
|
fi
|
|
116
|
+
# Non-empty inline `[ ... ]` — parse the bracketed body. May or
|
|
117
|
+
# may not close on the same line.
|
|
118
|
+
if printf '%s' "$line" | grep -qE "${key}:[[:space:]]*\["; then
|
|
119
|
+
# Strip everything up to and including the opening `[`.
|
|
120
|
+
inline_buf=$(printf '%s' "$line" | sed -E "s/^.*${key}:[[:space:]]*\[//")
|
|
121
|
+
if printf '%s' "$inline_buf" | grep -qE '\]'; then
|
|
122
|
+
# Single-line inline array.
|
|
123
|
+
_policy_emit_inline_array "$inline_buf"
|
|
124
|
+
return 0
|
|
125
|
+
fi
|
|
126
|
+
in_inline=1
|
|
127
|
+
continue
|
|
128
|
+
fi
|
|
129
|
+
# Block-form sequence header — entries follow on subsequent lines.
|
|
70
130
|
in_block=1
|
|
71
131
|
continue
|
|
72
132
|
fi
|
|
@@ -80,3 +140,31 @@ policy_list() {
|
|
|
80
140
|
fi
|
|
81
141
|
done < "$policy"
|
|
82
142
|
}
|
|
143
|
+
|
|
144
|
+
# Emit each entry of an inline-array body (everything between `[` and
|
|
145
|
+
# `]`, possibly across newlines if the caller concatenated lines with
|
|
146
|
+
# spaces). Strips outer brackets, splits on `,`, trims whitespace and
|
|
147
|
+
# matched outer quotes, drops empty entries (trailing-comma tolerance).
|
|
148
|
+
_policy_emit_inline_array() {
|
|
149
|
+
local buf="$1"
|
|
150
|
+
# Drop the closing `]` and anything after it (line comments etc).
|
|
151
|
+
buf=$(printf '%s' "$buf" | sed -E 's/\].*$//')
|
|
152
|
+
# Split on commas.
|
|
153
|
+
local IFS=','
|
|
154
|
+
local raw
|
|
155
|
+
for raw in $buf; do
|
|
156
|
+
# Trim leading + trailing whitespace.
|
|
157
|
+
raw="${raw#"${raw%%[![:space:]]*}"}"
|
|
158
|
+
raw="${raw%"${raw##*[![:space:]]}"}"
|
|
159
|
+
# Drop trailing inline comment (` # comment`).
|
|
160
|
+
raw=$(printf '%s' "$raw" | sed -E 's/[[:space:]]+#.*$//')
|
|
161
|
+
# Re-trim after comment stripping.
|
|
162
|
+
raw="${raw#"${raw%%[![:space:]]*}"}"
|
|
163
|
+
raw="${raw%"${raw##*[![:space:]]}"}"
|
|
164
|
+
# Skip empty entries (trailing comma, blank line in multi-line form).
|
|
165
|
+
[[ -z "$raw" ]] && continue
|
|
166
|
+
# Strip matched outer single or double quotes.
|
|
167
|
+
raw=$(printf '%s' "$raw" | sed -E "s/^[\"']//; s/[\"']$//")
|
|
168
|
+
printf '%s\n' "$raw"
|
|
169
|
+
done
|
|
170
|
+
}
|
|
@@ -58,6 +58,13 @@ REA_KILL_SWITCH_INVARIANTS=(
|
|
|
58
58
|
# first call to `rea_path_is_protected`; stays the same for the lifetime
|
|
59
59
|
# of the hook process.
|
|
60
60
|
REA_PROTECTED_PATTERNS=()
|
|
61
|
+
# 0.18.0 helix-020 G2 fix: track which patterns came from the consumer's
|
|
62
|
+
# explicit `protected_writes` override (vs. the hardcoded default). The
|
|
63
|
+
# override-first ordering in `rea_path_is_protected` checks ONLY this
|
|
64
|
+
# subset before consulting the extension-surface allow-list, so an
|
|
65
|
+
# explicit `protected_writes: [.husky/pre-push.d/]` can re-protect a
|
|
66
|
+
# path that the allow-list would otherwise let through.
|
|
67
|
+
REA_PROTECTED_OVERRIDE_PATTERNS=()
|
|
61
68
|
_REA_PROTECTED_PATTERNS_LOADED=0
|
|
62
69
|
|
|
63
70
|
# True if $1 is a kill-switch invariant (case-insensitive exact or
|
|
@@ -195,6 +202,31 @@ _rea_load_protected_patterns() {
|
|
|
195
202
|
fi
|
|
196
203
|
done
|
|
197
204
|
|
|
205
|
+
# 0.18.0 helix-020 G2: also expose the EXPLICIT-OVERRIDE subset so
|
|
206
|
+
# `rea_path_is_protected` can prioritize override matches over the
|
|
207
|
+
# extension-surface allow-list. Only entries that came from a
|
|
208
|
+
# `protected_writes:` declaration land here — kill-switch invariants
|
|
209
|
+
# added defensively in step 2 above are NOT included (they get the
|
|
210
|
+
# historical "extension surface relaxes them" treatment, since the
|
|
211
|
+
# user did NOT explicitly opt in to protecting husky fragments).
|
|
212
|
+
if [ "$protected_writes_set" = "1" ]; then
|
|
213
|
+
local ow ow_lc rentry_lc2 relaxed2
|
|
214
|
+
for ow in "${writes_list[@]+"${writes_list[@]}"}"; do
|
|
215
|
+
ow_lc=$(printf '%s' "$ow" | tr '[:upper:]' '[:lower:]')
|
|
216
|
+
relaxed2=0
|
|
217
|
+
for rentry in "${relaxed_set[@]+"${relaxed_set[@]}"}"; do
|
|
218
|
+
rentry_lc2=$(printf '%s' "$rentry" | tr '[:upper:]' '[:lower:]')
|
|
219
|
+
if [[ "$ow_lc" == "$rentry_lc2" ]]; then
|
|
220
|
+
relaxed2=1
|
|
221
|
+
break
|
|
222
|
+
fi
|
|
223
|
+
done
|
|
224
|
+
if [ "$relaxed2" = "0" ]; then
|
|
225
|
+
REA_PROTECTED_OVERRIDE_PATTERNS+=("$ow")
|
|
226
|
+
fi
|
|
227
|
+
done
|
|
228
|
+
fi
|
|
229
|
+
|
|
198
230
|
_REA_PROTECTED_PATTERNS_LOADED=1
|
|
199
231
|
}
|
|
200
232
|
|
|
@@ -243,18 +275,57 @@ rea_path_is_extension_surface() {
|
|
|
243
275
|
#
|
|
244
276
|
# 0.16.4 helix-018 Option B: paths inside the documented husky
|
|
245
277
|
# extension surface (`.husky/{commit-msg,pre-push,pre-commit}.d/*`)
|
|
246
|
-
# return 1 (not protected)
|
|
247
|
-
#
|
|
248
|
-
#
|
|
278
|
+
# return 1 (not protected) by default so they don't get caught by
|
|
279
|
+
# `.husky/`'s prefix block. This mirrors the §5b allow-list that has
|
|
280
|
+
# been in settings-protection.sh since 0.13.2.
|
|
281
|
+
#
|
|
282
|
+
# 0.18.0 helix-020 G2 fix: ORDER MATTERS. The pre-fix function checked
|
|
283
|
+
# the extension-surface allow-list FIRST and short-circuited "not
|
|
284
|
+
# protected" unconditionally. That made the `protected_writes` /
|
|
285
|
+
# `protected_paths` override silently ineffective for any path inside
|
|
286
|
+
# the extension surface — a consumer who wanted `.husky/pre-push.d/`
|
|
287
|
+
# hardened could not opt in. The fix: explicit overrides win FIRST
|
|
288
|
+
# (the consumer asked for this), then the extension-surface
|
|
289
|
+
# short-circuit applies to anything else, then the default protected
|
|
290
|
+
# list. Pseudocode is the canonical version from helix-020 Interactive
|
|
291
|
+
# Finding 1.
|
|
249
292
|
rea_path_is_protected() {
|
|
250
293
|
_rea_load_protected_patterns
|
|
251
|
-
# Extension-surface allow-list — short-circuit before pattern match.
|
|
252
|
-
if rea_path_is_extension_surface "$1"; then
|
|
253
|
-
return 1
|
|
254
|
-
fi
|
|
255
294
|
local p_lc
|
|
256
295
|
p_lc=$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')
|
|
257
296
|
local pattern pattern_lc
|
|
297
|
+
|
|
298
|
+
# 1. Explicit `protected_writes` overrides win. If the consumer
|
|
299
|
+
# listed this path (or its parent prefix) in `protected_writes`,
|
|
300
|
+
# we honor that intent even when the path is on the extension
|
|
301
|
+
# surface. This is what lets a consumer harden their managed
|
|
302
|
+
# `.husky/pre-push.d/` fragments — the carve-out for unmanaged
|
|
303
|
+
# consumer fragments is the default, but it can be undone.
|
|
304
|
+
for pattern in "${REA_PROTECTED_OVERRIDE_PATTERNS[@]+"${REA_PROTECTED_OVERRIDE_PATTERNS[@]}"}"; do
|
|
305
|
+
pattern_lc=$(printf '%s' "$pattern" | tr '[:upper:]' '[:lower:]')
|
|
306
|
+
if [[ "$p_lc" == "$pattern_lc" ]]; then
|
|
307
|
+
return 0
|
|
308
|
+
fi
|
|
309
|
+
if [[ "$pattern_lc" == */ ]] && [[ "$p_lc" == "$pattern_lc"* ]]; then
|
|
310
|
+
return 0
|
|
311
|
+
fi
|
|
312
|
+
done
|
|
313
|
+
|
|
314
|
+
# 2. Extension-surface allow-list. Paths inside the documented
|
|
315
|
+
# husky extension surface (`.husky/{commit-msg,pre-push,pre-commit}.d/*`)
|
|
316
|
+
# are NOT protected by default — the consumer manages those
|
|
317
|
+
# fragments freely; settings-protection.sh §5b has the same
|
|
318
|
+
# carve-out on the Write/Edit side. Step 1 above is what lets a
|
|
319
|
+
# consumer override that default per-path.
|
|
320
|
+
if rea_path_is_extension_surface "$1"; then
|
|
321
|
+
return 1
|
|
322
|
+
fi
|
|
323
|
+
|
|
324
|
+
# 3. Default protected list (kill-switch invariants + `.husky/`
|
|
325
|
+
# prefix block + `.claude/settings*` + `.rea/policy.yaml`). When
|
|
326
|
+
# `protected_writes` was set, kill-switch invariants are still
|
|
327
|
+
# enforced via this branch because they were added back into
|
|
328
|
+
# REA_PROTECTED_PATTERNS during `_rea_load_protected_patterns`.
|
|
258
329
|
for pattern in "${REA_PROTECTED_PATTERNS[@]+"${REA_PROTECTED_PATTERNS[@]}"}"; do
|
|
259
330
|
pattern_lc=$(printf '%s' "$pattern" | tr '[:upper:]' '[:lower:]')
|
|
260
331
|
if [[ "$p_lc" == "$pattern_lc" ]]; then
|
|
@@ -58,13 +58,24 @@ fi
|
|
|
58
58
|
source "$(dirname "$0")/_lib/cmd-segments.sh"
|
|
59
59
|
|
|
60
60
|
# ── 6. Check if this is a relevant command ────────────────────────────────────
|
|
61
|
+
# 0.18.0 helix-020 / discord-ops Round 10 #2 fix (G4.A): use
|
|
62
|
+
# `any_segment_starts_with`, not `any_segment_matches`. The pre-fix
|
|
63
|
+
# matcher used the unanchored form, so a segment like
|
|
64
|
+
# gh pr edit --body "tracked: gh pr create earlier in the run"
|
|
65
|
+
# triggered IS_RELEVANT=1 because the substring `gh pr create` was
|
|
66
|
+
# anywhere in the segment. The downstream attribution check then
|
|
67
|
+
# scanned the body for the markdown-link / Co-Authored-By patterns,
|
|
68
|
+
# and ANY mention of those terms in the body's prose got blocked
|
|
69
|
+
# even though the actual command was a `gh pr edit` whose intent had
|
|
70
|
+
# nothing to do with structural attribution. The same anchoring fix
|
|
71
|
+
# `dangerous-bash-interceptor.sh` got in 0.16.3 F5 finally lands here.
|
|
61
72
|
IS_RELEVANT=0
|
|
62
73
|
|
|
63
|
-
if
|
|
74
|
+
if any_segment_starts_with "$CMD" 'gh[[:space:]]+pr[[:space:]]+(create|edit)'; then
|
|
64
75
|
IS_RELEVANT=1
|
|
65
76
|
fi
|
|
66
77
|
|
|
67
|
-
if
|
|
78
|
+
if any_segment_starts_with "$CMD" 'git[[:space:]]+commit'; then
|
|
68
79
|
IS_RELEVANT=1
|
|
69
80
|
fi
|
|
70
81
|
|
|
@@ -77,7 +88,21 @@ fi
|
|
|
77
88
|
FOUND=0
|
|
78
89
|
|
|
79
90
|
# Co-Authored-By with noreply@ email
|
|
80
|
-
|
|
91
|
+
# 0.18.0 helix-020 / discord-ops Round 10 #3 fix (G4.B): exclude
|
|
92
|
+
# GitHub's legitimate `<user>@users.noreply.github.com` collaborator
|
|
93
|
+
# footers from the noreply match. Pre-fix the regex `Co-Authored-By:.*noreply@`
|
|
94
|
+
# matched both AI-tool noreply addresses (anthropic.com, openai.com,
|
|
95
|
+
# github-copilot, etc.) AND GitHub's per-user noreply form, blocking
|
|
96
|
+
# legitimate human collaborator credits. The new regex requires
|
|
97
|
+
# `noreply@` to be followed by something that ISN'T `users.noreply.github.com`
|
|
98
|
+
# — covered via a negative-lookahead simulation: match `noreply@` then
|
|
99
|
+
# either end-of-line, whitespace, `>`, or a domain that does NOT begin
|
|
100
|
+
# with `users.noreply.github.com`. Posix ERE has no lookarounds, so we
|
|
101
|
+
# enumerate the allowed-prefix shapes explicitly. The "AI names" branch
|
|
102
|
+
# below catches Co-Authored-By with named tools regardless of the email
|
|
103
|
+
# domain, so dropping `users.noreply.github.com` from the noreply
|
|
104
|
+
# pattern only relaxes the check for human collaborators — never for AI.
|
|
105
|
+
if any_segment_matches "$CMD" 'Co-Authored-By:.*noreply@(anthropic\.com|openai\.com|github-copilot|github\.com|claude\.ai|chatgpt\.com|googlemail\.com|google\.com|cursor\.com|codeium\.com|tabnine\.com|amazon\.com|amazonaws\.com|amazon-q\.amazonaws\.com|cody\.dev|sourcegraph\.com)'; then
|
|
81
106
|
FOUND=1
|
|
82
107
|
fi
|
|
83
108
|
|
|
@@ -171,6 +171,23 @@ _extract_body_file_paths() {
|
|
|
171
171
|
while (i <= n) {
|
|
172
172
|
ch = substr(line, i, 1)
|
|
173
173
|
if (mode == 0) {
|
|
174
|
+
# 0.18.0 helix-020 G3.B fix: in plain (unquoted) mode,
|
|
175
|
+
# `\X` (any character X) is the POSIX shell escape for
|
|
176
|
+
# the literal character X — most commonly a space in
|
|
177
|
+
# paths like `path\ with\ spaces.md`. Pre-fix the
|
|
178
|
+
# tokenizer treated the `\` as an ordinary character and
|
|
179
|
+
# truncated at the following space, dropping the rest of
|
|
180
|
+
# the path. We now consume the backslash and emit the
|
|
181
|
+
# following byte as a literal part of the current token.
|
|
182
|
+
# `\<eol>` (line-continuation) is left intact — emit the
|
|
183
|
+
# `\` and let the splitter flow into the next record on
|
|
184
|
+
# the assumption that the caller already joined the line.
|
|
185
|
+
if (ch == "\\" && i < n) {
|
|
186
|
+
nxt = substr(line, i + 1, 1)
|
|
187
|
+
tok = tok nxt
|
|
188
|
+
i += 2
|
|
189
|
+
continue
|
|
190
|
+
}
|
|
174
191
|
if (ch == " " || ch == "\t") {
|
|
175
192
|
if (tok != "") { emit_token(tok); tok = "" }
|
|
176
193
|
i++; continue
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bookedsolid/rea",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Agentic governance layer for Claude Code — policy enforcement, hook-based safety gates, audit logging, and Codex-integrated adversarial review for AI-assisted projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Booked Solid Technology <oss@bookedsolid.tech> (https://bookedsolid.tech)",
|