Adopt canonical permission standard v1 + installer verification gate
This commit is contained in:
@@ -77,6 +77,31 @@ if (( copied != EXPECTED_COUNT )); then
|
||||
echo "ERROR: expected $EXPECTED_COUNT agent files, but installed $copied. Aborting." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Decision-4 gate 1 — byte integrity: every installed file must be a faithful
|
||||
# copy of its repo source (install is cp -p, no transformation). Copy-all first,
|
||||
# verify-all after: a failure aborts with a nonzero exit and no success message.
|
||||
for src_path in "${AGENT_FILES[@]}"; do
|
||||
name="$(basename "$src_path")"
|
||||
if ! cmp -s "$src_path" "$TARGET/$name"; then
|
||||
echo "ERROR: integrity check failed for '$name' ($TARGET/$name differs from $src_path). Aborting." >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Decision-4 gate 2 — engine semantics: the installed definitions are only
|
||||
# trustworthy if the target opencode engine matches the documented matching
|
||||
# rules. Verifier exits: 0 = pass, 1 = engine drift, 2 = no usable runtime.
|
||||
echo "==> Verifying permission-engine semantics..."
|
||||
rc=0
|
||||
sh "$ROOT/scripts/verify-permission-patterns.sh" || rc=$?
|
||||
case "$rc" in
|
||||
0) ;;
|
||||
1) echo "ERROR: ENGINE DRIFT — opencode permission matching does NOT match documented semantics; installed definitions cannot be trusted. Aborting." >&2; exit 1 ;;
|
||||
2) echo "ERROR: NO RUNTIME — no opencode binary found (set OPENCODE_BIN to override); install completed but CANNOT be verified. Aborting." >&2; exit 2 ;;
|
||||
*) echo "ERROR: verifier exited unexpectedly (rc=$rc). Aborting." >&2; exit "$rc" ;;
|
||||
esac
|
||||
|
||||
echo "==> Installed $copied/$EXPECTED_COUNT agents."
|
||||
|
||||
if (( backed_up > 0 )); then
|
||||
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
# verify-permission-patterns.sh — test loaded opencode permission-engine semantics in a
|
||||
# THROWAWAY temp HOME. Prints PASS/FAIL per rule; exit 0=all pass, 1=drift, 2=no runtime.
|
||||
set -u
|
||||
T="$(mktemp -d)" || exit 2; trap 'rm -rf "$T"' EXIT
|
||||
# BIN resolution: OPENCODE_BIN env override -> 'opencode' on PATH -> no runtime (exit 2).
|
||||
BIN=""
|
||||
if [ -n "${OPENCODE_BIN:-}" ] && [ -r "$OPENCODE_BIN" ]; then
|
||||
BIN="$OPENCODE_BIN"
|
||||
elif command -v opencode >/dev/null 2>&1; then
|
||||
BIN="$(command -v opencode)"
|
||||
fi
|
||||
[ -n "$BIN" ] || { echo "FAIL no opencode runtime found (set OPENCODE_BIN or put 'opencode' on PATH)" >&2; exit 2; }
|
||||
if grep -aqF '.replace(/\*/g,".*").replace(/\?/g,".")' "$BIN"; then
|
||||
echo "PASS engine-signature present in loaded binary"
|
||||
else
|
||||
echo "FAIL engine-signature NOT found — binary changed, re-extract Wildcard.match"; exit 1
|
||||
fi
|
||||
command -v node >/dev/null || { echo "FAIL no node runtime"; exit 2; }
|
||||
HOME="$T" node -e '
|
||||
function m(i,p){if(i)i=i.replaceAll("\\","/");if(p)p=p.replaceAll("\\","/");
|
||||
let l=p.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");
|
||||
if(l.endsWith(" .*"))l=l.slice(0,-3)+"( .*)?";return new RegExp("^"+l+"$","s").test(i)}
|
||||
const C=[["**/AgentsReport/**","AgentsReport/toolsmith/x.md",false],["AgentsReport/**","AgentsReport/toolsmith/x.md",true],
|
||||
["**","AgentsReport/x.md",true],["git status*","git status",true],["*","head",true],["edit","edit",true]];
|
||||
let f=0;for(const[p,i,w]of C){const g=m(i,p);g===w||f++;console.log((g===w?"PASS":"FAIL")+" match("+JSON.stringify(i)+","+JSON.stringify(p)+")="+g+" want "+w)}
|
||||
process.exit(f?1:0)' && echo "RESULT: engine matches documented semantics" || echo "RESULT: DRIFT — re-read binary"
|
||||
Reference in New Issue
Block a user