aegis-mcp-server 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,305 @@
1
+ /**
2
+ * Aegis MCP Server — Core Type Definitions
3
+ *
4
+ * Aligned to the aegis-spec v0.2.0 schema contract and the aegis-cli v0.2.4
5
+ * extraction prompt. Skeleton fields (required by the spec) are typed precisely.
6
+ * Extension fields (domain-specific additions the LLM may generate) are typed
7
+ * as optional with their known shapes.
8
+ *
9
+ * The enforcement engine reads skeleton fields with confidence and leverages
10
+ * extension fields when present for deeper enforcement.
11
+ */
12
+
13
+ // ─── Constitution (constitution.json) ───────────────────────────────────────
14
+
15
+ export interface Constitution {
16
+ $schema?: string;
17
+ version: string;
18
+ project: {
19
+ name: string;
20
+ purpose: string;
21
+ architecture: string;
22
+ module_map?: ModuleMapEntry[];
23
+ required_artifacts?: RequiredArtifact[];
24
+ /** Extension: domain list with paths and descriptions */
25
+ domains?: DomainEntry[];
26
+ /** Extension: catch-all for other project fields */
27
+ [key: string]: unknown;
28
+ };
29
+ tech_stack: {
30
+ languages: string[];
31
+ frameworks?: string[];
32
+ infrastructure?: string[];
33
+ package_managers?: string[];
34
+ key_libraries?: Array<{ name: string; purpose: string; scope?: string }>;
35
+ [key: string]: unknown;
36
+ };
37
+ principles: Principle[];
38
+ build_commands?: BuildCommands;
39
+ /** Extension: sensitivity tier definitions */
40
+ sensitivity_tiers?: SensitivityTier[];
41
+ [key: string]: unknown;
42
+ }
43
+
44
+ export interface ModuleMapEntry {
45
+ path: string;
46
+ purpose: string;
47
+ owner?: string;
48
+ internal_dependencies?: string[];
49
+ }
50
+
51
+ export interface RequiredArtifact {
52
+ path: string;
53
+ purpose: string;
54
+ source?: string;
55
+ }
56
+
57
+ export interface DomainEntry {
58
+ name: string;
59
+ path: string;
60
+ description: string;
61
+ }
62
+
63
+ export interface Principle {
64
+ name: string;
65
+ statement: string;
66
+ priority?: number;
67
+ /** Extension: enforcement level */
68
+ id?: string;
69
+ enforcement?: string;
70
+ text?: string;
71
+ [key: string]: unknown;
72
+ }
73
+
74
+ export interface BuildCommands {
75
+ install?: string;
76
+ build?: string;
77
+ test?: string;
78
+ lint?: string;
79
+ typecheck?: string;
80
+ dev?: string;
81
+ custom?: Array<{ name: string; command: string; purpose: string }>;
82
+ [key: string]: unknown;
83
+ }
84
+
85
+ export interface SensitivityTier {
86
+ tier: string;
87
+ description: string;
88
+ examples: string[];
89
+ handling: Record<string, string>;
90
+ }
91
+
92
+ // ─── Governance (governance.json) ────────────────────────────────────────────
93
+
94
+ export interface Governance {
95
+ $schema?: string;
96
+ version: string;
97
+ autonomy: {
98
+ default_level: AutonomyLevel;
99
+ domains?: Record<string, AutonomyLevel>;
100
+ /** Extension: detailed level descriptions */
101
+ levels?: Record<string, { description: string }>;
102
+ /** Extension: per-domain overrides (alternate key) */
103
+ domain_overrides?: Record<string, AutonomyLevel | string>;
104
+ [key: string]: unknown;
105
+ };
106
+ permissions: {
107
+ boundaries: PermissionBoundaries;
108
+ sensitive_patterns?: SensitivePattern[];
109
+ [key: string]: unknown;
110
+ };
111
+ quality_gate: {
112
+ pre_commit: PreCommitGates;
113
+ /** Extension: richer gate array */
114
+ gates?: QualityGateEntry[];
115
+ /** Extension: override authority */
116
+ override_authority?: string;
117
+ [key: string]: unknown;
118
+ };
119
+ conventions?: Convention[];
120
+ escalation?: EscalationConfig;
121
+ override_protocol?: OverrideProtocol;
122
+ /** Extension: cross-domain enforcement rules */
123
+ cross_domain_rules?: CrossDomainRules;
124
+ /** Extension: data directory policy */
125
+ data_directory_policy?: Record<string, unknown>;
126
+ /** Extension: build commands (may appear here or in constitution) */
127
+ build_commands?: BuildCommands;
128
+ [key: string]: unknown;
129
+ }
130
+
131
+ export type AutonomyLevel = 'conservative' | 'advisory' | 'delegated';
132
+
133
+ export interface PermissionBoundaries {
134
+ writable?: string[];
135
+ read_only?: string[];
136
+ forbidden?: string[];
137
+ }
138
+
139
+ export interface SensitivePattern {
140
+ pattern: string;
141
+ reason: string;
142
+ }
143
+
144
+ export interface PreCommitGates {
145
+ must_pass_tests?: boolean;
146
+ must_pass_lint?: boolean;
147
+ must_pass_typecheck?: boolean;
148
+ must_add_tests?: boolean;
149
+ must_update_docs?: boolean;
150
+ max_files_changed?: number;
151
+ custom_checks?: Array<{
152
+ name: string;
153
+ command: string;
154
+ description?: string;
155
+ }>;
156
+ }
157
+
158
+ export interface QualityGateEntry {
159
+ name: string;
160
+ scope: string | string[];
161
+ required: boolean;
162
+ description: string;
163
+ }
164
+
165
+ export interface Convention {
166
+ id: string;
167
+ scope: string;
168
+ rule: string;
169
+ value?: string;
170
+ allowed?: string[];
171
+ forbidden?: string[];
172
+ enforcement: 'strict' | 'preferred' | 'suggestion';
173
+ rationale?: string;
174
+ }
175
+
176
+ export interface EscalationConfig {
177
+ on_ambiguity?: 'stop_and_ask' | 'best_judgment_and_flag' | 'best_judgment_silent';
178
+ on_conflict?: 'stop_and_ask' | 'principles_win' | 'convention_wins';
179
+ on_scope_boundary?: 'stop_and_ask' | 'flag_and_suggest' | 'stay_in_lane';
180
+ /** Extension: trigger list */
181
+ triggers?: string[];
182
+ /** Extension: escalation target */
183
+ target?: string;
184
+ /** Extension: escalation behavior description */
185
+ behavior?: string;
186
+ [key: string]: unknown;
187
+ }
188
+
189
+ export interface OverrideProtocol {
190
+ behavior?: 'block_and_log' | 'warn_confirm_and_log' | 'log_only';
191
+ log_path?: string;
192
+ log_entry_schema?: Record<string, unknown>;
193
+ immutable_policies?: string[];
194
+ }
195
+
196
+ export interface CrossDomainRules {
197
+ communication_method?: string;
198
+ shared_interfaces_path?: string;
199
+ violations?: Record<string, string>;
200
+ description?: string;
201
+ [key: string]: unknown;
202
+ }
203
+
204
+ // ─── Role (roles/*.json) ────────────────────────────────────────────────────
205
+
206
+ export interface RoleFile {
207
+ $schema?: string;
208
+ version: string;
209
+ /** Skeleton: nested role object */
210
+ role: {
211
+ name: string;
212
+ purpose: string;
213
+ specialization?: string[];
214
+ };
215
+ /** Skeleton: scoped paths */
216
+ scope: {
217
+ primary_paths: string[];
218
+ secondary_paths?: string[];
219
+ excluded_paths?: string[];
220
+ };
221
+ autonomy_overrides?: Record<string, AutonomyLevel>;
222
+ /** Extension: flat autonomy level for the role */
223
+ autonomy?: AutonomyLevel | string;
224
+ /** Extension: read/write path model */
225
+ paths?: {
226
+ read?: string[];
227
+ write?: string[];
228
+ };
229
+ /** Extension: prose list of forbidden actions */
230
+ forbidden_actions?: string[];
231
+ /** Extension: convention overrides or key-value conventions */
232
+ conventions?: unknown;
233
+ /** Extension: escalation triggers */
234
+ escalation_triggers?: string[];
235
+ /** Extension: QA validation responsibilities */
236
+ validation_responsibilities?: string[];
237
+ /** Extension: write mode (e.g. append-only) */
238
+ write_mode?: string;
239
+ /** Extension: report format config */
240
+ report_format?: Record<string, unknown>;
241
+ /** Extension: collaboration protocols */
242
+ collaboration?: Record<string, unknown>;
243
+ /** Extension: description (flat, alongside role.purpose) */
244
+ description?: string;
245
+ [key: string]: unknown;
246
+ }
247
+
248
+ /**
249
+ * Resolved role for enforcement — flattened from the RoleFile structure
250
+ * with skeleton and extension fields merged for fast lookups.
251
+ */
252
+ export interface ResolvedRole {
253
+ /** Filename without .json */
254
+ id: string;
255
+ /** role.name from skeleton */
256
+ name: string;
257
+ /** role.purpose from skeleton */
258
+ purpose: string;
259
+ /** Merged: scope.primary_paths + paths.write */
260
+ writable_paths: string[];
261
+ /** Merged: scope.secondary_paths */
262
+ secondary_paths: string[];
263
+ /** Merged: scope.excluded_paths */
264
+ excluded_paths: string[];
265
+ /** Merged: paths.read (when present) */
266
+ readable_paths: string[];
267
+ /** Autonomy level for this role */
268
+ autonomy: string;
269
+ /** Forbidden actions (prose, for informational responses) */
270
+ forbidden_actions: string[];
271
+ }
272
+
273
+ // ─── Enforcement Results ─────────────────────────────────────────────────────
274
+
275
+ export type EnforcementVerdict =
276
+ | { allowed: true }
277
+ | { allowed: false; reason: string; policy_ref: string; immutable: boolean };
278
+
279
+ export interface OverrideLogEntry {
280
+ timestamp: string;
281
+ policy_violated: string;
282
+ policy_text: string;
283
+ action_requested: string;
284
+ human_confirmed: boolean;
285
+ agent_role: string;
286
+ rationale: string;
287
+ }
288
+
289
+ // ─── Loaded Policy State ─────────────────────────────────────────────────────
290
+
291
+ export interface PolicyState {
292
+ constitution: Constitution;
293
+ governance: Governance;
294
+ roles: Map<string, ResolvedRole>;
295
+ projectRoot: string;
296
+ policyDir: string;
297
+ }
298
+
299
+ // ─── MCP Server Config ──────────────────────────────────────────────────────
300
+
301
+ export interface AegisMcpConfig {
302
+ role: string;
303
+ projectRoot: string;
304
+ policyDir?: string;
305
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "Node16",
5
+ "moduleResolution": "Node16",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "resolveJsonModule": true,
14
+ "declaration": true,
15
+ "declarationMap": true,
16
+ "sourceMap": true
17
+ },
18
+ "include": ["src/**/*"],
19
+ "exclude": ["node_modules", "dist"]
20
+ }