@coderifts/agent-guard 1.2.0 → 1.4.0

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.
@@ -32,4 +32,6 @@ export type { ResolveInput, ResolveConfig, ResolveResult, ResolvedArtifact, Reso
32
32
  export { matchGlob, globToRegExp } from './resolver-glob.js';
33
33
  export { guardToolRegistry, RegistryConstructionError } from './tool-registry.js';
34
34
  export type { RawTool, ProtectedTool, ToolMutationClass, EnforcementCoverage, RegistryCoverageReport, GuardToolRegistryConfig, RegistryResult, ToolBinder, RegistryConstructionErrorCode, } from './tool-registry.js';
35
+ export { gateDecision } from './merge-gate.js';
36
+ export type { GateDecisionInput, GateDecision, ReceiptView, RequiredContext, ProtectionState, GateReason, GateStatusState, EnforcementState, } from './merge-gate.js';
35
37
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAElE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC7F,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAGxG,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAC1G,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EACL,mBAAmB,EAAE,qBAAqB,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EACnF,iBAAiB,EAAE,YAAY,EAAE,eAAe,EA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AAClF,YAAY,EACV,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACd,UAAU,EACV,6BAA6B,GAC9B,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EACV,iBAAiB,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAC9E,UAAU,EAAE,eAAe,EAAE,gBAAgB,GAC9C,MAAM,iBAAiB,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -19,7 +19,7 @@
19
19
  * ```
20
20
  */
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.RegistryConstructionError = exports.guardToolRegistry = exports.globToRegExp = exports.matchGlob = exports.resolveArtifacts = exports.deriveKeySignal = exports.pathClass = exports.classifyCommand = exports.projectState = exports.emptySessionState = exports.computeTainted = exports.evaluate = exports.updateSession = exports.SESSION_TAINT_VERSION = exports.SessionTaintTracker = exports.readDecision = exports.computeBundleFingerprint = exports.computeArtifactDigest = exports.evaluateEnvelope = exports.canonicalJson = exports.computeBodyHash = exports.bindReceiptToEnvelope = exports.DETECTOR_VERSION = exports.builtinDetector = exports.guardToolCall = void 0;
22
+ exports.gateDecision = exports.RegistryConstructionError = exports.guardToolRegistry = exports.globToRegExp = exports.matchGlob = exports.resolveArtifacts = exports.deriveKeySignal = exports.pathClass = exports.classifyCommand = exports.projectState = exports.emptySessionState = exports.computeTainted = exports.evaluate = exports.updateSession = exports.SESSION_TAINT_VERSION = exports.SessionTaintTracker = exports.readDecision = exports.computeBundleFingerprint = exports.computeArtifactDigest = exports.evaluateEnvelope = exports.canonicalJson = exports.computeBodyHash = exports.bindReceiptToEnvelope = exports.DETECTOR_VERSION = exports.builtinDetector = exports.guardToolCall = void 0;
23
23
  var guard_js_1 = require("./guard.js");
24
24
  Object.defineProperty(exports, "guardToolCall", { enumerable: true, get: function () { return guard_js_1.guardToolCall; } });
25
25
  var detector_js_1 = require("./detector.js");
@@ -61,4 +61,7 @@ Object.defineProperty(exports, "globToRegExp", { enumerable: true, get: function
61
61
  var tool_registry_js_1 = require("./tool-registry.js");
62
62
  Object.defineProperty(exports, "guardToolRegistry", { enumerable: true, get: function () { return tool_registry_js_1.guardToolRegistry; } });
63
63
  Object.defineProperty(exports, "RegistryConstructionError", { enumerable: true, get: function () { return tool_registry_js_1.RegistryConstructionError; } });
64
+ // repo-merge-gate (#7) — the PURE repo-side merge decision (Placement B). No I/O; protection is input.
65
+ var merge_gate_js_1 = require("./merge-gate.js");
66
+ Object.defineProperty(exports, "gateDecision", { enumerable: true, get: function () { return merge_gate_js_1.gateDecision; } });
64
67
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;AAEH,uCAA2C;AAAlC,yGAAA,aAAa,OAAA;AACtB,6CAAkE;AAAzD,8GAAA,eAAe,OAAA;AAAE,+GAAA,gBAAgB,OAAA;AAC1C,2FAA2F;AAC3F,2DAA6F;AAApF,2HAAA,qBAAqB,OAAA;AAAE,qHAAA,eAAe,OAAA;AAAE,mHAAA,aAAa,OAAA;AAE9D,sGAAsG;AACtG,+DAA+D;AAC/D,6DAA0G;AAAjG,uHAAA,gBAAgB,OAAA;AAAE,4HAAA,qBAAqB,OAAA;AAAE,+HAAA,wBAAwB,OAAA;AAE1E,sCAA8C;AAArC,mGAAA,YAAY,OAAA;AACrB,+FAA+F;AAC/F,uDAG4B;AAF1B,uHAAA,mBAAmB,OAAA;AAAE,yHAAA,qBAAqB,OAAA;AAAE,iHAAA,aAAa,OAAA;AAAE,4GAAA,QAAQ,OAAA;AAAE,kHAAA,cAAc,OAAA;AACnF,qHAAA,iBAAiB,OAAA;AAAE,gHAAA,YAAY,OAAA;AAAE,mHAAA,eAAe,OAAA;AAAE,6GAAA,SAAS,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,OAAA;AAAE,6HAAA,yBAAyB,OAAA;AAarD,uGAAuG;AACvG,iDAA+C;AAAtC,6GAAA,YAAY,OAAA"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * repo-merge-gate (#7) — the PURE gate decision (repo-merge-gate-SPEC §1). Placement B: the repo-side
3
+ * required-status-check logic that answers "may THIS PR head merge, given the finished receipt and the
4
+ * observed branch-protection state?"
5
+ *
6
+ * This is a PURE function — it performs NO I/O and makes NO GitHub call (branch protection is an
7
+ * INPUT, observed by the host and passed in). It does NOT re-decide: it reads only the finished
8
+ * receipt fields (decision / lifecycle authz / binding) — the deterministic verdict stays the
9
+ * server's (M5). Same inputs → same output (M8).
10
+ *
11
+ * Scope honesty is the whole point (§4): `inescapable_merge` is true ONLY in the fully-enforcing,
12
+ * non-bypassable case. For absent / advisory / unknown protection, or when an admin can bypass the
13
+ * required check, the check may still be `success` for visibility but `inescapable_merge` is FALSE
14
+ * with the residual named. It never claims more than the platform actually enforces.
15
+ *
16
+ * Public source (ships in the npm package): it references only receipt/protection fields and generic
17
+ * merge-gate concepts — no scoring logic, weights, thresholds, pattern names, endpoints, or secrets.
18
+ */
19
+ export type GateStatusState = 'success' | 'failure' | 'pending';
20
+ /** The 14 gate reason codes (§1.1). Success uses allow_current_head; the protection_* / admin_bypass_open
21
+ * codes name the honesty residual; server_unreachable is a host-supplied fail-closed policy input. */
22
+ export type GateReason = 'allow_current_head' | 'no_receipt' | 'receipt_not_authorized' | 'stale_head' | 'fingerprint_mismatch' | 'operation_mismatch' | 'target_mismatch' | 'decision_not_allow' | 'body_hash_mismatch' | 'protection_not_configured' | 'protection_advisory_only' | 'admin_bypass_open' | 'inputs_incomplete' | 'server_unreachable';
23
+ export type EnforcementState = 'ENFORCING' | 'ADVISORY' | 'UNKNOWN' | 'ABSENT';
24
+ /** A view of the finished receipt (fields already produced by the server + lifecycle evaluation).
25
+ * Reuses the shipped field names — the gate never re-derives any of them. */
26
+ export type ReceiptView = {
27
+ /** Lifecycle authorization result (NOT signature validity alone). */
28
+ currently_authorized: boolean;
29
+ authz_reason?: string;
30
+ decision: 'ALLOW' | 'WARN' | 'REQUIRE_APPROVAL' | 'BLOCK' | string;
31
+ execution_action?: 'CONTINUE' | 'CONTINUE_WITH_MONITORING' | 'REQUEST_APPROVAL' | 'STOP' | string;
32
+ /** The PR head commit this receipt was issued for (required for a non-null receipt). */
33
+ bound_head_sha: string;
34
+ verdict_fingerprint?: string;
35
+ body_hash?: string;
36
+ operation?: 'merge' | 'deploy' | 'tool_call' | 'publish' | string;
37
+ target_id?: string;
38
+ environment?: string;
39
+ /** Structural signature ok — NOT sufficient alone (currently_authorized is the gate). */
40
+ signature_valid?: boolean;
41
+ };
42
+ /** Branch-protection observation (from the host's GitHub read — the pure gate consumes it as input). */
43
+ export type ProtectionState = {
44
+ enforcement: EnforcementState;
45
+ admin_bypass_possible: boolean;
46
+ required_context_name?: string;
47
+ };
48
+ export type RequiredContext = {
49
+ operation?: string;
50
+ repository?: string;
51
+ expected_fingerprint?: string;
52
+ expected_body_hash?: string;
53
+ protection: ProtectionState;
54
+ allowWarnMerge?: boolean;
55
+ allowPrefixCompare?: boolean;
56
+ allowPending?: boolean;
57
+ };
58
+ export type GateDecisionInput = {
59
+ prHeadSha: string;
60
+ receipt: ReceiptView | null;
61
+ requiredContext: RequiredContext;
62
+ /** Incomplete/no-receipt → pending when true, else failure (default false). */
63
+ allowPending?: boolean;
64
+ /** Green the gate on WARN as well as ALLOW (default false). */
65
+ allowWarnMerge?: boolean;
66
+ /** Compare head SHAs by prefix instead of full 40-char equality (default false). */
67
+ allowPrefixCompare?: boolean;
68
+ };
69
+ export type GateDecision = {
70
+ merge_allowed: boolean;
71
+ state: GateStatusState;
72
+ reason: GateReason;
73
+ enforcement_state: EnforcementState;
74
+ inescapable_merge: boolean;
75
+ /** Named residual when the check is green but NOT inescapable (honesty channel, §4.2). */
76
+ residual?: GateReason;
77
+ detail: {
78
+ prHeadSha: string;
79
+ bound_head_sha: string | null;
80
+ decision: string | null;
81
+ };
82
+ };
83
+ /**
84
+ * §1.4 — the normative, first-match-wins gate decision. Pure; no I/O; deterministic.
85
+ */
86
+ export declare function gateDecision(input: GateDecisionInput): GateDecision;
87
+ //# sourceMappingURL=merge-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-gate.d.ts","sourceRoot":"","sources":["../../src/merge-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAEhE;uGACuG;AACvG,MAAM,MAAM,UAAU,GAClB,oBAAoB,GACpB,YAAY,GACZ,wBAAwB,GACxB,YAAY,GACZ,sBAAsB,GACtB,oBAAoB,GACpB,iBAAiB,GACjB,oBAAoB,GACpB,oBAAoB,GACpB,2BAA2B,GAC3B,0BAA0B,GAC1B,mBAAmB,GACnB,mBAAmB,GACnB,oBAAoB,CAAC;AAEzB,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE/E;8EAC8E;AAC9E,MAAM,MAAM,WAAW,GAAG;IACxB,qEAAqE;IACrE,oBAAoB,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,kBAAkB,GAAG,OAAO,GAAG,MAAM,CAAC;IACnE,gBAAgB,CAAC,EAAE,UAAU,GAAG,0BAA0B,GAAG,kBAAkB,GAAG,MAAM,GAAG,MAAM,CAAC;IAClG,wFAAwF;IACxF,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,CAAC;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;I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,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACvF,CAAC;AAkCF;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CA6EnE"}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /**
3
+ * repo-merge-gate (#7) — the PURE gate decision (repo-merge-gate-SPEC §1). Placement B: the repo-side
4
+ * required-status-check logic that answers "may THIS PR head merge, given the finished receipt and the
5
+ * observed branch-protection state?"
6
+ *
7
+ * This is a PURE function — it performs NO I/O and makes NO GitHub call (branch protection is an
8
+ * INPUT, observed by the host and passed in). It does NOT re-decide: it reads only the finished
9
+ * receipt fields (decision / lifecycle authz / binding) — the deterministic verdict stays the
10
+ * server's (M5). Same inputs → same output (M8).
11
+ *
12
+ * Scope honesty is the whole point (§4): `inescapable_merge` is true ONLY in the fully-enforcing,
13
+ * non-bypassable case. For absent / advisory / unknown protection, or when an admin can bypass the
14
+ * required check, the check may still be `success` for visibility but `inescapable_merge` is FALSE
15
+ * with the residual named. It never claims more than the platform actually enforces.
16
+ *
17
+ * Public source (ships in the npm package): it references only receipt/protection fields and generic
18
+ * merge-gate concepts — no scoring logic, weights, thresholds, pattern names, endpoints, or secrets.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.gateDecision = gateDecision;
22
+ // ── helpers (pure) ────────────────────────────────────────────────────────────────────────────────
23
+ function normSha(s) {
24
+ return String(s == null ? '' : s).trim().toLowerCase();
25
+ }
26
+ /** §1.2 — full lowercase SHA equality by default; prefix comparison is opt-in. */
27
+ function sameHead(a, b, allowPrefix) {
28
+ const na = normSha(a);
29
+ const nb = normSha(b);
30
+ if (!na || !nb)
31
+ return false;
32
+ if (na === nb)
33
+ return true;
34
+ if (allowPrefix && na.length >= 7 && nb.length >= 7 && (na.startsWith(nb) || nb.startsWith(na)))
35
+ return true;
36
+ return false;
37
+ }
38
+ /** §1.3 — allow-class for the merge gate: ALLOW (or WARN only when opted in) + a continue-class action. */
39
+ function isAllowClass(receipt, allowWarnMerge) {
40
+ const dec = receipt.decision;
41
+ const decisionOk = dec === 'ALLOW' || (dec === 'WARN' && allowWarnMerge === true);
42
+ if (!decisionOk)
43
+ return false;
44
+ const ea = receipt.execution_action;
45
+ if (ea === undefined || ea === null || ea === '')
46
+ return true; // decision already allow-class, no action to contradict it
47
+ return ea === 'CONTINUE' || ea === 'CONTINUE_WITH_MONITORING';
48
+ }
49
+ /** Target/repo binding: the receipt's target must name this repository (exact or `repo:`/path/colon suffix). */
50
+ function targetMatches(targetId, repository) {
51
+ const t = String(targetId).toLowerCase();
52
+ const r = String(repository).toLowerCase();
53
+ return t === r || t === `repo:${r}` || t.endsWith(`:${r}`) || t.endsWith(`/${r}`);
54
+ }
55
+ /**
56
+ * §1.4 — the normative, first-match-wins gate decision. Pure; no I/O; deterministic.
57
+ */
58
+ function gateDecision(input) {
59
+ const rc = input.requiredContext || {};
60
+ const protection = rc.protection || { enforcement: 'UNKNOWN', admin_bypass_possible: true };
61
+ const enforcement_state = protection.enforcement;
62
+ const allowPending = input.allowPending ?? rc.allowPending ?? false;
63
+ const allowWarnMerge = input.allowWarnMerge ?? rc.allowWarnMerge ?? false;
64
+ const allowPrefix = input.allowPrefixCompare ?? rc.allowPrefixCompare ?? false;
65
+ const receipt = input.receipt;
66
+ const detail = {
67
+ prHeadSha: normSha(input.prHeadSha),
68
+ bound_head_sha: receipt ? normSha(receipt.bound_head_sha) : null,
69
+ decision: receipt ? String(receipt.decision) : null,
70
+ };
71
+ const fail = (state, reason) => ({
72
+ merge_allowed: false, state, reason, enforcement_state, inescapable_merge: false, detail,
73
+ });
74
+ // 1) incomplete head → pending/failure (fail-closed on missing evaluation input).
75
+ if (!input.prHeadSha || String(input.prHeadSha).trim() === '') {
76
+ return fail(allowPending ? 'pending' : 'failure', 'inputs_incomplete');
77
+ }
78
+ // 2) no receipt → fail-closed (M2).
79
+ if (receipt === null || receipt === undefined) {
80
+ return fail(allowPending ? 'pending' : 'failure', 'no_receipt');
81
+ }
82
+ // 3) lifecycle authorization — a valid signature alone is NOT sufficient (M3).
83
+ if (receipt.currently_authorized !== true) {
84
+ return fail('failure', 'receipt_not_authorized');
85
+ }
86
+ // 4) operation binding — a receipt for a different operation does not authorize this gate.
87
+ const op = rc.operation ?? 'merge';
88
+ if (receipt.operation != null && receipt.operation !== op) {
89
+ return fail('failure', 'operation_mismatch');
90
+ }
91
+ // 5) STALE HEAD — the central invariant: a receipt bound to an old head never greens a new one (M1).
92
+ if (!sameHead(receipt.bound_head_sha, input.prHeadSha, allowPrefix)) {
93
+ return fail('failure', 'stale_head');
94
+ }
95
+ // 6) optional re-bind to the current change set.
96
+ if (rc.expected_fingerprint != null && receipt.verdict_fingerprint !== rc.expected_fingerprint) {
97
+ return fail('failure', 'fingerprint_mismatch');
98
+ }
99
+ if (rc.expected_body_hash != null && receipt.body_hash !== rc.expected_body_hash) {
100
+ return fail('failure', 'body_hash_mismatch');
101
+ }
102
+ // 7) target / repository binding (only when both sides are present).
103
+ if (rc.repository && receipt.target_id && !targetMatches(receipt.target_id, rc.repository)) {
104
+ return fail('failure', 'target_mismatch');
105
+ }
106
+ // 8) decision class — only an allow-class verdict greens the merge gate (M4).
107
+ if (!isAllowClass(receipt, allowWarnMerge)) {
108
+ return fail('failure', 'decision_not_allow');
109
+ }
110
+ // 9) success for the CHECK — green for visibility regardless of protection strength.
111
+ // 10) inescapable_merge claim (STRICT, §1.4 step 10 / M6): only when the platform actually enforces
112
+ // the required check AND no admin can bypass it. Never true otherwise.
113
+ const inescapable_merge = enforcement_state === 'ENFORCING' && protection.admin_bypass_possible === false;
114
+ let residual;
115
+ if (!inescapable_merge) {
116
+ if (enforcement_state === 'ENFORCING')
117
+ residual = 'admin_bypass_open'; // required, but admins can override
118
+ else if (enforcement_state === 'ADVISORY')
119
+ residual = 'protection_advisory_only'; // posted but not required
120
+ else
121
+ residual = 'protection_not_configured'; // ABSENT or UNKNOWN — cannot attest
122
+ }
123
+ return {
124
+ merge_allowed: true,
125
+ state: 'success',
126
+ reason: 'allow_current_head',
127
+ enforcement_state,
128
+ inescapable_merge,
129
+ ...(residual ? { residual } : {}),
130
+ detail,
131
+ };
132
+ }
133
+ //# sourceMappingURL=merge-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-gate.js","sourceRoot":"","sources":["../../src/merge-gate.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAwHH,oCA6EC;AAhHD,qGAAqG;AACrG,SAAS,OAAO,CAAC,CAA4B;IAC3C,OAAO,MAAM,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AACzD,CAAC;AAED,kFAAkF;AAClF,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS,EAAE,WAAoB;IAC1D,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;IAC7B,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,WAAW,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7G,OAAO,KAAK,CAAC;AACf,CAAC;AAED,2GAA2G;AAC3G,SAAS,YAAY,CAAC,OAAoB,EAAE,cAAuB;IACjE,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;IAC7B,MAAM,UAAU,GAAG,GAAG,KAAK,OAAO,IAAI,CAAC,GA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AAC;IAE1G,IAAI,QAAgC,CAAC;IACrC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,IAAI,iBAAiB,KAAK,WAAW;YAAE,QAAQ,GAAG,mBAAmB,CAAC,CAAU,oCAAoC;aAC/G,IAAI,iBAAiB,KAAK,UAAU;YAAE,QAAQ,GAAG,0BAA0B,CAAC,CAAC,0BAA0B;;YACvG,QAAQ,GAAG,2BAA2B,CAAC,CAAqC,oCAAoC;IACvH,CAAC;IAED,OAAO;QACL,aAAa,EAAE,IAAI;QACnB,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,oBAAoB;QAC5B,iBAAiB;QACjB,iBAAiB;QACjB,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,MAAM;KACP,CAAC;AACJ,CAAC"}
@@ -32,4 +32,6 @@ export type { ResolveInput, ResolveConfig, ResolveResult, ResolvedArtifact, Reso
32
32
  export { matchGlob, globToRegExp } from './resolver-glob.js';
33
33
  export { guardToolRegistry, RegistryConstructionError } from './tool-registry.js';
34
34
  export type { RawTool, ProtectedTool, ToolMutationClass, EnforcementCoverage, RegistryCoverageReport, GuardToolRegistryConfig, RegistryResult, ToolBinder, RegistryConstructionErrorCode, } from './tool-registry.js';
35
+ export { gateDecision } from './merge-gate.js';
36
+ export type { GateDecisionInput, GateDecision, ReceiptView, RequiredContext, ProtectionState, GateReason, GateStatusState, EnforcementState, } from './merge-gate.js';
35
37
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAElE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,aA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B,EACtB,eAAe,EACf,QAAQ,GACT,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACrE,YAAY,EACV,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAC7E,eAAe,EAAE,gBAAgB,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,IAAI,oBAAoB,GAClG,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG7D,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAClF,YAAY,EACV,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACd,UAAU,EACV,6BAA6B,GAC9B,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EACV,iBAAiB,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAC9E,UAAU,EAAE,eAAe,EAAE,gBAAgB,GAC9C,MAAM,iBAAiB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -33,4 +33,6 @@ export { resolve as resolveArtifacts } from './artifact-resolver.js';
33
33
  export { matchGlob, globToRegExp } from './resolver-glob.js';
34
34
  // guardToolRegistry — the agent-runtime inescapability layer ABOVE guardToolCall (Placement A only).
35
35
  export { guardToolRegistry, RegistryConstructionError } from './tool-registry.js';
36
+ // repo-merge-gate (#7) — the PURE repo-side merge decision (Placement B). No I/O; protection is input.
37
+ export { gateDecision } from './merge-gate.js';
36
38
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,aAAa,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B,CAAC;AAC9C,+FAA+F;AAC/F,OAAO,EACL,mBAAmB,EAAE,qBAAqB,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EACnF,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,GAC7E,MAAM,oBAAoB,CAAC;AA0B5B,kGAAkG;AAClG,wFAAwF;AACxF,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAKrE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE7D,qGAAqG;AACrG,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAalF,uGAAuG;AACvG,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * repo-merge-gate (#7) — the PURE gate decision (repo-merge-gate-SPEC §1). Placement B: the repo-side
3
+ * required-status-check logic that answers "may THIS PR head merge, given the finished receipt and the
4
+ * observed branch-protection state?"
5
+ *
6
+ * This is a PURE function — it performs NO I/O and makes NO GitHub call (branch protection is an
7
+ * INPUT, observed by the host and passed in). It does NOT re-decide: it reads only the finished
8
+ * receipt fields (decision / lifecycle authz / binding) — the deterministic verdict stays the
9
+ * server's (M5). Same inputs → same output (M8).
10
+ *
11
+ * Scope honesty is the whole point (§4): `inescapable_merge` is true ONLY in the fully-enforcing,
12
+ * non-bypassable case. For absent / advisory / unknown protection, or when an admin can bypass the
13
+ * required check, the check may still be `success` for visibility but `inescapable_merge` is FALSE
14
+ * with the residual named. It never claims more than the platform actually enforces.
15
+ *
16
+ * Public source (ships in the npm package): it references only receipt/protection fields and generic
17
+ * merge-gate concepts — no scoring logic, weights, thresholds, pattern names, endpoints, or secrets.
18
+ */
19
+ export type GateStatusState = 'success' | 'failure' | 'pending';
20
+ /** The 14 gate reason codes (§1.1). Success uses allow_current_head; the protection_* / admin_bypass_open
21
+ * codes name the honesty residual; server_unreachable is a host-supplied fail-closed policy input. */
22
+ export type GateReason = 'allow_current_head' | 'no_receipt' | 'receipt_not_authorized' | 'stale_head' | 'fingerprint_mismatch' | 'operation_mismatch' | 'target_mismatch' | 'decision_not_allow' | 'body_hash_mismatch' | 'protection_not_configured' | 'protection_advisory_only' | 'admin_bypass_open' | 'inputs_incomplete' | 'server_unreachable';
23
+ export type EnforcementState = 'ENFORCING' | 'ADVISORY' | 'UNKNOWN' | 'ABSENT';
24
+ /** A view of the finished receipt (fields already produced by the server + lifecycle evaluation).
25
+ * Reuses the shipped field names — the gate never re-derives any of them. */
26
+ export type ReceiptView = {
27
+ /** Lifecycle authorization result (NOT signature validity alone). */
28
+ currently_authorized: boolean;
29
+ authz_reason?: string;
30
+ decision: 'ALLOW' | 'WARN' | 'REQUIRE_APPROVAL' | 'BLOCK' | string;
31
+ execution_action?: 'CONTINUE' | 'CONTINUE_WITH_MONITORING' | 'REQUEST_APPROVAL' | 'STOP' | string;
32
+ /** The PR head commit this receipt was issued for (required for a non-null receipt). */
33
+ bound_head_sha: string;
34
+ verdict_fingerprint?: string;
35
+ body_hash?: string;
36
+ operation?: 'merge' | 'deploy' | 'tool_call' | 'publish' | string;
37
+ target_id?: string;
38
+ environment?: string;
39
+ /** Structural signature ok — NOT sufficient alone (currently_authorized is the gate). */
40
+ signature_valid?: boolean;
41
+ };
42
+ /** Branch-protection observation (from the host's GitHub read — the pure gate consumes it as input). */
43
+ export type ProtectionState = {
44
+ enforcement: EnforcementState;
45
+ admin_bypass_possible: boolean;
46
+ required_context_name?: string;
47
+ };
48
+ export type RequiredContext = {
49
+ operation?: string;
50
+ repository?: string;
51
+ expected_fingerprint?: string;
52
+ expected_body_hash?: string;
53
+ protection: ProtectionState;
54
+ allowWarnMerge?: boolean;
55
+ allowPrefixCompare?: boolean;
56
+ allowPending?: boolean;
57
+ };
58
+ export type GateDecisionInput = {
59
+ prHeadSha: string;
60
+ receipt: ReceiptView | null;
61
+ requiredContext: RequiredContext;
62
+ /** Incomplete/no-receipt → pending when true, else failure (default false). */
63
+ allowPending?: boolean;
64
+ /** Green the gate on WARN as well as ALLOW (default false). */
65
+ allowWarnMerge?: boolean;
66
+ /** Compare head SHAs by prefix instead of full 40-char equality (default false). */
67
+ allowPrefixCompare?: boolean;
68
+ };
69
+ export type GateDecision = {
70
+ merge_allowed: boolean;
71
+ state: GateStatusState;
72
+ reason: GateReason;
73
+ enforcement_state: EnforcementState;
74
+ inescapable_merge: boolean;
75
+ /** Named residual when the check is green but NOT inescapable (honesty channel, §4.2). */
76
+ residual?: GateReason;
77
+ detail: {
78
+ prHeadSha: string;
79
+ bound_head_sha: string | null;
80
+ decision: string | null;
81
+ };
82
+ };
83
+ /**
84
+ * §1.4 — the normative, first-match-wins gate decision. Pure; no I/O; deterministic.
85
+ */
86
+ export declare function gateDecision(input: GateDecisionInput): GateDecision;
87
+ //# sourceMappingURL=merge-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-gate.d.ts","sourceRoot":"","sources":["../../src/merge-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAEhE;uGACuG;AACvG,MAAM,MAAM,UAAU,GAClB,oBAAoB,GACpB,YAAY,GACZ,wBAAwB,GACxB,YAAY,GACZ,sBAAsB,GACtB,oBAAoB,GACpB,iBAAiB,GACjB,oBAAoB,GACpB,oBAAoB,GACpB,2BAA2B,GAC3B,0BAA0B,GAC1B,mBAAmB,GACnB,mBAAmB,GACnB,oBAAoB,CAAC;AAEzB,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE/E;8EAC8E;AAC9E,MAAM,MAAM,WAAW,GAAG;IACxB,qEAAqE;IACrE,oBAAoB,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,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,EAAE,OAAO,CAAC;IACzB,oFAAoF;IACpF,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,KAAK,EAAE,eAAe,CAAC;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,iBAAiB,EAAE,gBAAgB,CAAC;IACpC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,0FAA0F;IAC1F,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACvF,CAAC;AAkCF;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CA6EnE"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * repo-merge-gate (#7) — the PURE gate decision (repo-merge-gate-SPEC §1). Placement B: the repo-side
3
+ * required-status-check logic that answers "may THIS PR head merge, given the finished receipt and the
4
+ * observed branch-protection state?"
5
+ *
6
+ * This is a PURE function — it performs NO I/O and makes NO GitHub call (branch protection is an
7
+ * INPUT, observed by the host and passed in). It does NOT re-decide: it reads only the finished
8
+ * receipt fields (decision / lifecycle authz / binding) — the deterministic verdict stays the
9
+ * server's (M5). Same inputs → same output (M8).
10
+ *
11
+ * Scope honesty is the whole point (§4): `inescapable_merge` is true ONLY in the fully-enforcing,
12
+ * non-bypassable case. For absent / advisory / unknown protection, or when an admin can bypass the
13
+ * required check, the check may still be `success` for visibility but `inescapable_merge` is FALSE
14
+ * with the residual named. It never claims more than the platform actually enforces.
15
+ *
16
+ * Public source (ships in the npm package): it references only receipt/protection fields and generic
17
+ * merge-gate concepts — no scoring logic, weights, thresholds, pattern names, endpoints, or secrets.
18
+ */
19
+ // ── helpers (pure) ────────────────────────────────────────────────────────────────────────────────
20
+ function normSha(s) {
21
+ return String(s == null ? '' : s).trim().toLowerCase();
22
+ }
23
+ /** §1.2 — full lowercase SHA equality by default; prefix comparison is opt-in. */
24
+ function sameHead(a, b, allowPrefix) {
25
+ const na = normSha(a);
26
+ const nb = normSha(b);
27
+ if (!na || !nb)
28
+ return false;
29
+ if (na === nb)
30
+ return true;
31
+ if (allowPrefix && na.length >= 7 && nb.length >= 7 && (na.startsWith(nb) || nb.startsWith(na)))
32
+ return true;
33
+ return false;
34
+ }
35
+ /** §1.3 — allow-class for the merge gate: ALLOW (or WARN only when opted in) + a continue-class action. */
36
+ function isAllowClass(receipt, allowWarnMerge) {
37
+ const dec = receipt.decision;
38
+ const decisionOk = dec === 'ALLOW' || (dec === 'WARN' && allowWarnMerge === true);
39
+ if (!decisionOk)
40
+ return false;
41
+ const ea = receipt.execution_action;
42
+ if (ea === undefined || ea === null || ea === '')
43
+ return true; // decision already allow-class, no action to contradict it
44
+ return ea === 'CONTINUE' || ea === 'CONTINUE_WITH_MONITORING';
45
+ }
46
+ /** Target/repo binding: the receipt's target must name this repository (exact or `repo:`/path/colon suffix). */
47
+ function targetMatches(targetId, repository) {
48
+ const t = String(targetId).toLowerCase();
49
+ const r = String(repository).toLowerCase();
50
+ return t === r || t === `repo:${r}` || t.endsWith(`:${r}`) || t.endsWith(`/${r}`);
51
+ }
52
+ /**
53
+ * §1.4 — the normative, first-match-wins gate decision. Pure; no I/O; deterministic.
54
+ */
55
+ export function gateDecision(input) {
56
+ const rc = input.requiredContext || {};
57
+ const protection = rc.protection || { enforcement: 'UNKNOWN', admin_bypass_possible: true };
58
+ const enforcement_state = protection.enforcement;
59
+ const allowPending = input.allowPending ?? rc.allowPending ?? false;
60
+ const allowWarnMerge = input.allowWarnMerge ?? rc.allowWarnMerge ?? false;
61
+ const allowPrefix = input.allowPrefixCompare ?? rc.allowPrefixCompare ?? false;
62
+ const receipt = input.receipt;
63
+ const detail = {
64
+ prHeadSha: normSha(input.prHeadSha),
65
+ bound_head_sha: receipt ? normSha(receipt.bound_head_sha) : null,
66
+ decision: receipt ? String(receipt.decision) : null,
67
+ };
68
+ const fail = (state, reason) => ({
69
+ merge_allowed: false, state, reason, enforcement_state, inescapable_merge: false, detail,
70
+ });
71
+ // 1) incomplete head → pending/failure (fail-closed on missing evaluation input).
72
+ if (!input.prHeadSha || String(input.prHeadSha).trim() === '') {
73
+ return fail(allowPending ? 'pending' : 'failure', 'inputs_incomplete');
74
+ }
75
+ // 2) no receipt → fail-closed (M2).
76
+ if (receipt === null || receipt === undefined) {
77
+ return fail(allowPending ? 'pending' : 'failure', 'no_receipt');
78
+ }
79
+ // 3) lifecycle authorization — a valid signature alone is NOT sufficient (M3).
80
+ if (receipt.currently_authorized !== true) {
81
+ return fail('failure', 'receipt_not_authorized');
82
+ }
83
+ // 4) operation binding — a receipt for a different operation does not authorize this gate.
84
+ const op = rc.operation ?? 'merge';
85
+ if (receipt.operation != null && receipt.operation !== op) {
86
+ return fail('failure', 'operation_mismatch');
87
+ }
88
+ // 5) STALE HEAD — the central invariant: a receipt bound to an old head never greens a new one (M1).
89
+ if (!sameHead(receipt.bound_head_sha, input.prHeadSha, allowPrefix)) {
90
+ return fail('failure', 'stale_head');
91
+ }
92
+ // 6) optional re-bind to the current change set.
93
+ if (rc.expected_fingerprint != null && receipt.verdict_fingerprint !== rc.expected_fingerprint) {
94
+ return fail('failure', 'fingerprint_mismatch');
95
+ }
96
+ if (rc.expected_body_hash != null && receipt.body_hash !== rc.expected_body_hash) {
97
+ return fail('failure', 'body_hash_mismatch');
98
+ }
99
+ // 7) target / repository binding (only when both sides are present).
100
+ if (rc.repository && receipt.target_id && !targetMatches(receipt.target_id, rc.repository)) {
101
+ return fail('failure', 'target_mismatch');
102
+ }
103
+ // 8) decision class — only an allow-class verdict greens the merge gate (M4).
104
+ if (!isAllowClass(receipt, allowWarnMerge)) {
105
+ return fail('failure', 'decision_not_allow');
106
+ }
107
+ // 9) success for the CHECK — green for visibility regardless of protection strength.
108
+ // 10) inescapable_merge claim (STRICT, §1.4 step 10 / M6): only when the platform actually enforces
109
+ // the required check AND no admin can bypass it. Never true otherwise.
110
+ const inescapable_merge = enforcement_state === 'ENFORCING' && protection.admin_bypass_possible === false;
111
+ let residual;
112
+ if (!inescapable_merge) {
113
+ if (enforcement_state === 'ENFORCING')
114
+ residual = 'admin_bypass_open'; // required, but admins can override
115
+ else if (enforcement_state === 'ADVISORY')
116
+ residual = 'protection_advisory_only'; // posted but not required
117
+ else
118
+ residual = 'protection_not_configured'; // ABSENT or UNKNOWN — cannot attest
119
+ }
120
+ return {
121
+ merge_allowed: true,
122
+ state: 'success',
123
+ reason: 'allow_current_head',
124
+ enforcement_state,
125
+ inescapable_merge,
126
+ ...(residual ? { residual } : {}),
127
+ detail,
128
+ };
129
+ }
130
+ //# sourceMappingURL=merge-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-gate.js","sourceRoot":"","sources":["../../src/merge-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAqFH,qGAAqG;AACrG,SAAS,OAAO,CAAC,CAA4B;IAC3C,OAAO,MAAM,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AACzD,CAAC;AAED,kFAAkF;AAClF,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS,EAAE,WAAoB;IAC1D,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;IAC7B,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,WAAW,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,CAA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C,SAAS,EAAE,iBAAiB,CAAC,CAAC;IAC5C,CAAC;IACD,8EAA8E;IAC9E,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,CAAC;QAC3C,OAAO,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;IAC/C,CAAC;IAED,qFAAqF;IACrF,oGAAoG;IACpG,2EAA2E;IAC3E,MAAM,iBAAiB,GAAG,iBAAiB,KAAK,WAAW,IAAI,UAAU,CAAC,qBAAqB,KAAK,KAAK,CAAC;IAE1G,IAAI,QAAgC,CAAC;IACrC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,IAAI,iBAAiB,KAAK,WAAW;YAAE,QAAQ,GAAG,mBAAmB,CAAC,CAAU,oCAAoC;aAC/G,IAAI,iBAAiB,KAAK,UAAU;YAAE,QAAQ,GAAG,0BAA0B,CAAC,CAAC,0BAA0B;;YACvG,QAAQ,GAAG,2BAA2B,CAAC,CAAqC,oCAAoC;IACvH,CAAC;IAED,OAAO;QACL,aAAa,EAAE,IAAI;QACnB,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,oBAAoB;QAC5B,iBAAiB;QACjB,iBAAiB;QACjB,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,MAAM;KACP,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coderifts/agent-guard",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Fail-closed guard for AI agent tool calls — preflight contract changes before they execute. Security core frozen (agent-guard-api v1.0); v1.1 adds client-side enforcement: receipt→envelope binding, decision↔action reconciliation, safe_for_agent + degraded fail-closed, and enforced⟺executed (P0 client-enforcement pack).",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",