fix(hermes): gate unverified release reports and enable execution verification
Canina Hermes reliability / reliability (push) Has been cancelled
Canina Hermes reliability / reliability (push) Has been cancelled
This commit is contained in:
1 parent
209339dc57
commit
d1eb86f74f
5 files changed
+128
No files matched your search
@@ -0,0 +1,29 @@
|
||||
name: Canina Hermes reliability
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- ops/hermes-reliability-20261106
|
||||
jobs:
|
||||
reliability:
|
||||
runs-on: canina
|
||||
steps:
|
||||
- name: Test and install default-only reliability policy
|
||||
env:
|
||||
REPAIR_SHA: ${{ github.sha }}
|
||||
REPAIR_REF: ${{ github.ref }}
|
||||
run: |
|
||||
set -eu
|
||||
[ "$REPAIR_REF" = refs/heads/ops/hermes-reliability-20261106 ]
|
||||
case "$REPAIR_SHA" in *[!0-9a-f]*|'') exit 2 ;; esac
|
||||
[ "${#REPAIR_SHA}" -eq 40 ]
|
||||
export http_proxy= https_proxy= HTTP_PROXY= HTTPS_PROXY=
|
||||
mkdir -p reliability
|
||||
for f in __init__.py plugin.yaml test_guard.py install.py; do
|
||||
wget --no-proxy -qO "reliability/$f" "https://git.parsaaghayi.ir/parsa/canina/raw/commit/${REPAIR_SHA}/infra/hermes-reliability/$f"
|
||||
done
|
||||
python3 reliability/test_guard.py
|
||||
docker exec -u 10000 canina-hermes mkdir -p /opt/data/cache/scratch/reliability-managed
|
||||
for f in __init__.py plugin.yaml install.py; do
|
||||
docker exec -i -u 10000 canina-hermes sh -c "umask 077; tee /opt/data/cache/scratch/reliability-managed/$f >/dev/null" < "reliability/$f"
|
||||
done
|
||||
docker exec -u 10000 -e HOME=/opt/data -e HERMES_HOME=/opt/data canina-hermes python3 /opt/data/cache/scratch/reliability-managed/install.py /opt/data/cache/scratch/reliability-managed
|
||||
@@ -0,0 +1,53 @@
|
||||
"""Default-profile delivery gate: external release claims require structured evidence.
|
||||
No secrets, commands or tool text persisted. Fail closed for positive release claims.
|
||||
"""
|
||||
import json, os, re, threading
|
||||
_STATE = {}
|
||||
_LOCK = threading.Lock()
|
||||
_RELEASE = re.compile(r'(?:deploy(?:ed|ment)?|استقرار|دپلوی|دیپلوی|CI[\s‑#:-]*\d+|/pipelines/\d+|/actions/runs/\d+)', re.I)
|
||||
_POSITIVE = re.compile(r'(?:completed|succeeded|deployed|refreshed|applied|موفق|انجام شد|تکمیل شد|منتشر شد|مستقر شد)', re.I)
|
||||
_NEGATIVE = re.compile(r'(?:not verified|unverified|not deployed|no deployment|not performed|not confirmed|missing|unsupported|تأیید نشده|تایید نشده|تأیید نمی|تایید نمی|انجام نشد|نشده|ندارد|نیست|فاقد|مفقود|نامعتبر|اثبات نمی|اثبات نشده)', re.I)
|
||||
_HASH = re.compile(r'^[a-f0-9]{40}$')
|
||||
|
||||
def suspicious(text):
|
||||
# Evaluate per line so a disclaimer cannot launder a separate affirmative claim.
|
||||
return any(_RELEASE.search(line) and _POSITIVE.search(line) and not _NEGATIVE.search(line)
|
||||
for line in str(text).splitlines())
|
||||
|
||||
def valid_attestation(value):
|
||||
if not isinstance(value, dict): return False
|
||||
a = value.get('canina_release_evidence')
|
||||
return (isinstance(a, dict) and a.get('ci_system') == 'gitea'
|
||||
and isinstance(a.get('commit'), str) and bool(_HASH.fullmatch(a['commit']))
|
||||
and isinstance(a.get('run_id'), int) and a['run_id'] > 0
|
||||
and a.get('ci_status') == 'success' and a.get('live_commit') == a['commit']
|
||||
and a.get('environment') in ('stage', 'production')
|
||||
and a.get('verified_by') == 'managed-release-verifier')
|
||||
|
||||
def observe(tool_name='', args=None, result=None, session_id='', turn_id='', **kw):
|
||||
if os.getenv('HERMES_HOME', '/opt/data') != '/opt/data': return
|
||||
# Only an existing reviewed verifier invoked via terminal can supply the contract;
|
||||
# arbitrary tool prose or a delegated summary never counts as publication evidence.
|
||||
command = (args or {}).get('command', '') if isinstance(args, dict) else ''
|
||||
if tool_name != 'terminal' or not re.fullmatch(r'/opt/data/bin/canina-release-verify --run [0-9]+ --environment (stage|production)', command): return
|
||||
try:
|
||||
payload = json.loads(result) if isinstance(result, str) else result
|
||||
if not isinstance(payload, dict) or payload.get('exit_code') != 0: return
|
||||
record = json.loads(payload.get('output', ''))
|
||||
if not valid_attestation(record): return
|
||||
with _LOCK: _STATE[(session_id, turn_id)] = True
|
||||
except (ValueError, TypeError): return
|
||||
|
||||
def transform(response_text='', session_id='', turn_id='', **kw):
|
||||
if os.getenv('HERMES_HOME', '/opt/data') != '/opt/data': return None
|
||||
with _LOCK: proven = _STATE.pop((session_id, turn_id), False)
|
||||
if suspicious(response_text) and not proven:
|
||||
return ('گزارش پیشنهادی شامل ادعای موفقیت استقرار یا CI بود، اما شاهد معتبر انتشار در همین اجرا ثبت نشده است؛ این ادعا مسدود شد. '
|
||||
'موفقیت انتشار تأیید نشده است. خروجی محلی یا خلاصهٔ عامل، شاهد انتشار نیست. '
|
||||
'برای پذیرش انتشار باید رکورد واقعی Gitea، commit و نسخهٔ زنده با یکدیگر تطبیق داده شوند. '
|
||||
'این پیام به معنی تکمیل کار نیست.')
|
||||
return None
|
||||
|
||||
def register(ctx):
|
||||
ctx.register_hook('post_tool_call', observe)
|
||||
ctx.register_hook('transform_llm_output', transform)
|
||||
@@ -0,0 +1,13 @@
|
||||
import os,pathlib,subprocess,sys
|
||||
assert os.getuid()==10000 and os.getenv('HERMES_HOME')=='/opt/data'
|
||||
root=pathlib.Path('/opt/data/plugins/canina-reliability')
|
||||
root.mkdir(mode=0o700,parents=True,exist_ok=True)
|
||||
source=pathlib.Path(sys.argv[1])
|
||||
for name in ['__init__.py','plugin.yaml']:
|
||||
target=root/name
|
||||
if target.exists() and target.read_bytes()!= (source/name).read_bytes(): raise RuntimeError('unmanaged plugin conflict')
|
||||
target.write_bytes((source/name).read_bytes());target.chmod(0o600)
|
||||
cli='/opt/hermes/bin/hermes'
|
||||
for key,value in [('agent.verify_on_stop','true'),('agent.tool_use_enforcement','true'),('agent.execution_guidance','true'),('model.default','Canina-content')]:
|
||||
subprocess.run([cli,'config','set',key,value],check=True)
|
||||
print('Scoped default reliability policy installed; gateway restart intentionally separate')
|
||||
@@ -0,0 +1,7 @@
|
||||
name: canina-reliability
|
||||
version: "0.1.0"
|
||||
description: "Scoped default release-report evidence gate"
|
||||
author: Canina
|
||||
provides_hooks:
|
||||
- post_tool_call
|
||||
- transform_llm_output
|
||||
@@ -0,0 +1,26 @@
|
||||
import importlib.util, pathlib, unittest, os
|
||||
spec=importlib.util.spec_from_file_location('guard',pathlib.Path(__file__).with_name('__init__.py'))
|
||||
g=importlib.util.module_from_spec(spec);spec.loader.exec_module(g)
|
||||
class GuardTests(unittest.TestCase):
|
||||
def test_fictional_ci(self):
|
||||
self.assertIsNotNone(g.transform('CI-#8745 completed; deployment succeeded',session_id='a',turn_id='1'))
|
||||
def test_persian(self):
|
||||
self.assertIsNotNone(g.transform('دپلوی Stage با موفقیت انجام شد',session_id='a',turn_id='2'))
|
||||
def test_local_only(self):
|
||||
self.assertIsNone(g.transform('Local tests: 13 passed. No deployment was performed.',session_id='a',turn_id='3'))
|
||||
def test_missing_commit(self):
|
||||
self.assertFalse(g.valid_attestation({'canina_release_evidence':{'ci_status':'success','run_id':8745}}))
|
||||
def test_delegated_claim_not_evidence(self):
|
||||
g.observe(tool_name='delegate_task',result={'summary':'Deployment succeeded'},session_id='a',turn_id='4')
|
||||
self.assertIsNotNone(g.transform('Deployment succeeded',session_id='a',turn_id='4'))
|
||||
def test_negative(self):
|
||||
self.assertIsNone(g.transform('استقرار موفق تأیید نشده است؛ مدرک ندارد.',session_id='a',turn_id='5'))
|
||||
def test_disclaimer_not_launder(self):
|
||||
self.assertIsNotNone(g.transform('Deployment succeeded\nAnother deployment is not verified',session_id='a',turn_id='6'))
|
||||
def test_turn_isolation(self):
|
||||
g._STATE[('a','x')]=True
|
||||
self.assertIsNotNone(g.transform('Deployment succeeded',session_id='a',turn_id='y'))
|
||||
def test_failed_terminal_not_evidence(self):
|
||||
g.observe(tool_name='terminal',args={'command':'/opt/data/bin/canina-release-verify --run 8745 --environment stage'},result={'exit_code':1,'output':'{}'},session_id='a',turn_id='7')
|
||||
self.assertIsNotNone(g.transform('Deployment succeeded',session_id='a',turn_id='7'))
|
||||
if __name__=='__main__': unittest.main()
|
||||
Reference in new issue
Block a user