@aumos/cowork-governance 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts ADDED
@@ -0,0 +1,349 @@
1
+ /**
2
+ * TypeScript interfaces for the AumOS cowork-governance library.
3
+ *
4
+ * Mirrors the Python types defined in:
5
+ * aumos_cowork_governance.policies.engine
6
+ * aumos_cowork_governance.constitution.schema
7
+ * aumos_cowork_governance.dashboard.api
8
+ *
9
+ * All interfaces use readonly fields to match Python's Pydantic models.
10
+ */
11
+
12
+ // ---------------------------------------------------------------------------
13
+ // Policy enumerations
14
+ // ---------------------------------------------------------------------------
15
+
16
+ /**
17
+ * Actions that a governance policy can mandate when its conditions are met.
18
+ * Maps to PolicyAction enum in Python.
19
+ */
20
+ export type PolicyAction =
21
+ | "allow"
22
+ | "block"
23
+ | "warn"
24
+ | "log"
25
+ | "approve";
26
+
27
+ /**
28
+ * Granular permissions that can be assigned to a role.
29
+ * Maps to Permission enum in Python.
30
+ */
31
+ export type Permission =
32
+ | "read"
33
+ | "write"
34
+ | "execute"
35
+ | "delegate"
36
+ | "approve"
37
+ | "escalate";
38
+
39
+ /**
40
+ * Strategy applied when two agents produce conflicting actions.
41
+ * Maps to ConflictStrategy enum in Python.
42
+ */
43
+ export type ConflictStrategy =
44
+ | "priority_based"
45
+ | "consensus"
46
+ | "leader_decides"
47
+ | "most_restrictive";
48
+
49
+ /**
50
+ * Constraint type categories.
51
+ * Maps to valid constraint_type values in Python.
52
+ */
53
+ export type ConstraintType =
54
+ | "budget_limit"
55
+ | "rate_limit"
56
+ | "scope_limit"
57
+ | "safety_rule";
58
+
59
+ // ---------------------------------------------------------------------------
60
+ // Policy definition
61
+ // ---------------------------------------------------------------------------
62
+
63
+ /**
64
+ * A single governance policy condition.
65
+ */
66
+ export interface PolicyCondition {
67
+ /** Dot-separated field path to evaluate from the action context. */
68
+ readonly field: string;
69
+ /** Comparison operator (e.g. "equals", "contains", "greater_than"). */
70
+ readonly operator: string;
71
+ /** The expected value to compare against. */
72
+ readonly value: unknown;
73
+ }
74
+
75
+ /**
76
+ * A governance policy rule that evaluates conditions and mandates an action.
77
+ */
78
+ export interface CompliancePolicy {
79
+ /** Human-readable policy name. */
80
+ readonly name: string;
81
+ /** The action to take when conditions are met. */
82
+ readonly action: PolicyAction;
83
+ /** Conditions that must be met (AND/OR logic per condition_logic). */
84
+ readonly conditions: readonly PolicyCondition[];
85
+ /** Logic for combining conditions: "AND" (default) or "OR". */
86
+ readonly condition_logic: "AND" | "OR";
87
+ /** Human-readable message explaining this policy's purpose. */
88
+ readonly message: string;
89
+ /** List of identifiers to notify when this policy triggers. */
90
+ readonly notify: readonly string[];
91
+ }
92
+
93
+ // ---------------------------------------------------------------------------
94
+ // Policy violation
95
+ // ---------------------------------------------------------------------------
96
+
97
+ /**
98
+ * Result of evaluating a single policy rule against an action context.
99
+ * Maps to PolicyResult dataclass in Python.
100
+ */
101
+ export interface PolicyViolation {
102
+ /** Name of the policy that produced this result. */
103
+ readonly policy_name: string;
104
+ /** Whether the policy conditions were matched. */
105
+ readonly matched: boolean;
106
+ /** The action mandated by this policy. */
107
+ readonly action: PolicyAction;
108
+ /** Human-readable message from the policy. */
109
+ readonly message: string;
110
+ /** Identifiers to notify when this policy triggers. */
111
+ readonly notify: readonly string[];
112
+ }
113
+
114
+ // ---------------------------------------------------------------------------
115
+ // Policy evaluation result
116
+ // ---------------------------------------------------------------------------
117
+
118
+ /**
119
+ * Aggregate result of running all policies against an action context.
120
+ * Maps to EvaluationResult dataclass in Python.
121
+ */
122
+ export interface PolicyEvaluationResult {
123
+ /** Whether the action is allowed (false only when a BLOCK policy matched). */
124
+ readonly allowed: boolean;
125
+ /** Per-policy evaluation results. */
126
+ readonly results: readonly PolicyViolation[];
127
+ /** Whether an APPROVE policy matched (human approval required). */
128
+ readonly requires_approval: boolean;
129
+ /** Name of the first BLOCK policy that triggered, or null. */
130
+ readonly blocking_policy: string | null;
131
+ }
132
+
133
+ // ---------------------------------------------------------------------------
134
+ // Constitution schema
135
+ // ---------------------------------------------------------------------------
136
+
137
+ /**
138
+ * Capabilities, budget limits, and tool access rules for a single agent role.
139
+ * Maps to RoleDefinition in Python.
140
+ */
141
+ export interface RoleDefinition {
142
+ /** Unique identifier for this role within the constitution. */
143
+ readonly name: string;
144
+ /** Set of Permission values granted to this role. */
145
+ readonly permissions: readonly Permission[];
146
+ /** Maximum cumulative spend in USD this role may authorise, or null for no cap. */
147
+ readonly max_budget_usd: number | null;
148
+ /** fnmatch-style patterns of tool names this role may invoke. */
149
+ readonly allowed_tools: readonly string[];
150
+ /** fnmatch-style patterns of tool names this role may never invoke. */
151
+ readonly denied_tools: readonly string[];
152
+ /** Names of other roles this role is permitted to delegate tasks to. */
153
+ readonly can_delegate_to: readonly string[];
154
+ /** Names of roles whose approval is needed before sensitive actions proceed. */
155
+ readonly requires_approval_from: readonly string[];
156
+ }
157
+
158
+ /**
159
+ * A parameterised governance rule applying to one or more roles.
160
+ * Maps to Constraint in Python.
161
+ */
162
+ export interface GovernanceConstraint {
163
+ /** Human-readable identifier for this constraint. */
164
+ readonly name: string;
165
+ /** Explanation of what the constraint enforces. */
166
+ readonly description: string;
167
+ /** The type of governance constraint. */
168
+ readonly constraint_type: ConstraintType;
169
+ /** Arbitrary key/value pairs that configure the constraint. */
170
+ readonly parameters: Readonly<Record<string, unknown>>;
171
+ /** List of role names this constraint targets. Use ["*"] for all roles. */
172
+ readonly applies_to: readonly string[];
173
+ /** Consequence of a violation: "warning", "error", or "critical". */
174
+ readonly severity: "warning" | "error" | "critical";
175
+ }
176
+
177
+ /**
178
+ * Defines when and how one role escalates to another.
179
+ * Maps to EscalationRule in Python.
180
+ */
181
+ export interface EscalationRule {
182
+ /** Natural-language description of the condition that causes escalation. */
183
+ readonly trigger: string;
184
+ /** The role that originates the escalation. */
185
+ readonly from_role: string;
186
+ /** The role that receives the escalated matter. */
187
+ readonly to_role: string;
188
+ /** When true the escalation happens automatically; otherwise it is suggested. */
189
+ readonly auto_escalate: boolean;
190
+ /** Maximum wait time in seconds before escalation is auto-resolved, or null. */
191
+ readonly timeout_seconds: number | null;
192
+ }
193
+
194
+ /**
195
+ * A constitution rule — a single named governance principle within a Constitution.
196
+ * Provides a named-rule abstraction layer over constraints and escalation rules.
197
+ */
198
+ export interface ConstitutionRule {
199
+ /** Unique rule identifier within the constitution. */
200
+ readonly rule_id: string;
201
+ /** Human-readable name of the rule. */
202
+ readonly name: string;
203
+ /** Description of what this rule enforces. */
204
+ readonly description: string;
205
+ /** Type of rule: "constraint", "escalation", or "permission". */
206
+ readonly rule_type: "constraint" | "escalation" | "permission";
207
+ /** Roles this rule applies to. */
208
+ readonly applies_to: readonly string[];
209
+ /** Whether violations of this rule are fatal (blocking). */
210
+ readonly is_fatal: boolean;
211
+ }
212
+
213
+ /**
214
+ * Top-level governance document for a multi-agent team.
215
+ * Maps to Constitution in Python.
216
+ */
217
+ export interface GovernanceConstitution {
218
+ /** Semantic version string for this constitution document. */
219
+ readonly version: string;
220
+ /** Name of the team or project this constitution governs. */
221
+ readonly team_name: string;
222
+ /** Human-readable summary of the team's governance philosophy. */
223
+ readonly description: string;
224
+ /** Ordered list of role definitions. Order matters for PRIORITY_BASED conflict resolution. */
225
+ readonly roles: readonly RoleDefinition[];
226
+ /** List of governance constraints enforced at runtime. */
227
+ readonly constraints: readonly GovernanceConstraint[];
228
+ /** List of escalation rules defining escalation paths. */
229
+ readonly escalation_rules: readonly EscalationRule[];
230
+ /** The default strategy applied when agent actions conflict. */
231
+ readonly conflict_strategy: ConflictStrategy;
232
+ /** ISO-8601 UTC timestamp when this constitution was first created. */
233
+ readonly created_at: string;
234
+ /** ISO-8601 UTC timestamp of the most recent modification. */
235
+ readonly updated_at: string;
236
+ }
237
+
238
+ // ---------------------------------------------------------------------------
239
+ // Workflow guardian
240
+ // ---------------------------------------------------------------------------
241
+
242
+ /**
243
+ * Configuration for the WorkflowGuardian that intercepts agent actions.
244
+ */
245
+ export interface WorkflowGuardianConfig {
246
+ /** Whether the guardian is active. */
247
+ readonly enabled: boolean;
248
+ /** Agent ID this guardian is protecting. */
249
+ readonly agent_id: string;
250
+ /** The governance constitution to enforce. */
251
+ readonly constitution?: GovernanceConstitution;
252
+ /** Whether to log all evaluated actions to the audit trail. */
253
+ readonly audit_all_actions: boolean;
254
+ /** Maximum action cost in USD to allow without approval. */
255
+ readonly auto_approve_below_cost_usd?: number;
256
+ }
257
+
258
+ // ---------------------------------------------------------------------------
259
+ // Governance dashboard
260
+ // ---------------------------------------------------------------------------
261
+
262
+ /** Summary of recent audit log activity. */
263
+ export interface AuditSummary {
264
+ /** List of recent audit log entries. */
265
+ readonly entries: readonly Readonly<Record<string, unknown>>[];
266
+ /** Total count of audit log entries. */
267
+ readonly total: number;
268
+ }
269
+
270
+ /** Cost tracking summary across all governed agents. */
271
+ export interface CostSummary {
272
+ /** Total cost in USD across all tracked calls. */
273
+ readonly total_cost_usd: number;
274
+ /** Total token count across all tracked calls. */
275
+ readonly total_tokens: number;
276
+ /** Total number of LLM API calls tracked. */
277
+ readonly call_count: number;
278
+ /** Cost breakdown by model name. */
279
+ readonly by_model: Readonly<Record<string, number>>;
280
+ /** Cost breakdown by task identifier. */
281
+ readonly by_task: Readonly<Record<string, number>>;
282
+ }
283
+
284
+ /** Aggregate governance health summary for the dashboard. */
285
+ export interface GovernanceDashboard {
286
+ /** Whether the governance system is operating normally. */
287
+ readonly healthy: boolean;
288
+ /** ISO-8601 UTC timestamp of this status snapshot. */
289
+ readonly timestamp: string;
290
+ /** Total number of audit log entries. */
291
+ readonly audit_count: number;
292
+ /** Total number of loaded governance policies. */
293
+ readonly policy_count: number;
294
+ /** Number of pending approval requests. */
295
+ readonly pending_approvals: number;
296
+ /** Accumulated cost across all governed agents in USD. */
297
+ readonly total_cost_usd: number;
298
+ }
299
+
300
+ /** A pending approval request awaiting human review. */
301
+ export interface ApprovalRequest {
302
+ /** Unique identifier for this approval request. */
303
+ readonly request_id: string;
304
+ /** Name of the policy that triggered the approval requirement. */
305
+ readonly policy_name: string;
306
+ /** Human-readable message describing what needs approval. */
307
+ readonly message: string;
308
+ /** ISO-8601 UTC timestamp when this request was created. */
309
+ readonly created_at: string;
310
+ /** Identifiers to notify about this pending approval. */
311
+ readonly notify: readonly string[];
312
+ /** The action context that triggered the approval requirement. */
313
+ readonly action_context: Readonly<Record<string, unknown>>;
314
+ }
315
+
316
+ /** Container for pending approval requests. */
317
+ export interface PendingApprovals {
318
+ /** List of pending approval request records. */
319
+ readonly pending: readonly ApprovalRequest[];
320
+ /** Total count of pending approval requests. */
321
+ readonly count: number;
322
+ }
323
+
324
+ // ---------------------------------------------------------------------------
325
+ // Workflow validation request
326
+ // ---------------------------------------------------------------------------
327
+
328
+ /** Request to validate an agent action against governance policies. */
329
+ export interface ValidateWorkflowRequest {
330
+ /** The action context to evaluate against all loaded policies. */
331
+ readonly action_context: Readonly<Record<string, unknown>>;
332
+ /** Optional agent ID for scoped evaluation. */
333
+ readonly agent_id?: string;
334
+ }
335
+
336
+ // ---------------------------------------------------------------------------
337
+ // API result wrapper
338
+ // ---------------------------------------------------------------------------
339
+
340
+ /** Standard error payload returned by the cowork-governance API. */
341
+ export interface ApiError {
342
+ readonly error: string;
343
+ readonly detail: string;
344
+ }
345
+
346
+ /** Result type for all client operations. */
347
+ export type ApiResult<T> =
348
+ | { readonly ok: true; readonly data: T }
349
+ | { readonly ok: false; readonly error: ApiError; readonly status: number };
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2020", "DOM"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "sourceMap": true,
12
+ "strict": true,
13
+ "noImplicitAny": true,
14
+ "strictNullChecks": true,
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+ "noImplicitReturns": true,
18
+ "exactOptionalPropertyTypes": true,
19
+ "forceConsistentCasingInFileNames": true,
20
+ "esModuleInterop": true,
21
+ "skipLibCheck": true
22
+ },
23
+ "include": ["src/**/*"],
24
+ "exclude": ["node_modules", "dist"]
25
+ }