@ai-dev-orchestrator/governance 0.1.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.
Files changed (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +60 -0
  3. package/dist/domain/governance/errors.d.ts +20 -0
  4. package/dist/domain/governance/errors.js +30 -0
  5. package/dist/domain/governance/index.d.ts +2 -0
  6. package/dist/domain/governance/index.js +1 -0
  7. package/dist/domain/governance/ownership-check-result.d.ts +5 -0
  8. package/dist/domain/governance/ownership-check-result.js +1 -0
  9. package/dist/domain/iteration-contracts/errors.d.ts +21 -0
  10. package/dist/domain/iteration-contracts/errors.js +32 -0
  11. package/dist/domain/iteration-contracts/index.d.ts +1 -0
  12. package/dist/domain/iteration-contracts/index.js +1 -0
  13. package/dist/index.d.ts +7 -0
  14. package/dist/index.js +10 -0
  15. package/dist/infrastructure/collaboration-model/default-collaboration-model.d.ts +19 -0
  16. package/dist/infrastructure/collaboration-model/default-collaboration-model.js +109 -0
  17. package/dist/infrastructure/collaboration-model/index.d.ts +1 -0
  18. package/dist/infrastructure/collaboration-model/index.js +1 -0
  19. package/dist/infrastructure/governance/decision-recorder.d.ts +14 -0
  20. package/dist/infrastructure/governance/decision-recorder.js +37 -0
  21. package/dist/infrastructure/governance/escalation-manager.d.ts +7 -0
  22. package/dist/infrastructure/governance/escalation-manager.js +49 -0
  23. package/dist/infrastructure/governance/index.d.ts +7 -0
  24. package/dist/infrastructure/governance/index.js +6 -0
  25. package/dist/infrastructure/governance/iteration-limiter.d.ts +9 -0
  26. package/dist/infrastructure/governance/iteration-limiter.js +33 -0
  27. package/dist/infrastructure/governance/ownership-enforcer.d.ts +16 -0
  28. package/dist/infrastructure/governance/ownership-enforcer.js +55 -0
  29. package/dist/infrastructure/governance/quality-gate-checker.d.ts +6 -0
  30. package/dist/infrastructure/governance/quality-gate-checker.js +29 -0
  31. package/dist/infrastructure/governance/transition-gate.d.ts +34 -0
  32. package/dist/infrastructure/governance/transition-gate.js +194 -0
  33. package/dist/infrastructure/iteration-contracts/built-in-contracts.d.ts +10 -0
  34. package/dist/infrastructure/iteration-contracts/built-in-contracts.js +160 -0
  35. package/dist/infrastructure/iteration-contracts/contract-registry.d.ts +32 -0
  36. package/dist/infrastructure/iteration-contracts/contract-registry.js +144 -0
  37. package/dist/infrastructure/iteration-contracts/index.d.ts +2 -0
  38. package/dist/infrastructure/iteration-contracts/index.js +2 -0
  39. package/package.json +44 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AI Dev Orchestrator Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @ai-dev-orchestrator/governance
2
+
3
+ Governance engine that enforces ownership rules, quality gates, escalation policies, and iteration contracts. Controls how agents interact, what they are allowed to do, and when human review is required.
4
+
5
+ ## Architecture Layer
6
+
7
+ **Domain** -- defines governance rules, ownership checks, and iteration contract semantics.
8
+
9
+ ## Workspace Dependencies
10
+
11
+ - `@ai-dev-orchestrator/ports`
12
+ - `@ai-dev-orchestrator/schemas`
13
+
14
+ ## Structure
15
+
16
+ ```
17
+ src/
18
+ domain/
19
+ governance/
20
+ __tests__/
21
+ iteration-contracts/
22
+ __tests__/
23
+ infrastructure/
24
+ governance/
25
+ __tests__/
26
+ iteration-contracts/
27
+ __tests__/
28
+ collaboration-model/
29
+ __tests__/
30
+ ```
31
+
32
+ ## Key Exports
33
+
34
+ ### Domain -- Governance
35
+
36
+ - `GovernanceError`, `EscalationError`, `PolicyLoadError` -- governance error hierarchy
37
+ - `OwnershipCheckResult` -- result type for ownership validation
38
+
39
+ ### Domain -- Iteration Contracts
40
+
41
+ - `ContractNotFoundError`, `ContractStateMismatchError`, `InvalidContractError` -- contract errors
42
+
43
+ ### Infrastructure -- Governance
44
+
45
+ - `DefaultGovernanceEngine` -- main governance engine coordinating all checks
46
+ - `OwnershipEnforcer` -- validates artifact ownership rules
47
+ - `QualityGateChecker` -- enforces quality gates before transitions
48
+ - `EscalationManager` -- handles escalation to human reviewers
49
+ - `IterationLimiter` -- enforces maximum iteration counts
50
+ - `DecisionRecorder` -- persists governance decisions
51
+
52
+ ### Infrastructure -- Iteration Contracts
53
+
54
+ - `DefaultIterationContractRegistry` -- registry of iteration contract definitions
55
+ - `buildContracts` -- factory for constructing contracts from configuration
56
+ - `BUILT_IN_CONTRACTS` -- predefined contracts (plan review, implementation review, clarification, acceptance validation)
57
+
58
+ ### Infrastructure -- Collaboration Model
59
+
60
+ - `DefaultCollaborationModel` -- manages multi-agent collaboration patterns
@@ -0,0 +1,20 @@
1
+ import { NonRecoverableErrorBase } from '@ai-dev-orchestrator/ports';
2
+ /** Thrown when governance evaluation fails unexpectedly. */
3
+ export declare class GovernanceError extends NonRecoverableErrorBase {
4
+ readonly cause: string;
5
+ readonly code = "GOVERNANCE_ERROR";
6
+ constructor(cause: string);
7
+ }
8
+ /** Thrown when governance policy cannot be loaded. */
9
+ export declare class PolicyLoadError extends NonRecoverableErrorBase {
10
+ readonly cause: string;
11
+ readonly code = "POLICY_LOAD_ERROR";
12
+ constructor(cause: string);
13
+ }
14
+ /** Thrown when escalation handling fails. */
15
+ export declare class EscalationError extends NonRecoverableErrorBase {
16
+ readonly stageId: string;
17
+ readonly cause: string;
18
+ readonly code = "ESCALATION_ERROR";
19
+ constructor(stageId: string, cause: string);
20
+ }
@@ -0,0 +1,30 @@
1
+ import { NonRecoverableErrorBase } from '@ai-dev-orchestrator/ports';
2
+ /** Thrown when governance evaluation fails unexpectedly. */
3
+ export class GovernanceError extends NonRecoverableErrorBase {
4
+ cause;
5
+ code = 'GOVERNANCE_ERROR';
6
+ constructor(cause) {
7
+ super(`Governance evaluation failed: ${cause}`);
8
+ this.cause = cause;
9
+ }
10
+ }
11
+ /** Thrown when governance policy cannot be loaded. */
12
+ export class PolicyLoadError extends NonRecoverableErrorBase {
13
+ cause;
14
+ code = 'POLICY_LOAD_ERROR';
15
+ constructor(cause) {
16
+ super(`Failed to load governance policy: ${cause}`);
17
+ this.cause = cause;
18
+ }
19
+ }
20
+ /** Thrown when escalation handling fails. */
21
+ export class EscalationError extends NonRecoverableErrorBase {
22
+ stageId;
23
+ cause;
24
+ code = 'ESCALATION_ERROR';
25
+ constructor(stageId, cause) {
26
+ super(`Escalation failed at stage "${stageId}": ${cause}`);
27
+ this.stageId = stageId;
28
+ this.cause = cause;
29
+ }
30
+ }
@@ -0,0 +1,2 @@
1
+ export { EscalationError, GovernanceError, PolicyLoadError } from './errors';
2
+ export type { OwnershipCheckResult } from './ownership-check-result';
@@ -0,0 +1 @@
1
+ export { EscalationError, GovernanceError, PolicyLoadError } from './errors';
@@ -0,0 +1,5 @@
1
+ /** Result of an ownership enforcement check. */
2
+ export interface OwnershipCheckResult {
3
+ readonly allowed: boolean;
4
+ readonly reason: string;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { NonRecoverableErrorBase } from '@ai-dev-orchestrator/ports';
2
+ /** Thrown when an iteration contract definition is invalid. */
3
+ export declare class InvalidContractError extends NonRecoverableErrorBase {
4
+ readonly contractId: string;
5
+ readonly cause: string;
6
+ readonly code = "INVALID_CONTRACT";
7
+ constructor(contractId: string, cause: string);
8
+ }
9
+ /** Thrown when a referenced contract does not exist. */
10
+ export declare class ContractNotFoundError extends NonRecoverableErrorBase {
11
+ readonly contractId: string;
12
+ readonly code = "CONTRACT_NOT_FOUND";
13
+ constructor(contractId: string);
14
+ }
15
+ /** Thrown when contract state cannot be derived for a given FSM state. */
16
+ export declare class ContractStateMismatchError extends NonRecoverableErrorBase {
17
+ readonly contractId: string;
18
+ readonly stateId: string;
19
+ readonly code = "CONTRACT_STATE_MISMATCH";
20
+ constructor(contractId: string, stateId: string);
21
+ }
@@ -0,0 +1,32 @@
1
+ import { NonRecoverableErrorBase } from '@ai-dev-orchestrator/ports';
2
+ /** Thrown when an iteration contract definition is invalid. */
3
+ export class InvalidContractError extends NonRecoverableErrorBase {
4
+ contractId;
5
+ cause;
6
+ code = 'INVALID_CONTRACT';
7
+ constructor(contractId, cause) {
8
+ super(`Invalid iteration contract "${contractId}": ${cause}`);
9
+ this.contractId = contractId;
10
+ this.cause = cause;
11
+ }
12
+ }
13
+ /** Thrown when a referenced contract does not exist. */
14
+ export class ContractNotFoundError extends NonRecoverableErrorBase {
15
+ contractId;
16
+ code = 'CONTRACT_NOT_FOUND';
17
+ constructor(contractId) {
18
+ super(`Iteration contract not found: "${contractId}"`);
19
+ this.contractId = contractId;
20
+ }
21
+ }
22
+ /** Thrown when contract state cannot be derived for a given FSM state. */
23
+ export class ContractStateMismatchError extends NonRecoverableErrorBase {
24
+ contractId;
25
+ stateId;
26
+ code = 'CONTRACT_STATE_MISMATCH';
27
+ constructor(contractId, stateId) {
28
+ super(`Contract "${contractId}" does not apply to state "${stateId}"`);
29
+ this.contractId = contractId;
30
+ this.stateId = stateId;
31
+ }
32
+ }
@@ -0,0 +1 @@
1
+ export { ContractNotFoundError, ContractStateMismatchError, InvalidContractError } from './errors';
@@ -0,0 +1 @@
1
+ export { ContractNotFoundError, ContractStateMismatchError, InvalidContractError } from './errors';
@@ -0,0 +1,7 @@
1
+ export { EscalationError, GovernanceError, PolicyLoadError } from './domain/governance/index';
2
+ export type { OwnershipCheckResult } from './domain/governance/index';
3
+ export { ContractNotFoundError, ContractStateMismatchError, InvalidContractError, } from './domain/iteration-contracts/index';
4
+ export { DecisionRecorder, DefaultGovernanceEngine, EscalationManager, IterationLimiter, OwnershipEnforcer, QualityGateChecker, } from './infrastructure/governance/index';
5
+ export type { GovernanceEngineOptions } from './infrastructure/governance/index';
6
+ export { ACCEPTANCE_VALIDATION_LOOP, buildContracts, BUILT_IN_CONTRACTS, CLARIFICATION_LOOP, IMPLEMENTATION_REVIEW_LOOP, PLAN_REVIEW_LOOP, DefaultIterationContractRegistry, } from './infrastructure/iteration-contracts/index';
7
+ export { DefaultCollaborationModel } from './infrastructure/collaboration-model/index';
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // Domain — Governance
2
+ export { EscalationError, GovernanceError, PolicyLoadError } from './domain/governance/index';
3
+ // Domain — Iteration Contracts
4
+ export { ContractNotFoundError, ContractStateMismatchError, InvalidContractError, } from './domain/iteration-contracts/index';
5
+ // Infrastructure — Governance
6
+ export { DecisionRecorder, DefaultGovernanceEngine, EscalationManager, IterationLimiter, OwnershipEnforcer, QualityGateChecker, } from './infrastructure/governance/index';
7
+ // Infrastructure — Iteration Contracts
8
+ export { ACCEPTANCE_VALIDATION_LOOP, buildContracts, BUILT_IN_CONTRACTS, CLARIFICATION_LOOP, IMPLEMENTATION_REVIEW_LOOP, PLAN_REVIEW_LOOP, DefaultIterationContractRegistry, } from './infrastructure/iteration-contracts/index';
9
+ // Infrastructure — Collaboration Model
10
+ export { DefaultCollaborationModel } from './infrastructure/collaboration-model/index';
@@ -0,0 +1,19 @@
1
+ import type { CollaborationModel, RoleRegistry } from '@ai-dev-orchestrator/ports';
2
+ import type { ArtifactFlowDefinition, ArtifactType, RoleId, RoleInteraction, VisibilityCheck } from '@ai-dev-orchestrator/schemas';
3
+ /** Default implementation of the CollaborationModel port backed by RoleRegistry. */
4
+ export declare class DefaultCollaborationModel implements CollaborationModel {
5
+ private readonly roleRegistry;
6
+ constructor(roleRegistry: RoleRegistry);
7
+ /** @inheritdoc */
8
+ getInteractions(roleId: RoleId): readonly RoleInteraction[];
9
+ /** @inheritdoc */
10
+ getFlowDefinitions(): readonly ArtifactFlowDefinition[];
11
+ /** @inheritdoc */
12
+ checkVisibility(roleId: RoleId, artifactType: ArtifactType): VisibilityCheck;
13
+ /** @inheritdoc */
14
+ getProducerFor(artifactType: ArtifactType): string | null;
15
+ /** @inheritdoc */
16
+ getConsumersFor(artifactType: ArtifactType): readonly string[];
17
+ /** @inheritdoc */
18
+ getReviewersFor(roleId: RoleId): readonly string[];
19
+ }
@@ -0,0 +1,109 @@
1
+ /** Default implementation of the CollaborationModel port backed by RoleRegistry. */
2
+ export class DefaultCollaborationModel {
3
+ roleRegistry;
4
+ constructor(roleRegistry) {
5
+ this.roleRegistry = roleRegistry;
6
+ }
7
+ /** @inheritdoc */
8
+ getInteractions(roleId) {
9
+ const role = this.roleRegistry.getRole(roleId);
10
+ if (!role) {
11
+ return [];
12
+ }
13
+ const interactions = [];
14
+ for (const artifactType of role.ownedArtifacts) {
15
+ const consumers = this.getConsumersFor(artifactType);
16
+ for (const consumerId of consumers) {
17
+ if (consumerId !== roleId) {
18
+ interactions.push({
19
+ producerRole: roleId,
20
+ consumerRole: consumerId,
21
+ artifactType,
22
+ relationship: 'produces_for',
23
+ });
24
+ }
25
+ }
26
+ }
27
+ for (const reviewedRoleId of role.reviews) {
28
+ const reviewedRole = this.roleRegistry.getRole(reviewedRoleId);
29
+ if (reviewedRole) {
30
+ for (const artifactType of reviewedRole.ownedArtifacts) {
31
+ interactions.push({
32
+ producerRole: reviewedRoleId,
33
+ consumerRole: roleId,
34
+ artifactType,
35
+ relationship: 'reviews',
36
+ });
37
+ }
38
+ }
39
+ }
40
+ return interactions;
41
+ }
42
+ /** @inheritdoc */
43
+ getFlowDefinitions() {
44
+ const roles = this.roleRegistry.listRoles();
45
+ const flows = [];
46
+ for (const role of roles) {
47
+ for (const artifactType of role.ownedArtifacts) {
48
+ const consumedBy = this.getConsumersFor(artifactType).filter((id) => id !== role.id);
49
+ const reviewedBy = role.reviewedBy.slice();
50
+ flows.push({
51
+ artifactType,
52
+ producedBy: role.id,
53
+ consumedBy,
54
+ reviewedBy,
55
+ });
56
+ }
57
+ }
58
+ return flows;
59
+ }
60
+ /** @inheritdoc */
61
+ checkVisibility(roleId, artifactType) {
62
+ const role = this.roleRegistry.getRole(roleId);
63
+ if (!role) {
64
+ return { allowed: false, reason: `Role "${roleId}" not found` };
65
+ }
66
+ if (role.forbiddenArtifacts.includes(artifactType)) {
67
+ return {
68
+ allowed: false,
69
+ reason: `Role "${roleId}" is forbidden from accessing "${artifactType}"`,
70
+ };
71
+ }
72
+ if (role.ownedArtifacts.includes(artifactType)) {
73
+ return { allowed: true, reason: `Role "${roleId}" owns "${artifactType}"` };
74
+ }
75
+ if (role.readableArtifacts.includes(artifactType)) {
76
+ return { allowed: true, reason: `Role "${roleId}" has read access to "${artifactType}"` };
77
+ }
78
+ return { allowed: false, reason: `Role "${roleId}" has no access to "${artifactType}"` };
79
+ }
80
+ /** @inheritdoc */
81
+ getProducerFor(artifactType) {
82
+ const roles = this.roleRegistry.listRoles();
83
+ for (const role of roles) {
84
+ if (role.ownedArtifacts.includes(artifactType)) {
85
+ return role.id;
86
+ }
87
+ }
88
+ return null;
89
+ }
90
+ /** @inheritdoc */
91
+ getConsumersFor(artifactType) {
92
+ const roles = this.roleRegistry.listRoles();
93
+ const consumers = [];
94
+ for (const role of roles) {
95
+ if (role.readableArtifacts.includes(artifactType)) {
96
+ consumers.push(role.id);
97
+ }
98
+ }
99
+ return consumers;
100
+ }
101
+ /** @inheritdoc */
102
+ getReviewersFor(roleId) {
103
+ const role = this.roleRegistry.getRole(roleId);
104
+ if (!role) {
105
+ return [];
106
+ }
107
+ return [...role.reviewedBy];
108
+ }
109
+ }
@@ -0,0 +1 @@
1
+ export { DefaultCollaborationModel } from './default-collaboration-model';
@@ -0,0 +1 @@
1
+ export { DefaultCollaborationModel } from './default-collaboration-model';
@@ -0,0 +1,14 @@
1
+ import type { JournalWriter } from '@ai-dev-orchestrator/ports';
2
+ import type { GovernanceDecision } from '@ai-dev-orchestrator/schemas';
3
+ /** Records governance decisions for audit trail. */
4
+ export declare class DecisionRecorder {
5
+ private readonly decisions;
6
+ private readonly journalWriter;
7
+ constructor(journalWriter?: JournalWriter);
8
+ /** Record a governance decision. */
9
+ record(decision: GovernanceDecision): void;
10
+ /** Get all recorded decisions. */
11
+ getDecisions(): readonly GovernanceDecision[];
12
+ /** Get decisions for a specific run. */
13
+ getDecisionsForRun(runId: string): readonly GovernanceDecision[];
14
+ }
@@ -0,0 +1,37 @@
1
+ /** Records governance decisions for audit trail. */
2
+ export class DecisionRecorder {
3
+ decisions = [];
4
+ journalWriter;
5
+ constructor(journalWriter) {
6
+ this.journalWriter = journalWriter ?? null;
7
+ }
8
+ /** Record a governance decision. */
9
+ record(decision) {
10
+ this.decisions.push(decision);
11
+ if (this.journalWriter) {
12
+ const data = {
13
+ kind: 'governance',
14
+ outcome: decision.outcome,
15
+ reason: decision.reason,
16
+ transitionFrom: decision.transitionRequested.from,
17
+ transitionTo: decision.transitionRequested.to,
18
+ policiesEvaluated: decision.policiesEvaluated.length,
19
+ };
20
+ this.journalWriter.append({
21
+ timestamp: decision.timestamp,
22
+ runId: decision.runId,
23
+ sequence: 0,
24
+ type: 'governance_decision',
25
+ data,
26
+ });
27
+ }
28
+ }
29
+ /** Get all recorded decisions. */
30
+ getDecisions() {
31
+ return [...this.decisions];
32
+ }
33
+ /** Get decisions for a specific run. */
34
+ getDecisionsForRun(runId) {
35
+ return this.decisions.filter((d) => d.runId === runId);
36
+ }
37
+ }
@@ -0,0 +1,7 @@
1
+ /** Builds escalation context when governance triggers escalation. */
2
+ import type { ArtifactRef, EscalationContext, EscalationReason, FindingSummary, IterationSummary, RunId } from '@ai-dev-orchestrator/schemas';
3
+ export declare class EscalationManager {
4
+ /** Assemble escalation context for the given trigger. */
5
+ buildContext(runId: RunId, stageId: string, reason: EscalationReason, findings: readonly FindingSummary[], artifacts: readonly ArtifactRef[], iterationHistory?: readonly IterationSummary[]): EscalationContext;
6
+ private suggestActions;
7
+ }
@@ -0,0 +1,49 @@
1
+ export class EscalationManager {
2
+ /** Assemble escalation context for the given trigger. */
3
+ buildContext(runId, stageId, reason, findings, artifacts, iterationHistory = []) {
4
+ const unresolvedFindings = findings.filter((f) => f.status === 'open' || f.status === 'escalated');
5
+ const suggestedActions = this.suggestActions(reason, unresolvedFindings);
6
+ return {
7
+ runId,
8
+ stageId,
9
+ reason,
10
+ iterationHistory,
11
+ unresolvedFindings,
12
+ artifactRefs: artifacts,
13
+ suggestedActions,
14
+ };
15
+ }
16
+ suggestActions(reason, unresolved) {
17
+ const actions = [];
18
+ switch (reason) {
19
+ case 'iteration_limit_exceeded':
20
+ actions.push('Review iteration history and consider adjusting limits');
21
+ actions.push('Manually resolve remaining findings');
22
+ break;
23
+ case 'quality_gate_failed':
24
+ actions.push(`Address ${String(unresolved.length)} unresolved findings`);
25
+ actions.push('Consider lowering quality thresholds if findings are acceptable');
26
+ break;
27
+ case 'unresolvable_conflict':
28
+ actions.push('Review conflicting findings and make a judgment call');
29
+ break;
30
+ case 'human_requested':
31
+ actions.push('Human intervention requested — review current state');
32
+ break;
33
+ case 'token_budget_exceeded':
34
+ actions.push('Token budget exceeded — consider increasing budget or reducing scope');
35
+ break;
36
+ case 'retry_limit_exceeded':
37
+ actions.push('Retry limit reached — review failures and consider manual intervention');
38
+ break;
39
+ case 'confidence_too_low':
40
+ actions.push('Agent confidence below threshold — review output quality');
41
+ break;
42
+ default: {
43
+ const _exhaustive = reason;
44
+ throw new Error(`Unhandled: ${String(_exhaustive)}`);
45
+ }
46
+ }
47
+ return actions;
48
+ }
49
+ }
@@ -0,0 +1,7 @@
1
+ export { DecisionRecorder } from './decision-recorder';
2
+ export { EscalationManager } from './escalation-manager';
3
+ export { IterationLimiter } from './iteration-limiter';
4
+ export { OwnershipEnforcer } from './ownership-enforcer';
5
+ export { QualityGateChecker } from './quality-gate-checker';
6
+ export { DefaultGovernanceEngine } from './transition-gate';
7
+ export type { GovernanceEngineOptions } from './transition-gate';
@@ -0,0 +1,6 @@
1
+ export { DecisionRecorder } from './decision-recorder';
2
+ export { EscalationManager } from './escalation-manager';
3
+ export { IterationLimiter } from './iteration-limiter';
4
+ export { OwnershipEnforcer } from './ownership-enforcer';
5
+ export { QualityGateChecker } from './quality-gate-checker';
6
+ export { DefaultGovernanceEngine } from './transition-gate';
@@ -0,0 +1,9 @@
1
+ import type { IterationContractRegistry } from '@ai-dev-orchestrator/ports';
2
+ import type { PolicyEvaluation } from '@ai-dev-orchestrator/schemas';
3
+ /** Checks iteration counts against contract limits. */
4
+ export declare class IterationLimiter {
5
+ private readonly contractRegistry;
6
+ constructor(contractRegistry: IterationContractRegistry);
7
+ /** Evaluate whether the iteration limit has been reached for the given state. */
8
+ evaluate(stateId: string, iterationCount: number): PolicyEvaluation;
9
+ }
@@ -0,0 +1,33 @@
1
+ /** Checks iteration counts against contract limits. */
2
+ export class IterationLimiter {
3
+ contractRegistry;
4
+ constructor(contractRegistry) {
5
+ this.contractRegistry = contractRegistry;
6
+ }
7
+ /** Evaluate whether the iteration limit has been reached for the given state. */
8
+ evaluate(stateId, iterationCount) {
9
+ const contract = this.contractRegistry.getContractForState(stateId);
10
+ if (!contract) {
11
+ return {
12
+ policy: 'iteration_limit',
13
+ evaluated: false,
14
+ result: 'skip',
15
+ detail: `No iteration contract for state "${stateId}"`,
16
+ };
17
+ }
18
+ if (iterationCount < contract.maxIterations) {
19
+ return {
20
+ policy: 'iteration_limit',
21
+ evaluated: true,
22
+ result: 'pass',
23
+ detail: `Iteration ${String(iterationCount)} within limit of ${String(contract.maxIterations)}`,
24
+ };
25
+ }
26
+ return {
27
+ policy: 'iteration_limit',
28
+ evaluated: true,
29
+ result: 'fail',
30
+ detail: `Iteration limit exceeded: ${String(iterationCount)} >= ${String(contract.maxIterations)}`,
31
+ };
32
+ }
33
+ }
@@ -0,0 +1,16 @@
1
+ import type { OwnershipRegistry } from '@ai-dev-orchestrator/ports';
2
+ import type { ArtifactRef } from '@ai-dev-orchestrator/schemas';
3
+ import type { OwnershipCheckResult } from '../../domain/governance/ownership-check-result';
4
+ export type { OwnershipCheckResult };
5
+ /** Enforces artifact ownership rules within governance decisions. */
6
+ export declare class OwnershipEnforcer {
7
+ private readonly ownershipRegistry;
8
+ /** Create a new OwnershipEnforcer with the given registry. */
9
+ constructor(ownershipRegistry: OwnershipRegistry);
10
+ /** Check if a role is allowed to produce/modify a given artifact. */
11
+ checkWriteAccess(roleId: string, artifactRef: ArtifactRef): OwnershipCheckResult;
12
+ /** Check if a role is allowed to read a given artifact (owners always can). */
13
+ checkReadAccess(roleId: string, artifactRef: ArtifactRef): OwnershipCheckResult;
14
+ /** Validate all artifacts in a transition request against ownership rules. */
15
+ validateTransitionArtifacts(roleId: string, artifacts: readonly ArtifactRef[], isProducing: boolean): OwnershipCheckResult;
16
+ }
@@ -0,0 +1,55 @@
1
+ /** Enforces artifact ownership rules within governance decisions. */
2
+ export class OwnershipEnforcer {
3
+ ownershipRegistry;
4
+ /** Create a new OwnershipEnforcer with the given registry. */
5
+ constructor(ownershipRegistry) {
6
+ this.ownershipRegistry = ownershipRegistry;
7
+ }
8
+ /** Check if a role is allowed to produce/modify a given artifact. */
9
+ checkWriteAccess(roleId, artifactRef) {
10
+ const authorized = this.ownershipRegistry.isAuthorized(roleId, artifactRef.type);
11
+ if (authorized) {
12
+ return {
13
+ allowed: true,
14
+ reason: `Role "${roleId}" is authorized to produce "${artifactRef.type}"`,
15
+ };
16
+ }
17
+ const owner = this.ownershipRegistry.getOwner(artifactRef.type);
18
+ if (!owner) {
19
+ return {
20
+ allowed: true,
21
+ reason: `No ownership constraint for artifact type "${artifactRef.type}"`,
22
+ };
23
+ }
24
+ return {
25
+ allowed: false,
26
+ reason: `Role "${roleId}" cannot write to "${artifactRef.type}" — owned by "${owner}"`,
27
+ };
28
+ }
29
+ /** Check if a role is allowed to read a given artifact (owners always can). */
30
+ checkReadAccess(roleId, artifactRef) {
31
+ const owner = this.ownershipRegistry.getOwner(artifactRef.type);
32
+ if (!owner) {
33
+ return { allowed: true, reason: `No ownership constraint for "${artifactRef.type}"` };
34
+ }
35
+ if (owner === roleId) {
36
+ return {
37
+ allowed: true,
38
+ reason: `Role "${roleId}" owns "${artifactRef.type}" (implicit read)`,
39
+ };
40
+ }
41
+ return { allowed: true, reason: `Read access to "${artifactRef.type}" granted by default` };
42
+ }
43
+ /** Validate all artifacts in a transition request against ownership rules. */
44
+ validateTransitionArtifacts(roleId, artifacts, isProducing) {
45
+ for (const artifact of artifacts) {
46
+ const check = isProducing
47
+ ? this.checkWriteAccess(roleId, artifact)
48
+ : this.checkReadAccess(roleId, artifact);
49
+ if (!check.allowed) {
50
+ return check;
51
+ }
52
+ }
53
+ return { allowed: true, reason: 'All artifact ownership checks passed' };
54
+ }
55
+ }
@@ -0,0 +1,6 @@
1
+ /** Evaluates findings against quality gate thresholds. */
2
+ import type { FindingSummary, PolicyEvaluation } from '@ai-dev-orchestrator/schemas';
3
+ export declare class QualityGateChecker {
4
+ /** Evaluate findings against severity thresholds. */
5
+ evaluate(findings: readonly FindingSummary[], maxHighSeverity: number, maxMediumSeverity: number): PolicyEvaluation;
6
+ }