akf 1.4.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.
Files changed (59) hide show
  1. akf/__init__.py +465 -0
  2. akf/__main__.py +6 -0
  3. akf/_auto.py +496 -0
  4. akf/a2a_bridge.py +190 -0
  5. akf/agent.py +452 -0
  6. akf/agent_card.py +155 -0
  7. akf/ai_detect.py +309 -0
  8. akf/builder.py +168 -0
  9. akf/certify.py +441 -0
  10. akf/cli.py +2186 -0
  11. akf/compliance.py +723 -0
  12. akf/context.py +454 -0
  13. akf/core.py +289 -0
  14. akf/daemon.py +202 -0
  15. akf/data.py +238 -0
  16. akf/delegation.py +113 -0
  17. akf/detection.py +632 -0
  18. akf/formats/__init__.py +1 -0
  19. akf/formats/_ooxml.py +337 -0
  20. akf/formats/audio.py +106 -0
  21. akf/formats/base.py +141 -0
  22. akf/formats/csv.py +65 -0
  23. akf/formats/docx.py +197 -0
  24. akf/formats/email.py +153 -0
  25. akf/formats/html.py +224 -0
  26. akf/formats/image.py +213 -0
  27. akf/formats/json_format.py +163 -0
  28. akf/formats/markdown.py +497 -0
  29. akf/formats/pdf.py +164 -0
  30. akf/formats/pptx.py +234 -0
  31. akf/formats/toml_format.py +80 -0
  32. akf/formats/video.py +106 -0
  33. akf/formats/xlsx.py +213 -0
  34. akf/fs_events.py +342 -0
  35. akf/git_ops.py +156 -0
  36. akf/i18n.py +88 -0
  37. akf/knowledge_base.py +278 -0
  38. akf/models.py +799 -0
  39. akf/presets.py +142 -0
  40. akf/provenance.py +159 -0
  41. akf/report.py +971 -0
  42. akf/security.py +485 -0
  43. akf/shell_hook.py +407 -0
  44. akf/sidecar.py +201 -0
  45. akf/signing.py +166 -0
  46. akf/stamp.py +233 -0
  47. akf/streaming.py +313 -0
  48. akf/team_stream.py +294 -0
  49. akf/tracking.py +305 -0
  50. akf/transform.py +91 -0
  51. akf/trust.py +369 -0
  52. akf/universal.py +873 -0
  53. akf/view.py +200 -0
  54. akf/watch.py +232 -0
  55. akf-1.4.0.dist-info/METADATA +116 -0
  56. akf-1.4.0.dist-info/RECORD +59 -0
  57. akf-1.4.0.dist-info/WHEEL +5 -0
  58. akf-1.4.0.dist-info/entry_points.txt +2 -0
  59. akf-1.4.0.dist-info/top_level.txt +1 -0
