@adhd/agent-core-policy 2.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/drizzle/0000_sleepy_bullseye.sql +16 -0
- package/drizzle/0001_pale_marvel_zombies.sql +11 -0
- package/drizzle/0002_category_policy_inheritance.sql +22 -0
- package/drizzle/meta/0000_snapshot.json +119 -0
- package/drizzle/meta/0001_snapshot.json +186 -0
- package/drizzle/meta/0002_snapshot.json +274 -0
- package/drizzle/meta/_journal.json +27 -0
- package/package.json +53 -0
- package/src/db/client.d.ts +7 -0
- package/src/db/client.d.ts.map +1 -0
- package/src/db/client.js +18 -0
- package/src/db/client.js.map +1 -0
- package/src/db/migrate-runner.d.ts +30 -0
- package/src/db/migrate-runner.d.ts.map +1 -0
- package/src/db/migrate-runner.js +34 -0
- package/src/db/migrate-runner.js.map +1 -0
- package/src/db/migrate.d.ts +9 -0
- package/src/db/migrate.d.ts.map +1 -0
- package/src/db/migrate.js +13 -0
- package/src/db/migrate.js.map +1 -0
- package/src/db/schema.d.ts +383 -0
- package/src/db/schema.d.ts.map +1 -0
- package/src/db/schema.js +139 -0
- package/src/db/schema.js.map +1 -0
- package/src/index.d.ts +14 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +20 -0
- package/src/index.js.map +1 -0
- package/src/plugin/index.d.ts +24 -0
- package/src/plugin/index.d.ts.map +1 -0
- package/src/plugin/index.js +140 -0
- package/src/plugin/index.js.map +1 -0
- package/src/plugin/rate-policy.d.ts +34 -0
- package/src/plugin/rate-policy.d.ts.map +1 -0
- package/src/plugin/rate-policy.js +36 -0
- package/src/plugin/rate-policy.js.map +1 -0
- package/src/seed/index.d.ts +39 -0
- package/src/seed/index.d.ts.map +1 -0
- package/src/seed/index.js +62 -0
- package/src/seed/index.js.map +1 -0
- package/src/seed/policy-templates.d.ts +45 -0
- package/src/seed/policy-templates.d.ts.map +1 -0
- package/src/seed/policy-templates.js +189 -0
- package/src/seed/policy-templates.js.map +1 -0
- package/src/seed/policy-types.d.ts +19 -0
- package/src/seed/policy-types.d.ts.map +1 -0
- package/src/seed/policy-types.js +44 -0
- package/src/seed/policy-types.js.map +1 -0
- package/src/store/agent-policy-store.d.ts +172 -0
- package/src/store/agent-policy-store.d.ts.map +1 -0
- package/src/store/agent-policy-store.js +241 -0
- package/src/store/agent-policy-store.js.map +1 -0
- package/src/store/policy-template-store.d.ts +72 -0
- package/src/store/policy-template-store.d.ts.map +1 -0
- package/src/store/policy-template-store.js +118 -0
- package/src/store/policy-template-store.js.map +1 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seed data for the `policy_policy_templates` table.
|
|
3
|
+
*
|
|
4
|
+
* Every entry carries REAL `rules` JSON from SEED_DATA.md §9. Placeholders
|
|
5
|
+
* defeat idempotency and the round-trip proof. [seed-and-roundtrip.2]
|
|
6
|
+
*
|
|
7
|
+
* Key invariants honoured here:
|
|
8
|
+
* - `enforcement` is ALWAYS a JSON array — never a scalar string.
|
|
9
|
+
* [inv:enforcement-is-array]
|
|
10
|
+
* - `no-credentials` carries `enforcement: ["agent","ci"]` — the multi-value
|
|
11
|
+
* case that round-trip tests must exercise.
|
|
12
|
+
* - `sox-audit-trail` is seeded as `hook_type: "observational"` (Decision 2 —
|
|
13
|
+
* its hook point is TOOL_CALL, not pre:model_request, so it must NOT be
|
|
14
|
+
* registered via registerEnforcement).
|
|
15
|
+
* - All entries are `is_system: true, version: 1`.
|
|
16
|
+
* - `INSERT OR IGNORE` semantics in the seeder keep re-runs as no-ops.
|
|
17
|
+
* [seed-and-roundtrip.1]
|
|
18
|
+
*
|
|
19
|
+
* Source: SEED_DATA.md §9 — Policy Templates.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The system policy templates that ship with the agent registry.
|
|
23
|
+
*
|
|
24
|
+
* Includes:
|
|
25
|
+
* - `reviewer-posture` — safety, ["agent"]
|
|
26
|
+
* - `no-credentials` — safety, ["agent","ci"] ← multi-value case
|
|
27
|
+
* - `sox-audit-trail` — audit, ["hook"] ← observational only (Decision 2)
|
|
28
|
+
* - `max-rework-3` — rate, ["runtime"]
|
|
29
|
+
* - `evidence-required` — quality, ["runtime"]
|
|
30
|
+
* - `read-only` — permission, ["settings"]
|
|
31
|
+
* - `phase-gate-required` — compliance, ["runtime","ci"]
|
|
32
|
+
* - `originality-check` — quality, ["ci"]
|
|
33
|
+
* - `allowed-delegation` — permission, ["runtime"]
|
|
34
|
+
*/
|
|
35
|
+
export const POLICY_TEMPLATES = [
|
|
36
|
+
// ── safety ────────────────────────────────────────────────────────────────
|
|
37
|
+
{
|
|
38
|
+
slug: 'reviewer-posture',
|
|
39
|
+
type: 'safety',
|
|
40
|
+
description: 'Default skeptic posture: NEEDS-WORK unless evidence confirms each criterion',
|
|
41
|
+
rules: {
|
|
42
|
+
default_verdict: 'NEEDS_WORK',
|
|
43
|
+
requires_explicit_pass_justification: true,
|
|
44
|
+
minimum_evidence_per_criterion: 1,
|
|
45
|
+
components_to_inject: ['default-skeptic', 'reviewer-boundary'],
|
|
46
|
+
},
|
|
47
|
+
enforcement: ['agent'],
|
|
48
|
+
version: 1,
|
|
49
|
+
isSystem: true,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
slug: 'no-credentials',
|
|
53
|
+
type: 'safety',
|
|
54
|
+
description: 'Prevent credential leakage in files, task output, and handoff text',
|
|
55
|
+
rules: {
|
|
56
|
+
forbidden_patterns: [
|
|
57
|
+
'sk-[a-zA-Z0-9]{32,}',
|
|
58
|
+
'AKIA[0-9A-Z]{16}',
|
|
59
|
+
'-----BEGIN (RSA|EC|OPENSSH) PRIVATE KEY-----',
|
|
60
|
+
'password\\s*=\\s*[\'"][^\'"]{4,}',
|
|
61
|
+
],
|
|
62
|
+
ci_scan_targets: ['committed_files', 'task_output', 'handoff_text'],
|
|
63
|
+
components_to_inject: ['no-credentials'],
|
|
64
|
+
},
|
|
65
|
+
// The multi-value enforcement that the round-trip test must verify.
|
|
66
|
+
// [inv:enforcement-is-array]
|
|
67
|
+
enforcement: ['agent', 'ci'],
|
|
68
|
+
version: 1,
|
|
69
|
+
isSystem: true,
|
|
70
|
+
},
|
|
71
|
+
// ── audit ─────────────────────────────────────────────────────────────────
|
|
72
|
+
{
|
|
73
|
+
slug: 'sox-audit-trail',
|
|
74
|
+
type: 'audit',
|
|
75
|
+
description: 'Log io and compute tool calls for SOX-compliant audit trail',
|
|
76
|
+
rules: {
|
|
77
|
+
hook_event: 'TOOL_CALL',
|
|
78
|
+
log_tool_types: ['io', 'compute'],
|
|
79
|
+
require_task_event_on: ['file_write', 'file_edit', 'shell_exec'],
|
|
80
|
+
// Decision 2: this hook is observational, not blocking. It is NOT
|
|
81
|
+
// registered via registerEnforcement("pre:model_request") — only via
|
|
82
|
+
// the observational hooks.register() path. [decisions.md Decision 2]
|
|
83
|
+
hook_type: 'observational',
|
|
84
|
+
},
|
|
85
|
+
enforcement: ['hook'],
|
|
86
|
+
version: 1,
|
|
87
|
+
isSystem: true,
|
|
88
|
+
},
|
|
89
|
+
// ── rate ─────────────────────────────────────────────────────────────────
|
|
90
|
+
{
|
|
91
|
+
slug: 'max-rework-3',
|
|
92
|
+
type: 'rate',
|
|
93
|
+
description: 'Cap rework attempts at 3; escalate to janitor on breach',
|
|
94
|
+
rules: {
|
|
95
|
+
max_rework: 3,
|
|
96
|
+
check_at: 'cmd_gate_changes_requested',
|
|
97
|
+
escalation_target: 'janitor',
|
|
98
|
+
escalation_template_component: 'sox-escalation-report',
|
|
99
|
+
inject_attempt_framing: true,
|
|
100
|
+
attempt_framing_component: 'attempt-framing',
|
|
101
|
+
},
|
|
102
|
+
enforcement: ['runtime'],
|
|
103
|
+
version: 1,
|
|
104
|
+
isSystem: true,
|
|
105
|
+
},
|
|
106
|
+
// ── quality ───────────────────────────────────────────────────────────────
|
|
107
|
+
{
|
|
108
|
+
slug: 'evidence-required',
|
|
109
|
+
type: 'quality',
|
|
110
|
+
description: 'Block verdict if required evidence fields are absent or empty',
|
|
111
|
+
rules: {
|
|
112
|
+
validator_agent_slug: 'evidence-validator',
|
|
113
|
+
validator_default_verdict: 'EVIDENCE_INSUFFICIENT',
|
|
114
|
+
required_fields: [
|
|
115
|
+
'changed_files',
|
|
116
|
+
'acceptance_criteria_addressed',
|
|
117
|
+
'test_results',
|
|
118
|
+
],
|
|
119
|
+
required_fields_except: {
|
|
120
|
+
test_results: ['SPIKE', 'CHORE'],
|
|
121
|
+
},
|
|
122
|
+
block_verdict_if_insufficient: true,
|
|
123
|
+
},
|
|
124
|
+
enforcement: ['runtime'],
|
|
125
|
+
version: 1,
|
|
126
|
+
isSystem: true,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
slug: 'originality-check',
|
|
130
|
+
type: 'quality',
|
|
131
|
+
description: 'Block duplicate agent commits above 0.85 similarity threshold',
|
|
132
|
+
rules: {
|
|
133
|
+
check_on: 'new_agent_commit',
|
|
134
|
+
similarity_threshold: 0.85,
|
|
135
|
+
comparison_fields: [
|
|
136
|
+
'role_component_content',
|
|
137
|
+
'capability_component_content',
|
|
138
|
+
],
|
|
139
|
+
action_on_duplicate: 'block_commit',
|
|
140
|
+
suggest_extend_existing: true,
|
|
141
|
+
},
|
|
142
|
+
enforcement: ['ci'],
|
|
143
|
+
version: 1,
|
|
144
|
+
isSystem: true,
|
|
145
|
+
},
|
|
146
|
+
// ── permission ────────────────────────────────────────────────────────────
|
|
147
|
+
{
|
|
148
|
+
slug: 'read-only',
|
|
149
|
+
type: 'permission',
|
|
150
|
+
description: 'Restrict agent to read-only tool access; forbid compute tools',
|
|
151
|
+
rules: {
|
|
152
|
+
allowed_tool_permissions: ['read_only'],
|
|
153
|
+
disallow_tool_types: ['compute'],
|
|
154
|
+
disallow_tools: ['file_write', 'file_edit', 'shell_exec'],
|
|
155
|
+
},
|
|
156
|
+
enforcement: ['settings'],
|
|
157
|
+
version: 1,
|
|
158
|
+
isSystem: true,
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
slug: 'allowed-delegation',
|
|
162
|
+
type: 'permission',
|
|
163
|
+
description: 'Allowlist sub-agent delegation targets; empty = unrestricted',
|
|
164
|
+
rules: {
|
|
165
|
+
mode: 'allowlist',
|
|
166
|
+
allowlist: [],
|
|
167
|
+
note: 'Empty allowlist = unrestricted delegation. Populate per-agent via AGENT_POLICY.override_config.',
|
|
168
|
+
},
|
|
169
|
+
enforcement: ['runtime'],
|
|
170
|
+
version: 1,
|
|
171
|
+
isSystem: true,
|
|
172
|
+
},
|
|
173
|
+
// ── compliance ────────────────────────────────────────────────────────────
|
|
174
|
+
{
|
|
175
|
+
slug: 'phase-gate-required',
|
|
176
|
+
type: 'compliance',
|
|
177
|
+
description: 'Require passing phase gate before ticket creation for next phase',
|
|
178
|
+
rules: {
|
|
179
|
+
gate_command: 'sox gate phase',
|
|
180
|
+
block_ticket_creation_for_next_phase: true,
|
|
181
|
+
gate_criteria_source: 'PHASE.gate_id',
|
|
182
|
+
require_all_criteria_met: true,
|
|
183
|
+
},
|
|
184
|
+
enforcement: ['runtime', 'ci'],
|
|
185
|
+
version: 1,
|
|
186
|
+
isSystem: true,
|
|
187
|
+
},
|
|
188
|
+
];
|
|
189
|
+
//# sourceMappingURL=policy-templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-templates.js","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-policy/src/seed/policy-templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAYH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAqC;IAChE,6EAA6E;IAE7E;QACE,IAAI,EAAE,kBAAkB;QACxB,IAAI,EAAE,QAAQ;QACd,WAAW,EACT,6EAA6E;QAC/E,KAAK,EAAE;YACL,eAAe,EAAE,YAAY;YAC7B,oCAAoC,EAAE,IAAI;YAC1C,8BAA8B,EAAE,CAAC;YACjC,oBAAoB,EAAE,CAAC,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,IAAI,EAAE,oBAAoB;QAC1B,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,8DAA8D;QAC3E,KAAK,EAAE;YACL,IAAI,EAAE,WAAW;YACjB,SAAS,EAAE,EAAE;YACb,IAAI,EAAE,iGAAiG;SACxG;QACD,WAAW,EAAE,CAAC,SAAS,CAAC;QACxB,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,IAAI;KACf;IAED,6EAA6E;IAE7E;QACE,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,YAAY;QAClB,WAAW,EACT,kEAAkE;QACpE,KAAK,EAAE;YACL,YAAY,EAAE,gBAAgB;YAC9B,oCAAoC,EAAE,IAAI;YAC1C,oBAAoB,EAAE,eAAe;YACrC,wBAAwB,EAAE,IAAI;SAC/B;QACD,WAAW,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC;QAC9B,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,IAAI;KACf;CACO,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seed data for the `policy_policy_types` lookup table.
|
|
3
|
+
*
|
|
4
|
+
* Each entry is a controlled-vocabulary slug with a description.
|
|
5
|
+
* New policy types are added by seeding a row — never by altering the column
|
|
6
|
+
* type or writing a migration. [inv:lookup-not-enum]
|
|
7
|
+
*
|
|
8
|
+
* Source: SEED_DATA.md §3 — Policy Types.
|
|
9
|
+
*/
|
|
10
|
+
export interface PolicyTypeSeedRow {
|
|
11
|
+
slug: string;
|
|
12
|
+
description: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The seven canonical policy types that ship with the agent registry.
|
|
16
|
+
* `INSERT OR IGNORE` semantics — running this list twice is a no-op.
|
|
17
|
+
*/
|
|
18
|
+
export declare const POLICY_TYPES: readonly PolicyTypeSeedRow[];
|
|
19
|
+
//# sourceMappingURL=policy-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-types.d.ts","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-policy/src/seed/policy-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,SAAS,iBAAiB,EA6B3C,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seed data for the `policy_policy_types` lookup table.
|
|
3
|
+
*
|
|
4
|
+
* Each entry is a controlled-vocabulary slug with a description.
|
|
5
|
+
* New policy types are added by seeding a row — never by altering the column
|
|
6
|
+
* type or writing a migration. [inv:lookup-not-enum]
|
|
7
|
+
*
|
|
8
|
+
* Source: SEED_DATA.md §3 — Policy Types.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The seven canonical policy types that ship with the agent registry.
|
|
12
|
+
* `INSERT OR IGNORE` semantics — running this list twice is a no-op.
|
|
13
|
+
*/
|
|
14
|
+
export const POLICY_TYPES = [
|
|
15
|
+
{
|
|
16
|
+
slug: 'permission',
|
|
17
|
+
description: 'What tools or agent delegations are allowed',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
slug: 'safety',
|
|
21
|
+
description: 'What content, actions, or outputs are forbidden',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
slug: 'audit',
|
|
25
|
+
description: 'What must be logged, traced, or recorded',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
slug: 'rate',
|
|
29
|
+
description: 'Token, call count, time, or rework limits',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
slug: 'scope',
|
|
33
|
+
description: 'Accessible file paths, domains, or ticket types',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
slug: 'compliance',
|
|
37
|
+
description: 'Regulatory or organizational requirements',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
slug: 'quality',
|
|
41
|
+
description: 'Output quality invariants enforced at gate time',
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
//# sourceMappingURL=policy-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-types.js","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-policy/src/seed/policy-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAiC;IACxD;QACE,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,6CAA6C;KAC3D;IACD;QACE,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,iDAAiD;KAC/D;IACD;QACE,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,0CAA0C;KACxD;IACD;QACE,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,2CAA2C;KACzD;IACD;QACE,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,iDAAiD;KAC/D;IACD;QACE,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,2CAA2C;KACzD;IACD;QACE,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,iDAAiD;KAC/D;CACO,CAAC"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
type AnyBetterSQLite3Database = import('drizzle-orm/better-sqlite3').BetterSQLite3Database<any>;
|
|
2
|
+
import { PolicyError } from './policy-template-store.js';
|
|
3
|
+
export type AgentPolicyErrorCode = 'AGENT_POLICY_ALREADY_ATTACHED' | 'CATEGORY_POLICY_ALREADY_ATTACHED' | 'AGENT_CATEGORY_ALREADY_JOINED';
|
|
4
|
+
/**
|
|
5
|
+
* Typed error thrown by {@link AgentPolicyStore} — mirrors the PolicyError
|
|
6
|
+
* pattern but for junction-specific error codes.
|
|
7
|
+
*/
|
|
8
|
+
export declare class AgentPolicyError extends Error {
|
|
9
|
+
readonly code: AgentPolicyErrorCode;
|
|
10
|
+
readonly data?: unknown;
|
|
11
|
+
constructor(code: AgentPolicyErrorCode, message: string, data?: unknown);
|
|
12
|
+
}
|
|
13
|
+
export { PolicyError };
|
|
14
|
+
/**
|
|
15
|
+
* One resolved `policy_agent_policies` row as returned by
|
|
16
|
+
* {@link AgentPolicyStore.listForAgent}.
|
|
17
|
+
*
|
|
18
|
+
* `overrideConfig` is the per-agent JSON customisation of the template's rules
|
|
19
|
+
* (Decision 3: shallow-merge semantics). `null` means "use the template unchanged."
|
|
20
|
+
*
|
|
21
|
+
* `inheritedFrom` is the taxonomy category slug a policy cascaded from, or
|
|
22
|
+
* `null` when attached directly to the agent. [Decision 1]
|
|
23
|
+
*/
|
|
24
|
+
export interface AgentPolicyRow {
|
|
25
|
+
/** Logical reference to registry_agents.slug — no cross-package FK. */
|
|
26
|
+
agentSlug: string;
|
|
27
|
+
/** FK to policy_policy_templates.slug (in-package, real FK). */
|
|
28
|
+
policySlug: string;
|
|
29
|
+
/** Per-agent rule overrides (shallow-merge over template.rules). Null = no override. */
|
|
30
|
+
overrideConfig: Record<string, unknown> | null;
|
|
31
|
+
/** True when this policy must be enforced regardless of agent config. */
|
|
32
|
+
isMandatory: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Category slug this policy cascaded from, or null if attached directly.
|
|
35
|
+
* Direct-attach sets this to null. [Decision 1, inv:reopen-proves-persistence]
|
|
36
|
+
*/
|
|
37
|
+
inheritedFrom: string | null;
|
|
38
|
+
}
|
|
39
|
+
/** Input for {@link AgentPolicyStore.attach} (direct-attach path). */
|
|
40
|
+
export interface AgentPolicyAttachInput {
|
|
41
|
+
/** Slug of the agent to attach the policy to. */
|
|
42
|
+
agentSlug: string;
|
|
43
|
+
/** Slug of the policy template to attach. */
|
|
44
|
+
policySlug: string;
|
|
45
|
+
/** Optional per-agent override (shallow-merged over template.rules). */
|
|
46
|
+
overrideConfig?: Record<string, unknown>;
|
|
47
|
+
/** When true, this policy is mandatory. Defaults to false. */
|
|
48
|
+
isMandatory?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Input for {@link AgentPolicyStore.attachToCategory}.
|
|
52
|
+
*
|
|
53
|
+
* Attaches a policy to a taxonomy category. All agents that belong to the
|
|
54
|
+
* category (now or in the future) will inherit this policy via the lazy
|
|
55
|
+
* resolver — no fanout rows are written. [Decision 1]
|
|
56
|
+
*/
|
|
57
|
+
export interface CategoryPolicyAttachInput {
|
|
58
|
+
/** Logical taxonomy category slug (cross-package ref, no FK). */
|
|
59
|
+
categorySlug: string;
|
|
60
|
+
/** Slug of the policy template to attach to the category. */
|
|
61
|
+
policySlug: string;
|
|
62
|
+
/** When true, every inheriting agent carries this as mandatory. */
|
|
63
|
+
isMandatory?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* One row returned by {@link AgentPolicyStore.attachToCategory} confirming the
|
|
67
|
+
* category-level attachment was stored.
|
|
68
|
+
*/
|
|
69
|
+
export interface CategoryPolicyRow {
|
|
70
|
+
categorySlug: string;
|
|
71
|
+
policySlug: string;
|
|
72
|
+
isMandatory: boolean;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Input for {@link AgentPolicyStore.addAgentToCategory}.
|
|
76
|
+
*
|
|
77
|
+
* Records that `agentSlug` is a member of `categorySlug`. At the next
|
|
78
|
+
* `resolveForAgent` call the agent automatically inherits all policies
|
|
79
|
+
* attached to that category. [Decision 1 — lazy, no re-fanout needed]
|
|
80
|
+
*/
|
|
81
|
+
export interface AgentCategoryInput {
|
|
82
|
+
/** Logical agent slug (cross-package ref, no FK). */
|
|
83
|
+
agentSlug: string;
|
|
84
|
+
/** Logical taxonomy category slug (cross-package ref, no FK). */
|
|
85
|
+
categorySlug: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Thin Drizzle wrapper for the `policy_agent_policies` junction table.
|
|
89
|
+
*
|
|
90
|
+
* Mirrors the `PolicyTemplateStore` / `agent-mcp` AgentStore pattern:
|
|
91
|
+
* - constructor takes a `BetterSQLite3Database` handle (caller owns lifecycle)
|
|
92
|
+
* - methods are synchronous Drizzle queries
|
|
93
|
+
* - errors throw {@link AgentPolicyError} with typed codes
|
|
94
|
+
*
|
|
95
|
+
* Direct-attach (`attach`) sets `inherited_from = NULL`. Category inheritance
|
|
96
|
+
* resolution (`resolveForAgent`, added in the `policy-inheritance` state) reads
|
|
97
|
+
* the joined category membership at query time — lazy, per Decision 1.
|
|
98
|
+
*/
|
|
99
|
+
export declare class AgentPolicyStore {
|
|
100
|
+
private readonly db;
|
|
101
|
+
constructor(db: AnyBetterSQLite3Database);
|
|
102
|
+
/**
|
|
103
|
+
* Attach a policy template DIRECTLY to an agent (`inherited_from = null`).
|
|
104
|
+
*
|
|
105
|
+
* @throws {AgentPolicyError} AGENT_POLICY_ALREADY_ATTACHED when the
|
|
106
|
+
* (agentSlug, policySlug) pair already exists.
|
|
107
|
+
*/
|
|
108
|
+
attach(input: AgentPolicyAttachInput): AgentPolicyRow;
|
|
109
|
+
/**
|
|
110
|
+
* Return all direct `policy_agent_policies` rows for the given agent slug.
|
|
111
|
+
*
|
|
112
|
+
* Returns only rows stored directly against the agent (`inherited_from IS NULL`
|
|
113
|
+
* for direct-attach rows). Use {@link resolveForAgent} to include inherited
|
|
114
|
+
* policies from category membership.
|
|
115
|
+
*
|
|
116
|
+
* @param agentSlug — the slug of the agent whose policies to retrieve.
|
|
117
|
+
*/
|
|
118
|
+
listForAgent(agentSlug: string): AgentPolicyRow[];
|
|
119
|
+
/**
|
|
120
|
+
* Attach a policy template to a taxonomy CATEGORY (lazy inheritance).
|
|
121
|
+
*
|
|
122
|
+
* Stores a single `policy_category_policies` row — does NOT fan out rows to
|
|
123
|
+
* individual agents. Any agent already in or later added to the category
|
|
124
|
+
* inherits this policy at the next `resolveForAgent` call. [Decision 1]
|
|
125
|
+
*
|
|
126
|
+
* @throws {AgentPolicyError} CATEGORY_POLICY_ALREADY_ATTACHED when the
|
|
127
|
+
* (categorySlug, policySlug) pair already exists.
|
|
128
|
+
*/
|
|
129
|
+
attachToCategory(input: CategoryPolicyAttachInput): CategoryPolicyRow;
|
|
130
|
+
/**
|
|
131
|
+
* Record that an agent is a member of a taxonomy category.
|
|
132
|
+
*
|
|
133
|
+
* At the next `resolveForAgent` call the agent automatically inherits all
|
|
134
|
+
* policies attached to the category — no re-fanout or migration needed.
|
|
135
|
+
* This is the "agent added AFTER the category-attach" case from Decision 1.
|
|
136
|
+
*
|
|
137
|
+
* @throws {AgentPolicyError} AGENT_CATEGORY_ALREADY_JOINED when the
|
|
138
|
+
* (agentSlug, categorySlug) pair already exists.
|
|
139
|
+
*/
|
|
140
|
+
addAgentToCategory(input: AgentCategoryInput): void;
|
|
141
|
+
/**
|
|
142
|
+
* Resolve the complete effective policy set for an agent at query time.
|
|
143
|
+
*
|
|
144
|
+
* Returns a union of:
|
|
145
|
+
* 1. Policies attached DIRECTLY to the agent (inheritedFrom = null).
|
|
146
|
+
* 2. Policies inherited from every category the agent belongs to,
|
|
147
|
+
* synthesised as rows with inheritedFrom = categorySlug. [Decision 1]
|
|
148
|
+
*
|
|
149
|
+
* The join is performed at call time so newly added category policies or
|
|
150
|
+
* membership changes are always reflected — there is no stale materialised
|
|
151
|
+
* cache to invalidate.
|
|
152
|
+
*
|
|
153
|
+
* If an agent has a direct-attach for a policy AND inherits the same policy
|
|
154
|
+
* from a category, the direct-attach row takes precedence (override wins).
|
|
155
|
+
*
|
|
156
|
+
* @param agentSlug — the slug of the agent to resolve policies for.
|
|
157
|
+
*/
|
|
158
|
+
resolveForAgent(agentSlug: string): AgentPolicyRow[];
|
|
159
|
+
private _toRow;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Compute effective rules by shallow-merging `overrideConfig` on top of
|
|
163
|
+
* `templateRules`. Override keys replace template keys (arrays and nested
|
|
164
|
+
* objects are replaced wholesale). An absent or empty override leaves the
|
|
165
|
+
* template unchanged. [Decision 3]
|
|
166
|
+
*
|
|
167
|
+
* @param templateRules — the base rules object from `policy_policy_templates`.
|
|
168
|
+
* @param overrideConfig — the per-agent override (may be null/undefined).
|
|
169
|
+
* @returns the effective merged rules object.
|
|
170
|
+
*/
|
|
171
|
+
export declare function resolveEffectiveRules(templateRules: Record<string, unknown>, overrideConfig: Record<string, unknown> | null | undefined): Record<string, unknown>;
|
|
172
|
+
//# sourceMappingURL=agent-policy-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-policy-store.d.ts","sourceRoot":"","sources":["../../../../../../packages/agent/agent-core-policy/src/store/agent-policy-store.ts"],"names":[],"mappings":"AAGA,KAAK,wBAAwB,GAAG,OAAO,4BAA4B,EAAE,qBAAqB,CAAC,GAAG,CAAC,CAAC;AAOhG,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAMzD,MAAM,MAAM,oBAAoB,GAC5B,+BAA+B,GAC/B,kCAAkC,GAClC,+BAA+B,CAAC;AAEpC;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;gBAEZ,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CAMxE;AAGD,OAAO,EAAE,WAAW,EAAE,CAAC;AAMvB;;;;;;;;;GASG;AACH,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAC;IACnB,wFAAwF;IACxF,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC/C,yEAAyE;IACzE,WAAW,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,sEAAsE;AACtE,MAAM,WAAW,sBAAsB;IACrC,iDAAiD;IACjD,SAA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