@predicatesystems/authority 0.3.1

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 (77) hide show
  1. package/LICENSE +24 -0
  2. package/LICENSE-APACHE +201 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +267 -0
  5. package/dist/src/contracts/action-request.d.ts +43 -0
  6. package/dist/src/contracts/action-request.d.ts.map +1 -0
  7. package/dist/src/contracts/action-request.js +32 -0
  8. package/dist/src/contracts/action-request.js.map +1 -0
  9. package/dist/src/contracts/authorization-decision.d.ts +11 -0
  10. package/dist/src/contracts/authorization-decision.d.ts.map +1 -0
  11. package/dist/src/contracts/authorization-decision.js +17 -0
  12. package/dist/src/contracts/authorization-decision.js.map +1 -0
  13. package/dist/src/contracts/decision.d.ts +10 -0
  14. package/dist/src/contracts/decision.d.ts.map +1 -0
  15. package/dist/src/contracts/decision.js +13 -0
  16. package/dist/src/contracts/decision.js.map +1 -0
  17. package/dist/src/contracts/enums.d.ts +7 -0
  18. package/dist/src/contracts/enums.d.ts.map +1 -0
  19. package/dist/src/contracts/enums.js +12 -0
  20. package/dist/src/contracts/enums.js.map +1 -0
  21. package/dist/src/contracts/index.d.ts +16 -0
  22. package/dist/src/contracts/index.d.ts.map +1 -0
  23. package/dist/src/contracts/index.js +9 -0
  24. package/dist/src/contracts/index.js.map +1 -0
  25. package/dist/src/contracts/mandate.d.ts +29 -0
  26. package/dist/src/contracts/mandate.d.ts.map +1 -0
  27. package/dist/src/contracts/mandate.js +24 -0
  28. package/dist/src/contracts/mandate.js.map +1 -0
  29. package/dist/src/contracts/policy-rule.d.ts +12 -0
  30. package/dist/src/contracts/policy-rule.d.ts.map +1 -0
  31. package/dist/src/contracts/policy-rule.js +17 -0
  32. package/dist/src/contracts/policy-rule.js.map +1 -0
  33. package/dist/src/contracts/proof-event.d.ts +13 -0
  34. package/dist/src/contracts/proof-event.d.ts.map +1 -0
  35. package/dist/src/contracts/proof-event.js +15 -0
  36. package/dist/src/contracts/proof-event.js.map +1 -0
  37. package/dist/src/contracts/verification.d.ts +4 -0
  38. package/dist/src/contracts/verification.d.ts.map +1 -0
  39. package/dist/src/contracts/verification.js +15 -0
  40. package/dist/src/contracts/verification.js.map +1 -0
  41. package/dist/src/errors.d.ts +13 -0
  42. package/dist/src/errors.d.ts.map +1 -0
  43. package/dist/src/errors.js +16 -0
  44. package/dist/src/errors.js.map +1 -0
  45. package/dist/src/evidence/non-web.d.ts +47 -0
  46. package/dist/src/evidence/non-web.d.ts.map +1 -0
  47. package/dist/src/evidence/non-web.js +58 -0
  48. package/dist/src/evidence/non-web.js.map +1 -0
  49. package/dist/src/evidence/web-state.d.ts +33 -0
  50. package/dist/src/evidence/web-state.d.ts.map +1 -0
  51. package/dist/src/evidence/web-state.js +58 -0
  52. package/dist/src/evidence/web-state.js.map +1 -0
  53. package/dist/src/guard/action-guard.d.ts +24 -0
  54. package/dist/src/guard/action-guard.d.ts.map +1 -0
  55. package/dist/src/guard/action-guard.js +49 -0
  56. package/dist/src/guard/action-guard.js.map +1 -0
  57. package/dist/src/index.d.ts +27 -0
  58. package/dist/src/index.d.ts.map +1 -0
  59. package/dist/src/index.js +142 -0
  60. package/dist/src/index.js.map +1 -0
  61. package/dist/src/policy/engine.d.ts +19 -0
  62. package/dist/src/policy/engine.d.ts.map +1 -0
  63. package/dist/src/policy/engine.js +82 -0
  64. package/dist/src/policy/engine.js.map +1 -0
  65. package/dist/src/policy/matching.d.ts +6 -0
  66. package/dist/src/policy/matching.d.ts.map +1 -0
  67. package/dist/src/policy/matching.js +46 -0
  68. package/dist/src/policy/matching.js.map +1 -0
  69. package/dist/src/types.d.ts +19 -0
  70. package/dist/src/types.d.ts.map +1 -0
  71. package/dist/src/types.js +11 -0
  72. package/dist/src/types.js.map +1 -0
  73. package/dist/src/wrappers/sensitive-operations.d.ts +44 -0
  74. package/dist/src/wrappers/sensitive-operations.d.ts.map +1 -0
  75. package/dist/src/wrappers/sensitive-operations.js +52 -0
  76. package/dist/src/wrappers/sensitive-operations.js.map +1 -0
  77. package/package.json +52 -0
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ # License
2
+
3
+ This project is dual-licensed under your choice of either:
4
+
5
+ * **MIT License** ([LICENSE-MIT](./LICENSE-MIT))
6
+ * **Apache License 2.0** ([LICENSE-APACHE](./LICENSE-APACHE))
7
+
8
+ ## Choosing a License
9
+
10
+ You may use this software under the terms of either license, at your option.
11
+
12
+ ### MIT License
13
+ The MIT License is a permissive license that is short and to the point. It lets people do almost anything they want with your project, like making and distributing closed source versions.
14
+
15
+ ### Apache License 2.0
16
+ The Apache License 2.0 is also a permissive license, similar to MIT, but it also provides an express grant of patent rights from contributors to users.
17
+
18
+ ## Contribution
19
+
20
+ Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you shall be dual-licensed as above, without any additional terms or conditions.
21
+
22
+ ---
23
+
24
+ Copyright (c) 2026 Predicate Systems Contributors
package/LICENSE-APACHE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Predicate Systems Contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Predicate Systems Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,267 @@
1
+ # Predicate Authority (TypeScript SDK)
2
+
3
+ **Deterministic Authority for AI Agents: secure sensitive actions with sidecar-backed, pre-execution authorization.**
4
+
5
+ [![License](https://img.shields.io/badge/License-MIT%2FApache--2.0-blue.svg)](LICENSE)
6
+ [![npm](https://img.shields.io/npm/v/@predicatesystems/authority.svg)](https://www.npmjs.com/package/@predicatesystems/authority)
7
+
8
+ `@predicatesystems/authority` is the TypeScript SDK companion to the Python
9
+ `predicate-authorityd` sidecar from [predicate-authority (Python)](https://github.com/PredicateSystems/predicate-authority). It keeps authority
10
+ decisions in the sidecar and gives Node/TS runtimes a thin, typed client for
11
+ fail-closed pre-execution checks.
12
+
13
+ ## Why Predicate Authority?
14
+
15
+ Most agent security failures come from over-broad delegated credentials and lack
16
+ of per-action runtime checks. Predicate Authority introduces short-lived mandates
17
+ bound to policy, identity, and evidence-backed state/intent checks.
18
+
19
+ - **Bridge, do not replace**: keep enterprise identity stacks (Entra/Okta/OIDC).
20
+ - **Fail-closed by default**: deny before execution when checks fail.
21
+ - **Deterministic binding**: decisions are tied to runtime evidence.
22
+ - **Provable controls**: reason codes and mandate IDs propagate to audit systems.
23
+
24
+ ## Repository Scope
25
+
26
+ This TS repository currently focuses on:
27
+
28
+ - typed sidecar transport for `POST /v1/authorize`,
29
+ - request/response contracts for authorization flows,
30
+ - runtime wrapper primitives (incremental),
31
+ - CI/release scaffolding for npm package delivery.
32
+
33
+ Out of scope for this package:
34
+
35
+ - re-implementing policy engine or mandate logic in TypeScript,
36
+ - replacing Python sidecar/control-plane authority logic.
37
+
38
+ ## Known Python Parity Baseline
39
+
40
+ This package targets compatibility with the current Python authority baseline in
41
+ [predicate-authority (Python)](https://github.com/PredicateSystems/predicate-authority):
42
+
43
+ - sidecar authorize route: `POST /v1/authorize` (`/authorize` compat alias),
44
+ - mandate/token baseline: ES256-default signing + standard JWT claim envelope,
45
+ - revocation baseline: explicit cascade semantics and global kill-switch runtime behavior,
46
+ - control-plane baseline: long-poll policy/revocation sync (runtime baseline),
47
+ - control-plane write hardening: replay freshness headers/signature support on Python client paths.
48
+
49
+ The TS SDK should preserve compatibility with these runtime behaviors before
50
+ adding TS-specific extensions.
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ npm install @predicatesystems/authority
56
+ ```
57
+
58
+ ## Quick Start
59
+
60
+ ```ts
61
+ import { AuthorityClient, type AuthorizationRequest } from "@predicatesystems/authority";
62
+
63
+ const client = new AuthorityClient({
64
+ baseUrl: "http://127.0.0.1:8787",
65
+ });
66
+
67
+ const request: AuthorizationRequest = {
68
+ principal: "agent:payments",
69
+ action: "http.post",
70
+ resource: "https://finance.example.com/transfers",
71
+ intent_hash: "intent-hash-placeholder",
72
+ labels: ["verified:user_presence"],
73
+ };
74
+
75
+ const decision = await client.authorize(request);
76
+ if (!decision.allowed) {
77
+ throw new Error(`Authority denied: ${decision.reason}`);
78
+ }
79
+ ```
80
+
81
+ ### Sidecar client retry/timeout tuning
82
+
83
+ ```ts
84
+ import { AuthorityClient } from "@predicatesystems/authority";
85
+
86
+ const client = new AuthorityClient({
87
+ baseUrl: "http://127.0.0.1:8787",
88
+ timeoutMs: 2000, // per-attempt timeout
89
+ maxRetries: 2, // retry budget on network/5xx failures
90
+ backoffInitialMs: 200, // linear backoff base (attempt * base)
91
+ });
92
+ ```
93
+
94
+ ### Choose your runtime mode
95
+
96
+ - **Sidecar client mode (recommended):** use `AuthorityClient` to call
97
+ `predicate-authorityd` (`/v1/authorize`) as the authority source of truth.
98
+ - **Local guard mode (optional):** use `PolicyEngine + ActionGuard` for local
99
+ evaluation in TS runtime flows (useful for tests/dev or controlled deployments).
100
+
101
+ ### Local guard mode example (`PolicyEngine + ActionGuard`)
102
+
103
+ ```ts
104
+ import {
105
+ ActionGuard,
106
+ PolicyEngine,
107
+ type ActionRequest,
108
+ type PolicyRule,
109
+ } from "@predicatesystems/authority";
110
+
111
+ const rules: PolicyRule[] = [
112
+ {
113
+ name: "allow-transfer-submit",
114
+ effect: "allow",
115
+ principals: ["agent:payments"],
116
+ actions: ["http.post"],
117
+ resources: ["https://finance.example.com/transfers"],
118
+ required_labels: ["verified:user_presence"],
119
+ },
120
+ ];
121
+
122
+ const guard = new ActionGuard({
123
+ policyEngine: new PolicyEngine(rules),
124
+ });
125
+
126
+ const request: ActionRequest = {
127
+ principal: { principal_id: "agent:payments" },
128
+ action_spec: {
129
+ action: "http.post",
130
+ resource: "https://finance.example.com/transfers",
131
+ intent: "submit transfer #123",
132
+ },
133
+ state_evidence: { source: "browser", state_hash: "state_abc" },
134
+ verification_evidence: {
135
+ signals: [{ label: "verified:user_presence", status: "passed" }],
136
+ },
137
+ };
138
+
139
+ const decision = guard.authorize(request);
140
+ if (!decision.allowed) {
141
+ throw new Error(`Local guard denied: ${decision.reason}`);
142
+ }
143
+ ```
144
+
145
+ ### Runtime adapter examples (TS frameworks)
146
+
147
+ See `docs/runtime-adapters.md` for copy-paste adapter patterns that map common
148
+ agent/tool runtime operations to authority checks in both:
149
+
150
+ - sidecar-first mode (`AuthorityClient`), and
151
+ - local wrapper mode (`ActionGuard` + `guardedShell`/`guardedFile*`/`guardedHttp`).
152
+
153
+ ### Web-first state evidence helper
154
+
155
+ Use `buildWebStateEvidence(...)` to map browser snapshot artifacts into canonical
156
+ `state_evidence`:
157
+
158
+ ```ts
159
+ import { buildWebStateEvidence } from "@predicatesystems/authority";
160
+
161
+ const stateEvidence = buildWebStateEvidence({
162
+ snapshot: {
163
+ url: "https://app.example.com/transfer",
164
+ title: "Transfer Funds",
165
+ dom_hash: "dom_hash_here",
166
+ visible_text_hash: "text_hash_here",
167
+ observed_at: new Date().toISOString(),
168
+ },
169
+ });
170
+ ```
171
+
172
+ If your runtime already produces `sdk-ts` snapshots, use
173
+ `buildWebStateEvidenceFromRuntimeSnapshot(...)` to map `timestamp`,
174
+ `dominant_group_key`, and diagnostics confidence directly.
175
+
176
+ Non-web evidence contracts are also available for Phase 4 adapter work:
177
+ `TerminalEvidenceProvider`, `DesktopAccessibilityEvidenceProvider`, and
178
+ `VerificationSignalProvider` (see `docs/runtime-adapters.md`).
179
+
180
+ ## Local Development
181
+
182
+ ```bash
183
+ npm install
184
+ npm run typecheck
185
+ npm test
186
+ npm run build
187
+ ```
188
+
189
+ ### Optional: sidecar integration tests
190
+
191
+ Run integration tests against a live `predicate-authorityd`:
192
+
193
+ ```bash
194
+ export SIDECAR_BASE_URL="http://127.0.0.1:8787"
195
+ npm run test:integration
196
+ ```
197
+
198
+ GitHub Actions `test.yml` also supports optional integration execution via
199
+ manual `workflow_dispatch` inputs (`run_integration`, `sidecar_base_url`).
200
+
201
+ For explicit allow/deny integration assertions, you can pass request fixtures:
202
+
203
+ ```bash
204
+ export RUN_SIDECAR_INTEGRATION_TESTS=true
205
+ export SIDECAR_BASE_URL="http://127.0.0.1:8787"
206
+ export SIDECAR_ALLOW_REQUEST_JSON='{"principal":"agent:allow","action":"http.get","resource":"https://example.com","intent_hash":"ih_allow"}'
207
+ export SIDECAR_DENY_REQUEST_JSON='{"principal":"agent:deny","action":"http.post","resource":"https://example.com/admin","intent_hash":"ih_deny"}'
208
+ export SIDECAR_EXPECTED_DENY_REASON="missing_required_verification"
209
+ export SIDECAR_REQUIRE_MANDATE_ON_ALLOW=false
210
+ npm run test:integration
211
+ ```
212
+
213
+ ## Release
214
+
215
+ GitHub Actions workflows are included for:
216
+
217
+ - test/build checks on push/PR: `.github/workflows/test.yml`
218
+ - npm release on `v*` tags or manual dispatch: `.github/workflows/release.yml`
219
+ - prerelease path: `rc-v*` tags publish to npm `next` dist-tag
220
+ - manual post-publish smoke evidence: `.github/workflows/post-publish-smoke.yml`
221
+
222
+ Required GitHub secret:
223
+
224
+ - `NPM_TOKEN` with publish access for `@predicatesystems`.
225
+
226
+ Release docs:
227
+
228
+ - `CHANGELOG.md`
229
+ - `docs/release-checklist.md`
230
+
231
+ Post-publish smoke:
232
+
233
+ ```bash
234
+ npm run smoke:npm -- latest
235
+ # optional live sidecar authorize check
236
+ SIDECAR_BASE_URL=http://127.0.0.1:8787 npm run smoke:npm -- latest
237
+ ```
238
+
239
+ ## Contributing
240
+
241
+ See `CONTRIBUTING.md` for branch, test, integration, and release conventions.
242
+
243
+ ## Troubleshooting
244
+
245
+ Common failure modes and first checks:
246
+
247
+ - `AuthorityClientError: timeout`
248
+ - sidecar may be unreachable or overloaded; verify sidecar health and increase `timeoutMs` for slow environments.
249
+ - `AuthorityClientError: network_error`
250
+ - check `baseUrl`, local networking, and whether `predicate-authorityd` is listening on expected host/port.
251
+ - `AuthorityClientError: protocol_error`
252
+ - sidecar returned non-JSON or unexpected payload shape; verify sidecar version compatibility.
253
+ - `AuthorityClientError: bad_request`
254
+ - request payload is invalid for `/v1/authorize`; compare fields with the fixture examples in `tests/fixtures/`.
255
+ - Frequent retries before success
256
+ - tune `maxRetries` and `backoffInitialMs`; investigate sidecar/host resource pressure.
257
+
258
+ ## License
259
+
260
+ Dual-licensed under **MIT** and **Apache 2.0**:
261
+
262
+ - `LICENSE-MIT`
263
+ - `LICENSE-APACHE`
264
+
265
+ ---
266
+
267
+ Copyright (c) 2026 Predicate Systems Contributors
@@ -0,0 +1,43 @@
1
+ import type { VerificationStatus } from "./enums.js";
2
+ export interface PrincipalRef {
3
+ principal_id: string;
4
+ tenant_id?: string;
5
+ session_id?: string;
6
+ }
7
+ export interface ActionSpec {
8
+ action: string;
9
+ resource: string;
10
+ intent: string;
11
+ }
12
+ export interface StateEvidence {
13
+ source: string;
14
+ state_hash: string;
15
+ schema_version?: string;
16
+ confidence?: number;
17
+ }
18
+ export interface VerificationSignal {
19
+ label: string;
20
+ status: VerificationStatus;
21
+ required?: boolean;
22
+ reason?: string;
23
+ }
24
+ export interface VerificationEvidence {
25
+ signals?: VerificationSignal[];
26
+ }
27
+ export interface ActionRequest {
28
+ principal: PrincipalRef;
29
+ action_spec: ActionSpec;
30
+ state_evidence: StateEvidence;
31
+ verification_evidence?: VerificationEvidence;
32
+ }
33
+ export interface SidecarAuthorizeRequest {
34
+ principal: string;
35
+ action: string;
36
+ resource: string;
37
+ intent_hash?: string;
38
+ context?: Record<string, unknown>;
39
+ labels?: string[];
40
+ }
41
+ export type AuthorizeRequest = ActionRequest | SidecarAuthorizeRequest;
42
+ export declare function toSidecarAuthorizeRequest(request: AuthorizeRequest): SidecarAuthorizeRequest;
43
+ //# sourceMappingURL=action-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-request.d.ts","sourceRoot":"","sources":["../../../src/contracts/action-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGrD,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,kBAAkB,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,kBAAkB,EAAE,CAAC;CAChC;AAGD,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,YAAY,CAAC;IACxB,WAAW,EAAE,UAAU,CAAC;IACxB,cAAc,EAAE,aAAa,CAAC;IAC9B,qBAAqB,CAAC,EAAE,oBAAoB,CAAC;CAC9C;AAGD,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG,uBAAuB,CAAC;AAEvE,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,gBAAgB,GAAG,uBAAuB,CAqB5F"}
@@ -0,0 +1,32 @@
1
+ import { passedLabels } from "./verification.js";
2
+ export function toSidecarAuthorizeRequest(request) {
3
+ if (isSidecarAuthorizeRequest(request)) {
4
+ return request;
5
+ }
6
+ const labels = passedLabels(request.verification_evidence);
7
+ const intentHash = stableIntentHashFromIntent(request.action_spec.intent);
8
+ return {
9
+ principal: request.principal.principal_id,
10
+ action: request.action_spec.action,
11
+ resource: request.action_spec.resource,
12
+ intent_hash: intentHash,
13
+ context: {
14
+ state_source: request.state_evidence.source,
15
+ state_hash: request.state_evidence.state_hash,
16
+ schema_version: request.state_evidence.schema_version ?? "v1",
17
+ confidence: request.state_evidence.confidence,
18
+ tenant_id: request.principal.tenant_id,
19
+ session_id: request.principal.session_id,
20
+ },
21
+ labels,
22
+ };
23
+ }
24
+ function isSidecarAuthorizeRequest(value) {
25
+ return typeof value.principal === "string";
26
+ }
27
+ function stableIntentHashFromIntent(intent) {
28
+ // Phase 0 compatibility placeholder: deterministic, local hash surrogate.
29
+ // Final parity helper will be replaced with python-compatible canonical hash.
30
+ return `ih_${intent.trim().toLowerCase().replace(/\s+/g, "_")}`;
31
+ }
32
+ //# sourceMappingURL=action-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-request.js","sourceRoot":"","sources":["../../../src/contracts/action-request.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAoDjD,MAAM,UAAU,yBAAyB,CAAC,OAAyB;IACjE,IAAI,yBAAyB,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,0BAA0B,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1E,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,YAAY;QACzC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,MAAM;QAClC,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,QAAQ;QACtC,WAAW,EAAE,UAAU;QACvB,OAAO,EAAE;YACP,YAAY,EAAE,OAAO,CAAC,cAAc,CAAC,MAAM;YAC3C,UAAU,EAAE,OAAO,CAAC,cAAc,CAAC,UAAU;YAC7C,cAAc,EAAE,OAAO,CAAC,cAAc,CAAC,cAAc,IAAI,IAAI;YAC7D,UAAU,EAAE,OAAO,CAAC,cAAc,CAAC,UAAU;YAC7C,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,SAAS;YACtC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,UAAU;SACzC;QACD,MAAM;KACP,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB,CAAC,KAAuB;IACxD,OAAO,OAAQ,KAAiC,CAAC,SAAS,KAAK,QAAQ,CAAC;AAC1E,CAAC;AAED,SAAS,0BAA0B,CAAC,MAAc;IAChD,0EAA0E;IAC1E,8EAA8E;IAC9E,OAAO,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;AAClE,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { AuthorizationReason } from "./enums.js";
2
+ import { type SignedMandate } from "./mandate.js";
3
+ export interface AuthorizationDecision {
4
+ allowed: boolean;
5
+ reason: AuthorizationReason | string;
6
+ mandate?: SignedMandate | null;
7
+ violated_rule?: string | null;
8
+ missing_labels?: string[];
9
+ }
10
+ export declare function isAuthorizationDecision(value: unknown): value is AuthorizationDecision;
11
+ //# sourceMappingURL=authorization-decision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-decision.d.ts","sourceRoot":"","sources":["../../../src/contracts/authorization-decision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,cAAc,CAAC;AAEnE,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAAC;IACrC,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,qBAAqB,CAgBtF"}
@@ -0,0 +1,17 @@
1
+ import { isSignedMandate } from "./mandate.js";
2
+ export function isAuthorizationDecision(value) {
3
+ if (typeof value !== "object" || value === null) {
4
+ return false;
5
+ }
6
+ const obj = value;
7
+ return (typeof obj.allowed === "boolean" &&
8
+ typeof obj.reason === "string" &&
9
+ (obj.mandate === undefined || obj.mandate === null || isSignedMandate(obj.mandate)) &&
10
+ (obj.violated_rule === undefined ||
11
+ obj.violated_rule === null ||
12
+ typeof obj.violated_rule === "string") &&
13
+ (obj.missing_labels === undefined ||
14
+ (Array.isArray(obj.missing_labels) &&
15
+ obj.missing_labels.every((label) => typeof label === "string"))));
16
+ }
17
+ //# sourceMappingURL=authorization-decision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-decision.js","sourceRoot":"","sources":["../../../src/contracts/authorization-decision.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,eAAe,EAAE,MAAM,cAAc,CAAC;AAUnE,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACpD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,OAAO,CACL,OAAO,GAAG,CAAC,OAAO,KAAK,SAAS;QAChC,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ;QAC9B,CAAC,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,GAAG,CAAC,OAAO,KAAK,IAAI,IAAI,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACnF,CAAC,GAAG,CAAC,aAAa,KAAK,SAAS;YAC9B,GAAG,CAAC,aAAa,KAAK,IAAI;YAC1B,OAAO,GAAG,CAAC,aAAa,KAAK,QAAQ,CAAC;QACxC,CAAC,GAAG,CAAC,cAAc,KAAK,SAAS;YAC/B,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;gBAChC,GAAG,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CACrE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { AuthorizationReason } from "./enums.js";
2
+ export interface AuthorizationResponse {
3
+ allowed: boolean;
4
+ reason: AuthorizationReason | string;
5
+ mandate_id: string | null;
6
+ violated_rule: string | null;
7
+ missing_labels: string[];
8
+ }
9
+ export declare function isAuthorizationResponse(value: unknown): value is AuthorizationResponse;
10
+ //# sourceMappingURL=decision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decision.d.ts","sourceRoot":"","sources":["../../../src/contracts/decision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAAC;IACrC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,qBAAqB,CAatF"}
@@ -0,0 +1,13 @@
1
+ export function isAuthorizationResponse(value) {
2
+ if (typeof value !== "object" || value === null) {
3
+ return false;
4
+ }
5
+ const obj = value;
6
+ return (typeof obj.allowed === "boolean" &&
7
+ typeof obj.reason === "string" &&
8
+ (obj.mandate_id === null || typeof obj.mandate_id === "string") &&
9
+ (obj.violated_rule === null || typeof obj.violated_rule === "string") &&
10
+ Array.isArray(obj.missing_labels) &&
11
+ obj.missing_labels.every((label) => typeof label === "string"));
12
+ }
13
+ //# sourceMappingURL=decision.js.map