akf/__init__.py ADDED
@@ -0,0 +1,465 @@
1
+ """AKF — Agent Knowledge Format v1.1.
2
+
3
+ The trust metadata standard for every file AI touches.
4
+
5
+ Usage:
6
+ import akf
7
+
8
+ # Standalone .akf
9
+ unit = akf.create("Revenue $4.2B", confidence=0.98)
10
+ unit.save("out.akf")
11
+
12
+ # Universal: embed into any format
13
+ akf.embed("report.docx", claims=[...], classification="confidential")
14
+ akf.extract("report.docx")
15
+ akf.scan("report.docx")
16
+ akf.info("report.docx")
17
+ """
18
+
19
+ from .models import (
20
+ AKF, Claim, Evidence, Fidelity, ProvHop,
21
+ Origin, GenerationParams, MadeBy, Review, SourceDetail,
22
+ ReasoningChain, Annotation, Freshness, CostMetadata, AgentProfile,
23
+ Calibration, DelegationPolicy,
24
+ )
25
+ from .core import create, create_multi, load, loads, validate, ValidationResult
26
+ from .universal import ConvertResult
27
+ from .builder import AKFBuilder
28
+ from .trust import (
29
+ effective_trust, compute_all, explain_trust, TrustResult, TrustLevel,
30
+ AUTHORITY_WEIGHTS, calibrated_trust, resolve_conflict, trust_summary,
31
+ is_expired, freshness_status,
32
+ )
33
+ from .provenance import add_hop, format_tree, compute_integrity_hash, models_used
34
+ from .security import (
35
+ validate_inheritance, can_share_external, inherit_label, security_score,
36
+ purview_signals, detect_laundering, SecurityScore, SecurityReport,
37
+ check_access, verify_trust_anchor, redaction_report, compute_security_hash,
38
+ full_report,
39
+ )
40
+ from .transform import AKFTransformer
41
+ from .agent import (
42
+ consume, derive, generation_prompt, validate_output,
43
+ response_schema, from_tool_call, to_context, detect,
44
+ )
45
+ from .delegation import delegate, validate_delegation
46
+ from .compliance import (
47
+ audit, check_regulation, audit_trail, verify_human_oversight, AuditResult,
48
+ check_explainability, check_fairness, export_audit, continuous_audit,
49
+ )
50
+ from .view import show, to_html, to_markdown, executive_summary
51
+ from .data import load_dataset, quality_report, merge, filter_claims
52
+ from .report import enterprise_report, EnterpriseReport, FileReport, register_renderer, RENDERERS
53
+ from .knowledge_base import KnowledgeBase
54
+ from .stamp import stamp, stamp_file
55
+ from .certify import (
56
+ certify_file, certify_directory, certify_team,
57
+ CertifyResult, CertifyReport, AgentCertifyReport, TeamCertifyReport,
58
+ parse_junit_xml, parse_evidence_json,
59
+ )
60
+ from .agent_card import (
61
+ AgentCard, AgentRegistry, create_agent_card, verify_agent_card, to_agent_profile,
62
+ )
63
+ from .a2a_bridge import (
64
+ to_a2a_card, from_a2a_card, save_a2a_card, discover_a2a_cards,
65
+ )
66
+ from .git_ops import stamp_commit, read_commit, trust_log
67
+ from .streaming import StreamSession, AKFStream, stream_start, stream_claim, stream_end, collect_stream, iter_stream
68
+ from .team_stream import (
69
+ TeamStreamSession, TeamTrustResult, TeamStream,
70
+ team_stream_start, team_stream_claim, team_stream_end, team_trust_aggregate,
71
+ )
72
+ from .detection import (
73
+ detect_ai_without_review, detect_trust_below_threshold,
74
+ detect_hallucination_risk, detect_knowledge_laundering,
75
+ detect_classification_downgrade, detect_stale_claims,
76
+ detect_ungrounded_claims, detect_trust_degradation_chain,
77
+ detect_excessive_ai_concentration, detect_provenance_gap,
78
+ run_all_detections, DetectionResult, DetectionReport,
79
+ )
80
+ from .i18n import t as translate
81
+
82
+ # Universal format layer — lazy imports to avoid optional dependency issues
83
+ def save(unit, filepath, compact=True):
84
+ """Save an AKF unit to a file."""
85
+ unit.save(filepath, compact=compact)
86
+
87
+
88
+ def embed(filepath, **kwargs):
89
+ """Embed AKF metadata into any supported file format."""
90
+ from .universal import embed as _embed
91
+ return _embed(filepath, **kwargs)
92
+
93
+ def extract(filepath):
94
+ """Extract AKF metadata from any supported file format."""
95
+ from .universal import extract as _extract
96
+ return _extract(filepath)
97
+
98
+ def scan(filepath):
99
+ """Security scan any file for AKF metadata."""
100
+ from .universal import scan as _scan
101
+ return _scan(filepath)
102
+
103
+ def info(filepath):
104
+ """Quick info check on any file's AKF metadata."""
105
+ from .universal import info as _info
106
+ return _info(filepath)
107
+
108
+ def is_enriched(filepath):
109
+ """Check if any file has AKF metadata."""
110
+ from .universal import is_enriched as _is_enriched
111
+ return _is_enriched(filepath)
112
+
113
+ def convert_directory(dirpath, **kwargs):
114
+ """Convert all files in a directory to standalone .akf files."""
115
+ from .universal import convert_directory as _convert_directory
116
+ return _convert_directory(dirpath, **kwargs)
117
+
118
+ def init(path=".", git_hooks=False, agent=None, classification="internal"):
119
+ """Initialize AKF in a project directory.
120
+
121
+ Args:
122
+ path: Project root directory.
123
+ git_hooks: Install post-commit hook for stamp-commit.
124
+ agent: Default AI agent ID.
125
+ classification: Default security classification.
126
+
127
+ Returns:
128
+ Path to created config file.
129
+ """
130
+ import json as _json
131
+ from pathlib import Path as _Path
132
+
133
+ root = _Path(path).resolve()
134
+ akf_dir = root / ".akf"
135
+ akf_dir.mkdir(exist_ok=True)
136
+
137
+ config = {
138
+ "version": "1.0",
139
+ "classification": classification,
140
+ "auto_embed": True,
141
+ }
142
+ if agent:
143
+ config["agent"] = agent
144
+
145
+ config_path = akf_dir / "config.json"
146
+ config_path.write_text(_json.dumps(config, indent=2) + "\n")
147
+
148
+ if git_hooks:
149
+ hooks_dir = root / ".git" / "hooks"
150
+ if hooks_dir.parent.exists():
151
+ hooks_dir.mkdir(exist_ok=True)
152
+ hook = hooks_dir / "post-commit"
153
+ hook.write_text("#!/bin/sh\nakf stamp-commit\n")
154
+ hook.chmod(0o755)
155
+
156
+ return str(config_path)
157
+
158
+
159
+ def stream(output_path=None, *, agent=None, model=None, confidence=0.7, **kwargs):
160
+ """Create a streaming context manager for incremental trust metadata.
161
+
162
+ Usage::
163
+
164
+ with akf.stream("output.md", model="gpt-4o") as s:
165
+ for chunk in llm.generate():
166
+ s.write(chunk)
167
+
168
+ Args:
169
+ output_path: Path for the output file.
170
+ agent: Agent identifier.
171
+ model: AI model identifier.
172
+ confidence: Default confidence for each write.
173
+ **kwargs: Additional stream parameters.
174
+
175
+ Returns:
176
+ AKFStream context manager.
177
+ """
178
+ return AKFStream(output_path, agent=agent, model=model, confidence=confidence, **kwargs)
179
+
180
+
181
+ def keygen(**kwargs):
182
+ """Generate an Ed25519 keypair for signing AKF units."""
183
+ from .signing import keygen as _keygen
184
+ return _keygen(**kwargs)
185
+
186
+ def sign_unit(unit, **kwargs):
187
+ """Sign an AKF unit with an Ed25519 private key."""
188
+ from .signing import sign as _sign
189
+ return _sign(unit, **kwargs)
190
+
191
+ def verify_signature(unit, **kwargs):
192
+ """Verify the Ed25519 signature on an AKF unit."""
193
+ from .signing import verify as _verify
194
+ return _verify(unit, **kwargs)
195
+
196
+ def install(user=True):
197
+ """Activate AKF auto-tracking for all LLM calls in this Python environment.
198
+
199
+ Writes a .pth file so every Python process auto-patches LLM SDKs.
200
+ Use ``akf uninstall`` or ``uninstall()`` to reverse.
201
+
202
+ Args:
203
+ user: Install for current user (True) or system-wide (False).
204
+
205
+ Returns:
206
+ Path to the created .pth file.
207
+ """
208
+ from ._auto import install as _install
209
+ return _install(user=user)
210
+
211
+
212
+ def uninstall():
213
+ """Remove AKF auto-tracking (reverses ``install()``).
214
+
215
+ Returns:
216
+ Path of the removed .pth file, or None if not found.
217
+ """
218
+ from ._auto import uninstall as _uninstall
219
+ return _uninstall()
220
+
221
+
222
+ def track(client, **kwargs):
223
+ """Wrap an LLM client to auto-track model/provider on every API call.
224
+
225
+ Supported: OpenAI, Anthropic, Mistral, Google GenerativeAI.
226
+ For OpenAI-compatible APIs (Groq, Together), pass provider= to override.
227
+
228
+ Usage::
229
+
230
+ client = akf.track(openai.OpenAI())
231
+ response = client.chat.completions.create(model="gpt-4o", ...)
232
+ unit = akf.create("claim", confidence=0.95)
233
+ # unit.origin.model == "gpt-4o" — automatic
234
+ """
235
+ from .tracking import track as _track
236
+ return _track(client, **kwargs)
237
+
238
+
239
+ def get_last_model():
240
+ """Return the last tracked LLM model/provider, or None."""
241
+ from .tracking import get_last_model as _get
242
+ return _get()
243
+
244
+
245
+ def get_tracking_history():
246
+ """Return all tracked LLM calls in this thread."""
247
+ from .tracking import get_tracking_history as _get
248
+ return _get()
249
+
250
+
251
+ def clear_tracking():
252
+ """Reset LLM tracking context."""
253
+ from .tracking import clear_tracking as _clear
254
+ _clear()
255
+
256
+
257
+ def read(filepath):
258
+ """Read AKF trust metadata from any file.
259
+
260
+ Extracts metadata and attempts to parse it as a full AKF model.
261
+
262
+ Args:
263
+ filepath: Path to any supported file.
264
+
265
+ Returns:
266
+ AKF model if parseable, raw metadata dict otherwise, or None.
267
+ """
268
+ from .universal import extract as _extract
269
+
270
+ meta = _extract(filepath)
271
+ if meta is None:
272
+ return None
273
+
274
+ # Try to parse as full AKF model
275
+ try:
276
+ return AKF.model_validate(meta)
277
+ except Exception:
278
+ return meta
279
+
280
+
281
+ __version__ = "1.4.0"
282
+ __all__ = [
283
+ # Models
284
+ "AKF",
285
+ "AKFBuilder",
286
+ "AKFTransformer",
287
+ "AUTHORITY_WEIGHTS",
288
+ "AuditResult",
289
+ "Claim",
290
+ "Evidence",
291
+ "Fidelity",
292
+ "KnowledgeBase",
293
+ "ProvHop",
294
+ "SecurityScore",
295
+ "TrustLevel",
296
+ "TrustResult",
297
+ "ValidationResult",
298
+ "Calibration",
299
+ # v1.1 models
300
+ "Origin",
301
+ "GenerationParams",
302
+ "MadeBy",
303
+ "Review",
304
+ "SourceDetail",
305
+ "ReasoningChain",
306
+ "Annotation",
307
+ "Freshness",
308
+ "CostMetadata",
309
+ "AgentProfile",
310
+ "DelegationPolicy",
311
+ # Delegation
312
+ "delegate",
313
+ "validate_delegation",
314
+ # Core
315
+ "add_hop",
316
+ "can_share_external",
317
+ "compute_all",
318
+ "compute_integrity_hash",
319
+ "create",
320
+ "create_multi",
321
+ "effective_trust",
322
+ "format_tree",
323
+ "models_used",
324
+ "inherit_label",
325
+ "load",
326
+ "loads",
327
+ "save",
328
+ "validate",
329
+ "validate_inheritance",
330
+ # Trust extras
331
+ "explain_trust",
332
+ "calibrated_trust",
333
+ "resolve_conflict",
334
+ "trust_summary",
335
+ "is_expired",
336
+ "freshness_status",
337
+ # Security extras
338
+ "check_access",
339
+ "compute_security_hash",
340
+ "detect_laundering",
341
+ "purview_signals",
342
+ "redaction_report",
343
+ "security_score",
344
+ "SecurityReport",
345
+ "full_report",
346
+ "verify_trust_anchor",
347
+ # Agent
348
+ "consume",
349
+ "derive",
350
+ "detect",
351
+ "from_tool_call",
352
+ "generation_prompt",
353
+ "response_schema",
354
+ "to_context",
355
+ "validate_output",
356
+ # Compliance
357
+ "audit",
358
+ "audit_trail",
359
+ "check_explainability",
360
+ "check_fairness",
361
+ "check_regulation",
362
+ "continuous_audit",
363
+ "export_audit",
364
+ "verify_human_oversight",
365
+ # Streaming
366
+ "AKFStream",
367
+ "StreamSession",
368
+ "collect_stream",
369
+ "iter_stream",
370
+ "stream_claim",
371
+ "stream_end",
372
+ "stream_start",
373
+ # Detection classes
374
+ "DetectionReport",
375
+ "DetectionResult",
376
+ "detect_ai_without_review",
377
+ "detect_classification_downgrade",
378
+ "detect_excessive_ai_concentration",
379
+ "detect_hallucination_risk",
380
+ "detect_knowledge_laundering",
381
+ "detect_provenance_gap",
382
+ "detect_stale_claims",
383
+ "detect_trust_below_threshold",
384
+ "detect_trust_degradation_chain",
385
+ "detect_ungrounded_claims",
386
+ "run_all_detections",
387
+ # Convenience
388
+ "stream",
389
+ # i18n
390
+ "translate",
391
+ # View
392
+ "executive_summary",
393
+ "show",
394
+ "to_html",
395
+ "to_markdown",
396
+ # Data
397
+ "filter_claims",
398
+ "load_dataset",
399
+ "merge",
400
+ "quality_report",
401
+ # Report
402
+ "enterprise_report",
403
+ "EnterpriseReport",
404
+ "FileReport",
405
+ "register_renderer",
406
+ "RENDERERS",
407
+ # Certify
408
+ "certify_file",
409
+ "certify_directory",
410
+ "CertifyResult",
411
+ "CertifyReport",
412
+ "parse_junit_xml",
413
+ "parse_evidence_json",
414
+ # Stamp & Git
415
+ "stamp",
416
+ "stamp_file",
417
+ "stamp_commit",
418
+ "read_commit",
419
+ "trust_log",
420
+ # Signing
421
+ "keygen",
422
+ "sign_unit",
423
+ "verify_signature",
424
+ # Auto-tracking
425
+ "install",
426
+ "uninstall",
427
+ # Tracking
428
+ "track",
429
+ "get_last_model",
430
+ "get_tracking_history",
431
+ "clear_tracking",
432
+ # Universal format layer
433
+ "ConvertResult",
434
+ "convert_directory",
435
+ "embed",
436
+ "extract",
437
+ "info",
438
+ "init",
439
+ "is_enriched",
440
+ "read",
441
+ "scan",
442
+ # Agent Card
443
+ "AgentCard",
444
+ "AgentRegistry",
445
+ "create_agent_card",
446
+ "verify_agent_card",
447
+ "to_agent_profile",
448
+ # A2A Bridge
449
+ "to_a2a_card",
450
+ "from_a2a_card",
451
+ "save_a2a_card",
452
+ "discover_a2a_cards",
453
+ # Team Streaming
454
+ "TeamStreamSession",
455
+ "TeamTrustResult",
456
+ "TeamStream",
457
+ "team_stream_start",
458
+ "team_stream_claim",
459
+ "team_stream_end",
460
+ "team_trust_aggregate",
461
+ # Team Certify
462
+ "certify_team",
463
+ "AgentCertifyReport",
464
+ "TeamCertifyReport",
465
+ ]
akf/__main__.py ADDED
@@ -0,0 +1,6 @@
1
+ """Allow running AKF CLI via `python -m akf`."""
2
+
3
+ from akf.cli import main
4
+
5
+ if __name__ == "__main__":
6
+ main()