@openagentsy/hooks 0.0.0-stage → 0.2.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 +674 -0
- package/README.md +32 -2
- package/dist/accountability.d.ts +29 -0
- package/dist/accountability.d.ts.map +1 -0
- package/dist/accountability.js +21 -0
- package/dist/accountability.js.map +1 -0
- package/dist/accountability.test.d.ts +2 -0
- package/dist/accountability.test.d.ts.map +1 -0
- package/dist/accountability.test.js +42 -0
- package/dist/accountability.test.js.map +1 -0
- package/dist/approvals.d.ts +110 -0
- package/dist/approvals.d.ts.map +1 -0
- package/dist/approvals.js +464 -0
- package/dist/approvals.js.map +1 -0
- package/dist/approvals.test.d.ts +2 -0
- package/dist/approvals.test.d.ts.map +1 -0
- package/dist/approvals.test.js +307 -0
- package/dist/approvals.test.js.map +1 -0
- package/dist/base-tool.d.ts +26 -0
- package/dist/base-tool.d.ts.map +1 -0
- package/dist/base-tool.js +37 -0
- package/dist/base-tool.js.map +1 -0
- package/dist/base-tool.test.d.ts +2 -0
- package/dist/base-tool.test.d.ts.map +1 -0
- package/dist/base-tool.test.js +34 -0
- package/dist/base-tool.test.js.map +1 -0
- package/dist/eval/index.d.ts +3 -0
- package/dist/eval/index.d.ts.map +1 -0
- package/dist/eval/index.js +3 -0
- package/dist/eval/index.js.map +1 -0
- package/dist/eval/runner.d.ts +179 -0
- package/dist/eval/runner.d.ts.map +1 -0
- package/dist/eval/runner.js +616 -0
- package/dist/eval/runner.js.map +1 -0
- package/dist/eval/runner.test.d.ts +2 -0
- package/dist/eval/runner.test.d.ts.map +1 -0
- package/dist/eval/runner.test.js +431 -0
- package/dist/eval/runner.test.js.map +1 -0
- package/dist/eval/types.d.ts +173 -0
- package/dist/eval/types.d.ts.map +1 -0
- package/dist/eval/types.js +104 -0
- package/dist/eval/types.js.map +1 -0
- package/dist/event.d.ts +59 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +178 -0
- package/dist/event.js.map +1 -0
- package/dist/event.test.d.ts +2 -0
- package/dist/event.test.d.ts.map +1 -0
- package/dist/event.test.js +49 -0
- package/dist/event.test.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/lessons/capture.d.ts +66 -0
- package/dist/lessons/capture.d.ts.map +1 -0
- package/dist/lessons/capture.js +166 -0
- package/dist/lessons/capture.js.map +1 -0
- package/dist/lessons/capture.test.d.ts +2 -0
- package/dist/lessons/capture.test.d.ts.map +1 -0
- package/dist/lessons/capture.test.js +200 -0
- package/dist/lessons/capture.test.js.map +1 -0
- package/dist/lessons/decide.d.ts +90 -0
- package/dist/lessons/decide.d.ts.map +1 -0
- package/dist/lessons/decide.js +334 -0
- package/dist/lessons/decide.js.map +1 -0
- package/dist/lessons/decide.test.d.ts +2 -0
- package/dist/lessons/decide.test.d.ts.map +1 -0
- package/dist/lessons/decide.test.js +527 -0
- package/dist/lessons/decide.test.js.map +1 -0
- package/dist/lessons/id.d.ts +5 -0
- package/dist/lessons/id.d.ts.map +1 -0
- package/dist/lessons/id.js +20 -0
- package/dist/lessons/id.js.map +1 -0
- package/dist/lessons/index.d.ts +5 -0
- package/dist/lessons/index.d.ts.map +1 -0
- package/dist/lessons/index.js +5 -0
- package/dist/lessons/index.js.map +1 -0
- package/dist/lessons/model.d.ts +163 -0
- package/dist/lessons/model.d.ts.map +1 -0
- package/dist/lessons/model.js +181 -0
- package/dist/lessons/model.js.map +1 -0
- package/dist/lessons/model.test.d.ts +2 -0
- package/dist/lessons/model.test.d.ts.map +1 -0
- package/dist/lessons/model.test.js +178 -0
- package/dist/lessons/model.test.js.map +1 -0
- package/dist/lessons/permissions.test.d.ts +2 -0
- package/dist/lessons/permissions.test.d.ts.map +1 -0
- package/dist/lessons/permissions.test.js +88 -0
- package/dist/lessons/permissions.test.js.map +1 -0
- package/dist/lessons/store.d.ts +74 -0
- package/dist/lessons/store.d.ts.map +1 -0
- package/dist/lessons/store.js +231 -0
- package/dist/lessons/store.js.map +1 -0
- package/dist/output-checks.d.ts +64 -0
- package/dist/output-checks.d.ts.map +1 -0
- package/dist/output-checks.js +248 -0
- package/dist/output-checks.js.map +1 -0
- package/dist/output-checks.test.d.ts +2 -0
- package/dist/output-checks.test.d.ts.map +1 -0
- package/dist/output-checks.test.js +58 -0
- package/dist/output-checks.test.js.map +1 -0
- package/dist/paths.d.ts +37 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +70 -0
- package/dist/paths.js.map +1 -0
- package/dist/paths.test.d.ts +2 -0
- package/dist/paths.test.d.ts.map +1 -0
- package/dist/paths.test.js +36 -0
- package/dist/paths.test.js.map +1 -0
- package/dist/policies/agi-framing.d.ts +12 -0
- package/dist/policies/agi-framing.d.ts.map +1 -0
- package/dist/policies/agi-framing.js +33 -0
- package/dist/policies/agi-framing.js.map +1 -0
- package/dist/policies/anti-anthropomorphism.d.ts +13 -0
- package/dist/policies/anti-anthropomorphism.d.ts.map +1 -0
- package/dist/policies/anti-anthropomorphism.js +34 -0
- package/dist/policies/anti-anthropomorphism.js.map +1 -0
- package/dist/policies/anti-dependence.d.ts +12 -0
- package/dist/policies/anti-dependence.d.ts.map +1 -0
- package/dist/policies/anti-dependence.js +33 -0
- package/dist/policies/anti-dependence.js.map +1 -0
- package/dist/policies/anti-sycophancy.d.ts +13 -0
- package/dist/policies/anti-sycophancy.d.ts.map +1 -0
- package/dist/policies/anti-sycophancy.js +34 -0
- package/dist/policies/anti-sycophancy.js.map +1 -0
- package/dist/policies/dark-pattern.d.ts +14 -0
- package/dist/policies/dark-pattern.d.ts.map +1 -0
- package/dist/policies/dark-pattern.js +44 -0
- package/dist/policies/dark-pattern.js.map +1 -0
- package/dist/policies/destructive-needs-approval.d.ts +14 -0
- package/dist/policies/destructive-needs-approval.d.ts.map +1 -0
- package/dist/policies/destructive-needs-approval.js +31 -0
- package/dist/policies/destructive-needs-approval.js.map +1 -0
- package/dist/policies/discovery.d.ts +12 -0
- package/dist/policies/discovery.d.ts.map +1 -0
- package/dist/policies/discovery.js +130 -0
- package/dist/policies/discovery.js.map +1 -0
- package/dist/policies/high-risk.d.ts +25 -0
- package/dist/policies/high-risk.d.ts.map +1 -0
- package/dist/policies/high-risk.js +105 -0
- package/dist/policies/high-risk.js.map +1 -0
- package/dist/policies/human-only-decisions.d.ts +14 -0
- package/dist/policies/human-only-decisions.d.ts.map +1 -0
- package/dist/policies/human-only-decisions.js +33 -0
- package/dist/policies/human-only-decisions.js.map +1 -0
- package/dist/policies/index.d.ts +29 -0
- package/dist/policies/index.d.ts.map +1 -0
- package/dist/policies/index.js +82 -0
- package/dist/policies/index.js.map +1 -0
- package/dist/policies/no-skip-git-hooks.d.ts +14 -0
- package/dist/policies/no-skip-git-hooks.d.ts.map +1 -0
- package/dist/policies/no-skip-git-hooks.js +31 -0
- package/dist/policies/no-skip-git-hooks.js.map +1 -0
- package/dist/policies/package-manager.d.ts +12 -0
- package/dist/policies/package-manager.d.ts.map +1 -0
- package/dist/policies/package-manager.js +29 -0
- package/dist/policies/package-manager.js.map +1 -0
- package/dist/policies/patterns.d.ts +17 -0
- package/dist/policies/patterns.d.ts.map +1 -0
- package/dist/policies/patterns.js +30 -0
- package/dist/policies/patterns.js.map +1 -0
- package/dist/policies/policies.test.d.ts +2 -0
- package/dist/policies/policies.test.d.ts.map +1 -0
- package/dist/policies/policies.test.js +210 -0
- package/dist/policies/policies.test.js.map +1 -0
- package/dist/policies/privacy-transparency.d.ts +14 -0
- package/dist/policies/privacy-transparency.d.ts.map +1 -0
- package/dist/policies/privacy-transparency.js +50 -0
- package/dist/policies/privacy-transparency.js.map +1 -0
- package/dist/policies/professional-displacement.d.ts +15 -0
- package/dist/policies/professional-displacement.d.ts.map +1 -0
- package/dist/policies/professional-displacement.js +45 -0
- package/dist/policies/professional-displacement.js.map +1 -0
- package/dist/policies/protect-policy.d.ts +14 -0
- package/dist/policies/protect-policy.d.ts.map +1 -0
- package/dist/policies/protect-policy.js +35 -0
- package/dist/policies/protect-policy.js.map +1 -0
- package/dist/policies/scope-enforcement.d.ts +14 -0
- package/dist/policies/scope-enforcement.d.ts.map +1 -0
- package/dist/policies/scope-enforcement.js +34 -0
- package/dist/policies/scope-enforcement.js.map +1 -0
- package/dist/policies/secret-scan-writes.d.ts +13 -0
- package/dist/policies/secret-scan-writes.d.ts.map +1 -0
- package/dist/policies/secret-scan-writes.js +38 -0
- package/dist/policies/secret-scan-writes.js.map +1 -0
- package/dist/policies/selection.d.ts +20 -0
- package/dist/policies/selection.d.ts.map +1 -0
- package/dist/policies/selection.js +93 -0
- package/dist/policies/selection.js.map +1 -0
- package/dist/policies/structural-bias.d.ts +14 -0
- package/dist/policies/structural-bias.d.ts.map +1 -0
- package/dist/policies/structural-bias.js +41 -0
- package/dist/policies/structural-bias.js.map +1 -0
- package/dist/policies/third-party-impact.d.ts +13 -0
- package/dist/policies/third-party-impact.d.ts.map +1 -0
- package/dist/policies/third-party-impact.js +38 -0
- package/dist/policies/third-party-impact.js.map +1 -0
- package/dist/policies/tool-call.d.ts +38 -0
- package/dist/policies/tool-call.d.ts.map +1 -0
- package/dist/policies/tool-call.js +53 -0
- package/dist/policies/tool-call.js.map +1 -0
- package/dist/policies/truthfulness-uncertainty.d.ts +13 -0
- package/dist/policies/truthfulness-uncertainty.d.ts.map +1 -0
- package/dist/policies/truthfulness-uncertainty.js +45 -0
- package/dist/policies/truthfulness-uncertainty.js.map +1 -0
- package/dist/policies/workspace-writes-only.d.ts +25 -0
- package/dist/policies/workspace-writes-only.d.ts.map +1 -0
- package/dist/policies/workspace-writes-only.js +54 -0
- package/dist/policies/workspace-writes-only.js.map +1 -0
- package/dist/policy-engine.d.ts +69 -0
- package/dist/policy-engine.d.ts.map +1 -0
- package/dist/policy-engine.js +145 -0
- package/dist/policy-engine.js.map +1 -0
- package/dist/policy-registry.d.ts +62 -0
- package/dist/policy-registry.d.ts.map +1 -0
- package/dist/policy-registry.js +63 -0
- package/dist/policy-registry.js.map +1 -0
- package/dist/policy-registry.test.d.ts +2 -0
- package/dist/policy-registry.test.d.ts.map +1 -0
- package/dist/policy-registry.test.js +79 -0
- package/dist/policy-registry.test.js.map +1 -0
- package/dist/policy-release.d.ts +44 -0
- package/dist/policy-release.d.ts.map +1 -0
- package/dist/policy-release.js +65 -0
- package/dist/policy-release.js.map +1 -0
- package/dist/policy.d.ts +141 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +22 -0
- package/dist/policy.js.map +1 -0
- package/dist/quality/audit.d.ts +56 -0
- package/dist/quality/audit.d.ts.map +1 -0
- package/dist/quality/audit.js +52 -0
- package/dist/quality/audit.js.map +1 -0
- package/dist/quality/findings.d.ts +34 -0
- package/dist/quality/findings.d.ts.map +1 -0
- package/dist/quality/findings.js +121 -0
- package/dist/quality/findings.js.map +1 -0
- package/dist/quality/findings.test.d.ts +2 -0
- package/dist/quality/findings.test.d.ts.map +1 -0
- package/dist/quality/findings.test.js +79 -0
- package/dist/quality/findings.test.js.map +1 -0
- package/dist/quality/index.d.ts +20 -0
- package/dist/quality/index.d.ts.map +1 -0
- package/dist/quality/index.js +20 -0
- package/dist/quality/index.js.map +1 -0
- package/dist/quality/rule.d.ts +43 -0
- package/dist/quality/rule.d.ts.map +1 -0
- package/dist/quality/rule.js +162 -0
- package/dist/quality/rule.js.map +1 -0
- package/dist/quality/rule.test.d.ts +2 -0
- package/dist/quality/rule.test.d.ts.map +1 -0
- package/dist/quality/rule.test.js +187 -0
- package/dist/quality/rule.test.js.map +1 -0
- package/dist/quality/tools.d.ts +30 -0
- package/dist/quality/tools.d.ts.map +1 -0
- package/dist/quality/tools.js +33 -0
- package/dist/quality/tools.js.map +1 -0
- package/dist/quality/tools.test.d.ts +2 -0
- package/dist/quality/tools.test.d.ts.map +1 -0
- package/dist/quality/tools.test.js +41 -0
- package/dist/quality/tools.test.js.map +1 -0
- package/dist/quality/waive.d.ts +37 -0
- package/dist/quality/waive.d.ts.map +1 -0
- package/dist/quality/waive.js +39 -0
- package/dist/quality/waive.js.map +1 -0
- package/dist/quality/waivers.d.ts +63 -0
- package/dist/quality/waivers.d.ts.map +1 -0
- package/dist/quality/waivers.js +132 -0
- package/dist/quality/waivers.js.map +1 -0
- package/dist/quality/waivers.test.d.ts +2 -0
- package/dist/quality/waivers.test.d.ts.map +1 -0
- package/dist/quality/waivers.test.js +138 -0
- package/dist/quality/waivers.test.js.map +1 -0
- package/dist/registry.d.ts +86 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +92 -0
- package/dist/registry.js.map +1 -0
- package/dist/registry.test.d.ts +2 -0
- package/dist/registry.test.d.ts.map +1 -0
- package/dist/registry.test.js +117 -0
- package/dist/registry.test.js.map +1 -0
- package/dist/rules.d.ts +107 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/rules.js +632 -0
- package/dist/rules.js.map +1 -0
- package/dist/rules.test.d.ts +2 -0
- package/dist/rules.test.d.ts.map +1 -0
- package/dist/rules.test.js +488 -0
- package/dist/rules.test.js.map +1 -0
- package/dist/secrets.d.ts +17 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +17 -0
- package/dist/secrets.js.map +1 -0
- package/dist/secrets.test.d.ts +2 -0
- package/dist/secrets.test.d.ts.map +1 -0
- package/dist/secrets.test.js +20 -0
- package/dist/secrets.test.js.map +1 -0
- package/dist/shell-env.d.ts +23 -0
- package/dist/shell-env.d.ts.map +1 -0
- package/dist/shell-env.js +34 -0
- package/dist/shell-env.js.map +1 -0
- package/dist/shell-env.test.d.ts +2 -0
- package/dist/shell-env.test.d.ts.map +1 -0
- package/dist/shell-env.test.js +45 -0
- package/dist/shell-env.test.js.map +1 -0
- package/package.json +49 -4
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The discovery of the policy modules a plugin brought (§21).
|
|
3
|
+
*
|
|
4
|
+
* A downstream project drops a module into `packages/hooks/src/policies/`
|
|
5
|
+
* and the host loads it. The host cannot trust what it loaded, so the shape
|
|
6
|
+
* is checked here: an id that is not a string, a version that is not a
|
|
7
|
+
* version, or a decision that is not a function is not a policy, and a
|
|
8
|
+
* module that fails the check is not in the stack.
|
|
9
|
+
*
|
|
10
|
+
* A module that came from a plugin is marked `external`, and an external
|
|
11
|
+
* module does not count towards the first-party release criteria.
|
|
12
|
+
*/
|
|
13
|
+
/** The layers a module may act at. */
|
|
14
|
+
const LAYERS = [1, 2, 3, 4, 5, 6, 7, 8];
|
|
15
|
+
/** The moments a module may be checked at. */
|
|
16
|
+
const MOMENTS = [
|
|
17
|
+
'UserPromptSubmit',
|
|
18
|
+
'PreToolCall',
|
|
19
|
+
'PostToolCall',
|
|
20
|
+
'PreResponse',
|
|
21
|
+
'PostResponse',
|
|
22
|
+
'PreCompact',
|
|
23
|
+
'SubagentStop',
|
|
24
|
+
];
|
|
25
|
+
/** Whether a version is a version. */
|
|
26
|
+
export function isSemver(version) {
|
|
27
|
+
return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(version);
|
|
28
|
+
}
|
|
29
|
+
/** The record of a candidate, as far as it is one. */
|
|
30
|
+
function readCandidate(candidate) {
|
|
31
|
+
if (typeof candidate !== 'object' || candidate === null)
|
|
32
|
+
return undefined;
|
|
33
|
+
return candidate;
|
|
34
|
+
}
|
|
35
|
+
/** The id of a candidate. */
|
|
36
|
+
function readId(record) {
|
|
37
|
+
const id = record['id'];
|
|
38
|
+
if (typeof id !== 'string' || id.length === 0)
|
|
39
|
+
return undefined;
|
|
40
|
+
return id;
|
|
41
|
+
}
|
|
42
|
+
/** The version of a candidate. */
|
|
43
|
+
function readVersion(record) {
|
|
44
|
+
const version = record['version'];
|
|
45
|
+
if (typeof version !== 'string' || !isSemver(version))
|
|
46
|
+
return undefined;
|
|
47
|
+
return version;
|
|
48
|
+
}
|
|
49
|
+
/** The layer of a candidate. */
|
|
50
|
+
function readLayer(record) {
|
|
51
|
+
const layer = record['layer'];
|
|
52
|
+
if (typeof layer !== 'number')
|
|
53
|
+
return undefined;
|
|
54
|
+
if (!LAYERS.includes(layer))
|
|
55
|
+
return undefined;
|
|
56
|
+
return layer;
|
|
57
|
+
}
|
|
58
|
+
/** The moments of a candidate. */
|
|
59
|
+
function readMoments(record) {
|
|
60
|
+
const appliesTo = record['appliesTo'];
|
|
61
|
+
if (!Array.isArray(appliesTo))
|
|
62
|
+
return undefined;
|
|
63
|
+
if (!appliesTo.every((moment) => MOMENTS.includes(moment)))
|
|
64
|
+
return undefined;
|
|
65
|
+
return appliesTo;
|
|
66
|
+
}
|
|
67
|
+
/** The decision of a candidate. */
|
|
68
|
+
function readDecision(record) {
|
|
69
|
+
const evaluate = record['evaluate'];
|
|
70
|
+
if (typeof evaluate !== 'function')
|
|
71
|
+
return undefined;
|
|
72
|
+
return evaluate;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The policy a candidate is, when it is one.
|
|
76
|
+
*
|
|
77
|
+
* The candidate is read field by field, and a field that is missing or of
|
|
78
|
+
* the wrong shape makes the whole candidate not a policy: a module that
|
|
79
|
+
* half-loads is worse than a module that does not load at all.
|
|
80
|
+
*/
|
|
81
|
+
function toPolicyModule(candidate) {
|
|
82
|
+
const record = readCandidate(candidate);
|
|
83
|
+
if (record === undefined)
|
|
84
|
+
return undefined;
|
|
85
|
+
const id = readId(record);
|
|
86
|
+
const version = readVersion(record);
|
|
87
|
+
const layer = readLayer(record);
|
|
88
|
+
const description = record['description'];
|
|
89
|
+
const appliesTo = readMoments(record);
|
|
90
|
+
const evaluate = readDecision(record);
|
|
91
|
+
if (id === undefined)
|
|
92
|
+
return undefined;
|
|
93
|
+
if (version === undefined)
|
|
94
|
+
return undefined;
|
|
95
|
+
if (layer === undefined)
|
|
96
|
+
return undefined;
|
|
97
|
+
if (typeof description !== 'string')
|
|
98
|
+
return undefined;
|
|
99
|
+
if (appliesTo === undefined)
|
|
100
|
+
return undefined;
|
|
101
|
+
if (evaluate === undefined)
|
|
102
|
+
return undefined;
|
|
103
|
+
return {
|
|
104
|
+
id,
|
|
105
|
+
version,
|
|
106
|
+
layer,
|
|
107
|
+
description,
|
|
108
|
+
appliesTo,
|
|
109
|
+
origin: 'external',
|
|
110
|
+
evaluate,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The policies among the candidates.
|
|
115
|
+
*
|
|
116
|
+
* A candidate that is not a policy is dropped, and the ones that are are
|
|
117
|
+
* marked external unless they say otherwise: a module that came from a
|
|
118
|
+
* plugin is the plugin's, whatever it says about its origin.
|
|
119
|
+
*/
|
|
120
|
+
export function discoverPolicyModules(candidates) {
|
|
121
|
+
const found = [];
|
|
122
|
+
for (const candidate of candidates) {
|
|
123
|
+
const module = toPolicyModule(candidate);
|
|
124
|
+
if (module === undefined)
|
|
125
|
+
continue;
|
|
126
|
+
found.push(module);
|
|
127
|
+
}
|
|
128
|
+
return found;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/policies/discovery.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type PolicyModule } from '../policy.js';
|
|
2
|
+
/**
|
|
3
|
+
* The high-risk domain policies (§21.2, §20.3).
|
|
4
|
+
*
|
|
5
|
+
* One module per domain of §20.3. The module is selected when the
|
|
6
|
+
* classifier fired on that domain (§21.4), and it flags the prose that
|
|
7
|
+
* touches it. It is a layer 4 module: the selection is layer 2, and the
|
|
8
|
+
* decision is about the output.
|
|
9
|
+
*/
|
|
10
|
+
/** The domains §20.3 names. */
|
|
11
|
+
export declare const HIGH_RISK_DOMAINS: readonly ["self-harm", "abuse", "medical", "legal", "financial", "criminal", "political", "relational", "automated-decision", "civic"];
|
|
12
|
+
/** The name of a high-risk domain. */
|
|
13
|
+
export type HighRiskDomain = (typeof HIGH_RISK_DOMAINS)[number];
|
|
14
|
+
/** The prefix every high-risk policy id carries. */
|
|
15
|
+
export declare const HIGH_RISK_PREFIX = "oa.high-risk.";
|
|
16
|
+
/**
|
|
17
|
+
* The policy of one high-risk domain.
|
|
18
|
+
*
|
|
19
|
+
* The id is the domain's, so a firing says which domain was in play, and
|
|
20
|
+
* the version is the policy's own.
|
|
21
|
+
*/
|
|
22
|
+
export declare function highRiskPolicy(domain: HighRiskDomain): PolicyModule;
|
|
23
|
+
/** The policies of every high-risk domain. */
|
|
24
|
+
export declare function highRiskPolicies(): PolicyModule[];
|
|
25
|
+
//# sourceMappingURL=high-risk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"high-risk.d.ts","sourceRoot":"","sources":["../../src/policies/high-risk.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAG1E;;;;;;;GAOG;AAEH,+BAA+B;AAC/B,eAAO,MAAM,iBAAiB,wIAWpB,CAAC;AAEX,sCAAsC;AACtC,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE,oDAAoD;AACpD,eAAO,MAAM,gBAAgB,kBAAkB,CAAC;AAoDhD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY,CAiBnE;AAED,8CAA8C;AAC9C,wBAAgB,gBAAgB,IAAI,YAAY,EAAE,CAEjD"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { allow, findingsOf, flag } from '../policy.js';
|
|
2
|
+
import { matches } from './patterns.js';
|
|
3
|
+
/**
|
|
4
|
+
* The high-risk domain policies (§21.2, §20.3).
|
|
5
|
+
*
|
|
6
|
+
* One module per domain of §20.3. The module is selected when the
|
|
7
|
+
* classifier fired on that domain (§21.4), and it flags the prose that
|
|
8
|
+
* touches it. It is a layer 4 module: the selection is layer 2, and the
|
|
9
|
+
* decision is about the output.
|
|
10
|
+
*/
|
|
11
|
+
/** The domains §20.3 names. */
|
|
12
|
+
export const HIGH_RISK_DOMAINS = [
|
|
13
|
+
'self-harm',
|
|
14
|
+
'abuse',
|
|
15
|
+
'medical',
|
|
16
|
+
'legal',
|
|
17
|
+
'financial',
|
|
18
|
+
'criminal',
|
|
19
|
+
'political',
|
|
20
|
+
'relational',
|
|
21
|
+
'automated-decision',
|
|
22
|
+
'civic',
|
|
23
|
+
];
|
|
24
|
+
/** The prefix every high-risk policy id carries. */
|
|
25
|
+
export const HIGH_RISK_PREFIX = 'oa.high-risk.';
|
|
26
|
+
/**
|
|
27
|
+
* The words of a domain.
|
|
28
|
+
*
|
|
29
|
+
* The lists are the prose signals of §20.3, and they are deliberately
|
|
30
|
+
* small: the classifier of §20.3 decides whether a domain is in play, and
|
|
31
|
+
* this module only says where the prose touches it.
|
|
32
|
+
*/
|
|
33
|
+
const DOMAIN_WORDS = {
|
|
34
|
+
'self-harm': [
|
|
35
|
+
/\b(?:self[- ]harm|suicid\w*|eating\s+disorder|anorexi\w*|bulimi\w*)\b/gi,
|
|
36
|
+
/\b(?:crisis\s+line|end\s+my\s+life|take\s+my\s+own\s+life)\b/gi,
|
|
37
|
+
],
|
|
38
|
+
abuse: [
|
|
39
|
+
/\b(?:abuse|coercive\s+control|stalking|domestic\s+violence)\b/gi,
|
|
40
|
+
/\b(?:violent\s+conflict|threat\w*\s+to\s+(?:hurt|harm))\b/gi,
|
|
41
|
+
],
|
|
42
|
+
medical: [
|
|
43
|
+
/\b(?:medical|clinical|diagnosis|dosage|prognosis|symptoms?\s+of)\b/gi,
|
|
44
|
+
/\b(?:prescri\w+|treatment\s+plan|patient)\b/gi,
|
|
45
|
+
],
|
|
46
|
+
legal: [
|
|
47
|
+
/\b(?:legal\s+advice|lawyer|attorney|litigat\w+|liability|statute)\b/gi,
|
|
48
|
+
/\b(?:court|prosecut\w+|defen[cs]e\s+rights)\b/gi,
|
|
49
|
+
],
|
|
50
|
+
financial: [
|
|
51
|
+
/\b(?:financial\s+advice|investment|tax\s+(?:advice|return)|mortgage|portfolio)\b/gi,
|
|
52
|
+
/\b(?:interest\s+rate|retirement\s+fund|insurance\s+advice)\b/gi,
|
|
53
|
+
],
|
|
54
|
+
criminal: [
|
|
55
|
+
/\b(?:evade\s+(?:the\s+)?(?:law|police)|criminal\s+activity|launder\w*)\b/gi,
|
|
56
|
+
/\b(?:cover\s+(?:up|your\s+tracks)|illegal\s+means)\b/gi,
|
|
57
|
+
],
|
|
58
|
+
political: [
|
|
59
|
+
/\b(?:political\s+persuasion|voter\s+suppression|targeted\s+influence)\b/gi,
|
|
60
|
+
/\b(?:campaign\s+messaging|identity[- ]based\s+(?:politics|persuasion))\b/gi,
|
|
61
|
+
],
|
|
62
|
+
relational: [
|
|
63
|
+
/\b(?:the\s+reviewer\s+was\s+wrong|they\s+are\s+the\s+problem\s+here)\b/gi,
|
|
64
|
+
/\b(?:moral\s+absolution|vindication|they\s+owe\s+me\s+an?\s+apology)\b/gi,
|
|
65
|
+
],
|
|
66
|
+
'automated-decision': [
|
|
67
|
+
/\b(?:ranks?\s+applicants|scores?\s+applicants|lending\s+model|rescoring)\b/gi,
|
|
68
|
+
/\b(?:hiring\s+model|automated\s+(?:hiring|lending|eviction)|public\s+benefits\s+decision)\b/gi,
|
|
69
|
+
],
|
|
70
|
+
civic: [
|
|
71
|
+
/\b(?:political\s+content\s+generation|generates?\s+political\s+content)\b/gi,
|
|
72
|
+
/\b(?:public\s+deliberation|voter\s+information\s+(?:campaign|service))\b/gi,
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The policy of one high-risk domain.
|
|
77
|
+
*
|
|
78
|
+
* The id is the domain's, so a firing says which domain was in play, and
|
|
79
|
+
* the version is the policy's own.
|
|
80
|
+
*/
|
|
81
|
+
export function highRiskPolicy(domain) {
|
|
82
|
+
const id = `${HIGH_RISK_PREFIX}${domain}`;
|
|
83
|
+
return {
|
|
84
|
+
id,
|
|
85
|
+
version: '1.0.0',
|
|
86
|
+
layer: 4,
|
|
87
|
+
description: `Flags the prose that touches the ${domain} domain (selected at layer 2).`,
|
|
88
|
+
appliesTo: ['UserPromptSubmit', 'PreResponse'],
|
|
89
|
+
origin: 'first-party',
|
|
90
|
+
evaluate(ctx) {
|
|
91
|
+
const text = ctx.response?.text ?? ctx.request?.text ?? '';
|
|
92
|
+
if (text === '')
|
|
93
|
+
return allow();
|
|
94
|
+
const found = matches(DOMAIN_WORDS[domain], text);
|
|
95
|
+
if (found.length === 0)
|
|
96
|
+
return allow();
|
|
97
|
+
return flag(findingsOf(id, 'high-risk-domain', found), 'error');
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** The policies of every high-risk domain. */
|
|
102
|
+
export function highRiskPolicies() {
|
|
103
|
+
return HIGH_RISK_DOMAINS.map((domain) => highRiskPolicy(domain));
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=high-risk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"high-risk.js","sourceRoot":"","sources":["../../src/policies/high-risk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAqB,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC;;;;;;;GAOG;AAEH,+BAA+B;AAC/B,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,WAAW;IACX,OAAO;IACP,SAAS;IACT,OAAO;IACP,WAAW;IACX,UAAU;IACV,WAAW;IACX,YAAY;IACZ,oBAAoB;IACpB,OAAO;CACC,CAAC;AAKX,oDAAoD;AACpD,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,YAAY,GAA8C;IAC9D,WAAW,EAAE;QACX,yEAAyE;QACzE,gEAAgE;KACjE;IACD,KAAK,EAAE;QACL,iEAAiE;QACjE,6DAA6D;KAC9D;IACD,OAAO,EAAE;QACP,sEAAsE;QACtE,+CAA+C;KAChD;IACD,KAAK,EAAE;QACL,uEAAuE;QACvE,iDAAiD;KAClD;IACD,SAAS,EAAE;QACT,oFAAoF;QACpF,gEAAgE;KACjE;IACD,QAAQ,EAAE;QACR,4EAA4E;QAC5E,wDAAwD;KACzD;IACD,SAAS,EAAE;QACT,2EAA2E;QAC3E,4EAA4E;KAC7E;IACD,UAAU,EAAE;QACV,0EAA0E;QAC1E,0EAA0E;KAC3E;IACD,oBAAoB,EAAE;QACpB,8EAA8E;QAC9E,+FAA+F;KAChG;IACD,KAAK,EAAE;QACL,6EAA6E;QAC7E,4EAA4E;KAC7E;CACF,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAAsB;IACnD,MAAM,EAAE,GAAG,GAAG,gBAAgB,GAAG,MAAM,EAAE,CAAC;IAC1C,OAAO;QACL,EAAE;QACF,OAAO,EAAE,OAAO;QAChB,KAAK,EAAE,CAAC;QACR,WAAW,EAAE,oCAAoC,MAAM,gCAAgC;QACvF,SAAS,EAAE,CAAC,kBAAkB,EAAE,aAAa,CAAC;QAC9C,MAAM,EAAE,aAAa;QACrB,QAAQ,CAAC,GAAG;YACV,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE,IAAI,IAAI,GAAG,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC;YAC3D,IAAI,IAAI,KAAK,EAAE;gBAAE,OAAO,KAAK,EAAE,CAAC;YAChC,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;YAClD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,KAAK,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;QAClE,CAAC;KACF,CAAC;AACJ,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,gBAAgB;IAC9B,OAAO,iBAAiB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type PolicyModule } from '../policy.js';
|
|
2
|
+
/**
|
|
3
|
+
* The human-only decisions policy (§21.2, layer 1).
|
|
4
|
+
*
|
|
5
|
+
* It blocks the calls that record a decision a person makes: a lesson
|
|
6
|
+
* decision, a quality waiver and a memory promotion. The permission map
|
|
7
|
+
* denies those tools to every agent role, and this policy is the second
|
|
8
|
+
* layer of the same guarantee.
|
|
9
|
+
*/
|
|
10
|
+
/** The stable id of the policy. */
|
|
11
|
+
export declare const HUMAN_ONLY_DECISIONS_ID = "oa.human-only-decisions";
|
|
12
|
+
/** The policy itself. */
|
|
13
|
+
export declare const humanOnlyDecisions: PolicyModule;
|
|
14
|
+
//# sourceMappingURL=human-only-decisions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"human-only-decisions.d.ts","sourceRoot":"","sources":["../../src/policies/human-only-decisions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAG/D;;;;;;;GAOG;AAEH,mCAAmC;AACnC,eAAO,MAAM,uBAAuB,4BAA4B,CAAC;AAKjE,yBAAyB;AACzB,eAAO,MAAM,kBAAkB,EAAE,YAkBhC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { allow, block } from '../policy.js';
|
|
2
|
+
import { readToolCall } from './tool-call.js';
|
|
3
|
+
/**
|
|
4
|
+
* The human-only decisions policy (§21.2, layer 1).
|
|
5
|
+
*
|
|
6
|
+
* It blocks the calls that record a decision a person makes: a lesson
|
|
7
|
+
* decision, a quality waiver and a memory promotion. The permission map
|
|
8
|
+
* denies those tools to every agent role, and this policy is the second
|
|
9
|
+
* layer of the same guarantee.
|
|
10
|
+
*/
|
|
11
|
+
/** The stable id of the policy. */
|
|
12
|
+
export const HUMAN_ONLY_DECISIONS_ID = 'oa.human-only-decisions';
|
|
13
|
+
/** The tools a person decides with. */
|
|
14
|
+
const HUMAN_ONLY_TOOLS = ['oa_lesson_decide', 'oa_quality_waive', 'oa_memory_decide'];
|
|
15
|
+
/** The policy itself. */
|
|
16
|
+
export const humanOnlyDecisions = {
|
|
17
|
+
id: HUMAN_ONLY_DECISIONS_ID,
|
|
18
|
+
version: '1.0.0',
|
|
19
|
+
layer: 1,
|
|
20
|
+
description: 'Blocks the calls that record a decision a person makes.',
|
|
21
|
+
appliesTo: ['PreToolCall'],
|
|
22
|
+
origin: 'first-party',
|
|
23
|
+
evaluate(ctx) {
|
|
24
|
+
const call = readToolCall(ctx);
|
|
25
|
+
if (call === undefined)
|
|
26
|
+
return allow();
|
|
27
|
+
const humanOnly = HUMAN_ONLY_TOOLS.some((name) => call.name === name || call.name.endsWith(`_${name}`));
|
|
28
|
+
if (!humanOnly)
|
|
29
|
+
return allow();
|
|
30
|
+
return block('Lesson decisions, quality waivers and memory promotions are recorded by a person (/oa lesson, /oa waive, /oa memory). Propose it in chat with your evidence.');
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=human-only-decisions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"human-only-decisions.js","sourceRoot":"","sources":["../../src/policies/human-only-decisions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAqB,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;GAOG;AAEH,mCAAmC;AACnC,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE,uCAAuC;AACvC,MAAM,gBAAgB,GAAG,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;AAEtF,yBAAyB;AACzB,MAAM,CAAC,MAAM,kBAAkB,GAAiB;IAC9C,EAAE,EAAE,uBAAuB;IAC3B,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,CAAC;IACR,WAAW,EAAE,yDAAyD;IACtE,SAAS,EAAE,CAAC,aAAa,CAAC;IAC1B,MAAM,EAAE,aAAa;IACrB,QAAQ,CAAC,GAAG;QACV,MAAM,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,KAAK,EAAE,CAAC;QACvC,MAAM,SAAS,GAAG,gBAAgB,CAAC,IAAI,CACrC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC,CAC/D,CAAC;QACF,IAAI,CAAC,SAAS;YAAE,OAAO,KAAK,EAAE,CAAC;QAC/B,OAAO,KAAK,CACV,8JAA8J,CAC/J,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PolicyModule } from '../policy.js';
|
|
2
|
+
export * from './discovery.js';
|
|
3
|
+
export * from './high-risk.js';
|
|
4
|
+
export * from './selection.js';
|
|
5
|
+
/** What the catalogue is built with. */
|
|
6
|
+
export interface PolicyCatalogueOptions {
|
|
7
|
+
/** The workspace root: the project the agent works in. */
|
|
8
|
+
workspace: string;
|
|
9
|
+
/** The home directory the worktrees live under; the home of the user by default. */
|
|
10
|
+
home?: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The first-party policies (§21.2).
|
|
14
|
+
*
|
|
15
|
+
* The catalogue is built with the workspace it guards, because one of the
|
|
16
|
+
* modules decides against the roots of the workspace. The order is the
|
|
17
|
+
* order of the layers: the guardrails that hold the tool call first, then
|
|
18
|
+
* the ones that read the prose.
|
|
19
|
+
*/
|
|
20
|
+
export declare function firstPartyPolicyModules(options: PolicyCatalogueOptions): PolicyModule[];
|
|
21
|
+
/**
|
|
22
|
+
* The ids of the first-party policies.
|
|
23
|
+
*
|
|
24
|
+
* The list is what the report compares the firing log against, so a policy
|
|
25
|
+
* that never fired is named. Every id is the one its module carries, so the
|
|
26
|
+
* list and the modules cannot drift apart.
|
|
27
|
+
*/
|
|
28
|
+
export declare const FIRST_PARTY_POLICY_IDS: readonly string[];
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/policies/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AA8BjD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAE/B,wCAAwC;AACxC,MAAM,WAAW,sBAAsB;IACrC,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,sBAAsB,GAAG,YAAY,EAAE,CAsBvF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAoBnD,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { AGI_FRAMING_ID, agiFraming } from './agi-framing.js';
|
|
2
|
+
import { ANTI_ANTHROPOMORPHISM_ID, antiAnthropomorphism } from './anti-anthropomorphism.js';
|
|
3
|
+
import { ANTI_DEPENDENCE_ID, antiDependence } from './anti-dependence.js';
|
|
4
|
+
import { ANTI_SYCOPHANCY_ID, antiSycophancy } from './anti-sycophancy.js';
|
|
5
|
+
import { DARK_PATTERN_ID, darkPattern } from './dark-pattern.js';
|
|
6
|
+
import { DESTRUCTIVE_NEEDS_APPROVAL_ID, destructiveNeedsApproval, } from './destructive-needs-approval.js';
|
|
7
|
+
import { HIGH_RISK_DOMAINS, highRiskPolicies } from './high-risk.js';
|
|
8
|
+
import { HUMAN_ONLY_DECISIONS_ID, humanOnlyDecisions } from './human-only-decisions.js';
|
|
9
|
+
import { NO_SKIP_GIT_HOOKS_ID, noSkipGitHooks } from './no-skip-git-hooks.js';
|
|
10
|
+
import { PACKAGE_MANAGER_ID, packageManager } from './package-manager.js';
|
|
11
|
+
import { PRIVACY_TRANSPARENCY_ID, privacyTransparency } from './privacy-transparency.js';
|
|
12
|
+
import { PROFESSIONAL_DISPLACEMENT_ID, professionalDisplacement, } from './professional-displacement.js';
|
|
13
|
+
import { PROTECT_POLICY_ID, protectPolicy } from './protect-policy.js';
|
|
14
|
+
import { SCOPE_ENFORCEMENT_ID, scopeEnforcement } from './scope-enforcement.js';
|
|
15
|
+
import { SECRET_SCAN_WRITES_ID, secretScanWrites } from './secret-scan-writes.js';
|
|
16
|
+
import { STRUCTURAL_BIAS_ID, structuralBias } from './structural-bias.js';
|
|
17
|
+
import { THIRD_PARTY_IMPACT_ID, thirdPartyImpact } from './third-party-impact.js';
|
|
18
|
+
import { TRUTHFULNESS_UNCERTAINTY_ID, truthfulnessUncertainty, } from './truthfulness-uncertainty.js';
|
|
19
|
+
import { WORKSPACE_WRITES_ONLY_ID, workspaceWritesOnly } from './workspace-writes-only.js';
|
|
20
|
+
export * from './discovery.js';
|
|
21
|
+
export * from './high-risk.js';
|
|
22
|
+
export * from './selection.js';
|
|
23
|
+
/**
|
|
24
|
+
* The first-party policies (§21.2).
|
|
25
|
+
*
|
|
26
|
+
* The catalogue is built with the workspace it guards, because one of the
|
|
27
|
+
* modules decides against the roots of the workspace. The order is the
|
|
28
|
+
* order of the layers: the guardrails that hold the tool call first, then
|
|
29
|
+
* the ones that read the prose.
|
|
30
|
+
*/
|
|
31
|
+
export function firstPartyPolicyModules(options) {
|
|
32
|
+
return [
|
|
33
|
+
noSkipGitHooks,
|
|
34
|
+
packageManager,
|
|
35
|
+
workspaceWritesOnly(options),
|
|
36
|
+
protectPolicy,
|
|
37
|
+
humanOnlyDecisions,
|
|
38
|
+
secretScanWrites,
|
|
39
|
+
destructiveNeedsApproval,
|
|
40
|
+
truthfulnessUncertainty,
|
|
41
|
+
antiSycophancy,
|
|
42
|
+
antiAnthropomorphism,
|
|
43
|
+
antiDependence,
|
|
44
|
+
agiFraming,
|
|
45
|
+
professionalDisplacement,
|
|
46
|
+
structuralBias,
|
|
47
|
+
darkPattern,
|
|
48
|
+
scopeEnforcement,
|
|
49
|
+
privacyTransparency,
|
|
50
|
+
thirdPartyImpact,
|
|
51
|
+
...highRiskPolicies(),
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The ids of the first-party policies.
|
|
56
|
+
*
|
|
57
|
+
* The list is what the report compares the firing log against, so a policy
|
|
58
|
+
* that never fired is named. Every id is the one its module carries, so the
|
|
59
|
+
* list and the modules cannot drift apart.
|
|
60
|
+
*/
|
|
61
|
+
export const FIRST_PARTY_POLICY_IDS = [
|
|
62
|
+
NO_SKIP_GIT_HOOKS_ID,
|
|
63
|
+
PACKAGE_MANAGER_ID,
|
|
64
|
+
WORKSPACE_WRITES_ONLY_ID,
|
|
65
|
+
PROTECT_POLICY_ID,
|
|
66
|
+
HUMAN_ONLY_DECISIONS_ID,
|
|
67
|
+
SECRET_SCAN_WRITES_ID,
|
|
68
|
+
DESTRUCTIVE_NEEDS_APPROVAL_ID,
|
|
69
|
+
TRUTHFULNESS_UNCERTAINTY_ID,
|
|
70
|
+
ANTI_SYCOPHANCY_ID,
|
|
71
|
+
ANTI_ANTHROPOMORPHISM_ID,
|
|
72
|
+
ANTI_DEPENDENCE_ID,
|
|
73
|
+
AGI_FRAMING_ID,
|
|
74
|
+
PROFESSIONAL_DISPLACEMENT_ID,
|
|
75
|
+
STRUCTURAL_BIAS_ID,
|
|
76
|
+
DARK_PATTERN_ID,
|
|
77
|
+
SCOPE_ENFORCEMENT_ID,
|
|
78
|
+
PRIVACY_TRANSPARENCY_ID,
|
|
79
|
+
THIRD_PARTY_IMPACT_ID,
|
|
80
|
+
...HIGH_RISK_DOMAINS.map((domain) => `oa.high-risk.${domain}`),
|
|
81
|
+
];
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/policies/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAC5F,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,GACzB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAE3F,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAU/B;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAA+B;IACrE,OAAO;QACL,cAAc;QACd,cAAc;QACd,mBAAmB,CAAC,OAAO,CAAC;QAC5B,aAAa;QACb,kBAAkB;QAClB,gBAAgB;QAChB,wBAAwB;QACxB,uBAAuB;QACvB,cAAc;QACd,oBAAoB;QACpB,cAAc;QACd,UAAU;QACV,wBAAwB;QACxB,cAAc;QACd,WAAW;QACX,gBAAgB;QAChB,mBAAmB;QACnB,gBAAgB;QAChB,GAAG,gBAAgB,EAAE;KACtB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAsB;IACvD,oBAAoB;IACpB,kBAAkB;IAClB,wBAAwB;IACxB,iBAAiB;IACjB,uBAAuB;IACvB,qBAAqB;IACrB,6BAA6B;IAC7B,2BAA2B;IAC3B,kBAAkB;IAClB,wBAAwB;IACxB,kBAAkB;IAClB,cAAc;IACd,4BAA4B;IAC5B,kBAAkB;IAClB,eAAe;IACf,oBAAoB;IACpB,uBAAuB;IACvB,qBAAqB;IACrB,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,MAAM,EAAE,CAAC;CAC/D,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type PolicyModule } from '../policy.js';
|
|
2
|
+
/**
|
|
3
|
+
* The no-skip-git-hooks policy (§21.2, layer 1).
|
|
4
|
+
*
|
|
5
|
+
* It blocks the flags that skip the pre-commit hook: `--no-verify`, its
|
|
6
|
+
* short form `-n`, `HUSKY=0` and a moved `core.hooksPath`. The hook is
|
|
7
|
+
* where the lint and the typecheck run, so a commit that skips it skips the
|
|
8
|
+
* checks too.
|
|
9
|
+
*/
|
|
10
|
+
/** The stable id of the policy. */
|
|
11
|
+
export declare const NO_SKIP_GIT_HOOKS_ID = "oa.no-skip-git-hooks";
|
|
12
|
+
/** The policy itself. */
|
|
13
|
+
export declare const noSkipGitHooks: PolicyModule;
|
|
14
|
+
//# sourceMappingURL=no-skip-git-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-skip-git-hooks.d.ts","sourceRoot":"","sources":["../../src/policies/no-skip-git-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAI/D;;;;;;;GAOG;AAEH,mCAAmC;AACnC,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAE3D,yBAAyB;AACzB,eAAO,MAAM,cAAc,EAAE,YAa5B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { allow, block } from '../policy.js';
|
|
2
|
+
import { skipsGitHooks } from '../rules.js';
|
|
3
|
+
import { readToolCall } from './tool-call.js';
|
|
4
|
+
/**
|
|
5
|
+
* The no-skip-git-hooks policy (§21.2, layer 1).
|
|
6
|
+
*
|
|
7
|
+
* It blocks the flags that skip the pre-commit hook: `--no-verify`, its
|
|
8
|
+
* short form `-n`, `HUSKY=0` and a moved `core.hooksPath`. The hook is
|
|
9
|
+
* where the lint and the typecheck run, so a commit that skips it skips the
|
|
10
|
+
* checks too.
|
|
11
|
+
*/
|
|
12
|
+
/** The stable id of the policy. */
|
|
13
|
+
export const NO_SKIP_GIT_HOOKS_ID = 'oa.no-skip-git-hooks';
|
|
14
|
+
/** The policy itself. */
|
|
15
|
+
export const noSkipGitHooks = {
|
|
16
|
+
id: NO_SKIP_GIT_HOOKS_ID,
|
|
17
|
+
version: '1.0.0',
|
|
18
|
+
layer: 1,
|
|
19
|
+
description: 'Blocks the flags that skip the git hooks.',
|
|
20
|
+
appliesTo: ['PreToolCall'],
|
|
21
|
+
origin: 'first-party',
|
|
22
|
+
evaluate(ctx) {
|
|
23
|
+
const call = readToolCall(ctx);
|
|
24
|
+
if (call === undefined || call.command === undefined)
|
|
25
|
+
return allow();
|
|
26
|
+
if (!skipsGitHooks(call.command))
|
|
27
|
+
return allow();
|
|
28
|
+
return block('Git hooks (lint, typecheck) cannot be skipped. Fix the reported errors instead.');
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=no-skip-git-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-skip-git-hooks.js","sourceRoot":"","sources":["../../src/policies/no-skip-git-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAqB,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;GAOG;AAEH,mCAAmC;AACnC,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAE3D,yBAAyB;AACzB,MAAM,CAAC,MAAM,cAAc,GAAiB;IAC1C,EAAE,EAAE,oBAAoB;IACxB,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,CAAC;IACR,WAAW,EAAE,2CAA2C;IACxD,SAAS,EAAE,CAAC,aAAa,CAAC;IAC1B,MAAM,EAAE,aAAa;IACrB,QAAQ,CAAC,GAAG;QACV,MAAM,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;YAAE,OAAO,KAAK,EAAE,CAAC;QACrE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,KAAK,EAAE,CAAC;QACjD,OAAO,KAAK,CAAC,iFAAiF,CAAC,CAAC;IAClG,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type PolicyModule } from '../policy.js';
|
|
2
|
+
/**
|
|
3
|
+
* The package manager policy (§21.2, layer 1).
|
|
4
|
+
*
|
|
5
|
+
* It blocks the other package managers: a second lockfile is a second
|
|
6
|
+
* answer to what the project depends on, and the two disagree.
|
|
7
|
+
*/
|
|
8
|
+
/** The stable id of the policy. */
|
|
9
|
+
export declare const PACKAGE_MANAGER_ID = "oa.package-manager";
|
|
10
|
+
/** The policy itself. */
|
|
11
|
+
export declare const packageManager: PolicyModule;
|
|
12
|
+
//# sourceMappingURL=package-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-manager.d.ts","sourceRoot":"","sources":["../../src/policies/package-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAI/D;;;;;GAKG;AAEH,mCAAmC;AACnC,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAEvD,yBAAyB;AACzB,eAAO,MAAM,cAAc,EAAE,YAe5B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { allow, block } from '../policy.js';
|
|
2
|
+
import { usesOtherPackageManager } from '../rules.js';
|
|
3
|
+
import { readToolCall } from './tool-call.js';
|
|
4
|
+
/**
|
|
5
|
+
* The package manager policy (§21.2, layer 1).
|
|
6
|
+
*
|
|
7
|
+
* It blocks the other package managers: a second lockfile is a second
|
|
8
|
+
* answer to what the project depends on, and the two disagree.
|
|
9
|
+
*/
|
|
10
|
+
/** The stable id of the policy. */
|
|
11
|
+
export const PACKAGE_MANAGER_ID = 'oa.package-manager';
|
|
12
|
+
/** The policy itself. */
|
|
13
|
+
export const packageManager = {
|
|
14
|
+
id: PACKAGE_MANAGER_ID,
|
|
15
|
+
version: '1.0.0',
|
|
16
|
+
layer: 1,
|
|
17
|
+
description: 'Blocks the package managers that are not the one this repo uses.',
|
|
18
|
+
appliesTo: ['PreToolCall'],
|
|
19
|
+
origin: 'first-party',
|
|
20
|
+
evaluate(ctx) {
|
|
21
|
+
const call = readToolCall(ctx);
|
|
22
|
+
if (call === undefined || call.command === undefined)
|
|
23
|
+
return allow();
|
|
24
|
+
if (!usesOtherPackageManager(call.command))
|
|
25
|
+
return allow();
|
|
26
|
+
return block('This repo uses Bun. Use `bun add` / `bun remove` / `bunx`, or `turbo run <task>`.');
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=package-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../../src/policies/package-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAqB,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;GAKG;AAEH,mCAAmC;AACnC,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AAEvD,yBAAyB;AACzB,MAAM,CAAC,MAAM,cAAc,GAAiB;IAC1C,EAAE,EAAE,kBAAkB;IACtB,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,CAAC;IACR,WAAW,EAAE,kEAAkE;IAC/E,SAAS,EAAE,CAAC,aAAa,CAAC;IAC1B,MAAM,EAAE,aAAa;IACrB,QAAQ,CAAC,GAAG;QACV,MAAM,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;YAAE,OAAO,KAAK,EAAE,CAAC;QACrE,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,KAAK,EAAE,CAAC;QAC3D,OAAO,KAAK,CACV,mFAAmF,CACpF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The patterns the output policies share.
|
|
3
|
+
*
|
|
4
|
+
* The detectors of §8.6 and the policies of §21.1 look at the same prose,
|
|
5
|
+
* so the way a pattern is applied to a text is written once: a pattern is
|
|
6
|
+
* tried against the text, the matches are collected, and a match that is
|
|
7
|
+
* already there is not collected twice.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The text a set of patterns matched.
|
|
11
|
+
*
|
|
12
|
+
* Every pattern is tried against the whole text, and the matches are
|
|
13
|
+
* returned in the order the patterns are written, so a text that trips two
|
|
14
|
+
* of them says which two.
|
|
15
|
+
*/
|
|
16
|
+
export declare function matches(patterns: readonly RegExp[], text: string): string[];
|
|
17
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../src/policies/patterns.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAW3E"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The patterns the output policies share.
|
|
3
|
+
*
|
|
4
|
+
* The detectors of §8.6 and the policies of §21.1 look at the same prose,
|
|
5
|
+
* so the way a pattern is applied to a text is written once: a pattern is
|
|
6
|
+
* tried against the text, the matches are collected, and a match that is
|
|
7
|
+
* already there is not collected twice.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The text a set of patterns matched.
|
|
11
|
+
*
|
|
12
|
+
* Every pattern is tried against the whole text, and the matches are
|
|
13
|
+
* returned in the order the patterns are written, so a text that trips two
|
|
14
|
+
* of them says which two.
|
|
15
|
+
*/
|
|
16
|
+
export function matches(patterns, text) {
|
|
17
|
+
const found = [];
|
|
18
|
+
for (const pattern of patterns) {
|
|
19
|
+
for (const match of text.matchAll(pattern)) {
|
|
20
|
+
const value = match[0];
|
|
21
|
+
if (value === undefined || value.length === 0)
|
|
22
|
+
continue;
|
|
23
|
+
if (found.includes(value))
|
|
24
|
+
continue;
|
|
25
|
+
found.push(value);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return found;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../src/policies/patterns.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,QAA2B,EAAE,IAAY;IAC/D,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACvB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,SAAS;YACxD,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAAE,SAAS;YACpC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policies.test.d.ts","sourceRoot":"","sources":["../../src/policies/policies.test.ts"],"names":[],"mappings":""}
|