@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,117 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { BLOCK_PRIORITY, createOaRegistry, orderRules, run } from './registry.js';
|
|
3
|
+
/** A rule that records that it ran and lets the call through. */
|
|
4
|
+
function recording(id, ran, options = {}) {
|
|
5
|
+
return {
|
|
6
|
+
id,
|
|
7
|
+
event: 'PreToolCall',
|
|
8
|
+
handler: () => {
|
|
9
|
+
ran.push(id);
|
|
10
|
+
return { continue: true };
|
|
11
|
+
},
|
|
12
|
+
...options,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
describe('the registry', () => {
|
|
16
|
+
it('runs the blocking rules first, then the priority, then the order they were written', () => {
|
|
17
|
+
const ran = [];
|
|
18
|
+
const rules = [
|
|
19
|
+
recording('plain', ran),
|
|
20
|
+
recording('blocking', ran, { block: true }),
|
|
21
|
+
recording('high', ran, { priority: 10 }),
|
|
22
|
+
recording('low', ran, { priority: 1 }),
|
|
23
|
+
recording('second-plain', ran),
|
|
24
|
+
];
|
|
25
|
+
expect(orderRules(rules).map((rule) => rule.id)).toEqual([
|
|
26
|
+
'blocking',
|
|
27
|
+
'high',
|
|
28
|
+
'low',
|
|
29
|
+
'plain',
|
|
30
|
+
'second-plain',
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
it('puts a blocking rule above a rule with a higher priority', () => {
|
|
34
|
+
const ran = [];
|
|
35
|
+
const rules = [
|
|
36
|
+
recording('high', ran, { priority: BLOCK_PRIORITY * 10 }),
|
|
37
|
+
recording('blocking', ran, { block: true }),
|
|
38
|
+
];
|
|
39
|
+
expect(orderRules(rules).map((rule) => rule.id)).toEqual(['blocking', 'high']);
|
|
40
|
+
});
|
|
41
|
+
it('stops the chain at the first rule that stops it and keeps the reason', async () => {
|
|
42
|
+
const ran = [];
|
|
43
|
+
const rules = [
|
|
44
|
+
{
|
|
45
|
+
id: 'first',
|
|
46
|
+
event: 'PreToolCall',
|
|
47
|
+
handler: () => {
|
|
48
|
+
ran.push('first');
|
|
49
|
+
return { continue: true };
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 'second',
|
|
54
|
+
event: 'PreToolCall',
|
|
55
|
+
handler: () => {
|
|
56
|
+
ran.push('second');
|
|
57
|
+
return { continue: false, reason: 'the reason' };
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 'third',
|
|
62
|
+
event: 'PreToolCall',
|
|
63
|
+
handler: () => {
|
|
64
|
+
ran.push('third');
|
|
65
|
+
return { continue: true };
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
const result = await run('PreToolCall', rules, {});
|
|
70
|
+
expect(result.continue).toBe(false);
|
|
71
|
+
expect(result.reasons).toEqual(['the reason']);
|
|
72
|
+
expect(ran).toEqual(['first', 'second']);
|
|
73
|
+
});
|
|
74
|
+
it('returns the transforms in order and lets the call through', async () => {
|
|
75
|
+
const rules = [
|
|
76
|
+
{ id: 'a', event: 'PreToolCall', handler: () => ({ transform: { a: 1 } }) },
|
|
77
|
+
{ id: 'b', event: 'PreToolCall', handler: () => ({ transform: { b: 2 } }) },
|
|
78
|
+
];
|
|
79
|
+
const result = await run('PreToolCall', rules, {});
|
|
80
|
+
expect(result.continue).toBe(true);
|
|
81
|
+
expect(result.transformed).toEqual([{ a: 1 }, { b: 2 }]);
|
|
82
|
+
});
|
|
83
|
+
it('runs only the rules of the moment', async () => {
|
|
84
|
+
const ran = [];
|
|
85
|
+
const rules = [
|
|
86
|
+
recording('before', ran),
|
|
87
|
+
{ ...recording('after', ran), event: 'PostToolCall' },
|
|
88
|
+
];
|
|
89
|
+
await run('PreToolCall', rules, {});
|
|
90
|
+
expect(ran).toEqual(['before']);
|
|
91
|
+
});
|
|
92
|
+
it('runs a rule only for the roles it names', async () => {
|
|
93
|
+
const ran = [];
|
|
94
|
+
const rules = [recording('builders', ran, { roles: ['builder'] })];
|
|
95
|
+
await run('PreToolCall', rules, { role: 'lead' });
|
|
96
|
+
expect(ran).toEqual([]);
|
|
97
|
+
await run('PreToolCall', rules, { role: 'builder' });
|
|
98
|
+
expect(ran).toEqual(['builders']);
|
|
99
|
+
});
|
|
100
|
+
it('runs a scoped rule for nobody when the role is unknown', async () => {
|
|
101
|
+
const ran = [];
|
|
102
|
+
const rules = [recording('builders', ran, { roles: ['builder'] })];
|
|
103
|
+
await run('PreToolCall', rules, {});
|
|
104
|
+
expect(ran).toEqual([]);
|
|
105
|
+
});
|
|
106
|
+
it('gives the registry the rules in the order they run', () => {
|
|
107
|
+
const ran = [];
|
|
108
|
+
const registry = createOaRegistry([
|
|
109
|
+
recording('plain', ran),
|
|
110
|
+
recording('blocking', ran, { block: true }),
|
|
111
|
+
]);
|
|
112
|
+
expect(registry.rules().map((rule) => rule.id)).toEqual(['blocking', 'plain']);
|
|
113
|
+
expect(registry.rules('PreToolCall').map((rule) => rule.id)).toEqual(['blocking', 'plain']);
|
|
114
|
+
expect(registry.rules('PostToolCall')).toEqual([]);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=registry.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.test.js","sourceRoot":"","sources":["../src/registry.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAa,GAAG,EAAE,MAAM,eAAe,CAAC;AAE7F,iEAAiE;AACjE,SAAS,SAAS,CAAC,EAAU,EAAE,GAAa,EAAE,UAAyB,EAAE;IACvE,OAAO;QACL,EAAE;QACF,KAAK,EAAE,aAAa;QACpB,OAAO,EAAE,GAAG,EAAE;YACZ,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACb,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAC5B,CAAC;QACD,GAAG,OAAO;KACX,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,oFAAoF,EAAE,GAAG,EAAE;QAC5F,MAAM,GAAG,GAAa,EAA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AAU,EAAE,OAAO,CAAC,CAAC,CAAC;QAC5F,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type PreToolCallEvent } from './event.js';
|
|
2
|
+
import { type QualityRuleOptions } from './quality/rule.js';
|
|
3
|
+
import type { Rule } from './registry.js';
|
|
4
|
+
/**
|
|
5
|
+
* The command, split into tokens.
|
|
6
|
+
*
|
|
7
|
+
* A quoted span is one token, so a command that is passed as a quoted
|
|
8
|
+
* argument stays one thing: `bash -c "git commit -n"` is three tokens and
|
|
9
|
+
* the third one holds the command. The quotes are kept, so the caller can
|
|
10
|
+
* tell a value from an argument.
|
|
11
|
+
*/
|
|
12
|
+
export declare function tokenise(command: string): string[];
|
|
13
|
+
/**
|
|
14
|
+
* The command, split into the segments a separator ends.
|
|
15
|
+
*
|
|
16
|
+
* A separator inside a quoted span does not end a segment: the span is one
|
|
17
|
+
* argument, and a command in it belongs to the command that holds the
|
|
18
|
+
* argument.
|
|
19
|
+
*/
|
|
20
|
+
export declare function commandSegments(command: string): string[];
|
|
21
|
+
/**
|
|
22
|
+
* The payload of every substitution in a command.
|
|
23
|
+
*
|
|
24
|
+
* The shell runs a substitution before the command that holds it, so the
|
|
25
|
+
* payload is a command of its own: `git commit -m "$(rm -rf /)"` removes
|
|
26
|
+
* the directory even though the message is only text.
|
|
27
|
+
*/
|
|
28
|
+
export declare function substitutionPayloads(command: string): string[];
|
|
29
|
+
/**
|
|
30
|
+
* The scope of the shell matcher.
|
|
31
|
+
*
|
|
32
|
+
* It covers: the flags of a removal in any order and either spelling, the
|
|
33
|
+
* git commands that skip the hooks, the other package managers, and the
|
|
34
|
+
* payload of every quoted span and every substitution, which is scanned as
|
|
35
|
+
* a command of its own.
|
|
36
|
+
*
|
|
37
|
+
* It does not cover: the shell. A payload behind a construct this matcher
|
|
38
|
+
* does not read - an alias, a function, a here-document, a variable - is
|
|
39
|
+
* not seen. A name the matcher does not know is treated as a writer, not
|
|
40
|
+
* as a reader.
|
|
41
|
+
*/
|
|
42
|
+
export declare function scannedParts(command: string): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Whether a command skips the git hooks.
|
|
45
|
+
*
|
|
46
|
+
* The `-n` of `git commit` is the short form of `--no-verify`, and it is
|
|
47
|
+
* caught in any position of the commit's own arguments:
|
|
48
|
+
* `git commit -n`, `git commit -m "wip" -n`, `git commit -a -n` and
|
|
49
|
+
* `git commit -nm "wip"` all skip the hooks. A command that is passed as a
|
|
50
|
+
* quoted argument is read too, so `bash -c "git commit -n"` is caught.
|
|
51
|
+
*/
|
|
52
|
+
export declare function skipsGitHooks(command: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Whether a path is one a person changes.
|
|
55
|
+
*
|
|
56
|
+
* The path is compared on its segments, so a directory is a directory
|
|
57
|
+
* whether or not the path names it with a trailing slash, and a file is a
|
|
58
|
+
* file wherever it sits. A delete or a move that names the directory
|
|
59
|
+
* itself is caught as well.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isProtected(path: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Whether a command destroys something.
|
|
64
|
+
*
|
|
65
|
+
* The command is read in parts, so a destructive command inside a
|
|
66
|
+
* substitution or inside a quoted argument is still one: `echo $(rm -rf
|
|
67
|
+
* /)` and `bash -c "rm -rf /"` are both caught. The flags of a removal
|
|
68
|
+
* are read per part, so `rm -r build; rm -f /tmp/x` is two removals and
|
|
69
|
+
* neither is the dangerous one.
|
|
70
|
+
*/
|
|
71
|
+
export declare function isDestructiveCommand(command: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Whether a command uses another package manager.
|
|
74
|
+
*/
|
|
75
|
+
export declare function usesOtherPackageManager(command: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The text a call would write.
|
|
78
|
+
*
|
|
79
|
+
* The host puts the content in the arguments: a write carries `content`,
|
|
80
|
+
* an edit carries `newString`, and a patch carries the whole patch. A
|
|
81
|
+
* patch is read for the lines it adds, so a secret in the text that is
|
|
82
|
+
* being added is found.
|
|
83
|
+
*/
|
|
84
|
+
export declare function contentOf(event: PreToolCallEvent): string;
|
|
85
|
+
/** The options the default rules are built with. */
|
|
86
|
+
export interface DefaultRuleOptions {
|
|
87
|
+
/** The workspace root: the project the agent works in. */
|
|
88
|
+
workspace: string;
|
|
89
|
+
/** The state root: where the `.openagentsy/` directory lives. */
|
|
90
|
+
stateRoot: string;
|
|
91
|
+
/** The home directory the worktrees live under; the home of the user by default. */
|
|
92
|
+
home?: string;
|
|
93
|
+
/**
|
|
94
|
+
* The quality check, when the project runs one.
|
|
95
|
+
*
|
|
96
|
+
* A project that names no mode runs no check, so the rule is left out
|
|
97
|
+
* rather than registered and idle.
|
|
98
|
+
*/
|
|
99
|
+
quality?: Omit<QualityRuleOptions, 'workspace' | 'stateRoot'>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The seven default rules.
|
|
103
|
+
*
|
|
104
|
+
* They run in the order they are written, and every one of them blocks.
|
|
105
|
+
*/
|
|
106
|
+
export declare const defaultRules: ({ workspace, stateRoot, home, quality, }: DefaultRuleOptions) => Rule[];
|
|
107
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAGA,OAAO,EAA+B,KAAK,gBAAgB,EAAmB,MAAM,YAAY,CAAC;AAEjG,OAAO,EAAE,KAAK,kBAAkB,EAAqB,MAAM,mBAAmB,CAAC;AAC/E,OAAO,KAAK,EAAiB,IAAI,EAAE,MAAM,eAAe,CAAC;AA+CzD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE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