armor-agent-plugin 6.0.0__py3-none-any.whl
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.
Potentially problematic release.
This version of armor-agent-plugin might be problematic. Click here for more details.
- armor/__init__.py +9 -0
- armor/__main__.py +3 -0
- armor/cli.py +209 -0
- armor/data/ai_standards/_catalog/latest.json +7 -0
- armor/data/ai_standards/_catalog/versions/2026-05-14__b1ed6db3/guardrail_catalog.json +1517 -0
- armor/data/ai_standards/_catalog/versions/2026-05-14__b1ed6db3/guardrail_catalog.md +345 -0
- armor/data/ai_standards/_catalog/versions/2026-05-14__b1ed6db3/guardrail_matrix.csv +54 -0
- armor/data/ai_standards/_catalog/versions/2026-05-14__b1ed6db3/guardrail_matrix.json +1446 -0
- armor/data/ai_standards/_catalog/versions/2026-05-14__b1ed6db3/guardrail_matrix.md +57 -0
- armor/data/ai_standards/_catalog/versions/2026-05-14__b1ed6db3/manifest.json +29 -0
- armor/data/ai_standards/_catalog/versions/2026-05-14__b1ed6db3/source_coverage.json +360 -0
- armor/data/ai_standards/eu-ai-act/history.jsonl +1 -0
- armor/data/ai_standards/eu-ai-act/latest.json +7 -0
- armor/data/ai_standards/eu-ai-act/versions/2026-06-04__e1a1c700/manifest.json +5 -0
- armor/data/ai_standards/mitre-atlas/history.jsonl +1 -0
- armor/data/ai_standards/mitre-atlas/latest.json +7 -0
- armor/data/ai_standards/mitre-atlas/versions/2026-06-04__32346fb3/manifest.json +5 -0
- armor/data/ai_standards/nist-ai-rmf/history.jsonl +1 -0
- armor/data/ai_standards/nist-ai-rmf/latest.json +7 -0
- armor/data/ai_standards/nist-ai-rmf/versions/2026-06-04__b157a100/manifest.json +5 -0
- armor/data/ai_standards/owasp-llm-top10/history.jsonl +1 -0
- armor/data/ai_standards/owasp-llm-top10/latest.json +7 -0
- armor/data/ai_standards/owasp-llm-top10/versions/2026-06-04__0a592025/manifest.json +5 -0
- armor/file_lock.py +114 -0
- armor/pipeline/__init__.py +17 -0
- armor/pipeline/adversary.py +140 -0
- armor/pipeline/conform.py +259 -0
- armor/pipeline/conform_audit.py +192 -0
- armor/pipeline/load.py +94 -0
- armor/pipeline/report.py +357 -0
- armor/pipeline/schema.py +113 -0
- armor/pipeline/schemas/posture_report.schema.json +400 -0
- armor/pipeline/state.py +182 -0
- armor/pipeline/triage.py +225 -0
- armor/pipeline/triage_audit.py +153 -0
- armor_agent_plugin-6.0.0.dist-info/METADATA +574 -0
- armor_agent_plugin-6.0.0.dist-info/RECORD +50 -0
- armor_agent_plugin-6.0.0.dist-info/WHEEL +5 -0
- armor_agent_plugin-6.0.0.dist-info/entry_points.txt +2 -0
- armor_agent_plugin-6.0.0.dist-info/licenses/LICENSE +21 -0
- armor_agent_plugin-6.0.0.dist-info/top_level.txt +2 -0
- catalog/__init__.py +1 -0
- catalog/ai_standards_versioning.py +114 -0
- catalog/download_aiid_slim.py +90 -0
- catalog/download_eu_ai_act_cellar.py +86 -0
- catalog/download_mitre_atlas.py +78 -0
- catalog/download_nist_ai_rmf.py +77 -0
- catalog/download_owasp_llm_top10.py +71 -0
- catalog/generate_guardrail_catalog.py +990 -0
- catalog/refresh_catalog.py +77 -0
armor/pipeline/triage.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""Phase 2: System profiling and guardrail applicability triage (LLM exchange)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from .state import RunDir, require_phase_done
|
|
10
|
+
|
|
11
|
+
ALLOWED_STATUS = {"applies", "partial_scope", "n_a"}
|
|
12
|
+
|
|
13
|
+
RESPONSE_SCHEMA: dict[str, Any] = {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"required": ["system_profile", "applicability"],
|
|
16
|
+
"properties": {
|
|
17
|
+
"system_profile": {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"required": ["one_liner", "languages", "deployment_model", "user_population"],
|
|
20
|
+
"properties": {
|
|
21
|
+
"one_liner": {"type": "string"},
|
|
22
|
+
"languages": {"type": "array", "items": {"type": "string"}},
|
|
23
|
+
"deployment_model": {"type": "string"},
|
|
24
|
+
"user_population": {"type": "string"},
|
|
25
|
+
"ai_modalities": {"type": "array", "items": {"type": "string"}},
|
|
26
|
+
"data_sensitivity": {"type": "string"},
|
|
27
|
+
"notes": {"type": "string"},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
"applicability": {
|
|
31
|
+
"type": "array",
|
|
32
|
+
"items": {
|
|
33
|
+
"type": "object",
|
|
34
|
+
"required": ["sid", "status", "reason"],
|
|
35
|
+
"properties": {
|
|
36
|
+
"sid": {"type": "string"},
|
|
37
|
+
"status": {"type": "string", "enum": sorted(ALLOWED_STATUS)},
|
|
38
|
+
"reason": {"type": "string", "minLength": 10},
|
|
39
|
+
"scope_notes": {"type": "string"},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_INSTRUCTIONS = (
|
|
47
|
+
"Profile the codebase under project_root and tag each of the guardrails with "
|
|
48
|
+
"status in {'applies', 'partial_scope', 'n_a'}. Be conservative — prefer 'applies' "
|
|
49
|
+
"when uncertain. Give a concise, project-specific reason (>=10 chars) for each row. "
|
|
50
|
+
"Do not score implementation here. Cover every sid in guardrails exactly once. "
|
|
51
|
+
"Output ONLY strict JSON conforming to response_schema (no Markdown fences, no prose)."
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
_MANIFEST_CANDIDATES = (
|
|
55
|
+
"README.md",
|
|
56
|
+
"README.rst",
|
|
57
|
+
"README.txt",
|
|
58
|
+
"pyproject.toml",
|
|
59
|
+
"package.json",
|
|
60
|
+
"pom.xml",
|
|
61
|
+
"build.gradle",
|
|
62
|
+
"Cargo.toml",
|
|
63
|
+
"go.mod",
|
|
64
|
+
"requirements.txt",
|
|
65
|
+
"Dockerfile",
|
|
66
|
+
"openspec/AGENTS.md",
|
|
67
|
+
"AGENTS.md",
|
|
68
|
+
"CLAUDE.md",
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _system_profile_inputs(project: Path) -> dict[str, Any]:
|
|
73
|
+
project_resolved = project.resolve()
|
|
74
|
+
manifests_and_docs: dict[str, str] = {}
|
|
75
|
+
for rel in _MANIFEST_CANDIDATES:
|
|
76
|
+
p = project_resolved / rel
|
|
77
|
+
if p.is_file():
|
|
78
|
+
try:
|
|
79
|
+
manifests_and_docs[rel] = p.read_text(encoding="utf-8", errors="replace")[:6000]
|
|
80
|
+
except OSError:
|
|
81
|
+
continue
|
|
82
|
+
|
|
83
|
+
top_level_layout: list[str] = []
|
|
84
|
+
if project_resolved.is_dir():
|
|
85
|
+
for entry in sorted(project_resolved.iterdir(), key=lambda e: e.name):
|
|
86
|
+
name = entry.name
|
|
87
|
+
if name.startswith(".") and name != ".github":
|
|
88
|
+
continue
|
|
89
|
+
if entry.is_dir():
|
|
90
|
+
top_level_layout.append(f"{name}/")
|
|
91
|
+
else:
|
|
92
|
+
top_level_layout.append(name)
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
"manifests_and_docs": manifests_and_docs,
|
|
96
|
+
"top_level_layout": top_level_layout,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def prepare(project: Path, run: RunDir) -> Path:
|
|
101
|
+
loaded = require_phase_done(run, "load")
|
|
102
|
+
payload = {
|
|
103
|
+
"phase": "triage",
|
|
104
|
+
"project_root": str(project.resolve()),
|
|
105
|
+
"instructions": _INSTRUCTIONS,
|
|
106
|
+
"system_profile_inputs": _system_profile_inputs(project),
|
|
107
|
+
"guardrails": loaded["guardrails"],
|
|
108
|
+
"response_schema": RESPONSE_SCHEMA,
|
|
109
|
+
}
|
|
110
|
+
req_path = run.request("triage")
|
|
111
|
+
req_path.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8")
|
|
112
|
+
return req_path
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _render_md(artifact: dict[str, Any]) -> str:
|
|
116
|
+
lines: list[str] = [
|
|
117
|
+
"# Phase 2 — Triage",
|
|
118
|
+
"",
|
|
119
|
+
"## System Profile",
|
|
120
|
+
"",
|
|
121
|
+
"```json",
|
|
122
|
+
json.dumps(artifact.get("system_profile", {}), indent=2),
|
|
123
|
+
"```",
|
|
124
|
+
"",
|
|
125
|
+
"## Applicability Summary",
|
|
126
|
+
"",
|
|
127
|
+
]
|
|
128
|
+
by_status = artifact.get("by_status", {})
|
|
129
|
+
for st in ("applies", "partial_scope", "n_a"):
|
|
130
|
+
lines.append(f"- **{st}**: {by_status.get(st, 0)}")
|
|
131
|
+
lines.extend(
|
|
132
|
+
[
|
|
133
|
+
"",
|
|
134
|
+
"## Guardrails",
|
|
135
|
+
"",
|
|
136
|
+
"| SID | Status | Reason |",
|
|
137
|
+
"| --- | --- | --- |",
|
|
138
|
+
]
|
|
139
|
+
)
|
|
140
|
+
for row in artifact.get("applicability", []):
|
|
141
|
+
reason = str(row.get("reason", "")).replace("|", "\\|").replace("\n", " ")
|
|
142
|
+
lines.append(f"| {row.get('sid', '')} | {row.get('status', '')} | {reason} |")
|
|
143
|
+
lines.append("")
|
|
144
|
+
return "\n".join(lines)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def finalize(project: Path, run: RunDir) -> dict[str, Any]:
|
|
148
|
+
loaded = require_phase_done(run, "load")
|
|
149
|
+
resp_path = run.response("triage")
|
|
150
|
+
if not resp_path.is_file():
|
|
151
|
+
raise SystemExit(f"triage response not found at {resp_path}")
|
|
152
|
+
|
|
153
|
+
try:
|
|
154
|
+
resp = json.loads(resp_path.read_text(encoding="utf-8"))
|
|
155
|
+
except json.JSONDecodeError as exc:
|
|
156
|
+
raise SystemExit(f"triage response invalid JSON: {exc}") from exc
|
|
157
|
+
|
|
158
|
+
known = {row["sid"] for row in loaded["guardrails"]}
|
|
159
|
+
seen: set[str] = set()
|
|
160
|
+
errors: list[str] = []
|
|
161
|
+
cleaned_rows: list[dict[str, Any]] = []
|
|
162
|
+
|
|
163
|
+
raw_rows = resp.get("applicability")
|
|
164
|
+
if not isinstance(raw_rows, list):
|
|
165
|
+
raise SystemExit("triage response invalid:\n - 'applicability' must be a list")
|
|
166
|
+
|
|
167
|
+
for idx, row in enumerate(raw_rows):
|
|
168
|
+
if not isinstance(row, dict):
|
|
169
|
+
errors.append(f"row {idx}: not an object")
|
|
170
|
+
continue
|
|
171
|
+
sid = row.get("sid")
|
|
172
|
+
status = row.get("status")
|
|
173
|
+
reason = str(row.get("reason") or "").strip()
|
|
174
|
+
|
|
175
|
+
if sid not in known:
|
|
176
|
+
errors.append(f"{sid}: unknown sid")
|
|
177
|
+
continue
|
|
178
|
+
if sid in seen:
|
|
179
|
+
errors.append(f"{sid}: duplicate row")
|
|
180
|
+
continue
|
|
181
|
+
seen.add(sid)
|
|
182
|
+
|
|
183
|
+
if status not in ALLOWED_STATUS:
|
|
184
|
+
errors.append(f"{sid}: bad status {status!r} (allowed: {sorted(ALLOWED_STATUS)})")
|
|
185
|
+
continue
|
|
186
|
+
if not reason:
|
|
187
|
+
errors.append(f"{sid}: empty reason")
|
|
188
|
+
continue
|
|
189
|
+
|
|
190
|
+
cleaned_rows.append(
|
|
191
|
+
{
|
|
192
|
+
"sid": sid,
|
|
193
|
+
"status": status,
|
|
194
|
+
"reason": reason,
|
|
195
|
+
"scope_notes": str(row.get("scope_notes") or ""),
|
|
196
|
+
}
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
missing = sorted(known - seen)
|
|
200
|
+
for sid in missing:
|
|
201
|
+
errors.append(f"{sid}: missing from response")
|
|
202
|
+
|
|
203
|
+
if errors:
|
|
204
|
+
msg = "\n - ".join(errors[:20])
|
|
205
|
+
raise SystemExit(f"triage response invalid:\n - {msg}")
|
|
206
|
+
|
|
207
|
+
by_status = {
|
|
208
|
+
"applies": sum(1 for r in cleaned_rows if r["status"] == "applies"),
|
|
209
|
+
"n_a": sum(1 for r in cleaned_rows if r["status"] == "n_a"),
|
|
210
|
+
"partial_scope": sum(1 for r in cleaned_rows if r["status"] == "partial_scope"),
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
artifact: dict[str, Any] = {
|
|
214
|
+
"phase": "triage",
|
|
215
|
+
"revision": 0,
|
|
216
|
+
"system_profile": resp.get("system_profile") or {},
|
|
217
|
+
"by_status": by_status,
|
|
218
|
+
"applicability": cleaned_rows,
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
art_path = run.artifact("triage")
|
|
222
|
+
art_path.write_text(json.dumps(artifact, indent=2) + "\n", encoding="utf-8")
|
|
223
|
+
md_path = run.root / "02_triage.md"
|
|
224
|
+
md_path.write_text(_render_md(artifact), encoding="utf-8")
|
|
225
|
+
return artifact
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""Phase 3: Adversarial red-team audit of triage applicability (LLM loop <= 3 rounds)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from . import adversary
|
|
10
|
+
from .state import MAX_AUDIT_REVISIONS, RunDir, require_phase_done
|
|
11
|
+
from .triage import ALLOWED_STATUS
|
|
12
|
+
|
|
13
|
+
PHASE = "triage-audit"
|
|
14
|
+
ROWS_KEY = "applicability"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _trail_path(run: RunDir) -> Path:
|
|
18
|
+
return run.root / ".triage_audit_trail.json"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _load_trail(run: RunDir) -> list[dict[str, Any]]:
|
|
22
|
+
p = _trail_path(run)
|
|
23
|
+
if p.is_file():
|
|
24
|
+
try:
|
|
25
|
+
return json.loads(p.read_text(encoding="utf-8"))
|
|
26
|
+
except json.JSONDecodeError:
|
|
27
|
+
return []
|
|
28
|
+
return []
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _save_trail(run: RunDir, trail: list[dict[str, Any]]) -> None:
|
|
32
|
+
_trail_path(run).write_text(json.dumps(trail, indent=2) + "\n", encoding="utf-8")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def prepare(project: Path, run: RunDir) -> Path:
|
|
36
|
+
req_path = run.request(PHASE)
|
|
37
|
+
if req_path.is_file():
|
|
38
|
+
return req_path
|
|
39
|
+
triage_art = require_phase_done(run, "triage")
|
|
40
|
+
payload = adversary.build_request(
|
|
41
|
+
audit_kind=PHASE,
|
|
42
|
+
target_artifact=triage_art,
|
|
43
|
+
rows_key=ROWS_KEY,
|
|
44
|
+
revision=1,
|
|
45
|
+
extra_context={
|
|
46
|
+
"system_profile": triage_art.get("system_profile", {}),
|
|
47
|
+
"allowed_statuses": sorted(ALLOWED_STATUS),
|
|
48
|
+
},
|
|
49
|
+
)
|
|
50
|
+
return adversary.write_request(run, PHASE, payload)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _render_md(artifact: dict[str, Any]) -> str:
|
|
54
|
+
lines: list[str] = [
|
|
55
|
+
"# Phase 3 — Triage Audit",
|
|
56
|
+
"",
|
|
57
|
+
f"- **Final revision**: {artifact.get('final_revision')}/{MAX_AUDIT_REVISIONS}",
|
|
58
|
+
f"- **Converged**: {artifact.get('converged')}",
|
|
59
|
+
"",
|
|
60
|
+
"## Status Counts",
|
|
61
|
+
"",
|
|
62
|
+
]
|
|
63
|
+
by_status = artifact.get("by_status", {})
|
|
64
|
+
for st in ("applies", "partial_scope", "n_a"):
|
|
65
|
+
lines.append(f"- **{st}**: {by_status.get(st, 0)}")
|
|
66
|
+
|
|
67
|
+
open_q = artifact.get("open_questions", [])
|
|
68
|
+
lines.extend(["", f"## Open Questions ({len(open_q)})", ""])
|
|
69
|
+
if open_q:
|
|
70
|
+
for q in open_q:
|
|
71
|
+
lines.append(f"- **{q.get('sid', '')}**: {q.get('critique', '')}")
|
|
72
|
+
else:
|
|
73
|
+
lines.append("_None._")
|
|
74
|
+
|
|
75
|
+
lines.extend(["", "## Audit Trail", ""])
|
|
76
|
+
for rec in artifact.get("audit_trail", []):
|
|
77
|
+
rev = rec.get("revision")
|
|
78
|
+
vc = rec.get("verdict_counts", {})
|
|
79
|
+
revs = len(rec.get("revisions_applied", []))
|
|
80
|
+
lines.append(f"- **Round {rev}**: verdicts={vc}, revisions_applied={revs}")
|
|
81
|
+
lines.append("")
|
|
82
|
+
return "\n".join(lines)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def finalize(project: Path, run: RunDir) -> dict[str, Any]:
|
|
86
|
+
req_path = run.request(PHASE)
|
|
87
|
+
if not req_path.is_file():
|
|
88
|
+
raise SystemExit(f"{PHASE} request not found at {req_path}")
|
|
89
|
+
req = json.loads(req_path.read_text(encoding="utf-8"))
|
|
90
|
+
resp = adversary.read_response(run, PHASE)
|
|
91
|
+
|
|
92
|
+
revision = int(req.get("revision", 1))
|
|
93
|
+
target = req["target_artifact"]
|
|
94
|
+
new_target, summary = adversary.apply_deltas(target, ROWS_KEY, resp)
|
|
95
|
+
|
|
96
|
+
audit_record: dict[str, Any] = {
|
|
97
|
+
"revision": revision,
|
|
98
|
+
"verdict_counts": summary["verdict_counts"],
|
|
99
|
+
"revisions_applied": summary["revisions_applied"],
|
|
100
|
+
"open_questions": summary["open_questions"],
|
|
101
|
+
"unknown_sids": summary["unknown_sids"],
|
|
102
|
+
"overall_note": summary["overall_note"],
|
|
103
|
+
}
|
|
104
|
+
trail = _load_trail(run)
|
|
105
|
+
trail.append(audit_record)
|
|
106
|
+
|
|
107
|
+
if adversary.converged(summary, revision):
|
|
108
|
+
rows = new_target.get(ROWS_KEY, [])
|
|
109
|
+
by_status = {
|
|
110
|
+
"applies": sum(1 for r in rows if r.get("status") == "applies"),
|
|
111
|
+
"n_a": sum(1 for r in rows if r.get("status") == "n_a"),
|
|
112
|
+
"partial_scope": sum(1 for r in rows if r.get("status") == "partial_scope"),
|
|
113
|
+
}
|
|
114
|
+
all_open_questions: list[dict[str, Any]] = []
|
|
115
|
+
for r_rec in trail:
|
|
116
|
+
all_open_questions.extend(r_rec.get("open_questions", []))
|
|
117
|
+
|
|
118
|
+
is_converged = len(summary["revisions_applied"]) == 0
|
|
119
|
+
artifact: dict[str, Any] = {
|
|
120
|
+
"phase": PHASE,
|
|
121
|
+
"final_revision": revision,
|
|
122
|
+
"converged": is_converged,
|
|
123
|
+
"by_status": by_status,
|
|
124
|
+
"system_profile": new_target.get("system_profile", {}),
|
|
125
|
+
"applicability": rows,
|
|
126
|
+
"audit_trail": trail,
|
|
127
|
+
"open_questions": all_open_questions,
|
|
128
|
+
}
|
|
129
|
+
art_path = run.artifact(PHASE)
|
|
130
|
+
art_path.write_text(json.dumps(artifact, indent=2) + "\n", encoding="utf-8")
|
|
131
|
+
(run.root / "03_triage_audit.md").write_text(_render_md(artifact), encoding="utf-8")
|
|
132
|
+
|
|
133
|
+
req_path.unlink(missing_ok=True)
|
|
134
|
+
run.response(PHASE).unlink(missing_ok=True)
|
|
135
|
+
_trail_path(run).unlink(missing_ok=True)
|
|
136
|
+
return artifact
|
|
137
|
+
|
|
138
|
+
next_rev = revision + 1
|
|
139
|
+
_save_trail(run, trail)
|
|
140
|
+
next_payload = adversary.build_request(
|
|
141
|
+
audit_kind=PHASE,
|
|
142
|
+
target_artifact=new_target,
|
|
143
|
+
rows_key=ROWS_KEY,
|
|
144
|
+
revision=next_rev,
|
|
145
|
+
extra_context={
|
|
146
|
+
"system_profile": new_target.get("system_profile", {}),
|
|
147
|
+
"allowed_statuses": sorted(ALLOWED_STATUS),
|
|
148
|
+
"previous_revisions": trail,
|
|
149
|
+
},
|
|
150
|
+
)
|
|
151
|
+
adversary.write_request(run, PHASE, next_payload)
|
|
152
|
+
run.response(PHASE).unlink(missing_ok=True)
|
|
153
|
+
return {"status": "another-round-required", "next_revision": next_rev}
|