@metamynd/agentsafe-guard 0.4.0 → 0.4.5

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/README.md CHANGED
@@ -15,6 +15,21 @@ compliance team edits in the dashboard, changeable live with no redeploy.
15
15
  `policy-core` the gate runs (MAGP §9.2 cooperative mode) — identical inputs give the identical
16
16
  verdict, with no network round-trip. See §4.
17
17
 
18
+ ## The protocol
19
+
20
+ This guard is one implementation of an open specification. You do not have to use it — the
21
+ protocol is published so you can implement it yourself, verify a verdict independently, or
22
+ re-implement the gate:
23
+
24
+ **[MAGP v1.0 — MetaMynd Agentic Governance Protocol](https://metamynd.ai/en/developers/spec)**
25
+ ([markdown](https://metamynd.ai/specs/magp-v1.0.md))
26
+
27
+ It defines agent identity, the canonical signed message (§8.3), the sixteen-stage order of
28
+ checks (§8.5), all 59 reason codes (Appendix A), delegation narrowing (§5.4), and evidence
29
+ you can verify offline without MetaMynd (§13.4). If you are writing a client in a language
30
+ other than JavaScript, read §8.3.3–8.3.5 first: key encoding, number stringification and
31
+ signed-vs-sent field identity each surface only as `SIGNATURE_INVALID`.
32
+
18
33
  ## Try it first — no account, no network
19
34
 
20
35
  ```bash
@@ -491,7 +491,7 @@ export function createGuard(opts = {}) {
491
491
  return {
492
492
  hello() {
493
493
  const nonceA = crypto.randomUUID();
494
- return { nonceA, message: { fromDid: agentDid, nonceA, protoVersion: '0.4' } };
494
+ return { nonceA, message: { fromDid: agentDid, nonceA, protoVersion: '1.0' } };
495
495
  },
496
496
  prove({ nonceA, challenge } = {}) {
497
497
  const { toDid, nonceB, sigB, handshakeId } = challenge ?? {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamynd/agentsafe-guard",
3
- "version": "0.4.0",
3
+ "version": "0.4.5",
4
4
  "description": "Zero-dependency runtime governance for any Node AI agent \u2014 gate tool calls through MetaMynd/AgentSafe (allow / block / escalate) against the agent's mandate, enforced Standards, and SOPs. Ed25519-signed, deterministic, fail-closed.",
5
5
  "type": "module",
6
6
  "main": "./agentsafe-guard.mjs",
@@ -48,8 +48,13 @@
48
48
  "author": "MetaMynd",
49
49
  "license": "MIT",
50
50
  "homepage": "https://metamynd.ai",
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/Metamynd/agentsafe-guard.git",
54
+ "directory": "packages/agentsafe-guard"
55
+ },
51
56
  "bugs": {
52
- "url": "https://metamynd.ai/en/support/contact"
57
+ "url": "https://github.com/Metamynd/agentsafe-guard/issues"
53
58
  },
54
59
  "publishConfig": {
55
60
  "access": "public"
package/policy-core.mjs CHANGED
@@ -334,6 +334,13 @@ function constraintSatisfied(c, req) {
334
334
  function targetOf(rule, mandate) {
335
335
  return rule.target ?? mandate.target;
336
336
  }
337
+ function isAuthorityFailure(result) {
338
+ return result.matched?.kind === "expiry" || result.matched?.kind === "no-permission";
339
+ }
340
+ function authorityFailure(mandate, target, now) {
341
+ const result = evaluateMandate(mandate, { target, now, values: {} });
342
+ return isAuthorityFailure(result) ? { ...result, decision: "block" } : null;
343
+ }
337
344
  function evaluateMandate(mandate, req) {
338
345
  const now = toTime(req.now);
339
346
  if (mandate.validFrom && now < toTime(mandate.validFrom)) {
@@ -402,14 +409,14 @@ function evaluate(input) {
402
409
  reasonCode = code;
403
410
  }
404
411
  };
412
+ const m = input.mandate && input.mandateRequest ? evaluateMandate(input.mandate, input.mandateRequest) : null;
413
+ const authority = m !== null && isAuthorityFailure(m);
414
+ if (m && authority) consider(m.decision, m.reasonCode);
405
415
  const std = evaluateBoundStandards(input.standards ?? [], input.context);
406
416
  if (std.decision !== "allow") consider(std.decision, std.reasonCode ?? "STANDARD_RULE");
407
417
  const sop = evaluateBoundStandards(input.sops ?? [], input.context);
408
418
  if (sop.decision !== "allow") consider(sop.decision, sop.reasonCode ?? "SOP_RULE");
409
- if (input.mandate && input.mandateRequest) {
410
- const m = evaluateMandate(input.mandate, input.mandateRequest);
411
- if (m.decision !== "allow") consider(m.decision, m.reasonCode);
412
- }
419
+ if (m && !authority && m.decision !== "allow") consider(m.decision, m.reasonCode);
413
420
  return { decision, reasonCode, authorizationId: null, remaining: null, proofRef: null };
414
421
  }
415
422
 
@@ -472,12 +479,14 @@ export {
472
479
  applyHold,
473
480
  applySignedLast,
474
481
  asOperatingMode,
482
+ authorityFailure,
475
483
  buildAuthMessage,
476
484
  canAuthorize,
477
485
  evaluate,
478
486
  evaluateBoundStandards,
479
487
  evaluateMandate,
480
488
  evaluateStandardRules,
489
+ isAuthorityFailure,
481
490
  isOperatingMode,
482
491
  moleculeFires,
483
492
  moreRestrictive,