@behavior-os/schemas 0.0.0-stage → 2.2.1
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 +21 -0
- package/dist/index.d.ts +1958 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1236 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge-graph.d.ts +138 -0
- package/dist/knowledge-graph.d.ts.map +1 -0
- package/dist/knowledge-graph.js +112 -0
- package/dist/knowledge-graph.js.map +1 -0
- package/package.json +25 -3
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,1236 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// ============================================================
|
|
3
|
+
// DNA Pattern Schemas
|
|
4
|
+
// ============================================================
|
|
5
|
+
export const GovernanceActionSchema = z.enum(['block', 'escalate', 'warn', 'log', 'transform']);
|
|
6
|
+
export const ConditionSchema = z.object({
|
|
7
|
+
type: z.string(),
|
|
8
|
+
value: z.unknown(),
|
|
9
|
+
});
|
|
10
|
+
export const GovernanceRuleSchema = z.object({
|
|
11
|
+
id: z.string(),
|
|
12
|
+
level: z.enum(['critical', 'high', 'medium', 'low']),
|
|
13
|
+
action: GovernanceActionSchema,
|
|
14
|
+
conditions: z.array(ConditionSchema),
|
|
15
|
+
description: z.string().optional(),
|
|
16
|
+
});
|
|
17
|
+
export const QualityGateSchema = z.object({
|
|
18
|
+
id: z.string(),
|
|
19
|
+
type: z.enum(['test_coverage', 'lint', 'typecheck', 'security', 'performance', 'access_control']),
|
|
20
|
+
threshold: z.number(),
|
|
21
|
+
operator: z.enum(['gte', 'lte', 'eq', 'neq']).optional(),
|
|
22
|
+
});
|
|
23
|
+
export const PersonaBoundarySchema = z.object({
|
|
24
|
+
id: z.string(),
|
|
25
|
+
type: z.enum(['max_modules', 'max_files', 'max_lines', 'max_time', 'max_actions']),
|
|
26
|
+
value: z.number(),
|
|
27
|
+
});
|
|
28
|
+
export const PersonaSchema = z.object({
|
|
29
|
+
role: z.string(),
|
|
30
|
+
name: z.string(),
|
|
31
|
+
/**
|
|
32
|
+
* Free-form authority label used by a persona (e.g. "architect", "tech-lead",
|
|
33
|
+
* "compliance", "pi"). This is intentionally a string: shipped DNA patterns in
|
|
34
|
+
* `dnas/*.yaml` use domain-specific authorities, so a closed enum would reject
|
|
35
|
+
* the project's own patterns.
|
|
36
|
+
*/
|
|
37
|
+
authority: z.string(),
|
|
38
|
+
boundaries: z.array(PersonaBoundarySchema).optional(),
|
|
39
|
+
skills: z.array(z.string()),
|
|
40
|
+
description: z.string().optional(),
|
|
41
|
+
});
|
|
42
|
+
export const WorkflowStepSchema = z.object({
|
|
43
|
+
id: z.string(),
|
|
44
|
+
name: z.string(),
|
|
45
|
+
required: z.boolean().default(true),
|
|
46
|
+
approvalRequired: z.boolean().default(false),
|
|
47
|
+
timeoutSeconds: z.number().optional(),
|
|
48
|
+
});
|
|
49
|
+
export const WorkflowSchema = z.object({
|
|
50
|
+
id: z.string(),
|
|
51
|
+
name: z.string(),
|
|
52
|
+
steps: z.array(WorkflowStepSchema),
|
|
53
|
+
});
|
|
54
|
+
// ============================================================
|
|
55
|
+
// DNA-Adaptive Construction Pipeline Schemas (G-021)
|
|
56
|
+
// ============================================================
|
|
57
|
+
/**
|
|
58
|
+
* The type of a construction pipeline phase. These mirror the
|
|
59
|
+
* phases a human software-factory director would mandate.
|
|
60
|
+
*/
|
|
61
|
+
export const PipelinePhaseDefinitionTypeSchema = z.enum([
|
|
62
|
+
'architecture',
|
|
63
|
+
'planning',
|
|
64
|
+
'dependencies',
|
|
65
|
+
'frontend',
|
|
66
|
+
'backend',
|
|
67
|
+
'integration',
|
|
68
|
+
'testing',
|
|
69
|
+
'deployment',
|
|
70
|
+
'documentation',
|
|
71
|
+
]);
|
|
72
|
+
/**
|
|
73
|
+
* A single gate within a construction pipeline phase.
|
|
74
|
+
* Gates are evaluated by the PipelineEngine and must pass
|
|
75
|
+
* before the phase (and subsequent phases) can proceed.
|
|
76
|
+
*/
|
|
77
|
+
export const ConstructionPipelineGateSchema = z.object({
|
|
78
|
+
id: z.string(),
|
|
79
|
+
name: z.string(),
|
|
80
|
+
/** Which pipeline phase this gate belongs to. */
|
|
81
|
+
phaseType: PipelinePhaseDefinitionTypeSchema,
|
|
82
|
+
/** Whether a failure halts the pipeline. */
|
|
83
|
+
blocking: z.boolean().default(true),
|
|
84
|
+
/**
|
|
85
|
+
* The gate evaluation condition as a structured key+value.
|
|
86
|
+
* Evaluated against the phase context and project artifacts.
|
|
87
|
+
*/
|
|
88
|
+
condition: z.object({
|
|
89
|
+
type: z.string(),
|
|
90
|
+
value: z.unknown(),
|
|
91
|
+
description: z.string(),
|
|
92
|
+
}),
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* A phase definition within a construction pipeline. Each phase
|
|
96
|
+
* is associated with specific agent personas, skills to autoload,
|
|
97
|
+
* and gates to evaluate before proceeding.
|
|
98
|
+
*/
|
|
99
|
+
export const PipelinePhaseDefinitionSchema = z.object({
|
|
100
|
+
id: z.string(),
|
|
101
|
+
name: z.string(),
|
|
102
|
+
description: z.string().optional(),
|
|
103
|
+
/** The construction phase type (maps to PipelinePhaseDefinitionType). */
|
|
104
|
+
type: PipelinePhaseDefinitionTypeSchema,
|
|
105
|
+
/**
|
|
106
|
+
* Agent personas that should own this phase (from the DNA personas).
|
|
107
|
+
* These are resolved against the DNA pattern's personas section.
|
|
108
|
+
*/
|
|
109
|
+
requiredAgents: z.array(z.string()),
|
|
110
|
+
/**
|
|
111
|
+
* Skills to auto-load when this phase begins. The SkillAutoLoader
|
|
112
|
+
* maps these to .opencode/skills/<id>/SKILL.md files.
|
|
113
|
+
*/
|
|
114
|
+
requiredSkills: z.array(z.string()),
|
|
115
|
+
/** Gates evaluated during this phase. */
|
|
116
|
+
gates: z.array(ConstructionPipelineGateSchema),
|
|
117
|
+
/** Order determines which gate fails first. */
|
|
118
|
+
order: z.number().int().nonnegative(),
|
|
119
|
+
/**
|
|
120
|
+
* Whether execution is blocked until this phase's gates pass.
|
|
121
|
+
* When true, the pipeline will refuse to proceed to the next phase.
|
|
122
|
+
*/
|
|
123
|
+
blocking: z.boolean().default(true),
|
|
124
|
+
/**
|
|
125
|
+
* Optional readiness artifact: a file or marker that must exist
|
|
126
|
+
* before this phase can start (e.g. "adr/0001-architecture.md").
|
|
127
|
+
*/
|
|
128
|
+
readinessArtifact: z.string().optional(),
|
|
129
|
+
});
|
|
130
|
+
/**
|
|
131
|
+
* A named construction pipeline defined in a DNA pattern.
|
|
132
|
+
* The PipelinePlanner selects which pipeline to use based on
|
|
133
|
+
* the project context (web-app, API, mobile, etc.).
|
|
134
|
+
*/
|
|
135
|
+
export const ConstructionPipelineSchema = z.object({
|
|
136
|
+
id: z.string(),
|
|
137
|
+
name: z.string(),
|
|
138
|
+
description: z.string().optional(),
|
|
139
|
+
/** Phases in order of execution. */
|
|
140
|
+
phases: z.array(PipelinePhaseDefinitionSchema),
|
|
141
|
+
/**
|
|
142
|
+
* Project types this pipeline is the default for.
|
|
143
|
+
* Used by PipelinePlanner to auto-select the right pipeline.
|
|
144
|
+
*/
|
|
145
|
+
appliesTo: z.array(z.string()),
|
|
146
|
+
});
|
|
147
|
+
export const DNASchema = z.object({
|
|
148
|
+
name: z.string(),
|
|
149
|
+
version: z.string(),
|
|
150
|
+
description: z.string(),
|
|
151
|
+
personas: z.array(PersonaSchema),
|
|
152
|
+
governance: z.array(GovernanceRuleSchema),
|
|
153
|
+
quality: z.array(QualityGateSchema),
|
|
154
|
+
workflows: z.array(WorkflowSchema).optional(),
|
|
155
|
+
/** G-021: Construction pipelines — ordered phases with gates, agents, skills. */
|
|
156
|
+
pipelines: z.array(ConstructionPipelineSchema).optional(),
|
|
157
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
158
|
+
});
|
|
159
|
+
// ============================================================
|
|
160
|
+
// Mission Schemas
|
|
161
|
+
// ============================================================
|
|
162
|
+
export const MissionTypeSchema = z.enum([
|
|
163
|
+
'feature',
|
|
164
|
+
'bugfix',
|
|
165
|
+
'deployment',
|
|
166
|
+
'research',
|
|
167
|
+
'refactor',
|
|
168
|
+
'audit',
|
|
169
|
+
'incident',
|
|
170
|
+
]);
|
|
171
|
+
export const MissionPrioritySchema = z.enum(['critical', 'high', 'medium', 'low']);
|
|
172
|
+
export const MissionStatusSchema = z.enum([
|
|
173
|
+
'pending',
|
|
174
|
+
'active',
|
|
175
|
+
'paused',
|
|
176
|
+
'completed',
|
|
177
|
+
'failed',
|
|
178
|
+
'cancelled',
|
|
179
|
+
]);
|
|
180
|
+
/**
|
|
181
|
+
* Where evidence came from.
|
|
182
|
+
*
|
|
183
|
+
* - `executed` — a real command/adapter ran and produced this record.
|
|
184
|
+
* - `reported` — a caller or agent asserted the result without execution.
|
|
185
|
+
* - `simulated` — the check was simulated (never a verification).
|
|
186
|
+
*/
|
|
187
|
+
export const EvidenceProvenanceSchema = z.enum(['executed', 'reported', 'simulated']);
|
|
188
|
+
/**
|
|
189
|
+
* Evidence attached to a mission transition. `simulated: true` marks a value
|
|
190
|
+
* produced without executing the check (for example a simulated audit); such
|
|
191
|
+
* evidence can be recorded but never authorizes completion of a required gate.
|
|
192
|
+
*
|
|
193
|
+
* `provenance` and `executionId` are what let a mission in
|
|
194
|
+
* `verificationMode: 'executed'` distinguish a real run from an assertion.
|
|
195
|
+
*/
|
|
196
|
+
export const MissionEvidenceSchema = z.object({
|
|
197
|
+
gate: z.string().min(1),
|
|
198
|
+
status: z.enum(['passed', 'failed', 'skipped']),
|
|
199
|
+
source: z.string().min(1),
|
|
200
|
+
detail: z.string().optional(),
|
|
201
|
+
simulated: z.boolean().optional(),
|
|
202
|
+
provenance: EvidenceProvenanceSchema.optional(),
|
|
203
|
+
/** Identity of the concrete execution that produced this evidence. */
|
|
204
|
+
executionId: z.string().min(1).optional(),
|
|
205
|
+
/** Task whose execution produced this evidence; prevents cross-task reuse. */
|
|
206
|
+
taskId: z.string().min(1).optional(),
|
|
207
|
+
/** Adapter/tool that executed the check (e.g. `shell`). */
|
|
208
|
+
tool: z.string().min(1).optional(),
|
|
209
|
+
/** Command or operation, when the source executed one. */
|
|
210
|
+
command: z.string().optional(),
|
|
211
|
+
/** Process exit status, when applicable. */
|
|
212
|
+
exitCode: z.number().int().optional(),
|
|
213
|
+
recordedAt: z.string(),
|
|
214
|
+
});
|
|
215
|
+
/** One auditable entry in a mission's transition history. */
|
|
216
|
+
export const MissionTransitionSchema = z.object({
|
|
217
|
+
from: MissionStatusSchema,
|
|
218
|
+
to: MissionStatusSchema,
|
|
219
|
+
at: z.string(),
|
|
220
|
+
actor: z.string(),
|
|
221
|
+
reason: z.string().optional(),
|
|
222
|
+
version: z.number().int().nonnegative(),
|
|
223
|
+
});
|
|
224
|
+
export const MissionSchema = z.object({
|
|
225
|
+
id: z.string(),
|
|
226
|
+
title: z.string(),
|
|
227
|
+
description: z.string().optional(),
|
|
228
|
+
type: MissionTypeSchema,
|
|
229
|
+
priority: MissionPrioritySchema,
|
|
230
|
+
status: MissionStatusSchema,
|
|
231
|
+
dnaPattern: z.string(),
|
|
232
|
+
createdBy: z.string(),
|
|
233
|
+
assignedTo: z.array(z.string()).optional(),
|
|
234
|
+
createdAt: z.string(),
|
|
235
|
+
updatedAt: z.string(),
|
|
236
|
+
progress: z.number().min(0).max(100).default(0),
|
|
237
|
+
tags: z.array(z.string()).optional(),
|
|
238
|
+
/** Monotonic revision used to reject stale concurrent writes. */
|
|
239
|
+
version: z.number().int().nonnegative().optional(),
|
|
240
|
+
/** Gates that must each have passing evidence before the mission completes. */
|
|
241
|
+
requiredChecks: z.array(z.string()).optional(),
|
|
242
|
+
/**
|
|
243
|
+
* `any` accepts caller-supplied evidence (historical behaviour).
|
|
244
|
+
* `executed` requires every required gate to have passing evidence with
|
|
245
|
+
* `provenance: 'executed'` and a non-empty `executionId`.
|
|
246
|
+
*/
|
|
247
|
+
verificationMode: z.enum(['any', 'executed']).optional(),
|
|
248
|
+
/** Evidence recorded by transitions (append-only). */
|
|
249
|
+
evidence: z.array(MissionEvidenceSchema).optional(),
|
|
250
|
+
/** Auditable transition history (append-only). */
|
|
251
|
+
transitions: z.array(MissionTransitionSchema).optional(),
|
|
252
|
+
/** Why the mission was allowed to complete. */
|
|
253
|
+
completionBasis: z.enum(['evidence', 'no-required-checks']).optional(),
|
|
254
|
+
/** Reason supplied with the most recent fail/cancel/pause transition. */
|
|
255
|
+
lastTransitionReason: z.string().optional(),
|
|
256
|
+
});
|
|
257
|
+
// ============================================================
|
|
258
|
+
// Task Orchestration Schemas
|
|
259
|
+
// ============================================================
|
|
260
|
+
export const TaskStatusSchema = z.enum([
|
|
261
|
+
'pending',
|
|
262
|
+
'dispatched',
|
|
263
|
+
'running',
|
|
264
|
+
'completed',
|
|
265
|
+
'failed',
|
|
266
|
+
'cancelled',
|
|
267
|
+
'blocked',
|
|
268
|
+
]);
|
|
269
|
+
export const TaskErrorCodeSchema = z.enum([
|
|
270
|
+
'INVALID_INPUT',
|
|
271
|
+
'INVALID_OUTPUT',
|
|
272
|
+
'AGENT_NOT_FOUND',
|
|
273
|
+
'ADAPTER_NOT_FOUND',
|
|
274
|
+
'DNA_NOT_FOUND',
|
|
275
|
+
'GOVERNANCE_DENIED',
|
|
276
|
+
'APPROVAL_REQUIRED',
|
|
277
|
+
'TIMEOUT',
|
|
278
|
+
'CANCELLED',
|
|
279
|
+
'RETRY_EXHAUSTED',
|
|
280
|
+
'LOOP_DETECTED',
|
|
281
|
+
'CIRCUIT_OPEN',
|
|
282
|
+
'DEPENDENCY_BLOCKED',
|
|
283
|
+
'ACCEPTANCE_FAILED',
|
|
284
|
+
'EXECUTION_FAILED',
|
|
285
|
+
'PERSISTENCE_FAILED',
|
|
286
|
+
]);
|
|
287
|
+
/** One machine-checkable acceptance criterion for a task. */
|
|
288
|
+
export const TaskAcceptanceSchema = z.object({
|
|
289
|
+
gate: z.string().min(1),
|
|
290
|
+
description: z.string().min(1),
|
|
291
|
+
type: z.enum(['exit-code', 'stdout-contains', 'stdout-matches', 'stderr-not-contains']),
|
|
292
|
+
/** Expected value: exit code (default `0`), stdout text/pattern, or stderr text. */
|
|
293
|
+
expected: z.string().optional(),
|
|
294
|
+
/** Only required criteria gate task success. Defaults to `true`. */
|
|
295
|
+
required: z.boolean().default(true),
|
|
296
|
+
});
|
|
297
|
+
export const TaskCheckResultSchema = z.object({
|
|
298
|
+
gate: z.string(),
|
|
299
|
+
type: TaskAcceptanceSchema.shape.type,
|
|
300
|
+
required: z.boolean(),
|
|
301
|
+
passed: z.boolean(),
|
|
302
|
+
detail: z.string(),
|
|
303
|
+
});
|
|
304
|
+
/** A dispatched, fully identified task. */
|
|
305
|
+
export const TaskDefinitionSchema = z.object({
|
|
306
|
+
id: z.string().min(1),
|
|
307
|
+
missionId: z.string().min(1),
|
|
308
|
+
parentTaskId: z.string().min(1).optional(),
|
|
309
|
+
/** Tasks that must complete before this task is eligible. */
|
|
310
|
+
dependsOn: z.array(z.string().min(1)).optional(),
|
|
311
|
+
correlationId: z.string().min(1),
|
|
312
|
+
idempotencyKey: z.string().min(1),
|
|
313
|
+
type: z.string().min(1),
|
|
314
|
+
objective: z.string().min(1),
|
|
315
|
+
input: z.record(z.string(), z.unknown()),
|
|
316
|
+
acceptance: z.array(TaskAcceptanceSchema).min(1),
|
|
317
|
+
agentId: z.string().min(1),
|
|
318
|
+
adapter: z.string().min(1),
|
|
319
|
+
status: TaskStatusSchema,
|
|
320
|
+
attempts: z.number().int().nonnegative(),
|
|
321
|
+
maxAttempts: z.number().int().positive(),
|
|
322
|
+
timeoutMs: z.number().int().positive().optional(),
|
|
323
|
+
deadline: z.string().optional(),
|
|
324
|
+
createdAt: z.string(),
|
|
325
|
+
updatedAt: z.string(),
|
|
326
|
+
});
|
|
327
|
+
/** Structured, classified task failure. */
|
|
328
|
+
export const TaskErrorSchema = z.object({
|
|
329
|
+
code: TaskErrorCodeSchema,
|
|
330
|
+
message: z.string(),
|
|
331
|
+
retryable: z.boolean(),
|
|
332
|
+
/** Deterministic signature used for repeated-failure/loop detection. */
|
|
333
|
+
fingerprint: z.string().optional(),
|
|
334
|
+
});
|
|
335
|
+
/**
|
|
336
|
+
* The raw result an execution adapter returns. It is **untrusted** until the
|
|
337
|
+
* orchestrator validates it with this schema.
|
|
338
|
+
*/
|
|
339
|
+
export const AdapterResultSchema = z.object({
|
|
340
|
+
exitCode: z.number().int().nullable(),
|
|
341
|
+
stdout: z.string(),
|
|
342
|
+
stderr: z.string(),
|
|
343
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
344
|
+
});
|
|
345
|
+
export const TaskResultSchema = z.object({
|
|
346
|
+
id: z.string(),
|
|
347
|
+
missionId: z.string(),
|
|
348
|
+
status: TaskStatusSchema,
|
|
349
|
+
agentId: z.string(),
|
|
350
|
+
adapter: z.string(),
|
|
351
|
+
attempts: z.number().int().nonnegative(),
|
|
352
|
+
correlationId: z.string(),
|
|
353
|
+
idempotencyKey: z.string(),
|
|
354
|
+
startedAt: z.string().optional(),
|
|
355
|
+
completedAt: z.string().optional(),
|
|
356
|
+
durationMs: z.number().nonnegative().optional(),
|
|
357
|
+
exitCode: z.number().int().nullable().optional(),
|
|
358
|
+
stdout: z.string().optional(),
|
|
359
|
+
stderr: z.string().optional(),
|
|
360
|
+
acceptance: z.array(TaskCheckResultSchema),
|
|
361
|
+
evidence: z.array(MissionEvidenceSchema),
|
|
362
|
+
error: TaskErrorSchema.optional(),
|
|
363
|
+
});
|
|
364
|
+
export const TaskEventTypeSchema = z.enum([
|
|
365
|
+
'mission.created',
|
|
366
|
+
'mission.completed',
|
|
367
|
+
'mission.failed',
|
|
368
|
+
'mission.cancelled',
|
|
369
|
+
'mission.blocked',
|
|
370
|
+
'task.created',
|
|
371
|
+
'task.dispatched',
|
|
372
|
+
'task.started',
|
|
373
|
+
'task.retried',
|
|
374
|
+
'task.completed',
|
|
375
|
+
'task.failed',
|
|
376
|
+
'task.cancelled',
|
|
377
|
+
'task.blocked',
|
|
378
|
+
]);
|
|
379
|
+
/** Correlated lifecycle event. Payloads never contain stdout/stderr or env. */
|
|
380
|
+
export const TaskEventSchema = z.object({
|
|
381
|
+
seq: z.number().int().nonnegative(),
|
|
382
|
+
type: TaskEventTypeSchema,
|
|
383
|
+
missionId: z.string(),
|
|
384
|
+
taskId: z.string().optional(),
|
|
385
|
+
correlationId: z.string(),
|
|
386
|
+
at: z.string(),
|
|
387
|
+
data: z.record(z.string(), z.unknown()),
|
|
388
|
+
});
|
|
389
|
+
// ============================================================
|
|
390
|
+
// Agent Schemas
|
|
391
|
+
// ============================================================
|
|
392
|
+
export const AgentTypeSchema = z.enum([
|
|
393
|
+
'orchestrator',
|
|
394
|
+
'developer',
|
|
395
|
+
'architect',
|
|
396
|
+
'reviewer',
|
|
397
|
+
'operator',
|
|
398
|
+
'analyst',
|
|
399
|
+
]);
|
|
400
|
+
export const AgentStatusSchema = z.enum(['idle', 'busy', 'offline', 'error']);
|
|
401
|
+
export const AgentSchema = z.object({
|
|
402
|
+
id: z.string(),
|
|
403
|
+
name: z.string(),
|
|
404
|
+
type: AgentTypeSchema,
|
|
405
|
+
status: AgentStatusSchema,
|
|
406
|
+
dnaPattern: z.string(),
|
|
407
|
+
capabilities: z.array(z.string()),
|
|
408
|
+
currentMission: z.string().nullable(),
|
|
409
|
+
metrics: z.object({
|
|
410
|
+
tasksCompleted: z.number(),
|
|
411
|
+
tasksFailed: z.number(),
|
|
412
|
+
avgResponseTime: z.number(),
|
|
413
|
+
governanceViolations: z.number(),
|
|
414
|
+
}),
|
|
415
|
+
});
|
|
416
|
+
// ============================================================
|
|
417
|
+
// Governance Schemas
|
|
418
|
+
// ============================================================
|
|
419
|
+
export const GovernanceVerdictSchema = z.enum(['allow', 'deny', 'escalate', 'transform']);
|
|
420
|
+
export const GovernanceDecisionSchema = z.object({
|
|
421
|
+
id: z.string(),
|
|
422
|
+
action: z.string(),
|
|
423
|
+
verdict: GovernanceVerdictSchema,
|
|
424
|
+
reason: z.string(),
|
|
425
|
+
rulesEvaluated: z.array(z.string()),
|
|
426
|
+
/**
|
|
427
|
+
* Rule ids that actually matched and fired (block/escalate/warn/log/
|
|
428
|
+
* transform) during this evaluation, as opposed to `rulesEvaluated`, which
|
|
429
|
+
* lists every rule examined. Optional for backward compatibility.
|
|
430
|
+
*/
|
|
431
|
+
firedRules: z.array(z.string()).optional(),
|
|
432
|
+
timestamp: z.string(),
|
|
433
|
+
agentId: z.string(),
|
|
434
|
+
missionId: z.string().optional(),
|
|
435
|
+
transformed: z.boolean().optional(),
|
|
436
|
+
warnings: z.array(z.string()).optional(),
|
|
437
|
+
});
|
|
438
|
+
// ============================================================
|
|
439
|
+
// Audit Schemas
|
|
440
|
+
// ============================================================
|
|
441
|
+
export const AuditStageSchema = z.enum([
|
|
442
|
+
'lint',
|
|
443
|
+
'typecheck',
|
|
444
|
+
'security',
|
|
445
|
+
'coverage',
|
|
446
|
+
'performance',
|
|
447
|
+
'governance',
|
|
448
|
+
]);
|
|
449
|
+
export const AuditResultSchema = z.object({
|
|
450
|
+
id: z.string(),
|
|
451
|
+
stage: AuditStageSchema,
|
|
452
|
+
status: z.enum(['passed', 'failed', 'warning', 'skipped']),
|
|
453
|
+
details: z.record(z.string(), z.unknown()),
|
|
454
|
+
timestamp: z.string(),
|
|
455
|
+
});
|
|
456
|
+
export const AuditReportSchema = z.object({
|
|
457
|
+
id: z.string(),
|
|
458
|
+
missionId: z.string(),
|
|
459
|
+
agentId: z.string(),
|
|
460
|
+
/** DNA pattern active when the audit ran. */
|
|
461
|
+
dnaPattern: z.string().nullable().optional(),
|
|
462
|
+
/** Persona that authorized the audit, when the DNA defines one. */
|
|
463
|
+
persona: z.string().nullable().optional(),
|
|
464
|
+
stages: z.array(AuditResultSchema),
|
|
465
|
+
overall: z.enum(['pass', 'fail', 'warning']),
|
|
466
|
+
summary: z.string(),
|
|
467
|
+
timestamp: z.string(),
|
|
468
|
+
/**
|
|
469
|
+
* `true` when the report comes from a simulated run. A simulated report is
|
|
470
|
+
* never a verification: it is forced to `overall: 'warning'` and must not be
|
|
471
|
+
* used as completion evidence.
|
|
472
|
+
*/
|
|
473
|
+
simulated: z.boolean().optional(),
|
|
474
|
+
});
|
|
475
|
+
// ============================================================
|
|
476
|
+
// Pipeline Schemas
|
|
477
|
+
// ============================================================
|
|
478
|
+
/** Whether a gate runs before (pre) or after (post) an action executes. */
|
|
479
|
+
export const PipelinePhaseSchema = z.enum(['pre', 'post']);
|
|
480
|
+
export const GateStatusSchema = z.enum(['passed', 'failed', 'warning', 'skipped']);
|
|
481
|
+
export const GateResultSchema = z.object({
|
|
482
|
+
id: z.string(),
|
|
483
|
+
name: z.string(),
|
|
484
|
+
phase: PipelinePhaseSchema,
|
|
485
|
+
/** When true, a `failed` status halts the run and blocks the action. */
|
|
486
|
+
blocking: z.boolean(),
|
|
487
|
+
status: GateStatusSchema,
|
|
488
|
+
details: z.record(z.string(), z.unknown()),
|
|
489
|
+
durationMs: z.number(),
|
|
490
|
+
timestamp: z.string(),
|
|
491
|
+
});
|
|
492
|
+
export const PipelineRunSchema = z.object({
|
|
493
|
+
id: z.string(),
|
|
494
|
+
overall: z.enum(['pass', 'fail', 'warning']),
|
|
495
|
+
blocked: z.boolean(),
|
|
496
|
+
blockedBy: z.string().optional(),
|
|
497
|
+
phases: z.array(PipelinePhaseSchema),
|
|
498
|
+
gates: z.array(GateResultSchema),
|
|
499
|
+
durationMs: z.number(),
|
|
500
|
+
timestamp: z.string(),
|
|
501
|
+
missionId: z.string().optional(),
|
|
502
|
+
agentId: z.string().optional(),
|
|
503
|
+
});
|
|
504
|
+
// ============================================================
|
|
505
|
+
// Decision (voting) Schemas
|
|
506
|
+
// ============================================================
|
|
507
|
+
export const VoteChoiceSchema = z.enum(['approve', 'reject', 'abstain']);
|
|
508
|
+
export const VoteSchema = z.object({
|
|
509
|
+
voterId: z.string(),
|
|
510
|
+
choice: VoteChoiceSchema,
|
|
511
|
+
/** Voting weight. Defaults to 1; negative weights are clamped to 0. */
|
|
512
|
+
weight: z.number().optional(),
|
|
513
|
+
reason: z.string().optional(),
|
|
514
|
+
});
|
|
515
|
+
export const DecisionPolicySchema = z.enum(['majority', 'supermajority', 'unanimous']);
|
|
516
|
+
export const DecisionOutcomeSchema = z.enum(['approved', 'rejected', 'no_quorum']);
|
|
517
|
+
export const DecisionSchema = z.object({
|
|
518
|
+
id: z.string(),
|
|
519
|
+
subject: z.string(),
|
|
520
|
+
policy: DecisionPolicySchema,
|
|
521
|
+
outcome: DecisionOutcomeSchema,
|
|
522
|
+
quorum: z.number(),
|
|
523
|
+
quorumMet: z.boolean(),
|
|
524
|
+
/** Sum of weights per choice. */
|
|
525
|
+
approve: z.number(),
|
|
526
|
+
reject: z.number(),
|
|
527
|
+
abstain: z.number(),
|
|
528
|
+
/** Total participating weight (approve + reject + abstain). */
|
|
529
|
+
participatingWeight: z.number(),
|
|
530
|
+
votes: z.array(VoteSchema),
|
|
531
|
+
/** Voters that cast a non-abstain vote. */
|
|
532
|
+
decidedBy: z.array(z.string()),
|
|
533
|
+
reasons: z.array(z.string()),
|
|
534
|
+
timestamp: z.string(),
|
|
535
|
+
missionId: z.string().optional(),
|
|
536
|
+
});
|
|
537
|
+
// ============================================================
|
|
538
|
+
// Consensus (multi-agent voting) Schemas
|
|
539
|
+
// ============================================================
|
|
540
|
+
export const ConsensusPolicySchema = z.enum(['unanimous', 'supermajority', 'majority']);
|
|
541
|
+
export const ConsensusVoteSchema = z.object({
|
|
542
|
+
agentId: z.string(),
|
|
543
|
+
weight: z.number().optional(),
|
|
544
|
+
choice: VoteChoiceSchema,
|
|
545
|
+
reason: z.string().optional(),
|
|
546
|
+
});
|
|
547
|
+
export const ConsensusTallySchema = z.object({
|
|
548
|
+
approveWeight: z.number(),
|
|
549
|
+
rejectWeight: z.number(),
|
|
550
|
+
abstainWeight: z.number(),
|
|
551
|
+
totalParticipating: z.number(),
|
|
552
|
+
approveRatio: z.number(),
|
|
553
|
+
rejectRatio: z.number(),
|
|
554
|
+
});
|
|
555
|
+
export const ConsensusOutcomeSchema = z.enum(['approved', 'rejected', 'inconclusive']);
|
|
556
|
+
export const ConsensusRoundSchema = z.object({
|
|
557
|
+
id: z.string(),
|
|
558
|
+
subject: z.string(),
|
|
559
|
+
policy: ConsensusPolicySchema,
|
|
560
|
+
quorum: z.number(),
|
|
561
|
+
votes: z.array(ConsensusVoteSchema),
|
|
562
|
+
tally: ConsensusTallySchema,
|
|
563
|
+
outcome: ConsensusOutcomeSchema,
|
|
564
|
+
reason: z.string(),
|
|
565
|
+
timestamp: z.string(),
|
|
566
|
+
});
|
|
567
|
+
// ============================================================
|
|
568
|
+
// Prediction Schemas
|
|
569
|
+
// ============================================================
|
|
570
|
+
export const PredictionTypeSchema = z.enum([
|
|
571
|
+
'governance-block',
|
|
572
|
+
'mission-failure',
|
|
573
|
+
'quality-fall',
|
|
574
|
+
'drift-significant',
|
|
575
|
+
'pattern-repeated',
|
|
576
|
+
]);
|
|
577
|
+
export const PredictionSchema = z.object({
|
|
578
|
+
id: z.string(),
|
|
579
|
+
type: PredictionTypeSchema,
|
|
580
|
+
subject: z.string(),
|
|
581
|
+
confidence: z.number(),
|
|
582
|
+
horizonHours: z.number(),
|
|
583
|
+
evidence: z.array(z.string()),
|
|
584
|
+
recommendation: z.string(),
|
|
585
|
+
timestamp: z.string(),
|
|
586
|
+
});
|
|
587
|
+
// ============================================================
|
|
588
|
+
// DNA Evolution (learning-driven) Schemas
|
|
589
|
+
// ============================================================
|
|
590
|
+
export const EvolutionProposalSchema = z.object({
|
|
591
|
+
id: z.string(),
|
|
592
|
+
dnaName: z.string(),
|
|
593
|
+
/**
|
|
594
|
+
* The type of change this proposal represents.
|
|
595
|
+
* - `add-warn`: add a new warn rule (no vote required, safe by construction)
|
|
596
|
+
* - `relax-block`: relax a `block` or `escalate` rule — requires vote gate (0.67 threshold)
|
|
597
|
+
* - `add-block`: add a new `block` rule — requires vote gate (0.90 threshold)
|
|
598
|
+
*/
|
|
599
|
+
changeType: z.enum(['add-warn', 'relax-block', 'add-block']),
|
|
600
|
+
kind: z.enum(['governance-warn']),
|
|
601
|
+
pattern: z.string(),
|
|
602
|
+
condition: z.object({ type: z.string(), value: z.unknown() }).optional(),
|
|
603
|
+
ruleId: z.string(),
|
|
604
|
+
description: z.string(),
|
|
605
|
+
confidence: z.number(),
|
|
606
|
+
occurrences: z.number(),
|
|
607
|
+
evidence: z.array(z.string()),
|
|
608
|
+
timestamp: z.string(),
|
|
609
|
+
/** Whether this proposal requires a vote to be applied. */
|
|
610
|
+
requiresVote: z.boolean().default(false),
|
|
611
|
+
/**
|
|
612
|
+
* Vote threshold (0..1) to approve this proposal when `requiresVote` is true.
|
|
613
|
+
* Default: 0.67 for relax-block, 0.90 for add-block, 0.0 for add-warn.
|
|
614
|
+
*/
|
|
615
|
+
voteThreshold: z.number().min(0).max(1).default(0),
|
|
616
|
+
});
|
|
617
|
+
export const CodeFixProposalSchema = z.object({
|
|
618
|
+
id: z.string(),
|
|
619
|
+
/** Learning event type or extracted keyword. */
|
|
620
|
+
pattern: z.string(),
|
|
621
|
+
/** 0..1; see `LearningEngine.confidenceFor`. */
|
|
622
|
+
confidence: z.number(),
|
|
623
|
+
occurrences: z.number(),
|
|
624
|
+
suggestion: z.string(),
|
|
625
|
+
/** Up to 5 representative examples of the pattern. */
|
|
626
|
+
evidence: z.array(z.string()),
|
|
627
|
+
timestamp: z.string(),
|
|
628
|
+
});
|
|
629
|
+
// ============================================================
|
|
630
|
+
// Learning Schemas
|
|
631
|
+
// ============================================================
|
|
632
|
+
export const LearningTypeSchema = z.enum(['insight', 'pattern', 'fix', 'failure', 'optimization']);
|
|
633
|
+
export const LearningImpactSchema = z.enum(['low', 'medium', 'high', 'critical']);
|
|
634
|
+
export const LearningEventSchema = z.object({
|
|
635
|
+
id: z.string(),
|
|
636
|
+
type: LearningTypeSchema,
|
|
637
|
+
source: z.string(),
|
|
638
|
+
content: z.string(),
|
|
639
|
+
impact: LearningImpactSchema,
|
|
640
|
+
relatedMission: z.string().optional(),
|
|
641
|
+
relatedPattern: z.string().optional(),
|
|
642
|
+
timestamp: z.string(),
|
|
643
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
644
|
+
});
|
|
645
|
+
/**
|
|
646
|
+
* Lifecycle of a governed learning:
|
|
647
|
+
* `observation -> lesson -> candidate -> validated -> policy -> monitored`.
|
|
648
|
+
* Each record moves exactly one stage forward and keeps an auditable trail of
|
|
649
|
+
* transitions; `validated` (and every later stage) requires evidence.
|
|
650
|
+
*/
|
|
651
|
+
export const LearningStageSchema = z.enum([
|
|
652
|
+
'observation',
|
|
653
|
+
'lesson',
|
|
654
|
+
'candidate',
|
|
655
|
+
'validated',
|
|
656
|
+
'policy',
|
|
657
|
+
'monitored',
|
|
658
|
+
]);
|
|
659
|
+
export const LearningTransitionSchema = z.object({
|
|
660
|
+
from: LearningStageSchema,
|
|
661
|
+
to: LearningStageSchema,
|
|
662
|
+
at: z.string(),
|
|
663
|
+
actor: z.string(),
|
|
664
|
+
reason: z.string().optional(),
|
|
665
|
+
});
|
|
666
|
+
export const LearningRecordSchema = z.object({
|
|
667
|
+
id: z.string(),
|
|
668
|
+
stage: LearningStageSchema,
|
|
669
|
+
title: z.string(),
|
|
670
|
+
content: z.string(),
|
|
671
|
+
source: z.string(),
|
|
672
|
+
impact: LearningImpactSchema,
|
|
673
|
+
/** Evidence accumulated while promoting the record (command output, ids, ...). */
|
|
674
|
+
evidence: z.array(z.string()),
|
|
675
|
+
transitions: z.array(LearningTransitionSchema),
|
|
676
|
+
relatedMission: z.string().optional(),
|
|
677
|
+
createdAt: z.string(),
|
|
678
|
+
updatedAt: z.string(),
|
|
679
|
+
});
|
|
680
|
+
// ============================================================
|
|
681
|
+
// Protocol Schemas
|
|
682
|
+
// ============================================================
|
|
683
|
+
export const ProtocolStepSchema = z.object({
|
|
684
|
+
number: z.number(),
|
|
685
|
+
name: z.string(),
|
|
686
|
+
description: z.string(),
|
|
687
|
+
tool: z.string(),
|
|
688
|
+
required: z.boolean().default(true),
|
|
689
|
+
});
|
|
690
|
+
export const AgentStateSchema = z.object({
|
|
691
|
+
currentStep: z.number().default(0),
|
|
692
|
+
selectedDna: z.string().nullable(),
|
|
693
|
+
/**
|
|
694
|
+
* Id of the governed agent acting in this session. Never a model name: it is
|
|
695
|
+
* either an explicitly registered agent id, or a DNA persona identity such as
|
|
696
|
+
* `persona:architect`, or `null` when no DNA/agent has been selected yet.
|
|
697
|
+
*/
|
|
698
|
+
agentId: z.string().nullable().default(null),
|
|
699
|
+
/** Persona name/role selected from the active DNA, if any. */
|
|
700
|
+
persona: z.string().nullable().default(null),
|
|
701
|
+
activeMission: z.string().nullable(),
|
|
702
|
+
stepHistory: z.array(z.record(z.string(), z.unknown())),
|
|
703
|
+
createdAt: z.string(),
|
|
704
|
+
updatedAt: z.string(),
|
|
705
|
+
});
|
|
706
|
+
// ============================================================
|
|
707
|
+
// MCP Schemas
|
|
708
|
+
// ============================================================
|
|
709
|
+
export const McpToolSchema = z.object({
|
|
710
|
+
name: z.string().max(64),
|
|
711
|
+
description: z.string(),
|
|
712
|
+
inputSchema: z.record(z.string(), z.unknown()),
|
|
713
|
+
});
|
|
714
|
+
export const McpResourceSchema = z.object({
|
|
715
|
+
uri: z.string(),
|
|
716
|
+
name: z.string(),
|
|
717
|
+
description: z.string().optional(),
|
|
718
|
+
mimeType: z.string().optional(),
|
|
719
|
+
});
|
|
720
|
+
export const CodeFixResultSchema = z.object({
|
|
721
|
+
id: z.string(),
|
|
722
|
+
/** The originating proposal id returned by `proposeCodeFixes`. */
|
|
723
|
+
proposalId: z.string(),
|
|
724
|
+
pattern: z.string(),
|
|
725
|
+
confidence: z.number(),
|
|
726
|
+
applied: z.boolean(),
|
|
727
|
+
/** Present when votes were supplied — mirrors DecisionOutcome. */
|
|
728
|
+
voteOutcome: z.enum(['approved', 'rejected', 'no_quorum']).optional(),
|
|
729
|
+
/** Vote tally at the time of application. */
|
|
730
|
+
voteTally: z.object({ approve: z.number(), reject: z.number(), abstain: z.number() }).optional(),
|
|
731
|
+
timestamp: z.string(),
|
|
732
|
+
missionId: z.string().optional(),
|
|
733
|
+
});
|
|
734
|
+
/**
|
|
735
|
+
* A governed, persisted code-edit record.
|
|
736
|
+
*
|
|
737
|
+
* Every evaluated edit is recorded — including dry-runs and refusals — so the
|
|
738
|
+
* history of rejected proposals is versioned, not just the applied ones.
|
|
739
|
+
*/
|
|
740
|
+
export const CodeEditRecordSchema = z.object({
|
|
741
|
+
id: z.string(),
|
|
742
|
+
/** File path relative to the workspace root, with `/` separators. */
|
|
743
|
+
file: z.string(),
|
|
744
|
+
/** `sha256:<hex>` of the file before the edit. */
|
|
745
|
+
beforeHash: z.string(),
|
|
746
|
+
/** `sha256:<hex>` the file has (applied) or would have (dry-run). */
|
|
747
|
+
afterHash: z.string(),
|
|
748
|
+
bytesBefore: z.number(),
|
|
749
|
+
bytesAfter: z.number(),
|
|
750
|
+
addedLines: z.number(),
|
|
751
|
+
removedLines: z.number(),
|
|
752
|
+
/** Occurrences of the searched text; exactly 1 is required to apply. */
|
|
753
|
+
occurrences: z.number(),
|
|
754
|
+
/** Whether the file on disk was actually rewritten. */
|
|
755
|
+
applied: z.boolean(),
|
|
756
|
+
/** Why nothing was written (`dry-run`, `opt-in-disabled`, `vote-rejected`, …). */
|
|
757
|
+
reason: z.string().optional(),
|
|
758
|
+
/** Agent identity that requested the edit (from the DNA, never the model). */
|
|
759
|
+
agentId: z.string(),
|
|
760
|
+
/** DNA pattern active at the time. */
|
|
761
|
+
dnaPattern: z.string().nullable().optional(),
|
|
762
|
+
/** Present when votes were supplied — mirrors DecisionOutcome. */
|
|
763
|
+
voteOutcome: z.enum(['approved', 'rejected', 'no_quorum']).optional(),
|
|
764
|
+
/** Vote tally at the time of the decision. */
|
|
765
|
+
voteTally: z.object({ approve: z.number(), reject: z.number(), abstain: z.number() }).optional(),
|
|
766
|
+
missionId: z.string().optional(),
|
|
767
|
+
timestamp: z.string(),
|
|
768
|
+
});
|
|
769
|
+
export const RankedRecommendationSchema = z.object({
|
|
770
|
+
id: z.string(),
|
|
771
|
+
text: z.string(),
|
|
772
|
+
score: z.number().min(0).max(1),
|
|
773
|
+
evidence: z.array(z.string()),
|
|
774
|
+
timestamp: z.string(),
|
|
775
|
+
});
|
|
776
|
+
export const DriftInfoSchema = z.object({
|
|
777
|
+
id: z.string(),
|
|
778
|
+
newerName: z.string(),
|
|
779
|
+
olderName: z.string(),
|
|
780
|
+
rulesAdded: z.number(),
|
|
781
|
+
rulesRemoved: z.number(),
|
|
782
|
+
/** Ids present in both DNAs whose rule body changed. */
|
|
783
|
+
rulesChanged: z.array(z.string()),
|
|
784
|
+
gatesAdded: z.number(),
|
|
785
|
+
gatesRemoved: z.number(),
|
|
786
|
+
/** Ids present in both DNAs whose quality-gate body changed. */
|
|
787
|
+
gatesChanged: z.array(z.string()),
|
|
788
|
+
totalChanges: z.number(),
|
|
789
|
+
significant: z.boolean(),
|
|
790
|
+
summary: z.string(),
|
|
791
|
+
timestamp: z.string(),
|
|
792
|
+
});
|
|
793
|
+
// ============================================================
|
|
794
|
+
// Anti-Pattern Schemas
|
|
795
|
+
// ============================================================
|
|
796
|
+
export const AntiPatternTypeSchema = z.enum([
|
|
797
|
+
'typescript-error',
|
|
798
|
+
'lint-violation',
|
|
799
|
+
'security-vulnerability',
|
|
800
|
+
'performance-issue',
|
|
801
|
+
'architecture-violation',
|
|
802
|
+
'code-smell',
|
|
803
|
+
'test-gap',
|
|
804
|
+
'documentation-gap',
|
|
805
|
+
'governance-bypass',
|
|
806
|
+
'pattern-debt',
|
|
807
|
+
]);
|
|
808
|
+
export const SeveritySchema = z.enum(['critical', 'high', 'medium', 'low', 'info']);
|
|
809
|
+
export const AntiPatternSchema = z.object({
|
|
810
|
+
id: z.string(),
|
|
811
|
+
type: AntiPatternTypeSchema,
|
|
812
|
+
severity: SeveritySchema,
|
|
813
|
+
pattern: z.string(),
|
|
814
|
+
description: z.string(),
|
|
815
|
+
location: z.string().optional(),
|
|
816
|
+
file: z.string().optional(),
|
|
817
|
+
line: z.number().optional(),
|
|
818
|
+
evidence: z.array(z.string()),
|
|
819
|
+
recommendation: z.string(),
|
|
820
|
+
detectedAt: z.string(),
|
|
821
|
+
resolved: z.boolean().default(false),
|
|
822
|
+
resolvedAt: z.string().optional(),
|
|
823
|
+
resolvedBy: z.string().optional(),
|
|
824
|
+
});
|
|
825
|
+
export const ConversationTurnSchema = z.object({
|
|
826
|
+
id: z.string(),
|
|
827
|
+
agentId: z.string(),
|
|
828
|
+
role: z.enum(['system', 'user', 'agent', 'expert']),
|
|
829
|
+
content: z.string(),
|
|
830
|
+
timestamp: z.string(),
|
|
831
|
+
});
|
|
832
|
+
export const PragmaticConversationSchema = z.object({
|
|
833
|
+
id: z.string(),
|
|
834
|
+
title: z.string(),
|
|
835
|
+
problem: z.string(),
|
|
836
|
+
status: z.enum(['open', 'in-progress', 'resolved', 'closed', 'cancelled']),
|
|
837
|
+
participants: z.array(z.string()),
|
|
838
|
+
turns: z.array(ConversationTurnSchema),
|
|
839
|
+
antiPatterns: z.array(z.string()),
|
|
840
|
+
solution: z.string().optional(),
|
|
841
|
+
resolvedBy: z.string().optional(),
|
|
842
|
+
lessonsLearned: z.array(z.string()),
|
|
843
|
+
createdAt: z.string(),
|
|
844
|
+
updatedAt: z.string(),
|
|
845
|
+
});
|
|
846
|
+
export const PolicyRuleSchema = z.object({
|
|
847
|
+
id: z.string(),
|
|
848
|
+
name: z.string(),
|
|
849
|
+
description: z.string(),
|
|
850
|
+
condition: z.string(),
|
|
851
|
+
action: z.enum(['require', 'warn', 'block', 'auto-fix']),
|
|
852
|
+
severity: SeveritySchema,
|
|
853
|
+
appliesTo: z.array(z.enum(['persona', 'role', 'agent', 'project'])).optional(),
|
|
854
|
+
effectiveFrom: z.string(),
|
|
855
|
+
effectiveUntil: z.string().optional(),
|
|
856
|
+
});
|
|
857
|
+
export const RoleSchema = z.object({
|
|
858
|
+
id: z.string(),
|
|
859
|
+
name: z.string(),
|
|
860
|
+
displayName: z.string(),
|
|
861
|
+
responsibilities: z.array(z.string()),
|
|
862
|
+
policies: z.array(z.string()).optional(),
|
|
863
|
+
canAudit: z.boolean().default(false),
|
|
864
|
+
canEnforce: z.boolean().default(false),
|
|
865
|
+
canTeach: z.boolean().default(false),
|
|
866
|
+
});
|
|
867
|
+
// ============================================================
|
|
868
|
+
// Knowledge Graph Schemas (G-001)
|
|
869
|
+
// ============================================================
|
|
870
|
+
export * from './knowledge-graph.js';
|
|
871
|
+
// ============================================================
|
|
872
|
+
// G-009: Behavioral Anomaly Detection
|
|
873
|
+
// ============================================================
|
|
874
|
+
export const BehaviorProfileSchema = z.object({
|
|
875
|
+
/** Action frequency per hour (0..1 normalized). */
|
|
876
|
+
actionRate: z.number().min(0).max(1),
|
|
877
|
+
/** Fraction of actions that were denied/blocked. */
|
|
878
|
+
denialRate: z.number().min(0).max(1),
|
|
879
|
+
/** Fraction of actions that were escalated. */
|
|
880
|
+
escalationRate: z.number().min(0).max(1),
|
|
881
|
+
/** Number of distinct tools used in the window. */
|
|
882
|
+
toolDiversity: z.number().int().nonnegative(),
|
|
883
|
+
/** Whether the agent operated outside its normal time window. */
|
|
884
|
+
offHoursRatio: z.number().min(0).max(1),
|
|
885
|
+
});
|
|
886
|
+
export const AnomalyScoreSchema = z.object({
|
|
887
|
+
id: z.string(),
|
|
888
|
+
agentId: z.string(),
|
|
889
|
+
baseline: BehaviorProfileSchema,
|
|
890
|
+
current: BehaviorProfileSchema,
|
|
891
|
+
/** 0..1 — higher = more anomalous. */
|
|
892
|
+
deviation: z.number().min(0).max(1),
|
|
893
|
+
/** Human-readable explanation. */
|
|
894
|
+
explanation: z.string(),
|
|
895
|
+
timestamp: z.string(),
|
|
896
|
+
});
|
|
897
|
+
// ============================================================
|
|
898
|
+
// G-013: Experiential Learning Loop
|
|
899
|
+
// ============================================================
|
|
900
|
+
export const ExperiencePhaseSchema = z.enum(['execute', 'observe', 'reflect', 'abstract', 'apply']);
|
|
901
|
+
export const ExperienceRecordSchema = z.object({
|
|
902
|
+
id: z.string(),
|
|
903
|
+
agentId: z.string(),
|
|
904
|
+
/** The action that was executed. */
|
|
905
|
+
action: z.string(),
|
|
906
|
+
/** Result of the execution. */
|
|
907
|
+
outcome: z.enum(['success', 'failure', 'partial']),
|
|
908
|
+
/** Observation collected after execution. */
|
|
909
|
+
observation: z.string(),
|
|
910
|
+
/** Reflection: what was learned. */
|
|
911
|
+
reflection: z.string(),
|
|
912
|
+
/** Abstracted principle. */
|
|
913
|
+
abstraction: z.string(),
|
|
914
|
+
/** How the abstraction was applied. */
|
|
915
|
+
application: z.string(),
|
|
916
|
+
phase: ExperiencePhaseSchema,
|
|
917
|
+
confidence: z.number().min(0).max(1),
|
|
918
|
+
createdAt: z.string(),
|
|
919
|
+
});
|
|
920
|
+
// ============================================================
|
|
921
|
+
// G-016: Regulatory Compliance Mapper
|
|
922
|
+
// ============================================================
|
|
923
|
+
export const ComplianceStatusSchema = z.enum(['compliant', 'at-risk', 'violation']);
|
|
924
|
+
export const ComplianceMapSchema = z.object({
|
|
925
|
+
id: z.string(),
|
|
926
|
+
/** e.g. "GDPR Article 5", "SOX 302", "HIPAA Privacy Rule". */
|
|
927
|
+
regulation: z.string(),
|
|
928
|
+
/** The mapping of governance rules to this regulation. */
|
|
929
|
+
rules: z.array(z.string()),
|
|
930
|
+
/** Evidence collected for compliance. */
|
|
931
|
+
evidence: z.array(z.string()),
|
|
932
|
+
lastAudit: z.string(),
|
|
933
|
+
status: ComplianceStatusSchema,
|
|
934
|
+
/** Score 0..1 — higher = more compliant. */
|
|
935
|
+
score: z.number().min(0).max(1),
|
|
936
|
+
});
|
|
937
|
+
// ============================================================
|
|
938
|
+
// G-004: Symbolic-Neural Hybrid Engine
|
|
939
|
+
// ============================================================
|
|
940
|
+
export const HybridEvaluationSchema = z.object({
|
|
941
|
+
id: z.string(),
|
|
942
|
+
/** The deterministic symbolic (rule-based) verdict. */
|
|
943
|
+
symbolicVerdict: z.enum(['allow', 'deny', 'escalate', 'warn']),
|
|
944
|
+
/** Neural confidence score (0..1). In PoC this is derived from pattern frequency. */
|
|
945
|
+
neuralConfidence: z.number().min(0).max(1),
|
|
946
|
+
/** The combined hybrid verdict. */
|
|
947
|
+
hybridVerdict: z.enum(['allow', 'deny', 'escalate', 'warn']),
|
|
948
|
+
/** Whether the hybrid diverged from the symbolic result and why. */
|
|
949
|
+
diverged: z.boolean(),
|
|
950
|
+
explanation: z.string(),
|
|
951
|
+
timestamp: z.string(),
|
|
952
|
+
});
|
|
953
|
+
// ============================================================
|
|
954
|
+
// G-010: Zero-Trust Identity
|
|
955
|
+
// ============================================================
|
|
956
|
+
export const AgentIdentitySchema = z.object({
|
|
957
|
+
agentId: z.string(),
|
|
958
|
+
/** Decentralized Identifier (DID) for the agent, e.g. "did:bos:abc123". */
|
|
959
|
+
did: z.string(),
|
|
960
|
+
/** SHA-256 hash of the public key (hex, 64 chars). */
|
|
961
|
+
publicKeyHash: z.string().length(64),
|
|
962
|
+
/** The capabilities this identity is authorized for. */
|
|
963
|
+
capabilities: z.array(z.string()),
|
|
964
|
+
/** When this identity was issued. */
|
|
965
|
+
issuedAt: z.string(),
|
|
966
|
+
/** When this identity expires, or null for indefinite. */
|
|
967
|
+
expiresAt: z.string().nullable(),
|
|
968
|
+
});
|
|
969
|
+
export const IdentityVerificationResultSchema = z.object({
|
|
970
|
+
agentId: z.string(),
|
|
971
|
+
did: z.string(),
|
|
972
|
+
/** Whether the signature was valid. */
|
|
973
|
+
valid: z.boolean(),
|
|
974
|
+
/** Reason when invalid. */
|
|
975
|
+
reason: z.string().optional(),
|
|
976
|
+
verifiedAt: z.string(),
|
|
977
|
+
});
|
|
978
|
+
// ============================================================
|
|
979
|
+
// G-011: Dynamic Policy Adjustment
|
|
980
|
+
// ============================================================
|
|
981
|
+
export const RiskLevelSchema = z.enum(['low', 'medium', 'high', 'critical']);
|
|
982
|
+
export const RiskAssessmentSchema = z.object({
|
|
983
|
+
id: z.string(),
|
|
984
|
+
agentId: z.string(),
|
|
985
|
+
/** The risk level assessed. */
|
|
986
|
+
level: RiskLevelSchema,
|
|
987
|
+
/** 0..1 risk score. */
|
|
988
|
+
score: z.number().min(0).max(1),
|
|
989
|
+
/** Which factors contributed to the risk score. */
|
|
990
|
+
factors: z.array(z.string()),
|
|
991
|
+
/** The threshold adjustments applied. */
|
|
992
|
+
adjustedThresholds: z.record(z.string(), z.number()),
|
|
993
|
+
timestamp: z.string(),
|
|
994
|
+
});
|
|
995
|
+
export const DynamicPolicySchema = z.object({
|
|
996
|
+
id: z.string(),
|
|
997
|
+
agentId: z.string(),
|
|
998
|
+
/** The base rule ids this policy is derived from. */
|
|
999
|
+
baseRuleIds: z.array(z.string()),
|
|
1000
|
+
/** The risk level at the time of assessment. */
|
|
1001
|
+
riskLevel: RiskLevelSchema,
|
|
1002
|
+
/** Multiplier applied to enforcement thresholds. */
|
|
1003
|
+
enforcementMultiplier: z.number().positive(),
|
|
1004
|
+
/** Whether elevated scrutiny is in effect. */
|
|
1005
|
+
elevatedScrutiny: z.boolean(),
|
|
1006
|
+
activeSince: z.string(),
|
|
1007
|
+
});
|
|
1008
|
+
// ============================================================
|
|
1009
|
+
// G-017: Counterfactual Audit
|
|
1010
|
+
// ============================================================
|
|
1011
|
+
export const CounterfactualResultSchema = z.object({
|
|
1012
|
+
id: z.string(),
|
|
1013
|
+
/** The original decision being replayed. */
|
|
1014
|
+
originalDecisionId: z.string(),
|
|
1015
|
+
/** The hypothetical modification applied. */
|
|
1016
|
+
modification: z.string(),
|
|
1017
|
+
/** The hypothetical result. */
|
|
1018
|
+
hypotheticalVerdict: z.enum(['allow', 'deny', 'escalate', 'warn', 'transform']),
|
|
1019
|
+
/** The actual verdict. */
|
|
1020
|
+
actualVerdict: z.enum(['allow', 'deny', 'escalate', 'warn', 'transform']),
|
|
1021
|
+
/** Whether the hypothetical differs from the actual. */
|
|
1022
|
+
diverged: z.boolean(),
|
|
1023
|
+
/** Human-readable explanation. */
|
|
1024
|
+
explanation: z.string(),
|
|
1025
|
+
timestamp: z.string(),
|
|
1026
|
+
});
|
|
1027
|
+
// ============================================================
|
|
1028
|
+
// G-018: Explainable Reports
|
|
1029
|
+
// ============================================================
|
|
1030
|
+
export const ExplainableReportSchema = z.object({
|
|
1031
|
+
id: z.string(),
|
|
1032
|
+
title: z.string(),
|
|
1033
|
+
/** The agent the report is about. */
|
|
1034
|
+
agentId: z.string(),
|
|
1035
|
+
/** The time window covered. */
|
|
1036
|
+
from: z.string(),
|
|
1037
|
+
to: z.string(),
|
|
1038
|
+
/** Number of decisions summarized. */
|
|
1039
|
+
decisionsAnalyzed: z.number().int().nonnegative(),
|
|
1040
|
+
/** Plain-language summary of what happened. */
|
|
1041
|
+
summary: z.string(),
|
|
1042
|
+
/** Key findings for non-technical stakeholders. */
|
|
1043
|
+
findings: z.array(z.string()),
|
|
1044
|
+
/** Recommendations. */
|
|
1045
|
+
recommendations: z.array(z.string()),
|
|
1046
|
+
/** Severity of the overall posture. */
|
|
1047
|
+
severity: z.enum(['healthy', 'attention', 'critical']),
|
|
1048
|
+
timestamp: z.string(),
|
|
1049
|
+
});
|
|
1050
|
+
// ============================================================
|
|
1051
|
+
// G-005: Temporal Pattern Engine
|
|
1052
|
+
// ============================================================
|
|
1053
|
+
export const TemporalPatternSchema = z.object({
|
|
1054
|
+
id: z.string(),
|
|
1055
|
+
/** Human-readable description of the pattern. */
|
|
1056
|
+
description: z.string(),
|
|
1057
|
+
/** The DNA rule id the pattern relates to. */
|
|
1058
|
+
ruleId: z.string().uuid().optional(),
|
|
1059
|
+
/** ISO cron expression for the recurring window. */
|
|
1060
|
+
cronSchedule: z.string(),
|
|
1061
|
+
/** Days of the week the pattern is active (0=Sun..6=Sat). */
|
|
1062
|
+
activeDays: z.array(z.number().int().min(0).max(6)).optional(),
|
|
1063
|
+
/** Number of times this pattern has been observed. */
|
|
1064
|
+
occurrences: z.number().int().nonnegative(),
|
|
1065
|
+
/** Average deviation when the pattern fires (0..1). */
|
|
1066
|
+
avgDeviation: z.number().min(0).max(1),
|
|
1067
|
+
/** Whether the pattern is flagged as a risk. */
|
|
1068
|
+
isRisk: z.boolean(),
|
|
1069
|
+
/** Detected timestamp (when the pattern was first identified). */
|
|
1070
|
+
detectedAt: z.string(),
|
|
1071
|
+
/** When the pattern was last observed. */
|
|
1072
|
+
lastSeen: z.string(),
|
|
1073
|
+
});
|
|
1074
|
+
export const TemporalPatternSuggestionSchema = z.object({
|
|
1075
|
+
patternId: z.string(),
|
|
1076
|
+
/** The suggested cron schedule for a new temporal rule. */
|
|
1077
|
+
suggestedCron: z.string(),
|
|
1078
|
+
/** Confidence in the suggestion (0..1). */
|
|
1079
|
+
confidence: z.number().min(0).max(1),
|
|
1080
|
+
reason: z.string(),
|
|
1081
|
+
});
|
|
1082
|
+
// ============================================================
|
|
1083
|
+
// G-007: Cross-Domain Knowledge Transfer (enhanced)
|
|
1084
|
+
// ============================================================
|
|
1085
|
+
export const CrossDomainTransferSchema = z.object({
|
|
1086
|
+
id: z.string(),
|
|
1087
|
+
/** Source DNA pattern. */
|
|
1088
|
+
sourceDna: z.string(),
|
|
1089
|
+
/** Target DNA pattern. */
|
|
1090
|
+
targetDna: z.string(),
|
|
1091
|
+
/** The rule id transferred. */
|
|
1092
|
+
ruleId: z.string(),
|
|
1093
|
+
/** Structural similarity score (0..1). */
|
|
1094
|
+
similarity: z.number().min(0).max(1),
|
|
1095
|
+
/** Why this transfer is suggested. */
|
|
1096
|
+
justification: z.string(),
|
|
1097
|
+
/** When the transfer was identified. */
|
|
1098
|
+
createdAt: z.string(),
|
|
1099
|
+
});
|
|
1100
|
+
// ============================================================
|
|
1101
|
+
// G-008: Memory Consolidation Engine
|
|
1102
|
+
// ============================================================
|
|
1103
|
+
export const SemanticFactSchema = z.object({
|
|
1104
|
+
id: z.string(),
|
|
1105
|
+
/** The factual statement. */
|
|
1106
|
+
fact: z.string(),
|
|
1107
|
+
/** Source episode ids that led to this fact. */
|
|
1108
|
+
sourceEpisodes: z.array(z.string()),
|
|
1109
|
+
/** Confidence in the fact (0..1). */
|
|
1110
|
+
confidence: z.number().min(0).max(1),
|
|
1111
|
+
/** When the fact was consolidated. */
|
|
1112
|
+
createdAt: z.string(),
|
|
1113
|
+
/** When the fact was last validated. */
|
|
1114
|
+
lastValidated: z.string().optional(),
|
|
1115
|
+
});
|
|
1116
|
+
export const ConsolidatedKnowledgeSchema = z.object({
|
|
1117
|
+
/** Semantic facts extracted from episodes. */
|
|
1118
|
+
semanticFacts: z.array(SemanticFactSchema),
|
|
1119
|
+
/** Summary of the consolidation run. */
|
|
1120
|
+
summary: z.string(),
|
|
1121
|
+
/** How many episodes were processed. */
|
|
1122
|
+
episodesProcessed: z.number().int().nonnegative(),
|
|
1123
|
+
/** How many facts were pruned (obsolete). */
|
|
1124
|
+
factsPruned: z.number().int().nonnegative(),
|
|
1125
|
+
timestamp: z.string(),
|
|
1126
|
+
});
|
|
1127
|
+
// ============================================================
|
|
1128
|
+
// G-012: Circuit Breaker Intelligence
|
|
1129
|
+
// ============================================================
|
|
1130
|
+
export const FailurePatternSchema = z.object({
|
|
1131
|
+
id: z.string(),
|
|
1132
|
+
/** The operation type that failed. */
|
|
1133
|
+
operationType: z.string(),
|
|
1134
|
+
/** Error signature (normalized error message pattern). */
|
|
1135
|
+
errorPattern: z.string(),
|
|
1136
|
+
/** Number of occurrences. */
|
|
1137
|
+
occurrences: z.number().int().nonnegative(),
|
|
1138
|
+
/** Failure rate (0..1). */
|
|
1139
|
+
failureRate: z.number().min(0).max(1),
|
|
1140
|
+
/** Recommended breaker threshold for this pattern. */
|
|
1141
|
+
recommendedThreshold: z.number().min(0).max(1),
|
|
1142
|
+
});
|
|
1143
|
+
export const BreakerAdjustmentSchema = z.object({
|
|
1144
|
+
id: z.string(),
|
|
1145
|
+
failurePatternId: z.string(),
|
|
1146
|
+
/** The breaker name adjusted. */
|
|
1147
|
+
breakerName: z.string(),
|
|
1148
|
+
/** Previous threshold. */
|
|
1149
|
+
previousThreshold: z.number(),
|
|
1150
|
+
/** New threshold applied. */
|
|
1151
|
+
newThreshold: z.number(),
|
|
1152
|
+
reason: z.string(),
|
|
1153
|
+
timestamp: z.string(),
|
|
1154
|
+
});
|
|
1155
|
+
// ============================================================
|
|
1156
|
+
// G-014: Value Alignment Engine
|
|
1157
|
+
// ============================================================
|
|
1158
|
+
export const ValueDefinitionSchema = z.object({
|
|
1159
|
+
id: z.string(),
|
|
1160
|
+
name: z.string(),
|
|
1161
|
+
description: z.string(),
|
|
1162
|
+
/** Keywords that indicate this value is at stake. */
|
|
1163
|
+
keywords: z.array(z.string()),
|
|
1164
|
+
});
|
|
1165
|
+
export const AlignmentScoreSchema = z.object({
|
|
1166
|
+
id: z.string(),
|
|
1167
|
+
agentId: z.string(),
|
|
1168
|
+
/** The values being scored. */
|
|
1169
|
+
values: z.array(ValueDefinitionSchema),
|
|
1170
|
+
/** Per-value alignment score (0..1). */
|
|
1171
|
+
scores: z.record(z.string(), z.number().min(0).max(1)),
|
|
1172
|
+
/** Overall alignment score (0..1). */
|
|
1173
|
+
overallScore: z.number().min(0).max(1),
|
|
1174
|
+
/** Violations detected (actions that conflict with values). */
|
|
1175
|
+
violations: z.array(z.string()),
|
|
1176
|
+
timestamp: z.string(),
|
|
1177
|
+
});
|
|
1178
|
+
// ============================================================
|
|
1179
|
+
// G-015: Collective Intelligence Aggregation
|
|
1180
|
+
// ============================================================
|
|
1181
|
+
export const CollectiveVoteSchema = z.object({
|
|
1182
|
+
id: z.string(),
|
|
1183
|
+
/** The proposal being voted on. */
|
|
1184
|
+
proposal: z.string(),
|
|
1185
|
+
/** Per-agent votes. */
|
|
1186
|
+
votes: z
|
|
1187
|
+
.array(z.object({
|
|
1188
|
+
agentId: z.string(),
|
|
1189
|
+
choice: z.enum(['approve', 'reject', 'abstain']),
|
|
1190
|
+
weight: z.number().nonnegative(),
|
|
1191
|
+
confidence: z.number().min(0).max(1),
|
|
1192
|
+
rationale: z.string().optional(),
|
|
1193
|
+
}))
|
|
1194
|
+
.min(1),
|
|
1195
|
+
/** Aggregated result. */
|
|
1196
|
+
result: z.enum(['approved', 'rejected', 'tie']),
|
|
1197
|
+
/** Confidence in the collective decision (0..1). */
|
|
1198
|
+
collectiveConfidence: z.number().min(0).max(1),
|
|
1199
|
+
});
|
|
1200
|
+
// ============================================================
|
|
1201
|
+
// G-019: External System Adapter Framework
|
|
1202
|
+
// ============================================================
|
|
1203
|
+
export const ExternalEventSchema = z.object({
|
|
1204
|
+
id: z.string(),
|
|
1205
|
+
source: z.string(),
|
|
1206
|
+
type: z.string(),
|
|
1207
|
+
payload: z.record(z.string(), z.unknown()),
|
|
1208
|
+
receivedAt: z.string(),
|
|
1209
|
+
});
|
|
1210
|
+
export const ExternalPolicySchema = z.object({
|
|
1211
|
+
id: z.string(),
|
|
1212
|
+
source: z.string(),
|
|
1213
|
+
ruleId: z.string(),
|
|
1214
|
+
action: GovernanceActionSchema,
|
|
1215
|
+
conditions: z.array(ConditionSchema),
|
|
1216
|
+
/** When the policy was imported. */
|
|
1217
|
+
importedAt: z.string(),
|
|
1218
|
+
});
|
|
1219
|
+
// ============================================================
|
|
1220
|
+
// G-020: Governance-as-Code Repository
|
|
1221
|
+
// ============================================================
|
|
1222
|
+
export const GovernanceChangeRequestSchema = z.object({
|
|
1223
|
+
id: z.string(),
|
|
1224
|
+
/** The DNA pattern being modified. */
|
|
1225
|
+
dnaName: z.string(),
|
|
1226
|
+
/** The rule id being added/changed/removed. */
|
|
1227
|
+
ruleId: z.string(),
|
|
1228
|
+
changeType: z.enum(['add', 'modify', 'delete']),
|
|
1229
|
+
proposedRule: GovernanceRuleSchema.optional(),
|
|
1230
|
+
/** Rationale for the change. */
|
|
1231
|
+
rationale: z.string(),
|
|
1232
|
+
/** CI status of the change. */
|
|
1233
|
+
ciStatus: z.enum(['pending', 'passing', 'failing', 'approved']),
|
|
1234
|
+
createdAt: z.string(),
|
|
1235
|
+
});
|
|
1236
|
+
//# sourceMappingURL=index.js.map
|