@melra/policy-core 0.3.0-alpha.3

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,49 @@
1
+ import type { ApprovalChallenge, ApprovalResponse, Effect, EvidencePredicate, Operation, PolicyDecision, Risk, TaskRequest } from "@melra/protocol";
2
+ export interface LocalPolicy {
3
+ version: string;
4
+ workspaceRoot: string;
5
+ allowedCommands: string[];
6
+ allowedDomains: string[];
7
+ allowLocalhost: boolean;
8
+ mutations: "deny" | "confirm";
9
+ approvalTtlMs: number;
10
+ maxFileBytes: number;
11
+ }
12
+ export interface PolicyEvaluation {
13
+ decision: PolicyDecision;
14
+ challenge?: ApprovalChallenge;
15
+ }
16
+ export declare function normalizeCommandName(command: string): string;
17
+ export declare function createDefaultPolicy(workspaceRoot: string): LocalPolicy;
18
+ export declare function loadPolicy(path: string | undefined, workspaceRoot: string): Promise<LocalPolicy>;
19
+ export declare function classifyOperation(operation: Operation): {
20
+ effect: Effect;
21
+ risk: Risk;
22
+ capability: string;
23
+ target: string;
24
+ };
25
+ /**
26
+ * Evidence a mutation must satisfy when the caller declared none.
27
+ *
28
+ * Mutations still require evidence — that rule is the product's verification
29
+ * thesis and is not relaxed here. What changed is the failure mode: previously a
30
+ * caller who omitted `requiredEvidence` got a flat `mutation_requires_evidence`
31
+ * deny and had to guess the right predicate, so most callers simply gave up. Now
32
+ * the obvious post-condition is derived from the operation itself, and the task
33
+ * is held to it exactly as if the caller had written it.
34
+ *
35
+ * Returns `[]` when no post-condition is derivable from the request alone (for
36
+ * example a `terminal run`, whose effect depends on the command). Those still
37
+ * deny, because a mutation nobody can check is precisely what should not run
38
+ * unattended.
39
+ */
40
+ export declare function defaultEvidenceFor(operation: Operation): EvidencePredicate[];
41
+ export declare function evaluatePolicy(taskId: string, request: TaskRequest, policy: LocalPolicy): PolicyEvaluation;
42
+ export declare function digestOperation(taskId: string, operation: Operation): string;
43
+ export declare function validateApproval(challenge: ApprovalChallenge | undefined, response: ApprovalResponse | undefined): {
44
+ ok: true;
45
+ } | {
46
+ ok: false;
47
+ reason: string;
48
+ };
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,EACN,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,IAAI,EACJ,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,cAAc,CAAC;IACzB,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAqDD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI5D;AAED,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW,CAgCtE;AAED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,WAAW,CAAC,CAWtB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,SAAS,GAAG;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CA0HA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,GACnB,iBAAiB,EAAE,CAyCrB;AAoCD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,WAAW,GAClB,gBAAgB,CAoGlB;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAI5E;AAYD,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,iBAAiB,GAAG,SAAS,EACxC,QAAQ,EAAE,gBAAgB,GAAG,SAAS,GACrC;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAc9C"}
package/dist/index.js ADDED
@@ -0,0 +1,406 @@
1
+ // Copyright 2026 XAGI Labs Private Limited
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { readFile } from "node:fs/promises";
4
+ import { basename, resolve } from "node:path";
5
+ import { createHash, randomUUID } from "node:crypto";
6
+ const READ_ONLY_GIT_ACTIONS = new Set([
7
+ "branch",
8
+ "diff",
9
+ "log",
10
+ "rev-parse",
11
+ "show",
12
+ "status",
13
+ "tag",
14
+ ]);
15
+ const ALWAYS_DENIED_COMMANDS = new Set([
16
+ "bash",
17
+ "cmd",
18
+ "fish",
19
+ "osascript",
20
+ "powershell",
21
+ "pwsh",
22
+ "sh",
23
+ "sudo",
24
+ "su",
25
+ "zsh",
26
+ ]);
27
+ /**
28
+ * Defaults tuned so a fresh install is usable without editing `policy.json`.
29
+ *
30
+ * `allowedDomains: ["*"]` is not the SSRF boundary and never was. `assertSafeUrl`
31
+ * in `@melra/browser-runtime` independently rejects non-http(s) protocols, URL
32
+ * credentials, private ranges, and cloud metadata (169.254/16), and it resolves
33
+ * DNS before allowing a navigation so a public name cannot be rebound to a
34
+ * private address. The domain list is a *narrowing* control on top of that guard,
35
+ * for operators who want to restrict which public sites are reachable — it is not
36
+ * what stops a browser from reaching the loopback interface.
37
+ *
38
+ * Defaulting it to `[]` made every single navigation fail with
39
+ * `browser_domain_not_allowed` out of the box, which is why browser use was
40
+ * reported as unusable. Operators who want an allowlist set one explicitly.
41
+ */
42
+ /**
43
+ * Reduce a command to the name the allowlist is written in.
44
+ *
45
+ * On Windows an executable is spelled with an extension (`npm.cmd`, `node.exe`,
46
+ * `git.exe`), while allowlists are written bare. Comparing the raw basename made
47
+ * every extension-qualified spelling fail, so Windows users had no working
48
+ * spelling at all: bare `npm` passed policy but is a `.cmd` shim that does not
49
+ * spawn, and `npm.cmd` spawns but was denied. Only the executable suffixes in
50
+ * PATHEXT are stripped, so a command that merely contains a dot (`python3.11`)
51
+ * is left intact.
52
+ */
53
+ const EXECUTABLE_SUFFIXES = [".exe", ".cmd", ".bat", ".com", ".ps1"];
54
+ export function normalizeCommandName(command) {
55
+ const name = basename(command.replaceAll("\\", "/")).toLowerCase();
56
+ const suffix = EXECUTABLE_SUFFIXES.find((item) => name.endsWith(item));
57
+ return suffix === undefined ? name : name.slice(0, -suffix.length);
58
+ }
59
+ export function createDefaultPolicy(workspaceRoot) {
60
+ return {
61
+ version: "1",
62
+ workspaceRoot: resolve(workspaceRoot),
63
+ // One list for every platform. An entry naming a program the host does not
64
+ // have is inert — it fails at spawn with `terminal_command_not_found`, not
65
+ // at policy — so the Windows and POSIX read tools can both sit here rather
66
+ // than making the same policy mean different things on different machines.
67
+ allowedCommands: [
68
+ "cat",
69
+ "echo",
70
+ "findstr",
71
+ "git",
72
+ "head",
73
+ "ls",
74
+ "node",
75
+ "npm",
76
+ "npx",
77
+ "pnpm",
78
+ "pwd",
79
+ "rg",
80
+ "tail",
81
+ "tasklist",
82
+ "wc",
83
+ "where",
84
+ ],
85
+ allowedDomains: ["*"],
86
+ allowLocalhost: true,
87
+ mutations: "confirm",
88
+ approvalTtlMs: 5 * 60_000,
89
+ maxFileBytes: 10 * 1024 * 1024,
90
+ };
91
+ }
92
+ export async function loadPolicy(path, workspaceRoot) {
93
+ const defaults = createDefaultPolicy(workspaceRoot);
94
+ if (path === undefined)
95
+ return defaults;
96
+ const parsed = JSON.parse(await readFile(path, "utf8"));
97
+ return {
98
+ ...defaults,
99
+ ...parsed,
100
+ workspaceRoot: resolve(parsed.workspaceRoot ?? workspaceRoot),
101
+ allowedCommands: parsed.allowedCommands ?? defaults.allowedCommands,
102
+ allowedDomains: parsed.allowedDomains ?? defaults.allowedDomains,
103
+ };
104
+ }
105
+ export function classifyOperation(operation) {
106
+ switch (operation.kind) {
107
+ case "file": {
108
+ const read = new Set(["list", "read", "stat", "hash"]).has(operation.action);
109
+ const destructive = operation.action === "delete";
110
+ return {
111
+ effect: destructive ? "destructive" : read ? "read" : "mutate",
112
+ risk: destructive ? "high" : read ? "low" : "medium",
113
+ capability: `file.${operation.action}`,
114
+ target: operation.path,
115
+ };
116
+ }
117
+ case "terminal": {
118
+ if (operation.action === "status" || operation.action === "output") {
119
+ return {
120
+ effect: "read",
121
+ risk: "low",
122
+ capability: `terminal.${operation.action}`,
123
+ target: `job:${operation.jobId ?? "unknown"}`,
124
+ };
125
+ }
126
+ const command = normalizeCommandName(operation.command ?? "");
127
+ const gitRead = operation.action === "run" &&
128
+ command === "git" &&
129
+ operation.args.length > 0 &&
130
+ READ_ONLY_GIT_ACTIONS.has(operation.args[0] ?? "");
131
+ const readCommands = new Set([
132
+ "cat",
133
+ "findstr",
134
+ "head",
135
+ "ls",
136
+ "pwd",
137
+ "rg",
138
+ "tail",
139
+ "tasklist",
140
+ "wc",
141
+ "where",
142
+ ]);
143
+ const read = readCommands.has(command) || gitRead;
144
+ const packageMutation = new Set(["npm", "npx", "pnpm"]).has(command);
145
+ return {
146
+ effect: read ? "read" : "mutate",
147
+ risk: packageMutation ? "high" : read ? "low" : "medium",
148
+ capability: `terminal.${operation.action}`,
149
+ target: operation.action === "stop"
150
+ ? `job:${operation.jobId ?? "unknown"}`
151
+ : `command:${command}`,
152
+ };
153
+ }
154
+ case "browser": {
155
+ // Navigation and observation read the world; only actions that drive the
156
+ // page (click, type, upload, ...) change anything. `tab_new` and
157
+ // `tab_switch` are classified with `navigate` for the same reason it is:
158
+ // they move where we are looking, they do not act on a document. `wait`
159
+ // joins them — it blocks until the page reaches a state, and blocking is
160
+ // not acting.
161
+ const read = new Set([
162
+ "navigate",
163
+ "back",
164
+ "forward",
165
+ "reload",
166
+ "inspect",
167
+ "wait",
168
+ "screenshot",
169
+ "tabs",
170
+ "tab_new",
171
+ "tab_switch",
172
+ "scroll",
173
+ ]).has(operation.action);
174
+ return {
175
+ effect: read ? "read" : "mutate",
176
+ risk: read ? "low" : "medium",
177
+ capability: `browser.${operation.action}`,
178
+ target: operation.url === undefined
179
+ ? operation.target?.selector ??
180
+ operation.target?.name ??
181
+ "active-page"
182
+ : (() => {
183
+ const target = new URL(operation.url);
184
+ target.search = "";
185
+ target.hash = "";
186
+ return target.toString();
187
+ })(),
188
+ };
189
+ }
190
+ case "memory": {
191
+ const read = operation.action === "search" || operation.action === "list";
192
+ const destructive = operation.action === "delete" || operation.action === "clear";
193
+ return {
194
+ effect: destructive ? "destructive" : read ? "read" : "mutate",
195
+ risk: destructive ? "high" : read ? "low" : "medium",
196
+ capability: `memory.${operation.action}`,
197
+ target: `${operation.scope}:${operation.action}:${operation.id ?? operation.key ?? "*"}`,
198
+ };
199
+ }
200
+ case "computer": {
201
+ const read = operation.action === "capabilities" ||
202
+ operation.action === "screenshot";
203
+ return {
204
+ effect: read ? "read" : "mutate",
205
+ risk: read ? "low" : "high",
206
+ capability: `computer.${operation.action}`,
207
+ target: operation.action === "click" || operation.action === "move"
208
+ ? `${operation.coordinateSpace}:${operation.x ?? "?"},${operation.y ?? "?"}`
209
+ : "active-desktop",
210
+ };
211
+ }
212
+ case "system":
213
+ return {
214
+ effect: "read",
215
+ risk: "low",
216
+ capability: "system.info",
217
+ target: "local-system",
218
+ };
219
+ }
220
+ }
221
+ /**
222
+ * Evidence a mutation must satisfy when the caller declared none.
223
+ *
224
+ * Mutations still require evidence — that rule is the product's verification
225
+ * thesis and is not relaxed here. What changed is the failure mode: previously a
226
+ * caller who omitted `requiredEvidence` got a flat `mutation_requires_evidence`
227
+ * deny and had to guess the right predicate, so most callers simply gave up. Now
228
+ * the obvious post-condition is derived from the operation itself, and the task
229
+ * is held to it exactly as if the caller had written it.
230
+ *
231
+ * Returns `[]` when no post-condition is derivable from the request alone (for
232
+ * example a `terminal run`, whose effect depends on the command). Those still
233
+ * deny, because a mutation nobody can check is precisely what should not run
234
+ * unattended.
235
+ */
236
+ export function defaultEvidenceFor(operation) {
237
+ // Reads are never denied for missing evidence and already fall back to a
238
+ // synthetic `operation_completed` item, so synthesizing a predicate for them
239
+ // would only invent a way for a successful read to verify as `partial`.
240
+ if (classifyOperation(operation).effect === "read")
241
+ return [];
242
+ switch (operation.kind) {
243
+ case "file":
244
+ switch (operation.action) {
245
+ case "write":
246
+ case "mkdir":
247
+ return [{ type: "file_exists", path: operation.path }];
248
+ case "delete":
249
+ return [{ type: "file_absent", path: operation.path }];
250
+ case "move":
251
+ return operation.destination === undefined
252
+ ? []
253
+ : [
254
+ { type: "file_absent", path: operation.path },
255
+ { type: "file_exists", path: operation.destination },
256
+ ];
257
+ default:
258
+ return [];
259
+ }
260
+ case "memory":
261
+ // Field names differ per action; each is the adapter's own report that the
262
+ // record actually changed, so a silent no-op cannot pass as a success.
263
+ // `clear` returns a count rather than a flag, so it has no boolean
264
+ // post-condition to assert.
265
+ return operation.action === "put"
266
+ ? [{ type: "result_equals", path: "stored", value: true }]
267
+ : operation.action === "delete"
268
+ ? [{ type: "result_equals", path: "deleted", value: true }]
269
+ : [];
270
+ case "browser":
271
+ case "computer":
272
+ // These adapters report an explicit `success` flag; hold the task to it
273
+ // rather than letting a silent no-op pass as a completed action.
274
+ return [{ type: "result_equals", path: "success", value: true }];
275
+ default:
276
+ return [];
277
+ }
278
+ }
279
+ function deny(effect, risk, reason, version) {
280
+ return { outcome: "deny", effect, risk, reason, policyVersion: version };
281
+ }
282
+ function isCommandAllowed(operation, policy) {
283
+ if (operation.kind !== "terminal")
284
+ return true;
285
+ if (operation.action === "status" || operation.action === "output") {
286
+ return operation.jobId !== undefined;
287
+ }
288
+ if (operation.action === "stop")
289
+ return operation.jobId !== undefined;
290
+ if (operation.command === undefined)
291
+ return false;
292
+ const command = normalizeCommandName(operation.command);
293
+ // Normalized on both sides so `powershell.exe` cannot slip past a deny entry
294
+ // written as `powershell`, and an operator's allowlist matches either spelling.
295
+ if (ALWAYS_DENIED_COMMANDS.has(command))
296
+ return false;
297
+ return policy.allowedCommands.some((allowed) => normalizeCommandName(allowed) === command);
298
+ }
299
+ function domainAllowed(operation, policy) {
300
+ if (operation.kind !== "browser" || operation.url === undefined)
301
+ return true;
302
+ const url = new URL(operation.url);
303
+ if (!["http:", "https:"].includes(url.protocol))
304
+ return false;
305
+ const host = url.hostname.toLowerCase();
306
+ if (host === "localhost" || host.endsWith(".localhost"))
307
+ return policy.allowLocalhost;
308
+ return policy.allowedDomains.some((domain) => domain === "*" ||
309
+ host === domain.toLowerCase() ||
310
+ host.endsWith(`.${domain.toLowerCase()}`));
311
+ }
312
+ export function evaluatePolicy(taskId, request, policy) {
313
+ const classified = classifyOperation(request.operation);
314
+ if (request.constraints.length > 0) {
315
+ return {
316
+ decision: deny(classified.effect, classified.risk, "freeform_constraints_not_enforceable", policy.version),
317
+ };
318
+ }
319
+ if (request.forbiddenEffects.includes(classified.effect)) {
320
+ return {
321
+ decision: deny(classified.effect, classified.risk, "effect_forbidden_by_request", policy.version),
322
+ };
323
+ }
324
+ if (!isCommandAllowed(request.operation, policy)) {
325
+ return {
326
+ decision: deny(classified.effect, "critical", "command_not_allowlisted", policy.version),
327
+ };
328
+ }
329
+ if (!domainAllowed(request.operation, policy)) {
330
+ return {
331
+ decision: deny(classified.effect, "high", "browser_domain_not_allowed", policy.version),
332
+ };
333
+ }
334
+ if (classified.effect !== "read" && request.requiredEvidence.length === 0) {
335
+ return {
336
+ decision: deny(classified.effect, classified.risk, "mutation_requires_evidence", policy.version),
337
+ };
338
+ }
339
+ if (classified.effect === "read") {
340
+ return {
341
+ decision: {
342
+ outcome: "allow",
343
+ effect: classified.effect,
344
+ risk: classified.risk,
345
+ reason: "read_only_operation",
346
+ policyVersion: policy.version,
347
+ },
348
+ };
349
+ }
350
+ if (policy.mutations === "deny") {
351
+ return {
352
+ decision: deny(classified.effect, classified.risk, "mutations_disabled", policy.version),
353
+ };
354
+ }
355
+ const digest = digestOperation(taskId, request.operation);
356
+ const approvalId = randomUUID();
357
+ const phrase = `APPROVE ${digest.slice(0, 12)}`;
358
+ return {
359
+ decision: {
360
+ outcome: "confirm",
361
+ effect: classified.effect,
362
+ risk: classified.risk,
363
+ reason: "explicit_approval_required",
364
+ policyVersion: policy.version,
365
+ },
366
+ challenge: {
367
+ approvalId,
368
+ taskId,
369
+ actionDigest: digest,
370
+ phrase,
371
+ expiresAt: new Date(Date.now() + policy.approvalTtlMs).toISOString(),
372
+ },
373
+ };
374
+ }
375
+ export function digestOperation(taskId, operation) {
376
+ return createHash("sha256")
377
+ .update(stableJson({ taskId, operation }))
378
+ .digest("hex");
379
+ }
380
+ function stableJson(value) {
381
+ if (value === null || typeof value !== "object")
382
+ return JSON.stringify(value) ?? "null";
383
+ if (Array.isArray(value))
384
+ return `[${value.map(stableJson).join(",")}]`;
385
+ const object = value;
386
+ return `{${Object.keys(object)
387
+ .sort()
388
+ .map((key) => `${JSON.stringify(key)}:${stableJson(object[key])}`)
389
+ .join(",")}}`;
390
+ }
391
+ export function validateApproval(challenge, response) {
392
+ if (challenge === undefined || response === undefined) {
393
+ return { ok: false, reason: "approval_required" };
394
+ }
395
+ if (challenge.approvalId !== response.approvalId) {
396
+ return { ok: false, reason: "approval_id_mismatch" };
397
+ }
398
+ if (challenge.phrase !== response.phrase) {
399
+ return { ok: false, reason: "approval_phrase_mismatch" };
400
+ }
401
+ if (Date.parse(challenge.expiresAt) <= Date.now()) {
402
+ return { ok: false, reason: "approval_expired" };
403
+ }
404
+ return { ok: true };
405
+ }
406
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA4BrD,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,QAAQ;IACR,MAAM;IACN,KAAK;IACL,WAAW;IACX,MAAM;IACN,QAAQ;IACR,KAAK;CACN,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,MAAM;IACN,KAAK;IACL,MAAM;IACN,WAAW;IACX,YAAY;IACZ,MAAM;IACN,IAAI;IACJ,MAAM;IACN,IAAI;IACJ,KAAK;CACN,CAAC,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH;;;;;;;;;;GAUG;AACH,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAErE,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACnE,MAAM,MAAM,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACvE,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAA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SAAS,EAAE,CAAC;QACtD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;IACpD,CAAC;IACD,IAAI,SAAS,CAAC,UAAU,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC;QACjD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;IACvD,CAAC;IACD,IAAI,SAAS,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;QACzC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,0BAA0B,EAAE,CAAC;IAC3D,CAAC;IACD,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QAClD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;IACnD,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,259 @@
1
+ // Copyright 2026 XAGI Labs Private Limited
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { describe, expect, it } from "vitest";
4
+ import { TaskRequestSchema } from "@melra/protocol";
5
+ import { createDefaultPolicy, defaultEvidenceFor, evaluatePolicy, validateApproval, } from "./index.js";
6
+ const root = "/tmp/melra-policy-test";
7
+ describe("local policy", () => {
8
+ it("allows a read-only file operation", () => {
9
+ const request = TaskRequestSchema.parse({
10
+ goal: "Read the changelog",
11
+ operation: { kind: "file", action: "read", path: "CHANGELOG.md" },
12
+ });
13
+ const result = evaluatePolicy("4c5a0130-71a5-4c48-b22d-c7901f12688f", request, createDefaultPolicy(root));
14
+ expect(result.decision.outcome).toBe("allow");
15
+ expect(result.challenge).toBeUndefined();
16
+ });
17
+ it("requires evidence and approval for mutation", () => {
18
+ const missingEvidence = TaskRequestSchema.parse({
19
+ goal: "Write a file",
20
+ operation: {
21
+ kind: "file",
22
+ action: "write",
23
+ path: "result.txt",
24
+ content: "verified",
25
+ },
26
+ });
27
+ expect(evaluatePolicy("b47dded2-4e20-4d96-a993-fdf6b0034664", missingEvidence, createDefaultPolicy(root)).decision.reason).toBe("mutation_requires_evidence");
28
+ const request = TaskRequestSchema.parse({
29
+ ...missingEvidence,
30
+ requiredEvidence: [{ type: "file_exists", path: "result.txt" }],
31
+ });
32
+ const result = evaluatePolicy("b47dded2-4e20-4d96-a993-fdf6b0034664", request, createDefaultPolicy(root));
33
+ expect(result.decision.outcome).toBe("confirm");
34
+ expect(result.challenge?.phrase).toMatch(/^APPROVE [a-f0-9]{12}$/);
35
+ });
36
+ it("denies shells even if added to the allowlist", () => {
37
+ const request = TaskRequestSchema.parse({
38
+ goal: "Run an unrestricted shell",
39
+ operation: {
40
+ kind: "terminal",
41
+ action: "run",
42
+ command: "bash",
43
+ args: ["-lc", "echo unsafe"],
44
+ },
45
+ });
46
+ const policy = createDefaultPolicy(root);
47
+ policy.allowedCommands.push("bash");
48
+ expect(evaluatePolicy("71942756-af2a-407d-806e-73d7bb4fe5d0", request, policy).decision.reason).toBe("command_not_allowlisted");
49
+ });
50
+ it("allows computer inspection but gates input behind evidence and approval", () => {
51
+ const inspect = TaskRequestSchema.parse({
52
+ goal: "Inspect local computer-use support",
53
+ operation: { kind: "computer", action: "capabilities" },
54
+ });
55
+ expect(evaluatePolicy("c4e05bc0-c809-4ba3-a2a4-69102cdcf688", inspect, createDefaultPolicy(root)).decision.outcome).toBe("allow");
56
+ const click = TaskRequestSchema.parse({
57
+ goal: "Click a verified desktop target",
58
+ operation: {
59
+ kind: "computer",
60
+ action: "click",
61
+ coordinateSpace: "normalized",
62
+ x: 0.5,
63
+ y: 0.5,
64
+ },
65
+ requiredEvidence: [
66
+ { type: "result_equals", path: "success", value: true },
67
+ ],
68
+ });
69
+ const decision = evaluatePolicy("1aa2432a-a584-4b3f-b256-9ac3a6887630", click, createDefaultPolicy(root));
70
+ expect(decision.decision.outcome).toBe("confirm");
71
+ expect(decision.decision.risk).toBe("high");
72
+ });
73
+ it("validates the scoped approval phrase", () => {
74
+ const request = TaskRequestSchema.parse({
75
+ goal: "Store a memory",
76
+ operation: {
77
+ kind: "memory",
78
+ action: "put",
79
+ scope: "workspace",
80
+ key: "project",
81
+ value: "MELRA",
82
+ },
83
+ requiredEvidence: [
84
+ { type: "result_equals", path: "stored", value: true },
85
+ ],
86
+ });
87
+ const result = evaluatePolicy("db65d7da-9d59-46a7-86f7-aa1bd205382c", request, createDefaultPolicy(root));
88
+ const challenge = result.challenge;
89
+ expect(challenge).toBeDefined();
90
+ expect(validateApproval(challenge, {
91
+ approvalId: challenge.approvalId,
92
+ phrase: challenge.phrase,
93
+ })).toEqual({ ok: true });
94
+ });
95
+ it("never silently ignores caller constraints or forbidden effects", () => {
96
+ const constrained = TaskRequestSchema.parse({
97
+ goal: "Read with an unenforceable natural-language constraint",
98
+ operation: { kind: "file", action: "read", path: "README.md" },
99
+ constraints: ["only if the file is recent"],
100
+ });
101
+ expect(evaluatePolicy("ae8e57dd-e9f7-4821-82d7-ce50dc896008", constrained, createDefaultPolicy(root)).decision.reason).toBe("freeform_constraints_not_enforceable");
102
+ const forbidden = TaskRequestSchema.parse({
103
+ goal: "Do not permit a mutation",
104
+ operation: {
105
+ kind: "file",
106
+ action: "write",
107
+ path: "result.txt",
108
+ content: "blocked",
109
+ },
110
+ forbiddenEffects: ["mutate"],
111
+ requiredEvidence: [{ type: "file_exists", path: "result.txt" }],
112
+ });
113
+ expect(evaluatePolicy("e299a821-8dbf-4784-8ecf-f79d6812cc64", forbidden, createDefaultPolicy(root)).decision.reason).toBe("effect_forbidden_by_request");
114
+ });
115
+ it("allows a browser navigation with the shipped defaults", () => {
116
+ // Regression: allowedDomains defaulted to [] and denied every navigation
117
+ // out of the box, which is what made browser use unusable on a fresh install.
118
+ const request = TaskRequestSchema.parse({
119
+ goal: "Open a docs page",
120
+ operation: {
121
+ kind: "browser",
122
+ action: "navigate",
123
+ url: "https://example.com/docs",
124
+ },
125
+ });
126
+ expect(evaluatePolicy("0f9e6d2a-3c41-4b8e-9a77-1d5b8c2e4f60", request, createDefaultPolicy(root)).decision.outcome).toBe("allow");
127
+ });
128
+ });
129
+ describe("default evidence", () => {
130
+ it("derives the obvious post-condition per file action", () => {
131
+ expect(defaultEvidenceFor({
132
+ kind: "file",
133
+ action: "write",
134
+ path: "out.txt",
135
+ encoding: "utf8",
136
+ recursive: false,
137
+ })).toEqual([{ type: "file_exists", path: "out.txt" }]);
138
+ expect(defaultEvidenceFor({
139
+ kind: "file",
140
+ action: "delete",
141
+ path: "out.txt",
142
+ encoding: "utf8",
143
+ recursive: false,
144
+ })).toEqual([{ type: "file_absent", path: "out.txt" }]);
145
+ expect(defaultEvidenceFor({
146
+ kind: "file",
147
+ action: "move",
148
+ path: "a.txt",
149
+ destination: "b.txt",
150
+ encoding: "utf8",
151
+ recursive: false,
152
+ })).toEqual([
153
+ { type: "file_absent", path: "a.txt" },
154
+ { type: "file_exists", path: "b.txt" },
155
+ ]);
156
+ });
157
+ it("derives nothing for a terminal run, so it still denies", () => {
158
+ // The request says nothing about what the command should leave behind, so
159
+ // there is no honest post-condition to synthesize.
160
+ expect(defaultEvidenceFor({
161
+ kind: "terminal",
162
+ action: "run",
163
+ command: "npm",
164
+ args: ["run", "build"],
165
+ timeoutMs: 30_000,
166
+ maxOutputChars: 100_000,
167
+ })).toEqual([]);
168
+ });
169
+ it("derives nothing for a read, which already has a fallback", () => {
170
+ expect(defaultEvidenceFor({
171
+ kind: "file",
172
+ action: "read",
173
+ path: "a.txt",
174
+ encoding: "utf8",
175
+ recursive: false,
176
+ })).toEqual([]);
177
+ });
178
+ it("matches the field each memory action actually reports", () => {
179
+ expect(defaultEvidenceFor({
180
+ kind: "memory",
181
+ action: "put",
182
+ scope: "workspace",
183
+ key: "k",
184
+ value: "v",
185
+ confidence: 1,
186
+ tags: [],
187
+ includeSuperseded: false,
188
+ limit: 20,
189
+ })).toEqual([{ type: "result_equals", path: "stored", value: true }]);
190
+ // `clear` reports a count, not a boolean, so nothing is derivable.
191
+ expect(defaultEvidenceFor({
192
+ kind: "memory",
193
+ action: "clear",
194
+ scope: "workspace",
195
+ confidence: 1,
196
+ tags: [],
197
+ includeSuperseded: false,
198
+ limit: 20,
199
+ })).toEqual([]);
200
+ });
201
+ it("holds a browser mutation to the flag the runtime actually reports", () => {
202
+ // This predicate is only honest because `BrowserRuntime.execute` stamps
203
+ // `success: true` on every result. It did not, so a click with no declared
204
+ // evidence executed, mutated the page, and then verified as `partial`
205
+ // because the derived predicate read a key nobody wrote.
206
+ expect(defaultEvidenceFor({
207
+ kind: "browser",
208
+ action: "click",
209
+ target: { selector: "#go" },
210
+ fullPage: false,
211
+ timeoutMs: 30_000,
212
+ settleQuietMs: 180,
213
+ settleTimeoutMs: 1_500,
214
+ maxChars: 20_000,
215
+ delayMs: 0,
216
+ clearFirst: true,
217
+ pixels: 600,
218
+ })).toEqual([{ type: "result_equals", path: "success", value: true }]);
219
+ });
220
+ });
221
+ describe("Windows command spellings", () => {
222
+ const plan = (command, args = []) => evaluatePolicy("00000000-0000-4000-8000-000000000000", TaskRequestSchema.parse({
223
+ goal: "Run an allowlisted program",
224
+ operation: { kind: "terminal", action: "run", command, args },
225
+ requiredEvidence: [{ type: "exit_code", value: 0 }],
226
+ }), createDefaultPolicy(root)).decision;
227
+ it("accepts the extension-qualified spelling Windows actually runs", () => {
228
+ // The deadlock this closes: `npm` passed policy but is a `.cmd` shim that
229
+ // cannot be spawned, while `npm.cmd` could be spawned but was denied — so on
230
+ // Windows no spelling of an allowlisted command worked at all.
231
+ expect(plan("npm").reason).not.toBe("command_not_allowlisted");
232
+ expect(plan("npm.cmd").reason).not.toBe("command_not_allowlisted");
233
+ expect(plan("C:\\Program Files\\nodejs\\npm.cmd").reason).not.toBe("command_not_allowlisted");
234
+ });
235
+ it("still denies a shell however it is spelled", () => {
236
+ // Normalisation must apply to the deny list too, or stripping the extension
237
+ // would have turned it into a bypass.
238
+ for (const command of [
239
+ "powershell",
240
+ "powershell.exe",
241
+ "PowerShell.EXE",
242
+ "C:\\Windows\\System32\\cmd.exe",
243
+ "pwsh.exe",
244
+ "/bin/bash",
245
+ ]) {
246
+ expect(plan(command).reason).toBe("command_not_allowlisted");
247
+ }
248
+ });
249
+ it("does not strip a suffix that is merely part of the name", () => {
250
+ // `python3.11` ends in a dot-segment but not an executable suffix.
251
+ expect(plan("python3.11").reason).toBe("command_not_allowlisted");
252
+ });
253
+ it("classifies a Windows-spelled read command without demanding approval", () => {
254
+ expect(plan("git.exe", ["status"]).effect).toBe("read");
255
+ expect(plan("git.exe", ["push"]).effect).toBe("mutate");
256
+ expect(plan("npm.cmd", ["install"]).risk).toBe("high");
257
+ });
258
+ });
259
+ //# sourceMappingURL=index.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAEpB,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAEtC,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC;YACtC,IAAI,EAAE,oBAAoB;YAC1B,SAAS,EAAE,EA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I,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@melra/policy-core",
3
+ "version": "0.3.0-alpha.3",
4
+ "description": "Policy evaluation and scoped approval primitives for MELRA.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/XAGI-Lab/melra.git",
9
+ "directory": "packages/policy-core"
10
+ },
11
+ "homepage": "https://github.com/XAGI-Lab/melra#readme",
12
+ "bugs": "https://github.com/XAGI-Lab/melra/issues",
13
+ "type": "module",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "dependencies": {
24
+ "@melra/protocol": "0.3.0-alpha.3"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.json",
28
+ "clean": "rm -rf dist",
29
+ "test": "vitest run",
30
+ "typecheck": "tsc -p tsconfig.json --noEmit"
31
+ }
32
+ }