@zanii/walls 0.1.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.
- package/LICENSE +159 -0
- package/README.md +45 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +88 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
- package/src/index.ts +109 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
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 Derivative
|
|
95
|
+
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; and
|
|
103
|
+
|
|
104
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
105
|
+
distribution, then any Derivative Works that You distribute must
|
|
106
|
+
include a readable copy of the attribution notices contained
|
|
107
|
+
within such NOTICE file.
|
|
108
|
+
|
|
109
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
110
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
111
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
112
|
+
this License, without any additional terms or conditions.
|
|
113
|
+
|
|
114
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
115
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
116
|
+
except as required for reasonable and customary use in describing the
|
|
117
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
118
|
+
|
|
119
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
120
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
121
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
122
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including,
|
|
123
|
+
without limitation, any warranties or conditions of TITLE,
|
|
124
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
|
|
125
|
+
|
|
126
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
127
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
128
|
+
unless required by applicable law (such as deliberate and grossly
|
|
129
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
130
|
+
liable to You for damages, including any direct, indirect, special,
|
|
131
|
+
incidental, or consequential damages of any character arising as a
|
|
132
|
+
result of this License or out of the use or inability to use the
|
|
133
|
+
Work.
|
|
134
|
+
|
|
135
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
136
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
137
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
138
|
+
or other liability obligations and/or rights consistent with this
|
|
139
|
+
License. However, in accepting such obligations, You may act only
|
|
140
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
141
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
142
|
+
defend, and hold each Contributor harmless for any liability
|
|
143
|
+
incurred by, or claims asserted against, such Contributor.
|
|
144
|
+
|
|
145
|
+
END OF TERMS AND CONDITIONS
|
|
146
|
+
|
|
147
|
+
Copyright 2026 Zanii
|
|
148
|
+
|
|
149
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
150
|
+
you may not use this file except in compliance with the License.
|
|
151
|
+
You may obtain a copy of the License at
|
|
152
|
+
|
|
153
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
154
|
+
|
|
155
|
+
Unless required by applicable law or agreed to in writing, software
|
|
156
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
157
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
158
|
+
See the License for the specific language governing permissions and
|
|
159
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @zanii/walls
|
|
2
|
+
|
|
3
|
+
UAE vertical **"wall" presets** as enforceable, auditable artifacts. A wall = a scope the
|
|
4
|
+
delegation never grants + a policy that denies the risky action + a `manifest_hash` you
|
|
5
|
+
receipt per deploy (so the enforced rulebook is provably unaltered, not just the prose).
|
|
6
|
+
|
|
7
|
+
**Flagship: SCA trading** — "education only, NEVER 'buy this'", the most sensitive vertical
|
|
8
|
+
(investment advice/execution is a licensed activity). Plus **RERA** (realty), **TDRA**
|
|
9
|
+
(messaging), **Legal**, **Consumer/collections**, and **DIFC/ADGM** free-zone
|
|
10
|
+
data-protection variants (which differ from federal PDPL).
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @zanii/walls @zanii/policy @zanii/core
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { WALLS, wallPolicy, wallManifestHash, checkOutput, buildEvalReceipt } from '@zanii/walls';
|
|
20
|
+
import { createPolicyEngine } from '@zanii/policy';
|
|
21
|
+
|
|
22
|
+
const wall = WALLS['sca-trading'];
|
|
23
|
+
|
|
24
|
+
// 1. enforce the wall (deny what it forbids):
|
|
25
|
+
const engine = createPolicyEngine(wallPolicy(wall));
|
|
26
|
+
engine.evaluate({ target: 'trading.execute.order' }).decision; // 'deny'
|
|
27
|
+
|
|
28
|
+
// 2. anchor the enforced rulebook — receipt this per deploy:
|
|
29
|
+
const manifestHash = wallManifestHash(wall);
|
|
30
|
+
|
|
31
|
+
// 3. catch a crossing at output time + receipt the eval suite:
|
|
32
|
+
checkOutput(wall, 'You should buy this now').ok; // false — flagged
|
|
33
|
+
await agent.record(buildEvalReceipt(wall, { passed: 23, failed: 0 }));
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`checkOutput` is a heuristic (phrase match) — a published, auditable first line; swap in a
|
|
37
|
+
classifier for higher assurance. `wallManifestHash` is order-independent (stable across deploys).
|
|
38
|
+
|
|
39
|
+
## Changelog
|
|
40
|
+
|
|
41
|
+
- **0.1.0** — initial release: `WALLS` (sca-trading, rera, tdra, legal, consumer, difc, adgm), `wallPolicy`, `wallManifestHash`, `checkOutput`, `buildEvalReceipt`.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
Apache-2.0.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface Wall {
|
|
2
|
+
id: string;
|
|
3
|
+
regulator: string;
|
|
4
|
+
/** Scopes the agent MAY be granted. */
|
|
5
|
+
scopes: string[];
|
|
6
|
+
/** The wall — scopes/targets the delegation must never grant. */
|
|
7
|
+
denies: string[];
|
|
8
|
+
/** Output phrases the eval flags (heuristic; upgrade to a classifier as needed). */
|
|
9
|
+
forbidden: string[];
|
|
10
|
+
note: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const WALLS: Record<string, Wall>;
|
|
13
|
+
/** A `@zanii/policy` config that denies everything the wall forbids. Pass to `createPolicyEngine`. */
|
|
14
|
+
export declare function wallPolicy(wall: Wall): {
|
|
15
|
+
default: 'allow';
|
|
16
|
+
rules: Array<{
|
|
17
|
+
id: string;
|
|
18
|
+
effect: 'deny';
|
|
19
|
+
targets: string[];
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
/** Deterministic hash of the wall — receipt it per deploy so the enforced rulebook is provably unaltered. */
|
|
23
|
+
export declare function wallManifestHash(wall: Wall): string;
|
|
24
|
+
export interface OutputCheck {
|
|
25
|
+
ok: boolean;
|
|
26
|
+
violations: string[];
|
|
27
|
+
}
|
|
28
|
+
/** Heuristic eval: does an agent output cross the wall (e.g. say "buy this")? */
|
|
29
|
+
export declare function checkOutput(wall: Wall, text: string): OutputCheck;
|
|
30
|
+
/** Receipt a wall's eval-suite results — a published, auditable artifact. `wall.<id>.eval`. */
|
|
31
|
+
export declare function buildEvalReceipt(wall: Wall, results: {
|
|
32
|
+
passed: number;
|
|
33
|
+
failed: number;
|
|
34
|
+
suite?: string;
|
|
35
|
+
}): {
|
|
36
|
+
target: string;
|
|
37
|
+
payload: Record<string, unknown>;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,iEAAiE;IACjE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,oFAAoF;IACpF,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAgDtC,CAAC;AAEF,sGAAsG;AACtG,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,CAE5H;AAED,6GAA6G;AAC7G,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEnD;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAIjE;AAED,+FAA+F;AAC/F,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAS9J"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zanii/walls — UAE vertical "wall" presets as enforceable, auditable artifacts.
|
|
3
|
+
*
|
|
4
|
+
* A wall = a scope the delegation never grants + a policy that denies the risky action +
|
|
5
|
+
* a `manifest_hash` you receipt per deploy (so the enforced rulebook is provably
|
|
6
|
+
* unaltered, not just the prose). Flagship: **SCA trading** — "education only, NEVER
|
|
7
|
+
* 'buy this'", the most sensitive vertical (licensed activity). Plus RERA/TDRA/Legal/
|
|
8
|
+
* Consumer and DIFC/ADGM free-zone data-protection variants.
|
|
9
|
+
*
|
|
10
|
+
* `wallPolicy(wall)` → a `@zanii/policy` config; `wallManifestHash(wall)` → the anchor;
|
|
11
|
+
* `checkOutput(wall, text)` → a heuristic eval; `buildEvalReceipt(...)` → receipt the results.
|
|
12
|
+
*/
|
|
13
|
+
import { jcsHash } from '@zanii/core';
|
|
14
|
+
export const WALLS = {
|
|
15
|
+
'sca-trading': {
|
|
16
|
+
id: 'sca-trading', regulator: 'SCA',
|
|
17
|
+
scopes: ['trading.education.*', 'market.read.*'],
|
|
18
|
+
denies: ['trading.execute.*', 'trading.advise.*', 'trading.recommend.*'],
|
|
19
|
+
forbidden: ['buy this', 'sell this', 'you should buy', 'you should sell', 'i recommend buying',
|
|
20
|
+
'i recommend selling', 'guaranteed return', 'guaranteed profit', 'this will go up', 'will moon'],
|
|
21
|
+
note: 'education only; NEVER "buy this" — investment advice/execution is a licensed SCA activity',
|
|
22
|
+
},
|
|
23
|
+
'rera-realty': {
|
|
24
|
+
id: 'rera-realty', regulator: 'RERA/DLD',
|
|
25
|
+
scopes: ['realty.inform.*', 'realty.read.*'],
|
|
26
|
+
denies: ['realty.broker.*', 'realty.list.*'],
|
|
27
|
+
forbidden: ['i can broker', 'i will list', 'sign the deal'],
|
|
28
|
+
note: 'informs; never brokers or lists unpermitted properties',
|
|
29
|
+
},
|
|
30
|
+
'tdra-messaging': {
|
|
31
|
+
id: 'tdra-messaging', regulator: 'TDRA',
|
|
32
|
+
scopes: ['messaging.send.optin.*'],
|
|
33
|
+
denies: ['messaging.send.bulk.*', 'messaging.send.nonoptin.*'],
|
|
34
|
+
forbidden: [],
|
|
35
|
+
note: 'opt-in only; must announce it is a bot',
|
|
36
|
+
},
|
|
37
|
+
'legal-drafting': {
|
|
38
|
+
id: 'legal-drafting', regulator: 'Legal Affairs',
|
|
39
|
+
scopes: ['legal.draft.*', 'legal.read.*'],
|
|
40
|
+
denies: ['legal.opine.*', 'legal.advise.*'],
|
|
41
|
+
forbidden: ['my legal opinion is', 'you should sue', 'this is legally binding advice'],
|
|
42
|
+
note: 'drafts; never gives legal opinions',
|
|
43
|
+
},
|
|
44
|
+
'consumer-due': {
|
|
45
|
+
id: 'consumer-due', regulator: 'Consumer Protection / Central Bank',
|
|
46
|
+
scopes: ['collections.remind.*'],
|
|
47
|
+
denies: ['collections.threaten.*'],
|
|
48
|
+
forbidden: ['we will sue you', 'legal action today', 'you will be arrested'],
|
|
49
|
+
note: 'reminds; never threatens; frequency limits',
|
|
50
|
+
},
|
|
51
|
+
// Free-zone data-protection variants (differ from federal PDPL).
|
|
52
|
+
'difc-dp': {
|
|
53
|
+
id: 'difc-dp', regulator: 'DIFC (DP Law 2020)',
|
|
54
|
+
scopes: ['data.process.difc.*'], denies: ['data.export.nonadequate.*'], forbidden: [],
|
|
55
|
+
note: 'DIFC free-zone data protection; select per deployment (not federal PDPL)',
|
|
56
|
+
},
|
|
57
|
+
'adgm-dp': {
|
|
58
|
+
id: 'adgm-dp', regulator: 'ADGM (DP Regs 2021)',
|
|
59
|
+
scopes: ['data.process.adgm.*'], denies: ['data.export.nonadequate.*'], forbidden: [],
|
|
60
|
+
note: 'ADGM free-zone data protection; select per deployment (not federal PDPL)',
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
/** A `@zanii/policy` config that denies everything the wall forbids. Pass to `createPolicyEngine`. */
|
|
64
|
+
export function wallPolicy(wall) {
|
|
65
|
+
return { default: 'allow', rules: [{ id: `${wall.id}-wall`, effect: 'deny', targets: wall.denies }] };
|
|
66
|
+
}
|
|
67
|
+
/** Deterministic hash of the wall — receipt it per deploy so the enforced rulebook is provably unaltered. */
|
|
68
|
+
export function wallManifestHash(wall) {
|
|
69
|
+
return jcsHash({ id: wall.id, scopes: [...wall.scopes].sort(), denies: [...wall.denies].sort() });
|
|
70
|
+
}
|
|
71
|
+
/** Heuristic eval: does an agent output cross the wall (e.g. say "buy this")? */
|
|
72
|
+
export function checkOutput(wall, text) {
|
|
73
|
+
const lower = text.toLowerCase();
|
|
74
|
+
const violations = wall.forbidden.filter((phrase) => lower.includes(phrase));
|
|
75
|
+
return { ok: violations.length === 0, violations };
|
|
76
|
+
}
|
|
77
|
+
/** Receipt a wall's eval-suite results — a published, auditable artifact. `wall.<id>.eval`. */
|
|
78
|
+
export function buildEvalReceipt(wall, results) {
|
|
79
|
+
return {
|
|
80
|
+
target: `wall.${wall.id}.eval`,
|
|
81
|
+
payload: {
|
|
82
|
+
_zr_kind: 'wall_eval', v: 1, wall: wall.id, regulator: wall.regulator,
|
|
83
|
+
manifest_hash: wallManifestHash(wall), passed: results.passed, failed: results.failed,
|
|
84
|
+
suite: results.suite, ok: results.failed === 0,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AActC,MAAM,CAAC,MAAM,KAAK,GAAyB;IACzC,aAAa,EAAE;QACb,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,KAAK;QACnC,MAAM,EAAE,CAAC,qBAAqB,EAAE,eAAe,CAAC;QAChD,MAAM,EAAE,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,qBAAqB,CAAC;QACxE,SAAS,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,oBAAoB;YAC5F,qBAAqB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,WAAW,CAAC;QAClG,IAAI,EAAE,2FAA2F;KAClG;IACD,aAAa,EAAE;QACb,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU;QACxC,MAAM,EAAE,CAAC,iBAAiB,EAAE,eAAe,CAAC;QAC5C,MAAM,EAAE,CAAC,iBAAiB,EAAE,eAAe,CAAC;QAC5C,SAAS,EAAE,CAAC,cAAc,EAAE,aAAa,EAAE,eAAe,CAAC;QAC3D,IAAI,EAAE,wDAAwD;KAC/D;IACD,gBAAgB,EAAE;QAChB,EAAE,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM;QACvC,MAAM,EAAE,CAAC,wBAAwB,CAAC;QAClC,MAAM,EAAE,CAAC,uBAA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1
|
+
{
|
|
2
|
+
"name": "@zanii/walls",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "UAE vertical 'wall' presets as enforceable, auditable artifacts - scopes never granted + a policy config + a manifest_hash + a receipted eval. SCA trading ('education only, never buy this'), RERA, TDRA, Legal, Consumer, DIFC/ADGM.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://ledger.zanii.agency",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^26.1.0",
|
|
30
|
+
"typescript": "^5.8.2",
|
|
31
|
+
"vitest": "^3.0.9"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@zanii/core": "0.3.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.build.json",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"typecheck": "tsc --noEmit"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zanii/walls — UAE vertical "wall" presets as enforceable, auditable artifacts.
|
|
3
|
+
*
|
|
4
|
+
* A wall = a scope the delegation never grants + a policy that denies the risky action +
|
|
5
|
+
* a `manifest_hash` you receipt per deploy (so the enforced rulebook is provably
|
|
6
|
+
* unaltered, not just the prose). Flagship: **SCA trading** — "education only, NEVER
|
|
7
|
+
* 'buy this'", the most sensitive vertical (licensed activity). Plus RERA/TDRA/Legal/
|
|
8
|
+
* Consumer and DIFC/ADGM free-zone data-protection variants.
|
|
9
|
+
*
|
|
10
|
+
* `wallPolicy(wall)` → a `@zanii/policy` config; `wallManifestHash(wall)` → the anchor;
|
|
11
|
+
* `checkOutput(wall, text)` → a heuristic eval; `buildEvalReceipt(...)` → receipt the results.
|
|
12
|
+
*/
|
|
13
|
+
import { jcsHash } from '@zanii/core';
|
|
14
|
+
|
|
15
|
+
export interface Wall {
|
|
16
|
+
id: string;
|
|
17
|
+
regulator: string;
|
|
18
|
+
/** Scopes the agent MAY be granted. */
|
|
19
|
+
scopes: string[];
|
|
20
|
+
/** The wall — scopes/targets the delegation must never grant. */
|
|
21
|
+
denies: string[];
|
|
22
|
+
/** Output phrases the eval flags (heuristic; upgrade to a classifier as needed). */
|
|
23
|
+
forbidden: string[];
|
|
24
|
+
note: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const WALLS: Record<string, Wall> = {
|
|
28
|
+
'sca-trading': {
|
|
29
|
+
id: 'sca-trading', regulator: 'SCA',
|
|
30
|
+
scopes: ['trading.education.*', 'market.read.*'],
|
|
31
|
+
denies: ['trading.execute.*', 'trading.advise.*', 'trading.recommend.*'],
|
|
32
|
+
forbidden: ['buy this', 'sell this', 'you should buy', 'you should sell', 'i recommend buying',
|
|
33
|
+
'i recommend selling', 'guaranteed return', 'guaranteed profit', 'this will go up', 'will moon'],
|
|
34
|
+
note: 'education only; NEVER "buy this" — investment advice/execution is a licensed SCA activity',
|
|
35
|
+
},
|
|
36
|
+
'rera-realty': {
|
|
37
|
+
id: 'rera-realty', regulator: 'RERA/DLD',
|
|
38
|
+
scopes: ['realty.inform.*', 'realty.read.*'],
|
|
39
|
+
denies: ['realty.broker.*', 'realty.list.*'],
|
|
40
|
+
forbidden: ['i can broker', 'i will list', 'sign the deal'],
|
|
41
|
+
note: 'informs; never brokers or lists unpermitted properties',
|
|
42
|
+
},
|
|
43
|
+
'tdra-messaging': {
|
|
44
|
+
id: 'tdra-messaging', regulator: 'TDRA',
|
|
45
|
+
scopes: ['messaging.send.optin.*'],
|
|
46
|
+
denies: ['messaging.send.bulk.*', 'messaging.send.nonoptin.*'],
|
|
47
|
+
forbidden: [],
|
|
48
|
+
note: 'opt-in only; must announce it is a bot',
|
|
49
|
+
},
|
|
50
|
+
'legal-drafting': {
|
|
51
|
+
id: 'legal-drafting', regulator: 'Legal Affairs',
|
|
52
|
+
scopes: ['legal.draft.*', 'legal.read.*'],
|
|
53
|
+
denies: ['legal.opine.*', 'legal.advise.*'],
|
|
54
|
+
forbidden: ['my legal opinion is', 'you should sue', 'this is legally binding advice'],
|
|
55
|
+
note: 'drafts; never gives legal opinions',
|
|
56
|
+
},
|
|
57
|
+
'consumer-due': {
|
|
58
|
+
id: 'consumer-due', regulator: 'Consumer Protection / Central Bank',
|
|
59
|
+
scopes: ['collections.remind.*'],
|
|
60
|
+
denies: ['collections.threaten.*'],
|
|
61
|
+
forbidden: ['we will sue you', 'legal action today', 'you will be arrested'],
|
|
62
|
+
note: 'reminds; never threatens; frequency limits',
|
|
63
|
+
},
|
|
64
|
+
// Free-zone data-protection variants (differ from federal PDPL).
|
|
65
|
+
'difc-dp': {
|
|
66
|
+
id: 'difc-dp', regulator: 'DIFC (DP Law 2020)',
|
|
67
|
+
scopes: ['data.process.difc.*'], denies: ['data.export.nonadequate.*'], forbidden: [],
|
|
68
|
+
note: 'DIFC free-zone data protection; select per deployment (not federal PDPL)',
|
|
69
|
+
},
|
|
70
|
+
'adgm-dp': {
|
|
71
|
+
id: 'adgm-dp', regulator: 'ADGM (DP Regs 2021)',
|
|
72
|
+
scopes: ['data.process.adgm.*'], denies: ['data.export.nonadequate.*'], forbidden: [],
|
|
73
|
+
note: 'ADGM free-zone data protection; select per deployment (not federal PDPL)',
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** A `@zanii/policy` config that denies everything the wall forbids. Pass to `createPolicyEngine`. */
|
|
78
|
+
export function wallPolicy(wall: Wall): { default: 'allow'; rules: Array<{ id: string; effect: 'deny'; targets: string[] }> } {
|
|
79
|
+
return { default: 'allow', rules: [{ id: `${wall.id}-wall`, effect: 'deny', targets: wall.denies }] };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Deterministic hash of the wall — receipt it per deploy so the enforced rulebook is provably unaltered. */
|
|
83
|
+
export function wallManifestHash(wall: Wall): string {
|
|
84
|
+
return jcsHash({ id: wall.id, scopes: [...wall.scopes].sort(), denies: [...wall.denies].sort() });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface OutputCheck {
|
|
88
|
+
ok: boolean;
|
|
89
|
+
violations: string[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Heuristic eval: does an agent output cross the wall (e.g. say "buy this")? */
|
|
93
|
+
export function checkOutput(wall: Wall, text: string): OutputCheck {
|
|
94
|
+
const lower = text.toLowerCase();
|
|
95
|
+
const violations = wall.forbidden.filter((phrase) => lower.includes(phrase));
|
|
96
|
+
return { ok: violations.length === 0, violations };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Receipt a wall's eval-suite results — a published, auditable artifact. `wall.<id>.eval`. */
|
|
100
|
+
export function buildEvalReceipt(wall: Wall, results: { passed: number; failed: number; suite?: string }): { target: string; payload: Record<string, unknown> } {
|
|
101
|
+
return {
|
|
102
|
+
target: `wall.${wall.id}.eval`,
|
|
103
|
+
payload: {
|
|
104
|
+
_zr_kind: 'wall_eval', v: 1, wall: wall.id, regulator: wall.regulator,
|
|
105
|
+
manifest_hash: wallManifestHash(wall), passed: results.passed, failed: results.failed,
|
|
106
|
+
suite: results.suite, ok: results.failed === 0,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|