@ai-dev-orchestrator/artifacts 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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/domain/agreement-artifacts/errors.d.ts +16 -0
  4. package/dist/domain/agreement-artifacts/errors.js +23 -0
  5. package/dist/domain/agreement-artifacts/index.d.ts +1 -0
  6. package/dist/domain/agreement-artifacts/index.js +1 -0
  7. package/dist/domain/artifact-system/artifact-content-schemas.d.ts +487 -0
  8. package/dist/domain/artifact-system/artifact-content-schemas.js +464 -0
  9. package/dist/domain/artifact-system/artifact-descriptors.d.ts +9 -0
  10. package/dist/domain/artifact-system/artifact-descriptors.js +165 -0
  11. package/dist/domain/artifact-system/constants.d.ts +7 -0
  12. package/dist/domain/artifact-system/constants.js +29 -0
  13. package/dist/domain/artifact-system/errors.d.ts +55 -0
  14. package/dist/domain/artifact-system/errors.js +75 -0
  15. package/dist/domain/artifact-system/index.d.ts +5 -0
  16. package/dist/domain/artifact-system/index.js +4 -0
  17. package/dist/index.d.ts +9 -0
  18. package/dist/index.js +11 -0
  19. package/dist/infrastructure/agreement-artifacts/agreement-gate.d.ts +27 -0
  20. package/dist/infrastructure/agreement-artifacts/agreement-gate.js +105 -0
  21. package/dist/infrastructure/agreement-artifacts/agreement-generator.d.ts +28 -0
  22. package/dist/infrastructure/agreement-artifacts/agreement-generator.js +89 -0
  23. package/dist/infrastructure/agreement-artifacts/agreement-validator.d.ts +7 -0
  24. package/dist/infrastructure/agreement-artifacts/agreement-validator.js +38 -0
  25. package/dist/infrastructure/agreement-artifacts/index.d.ts +3 -0
  26. package/dist/infrastructure/agreement-artifacts/index.js +3 -0
  27. package/dist/infrastructure/artifact-system/artifact-type-validator.d.ts +6 -0
  28. package/dist/infrastructure/artifact-system/artifact-type-validator.js +38 -0
  29. package/dist/infrastructure/artifact-system/checksum-engine.d.ts +4 -0
  30. package/dist/infrastructure/artifact-system/checksum-engine.js +9 -0
  31. package/dist/infrastructure/artifact-system/content-parser.d.ts +26 -0
  32. package/dist/infrastructure/artifact-system/content-parser.js +64 -0
  33. package/dist/infrastructure/artifact-system/default-ownership-registry.d.ts +14 -0
  34. package/dist/infrastructure/artifact-system/default-ownership-registry.js +65 -0
  35. package/dist/infrastructure/artifact-system/disk-reader.d.ts +7 -0
  36. package/dist/infrastructure/artifact-system/disk-reader.js +22 -0
  37. package/dist/infrastructure/artifact-system/disk-writer.d.ts +3 -0
  38. package/dist/infrastructure/artifact-system/disk-writer.js +21 -0
  39. package/dist/infrastructure/artifact-system/filesystem-artifact-store.d.ts +26 -0
  40. package/dist/infrastructure/artifact-system/filesystem-artifact-store.js +191 -0
  41. package/dist/infrastructure/artifact-system/index.d.ts +8 -0
  42. package/dist/infrastructure/artifact-system/index.js +7 -0
  43. package/dist/infrastructure/artifact-system/inventory-manager.d.ts +18 -0
  44. package/dist/infrastructure/artifact-system/inventory-manager.js +142 -0
  45. package/dist/infrastructure/artifact-system/version-manager.d.ts +12 -0
  46. package/dist/infrastructure/artifact-system/version-manager.js +42 -0
  47. package/dist/infrastructure/shared/hash.d.ts +2 -0
  48. package/dist/infrastructure/shared/hash.js +10 -0
  49. package/package.json +47 -0
@@ -0,0 +1,55 @@
1
+ import { NonRecoverableErrorBase } from '@ai-dev-orchestrator/ports';
2
+ import type { ArtifactRef, ArtifactType } from '@ai-dev-orchestrator/schemas';
3
+ /** Thrown when a role attempts to produce an artifact type it does not own. */
4
+ export declare class OwnershipViolationError extends NonRecoverableErrorBase {
5
+ readonly role: string;
6
+ readonly artifactType: ArtifactType;
7
+ readonly ownerRole: string;
8
+ readonly code = "OWNERSHIP_VIOLATION";
9
+ constructor(role: string, artifactType: ArtifactType, ownerRole: string);
10
+ }
11
+ /** Thrown when an attempt is made to overwrite an existing artifact version. */
12
+ export declare class ImmutabilityViolationError extends NonRecoverableErrorBase {
13
+ readonly ref: ArtifactRef;
14
+ readonly code = "IMMUTABILITY_VIOLATION";
15
+ constructor(ref: ArtifactRef);
16
+ }
17
+ /** Thrown when a stored artifact's content does not match its checksum. */
18
+ export declare class ChecksumMismatchError extends NonRecoverableErrorBase {
19
+ readonly ref: ArtifactRef;
20
+ readonly expectedChecksum: string;
21
+ readonly actualChecksum: string;
22
+ readonly code = "CHECKSUM_MISMATCH";
23
+ constructor(ref: ArtifactRef, expectedChecksum: string, actualChecksum: string);
24
+ }
25
+ /** Thrown when a requested artifact cannot be found on disk. */
26
+ export declare class ArtifactNotFoundError extends NonRecoverableErrorBase {
27
+ readonly ref: ArtifactRef;
28
+ readonly code = "ARTIFACT_NOT_FOUND";
29
+ constructor(ref: ArtifactRef);
30
+ }
31
+ /** Thrown when artifact content fails type schema validation. */
32
+ export declare class TypeValidationError extends NonRecoverableErrorBase {
33
+ readonly artifactType: ArtifactType;
34
+ readonly validationErrors: readonly {
35
+ readonly path: string;
36
+ readonly message: string;
37
+ }[];
38
+ readonly code = "TYPE_VALIDATION_ERROR";
39
+ constructor(artifactType: ArtifactType, validationErrors: readonly {
40
+ readonly path: string;
41
+ readonly message: string;
42
+ }[]);
43
+ }
44
+ /** Thrown when the inventory file is inconsistent with artifacts on disk. */
45
+ export declare class InventoryCorruptionError extends NonRecoverableErrorBase {
46
+ readonly code = "INVENTORY_CORRUPTION";
47
+ constructor(message: string);
48
+ }
49
+ /** Thrown when a filesystem write operation fails. */
50
+ export declare class DiskWriteError extends NonRecoverableErrorBase {
51
+ readonly filePath: string;
52
+ readonly cause: string;
53
+ readonly code = "DISK_WRITE_ERROR";
54
+ constructor(filePath: string, cause: string);
55
+ }
@@ -0,0 +1,75 @@
1
+ import { NonRecoverableErrorBase } from '@ai-dev-orchestrator/ports';
2
+ /** Thrown when a role attempts to produce an artifact type it does not own. */
3
+ export class OwnershipViolationError extends NonRecoverableErrorBase {
4
+ role;
5
+ artifactType;
6
+ ownerRole;
7
+ code = 'OWNERSHIP_VIOLATION';
8
+ constructor(role, artifactType, ownerRole) {
9
+ super(`Role "${role}" cannot produce artifact type "${artifactType}"; owner is "${ownerRole}"`);
10
+ this.role = role;
11
+ this.artifactType = artifactType;
12
+ this.ownerRole = ownerRole;
13
+ }
14
+ }
15
+ /** Thrown when an attempt is made to overwrite an existing artifact version. */
16
+ export class ImmutabilityViolationError extends NonRecoverableErrorBase {
17
+ ref;
18
+ code = 'IMMUTABILITY_VIOLATION';
19
+ constructor(ref) {
20
+ super(`Cannot overwrite artifact ${ref.type}/${ref.name} v${String(ref.version)}: artifacts are immutable`);
21
+ this.ref = ref;
22
+ }
23
+ }
24
+ /** Thrown when a stored artifact's content does not match its checksum. */
25
+ export class ChecksumMismatchError extends NonRecoverableErrorBase {
26
+ ref;
27
+ expectedChecksum;
28
+ actualChecksum;
29
+ code = 'CHECKSUM_MISMATCH';
30
+ constructor(ref, expectedChecksum, actualChecksum) {
31
+ super(`Checksum mismatch for ${ref.type}/${ref.name} v${String(ref.version)}: expected ${expectedChecksum}, got ${actualChecksum}`);
32
+ this.ref = ref;
33
+ this.expectedChecksum = expectedChecksum;
34
+ this.actualChecksum = actualChecksum;
35
+ }
36
+ }
37
+ /** Thrown when a requested artifact cannot be found on disk. */
38
+ export class ArtifactNotFoundError extends NonRecoverableErrorBase {
39
+ ref;
40
+ code = 'ARTIFACT_NOT_FOUND';
41
+ constructor(ref) {
42
+ super(`Artifact not found: ${ref.type}/${ref.name} v${String(ref.version)}`);
43
+ this.ref = ref;
44
+ }
45
+ }
46
+ /** Thrown when artifact content fails type schema validation. */
47
+ export class TypeValidationError extends NonRecoverableErrorBase {
48
+ artifactType;
49
+ validationErrors;
50
+ code = 'TYPE_VALIDATION_ERROR';
51
+ constructor(artifactType, validationErrors) {
52
+ const details = validationErrors.map((e) => `${e.path}: ${e.message}`).join('; ');
53
+ super(`Type validation failed for "${artifactType}": ${details}`);
54
+ this.artifactType = artifactType;
55
+ this.validationErrors = validationErrors;
56
+ }
57
+ }
58
+ /** Thrown when the inventory file is inconsistent with artifacts on disk. */
59
+ export class InventoryCorruptionError extends NonRecoverableErrorBase {
60
+ code = 'INVENTORY_CORRUPTION';
61
+ constructor(message) {
62
+ super(`Inventory corruption: ${message}`);
63
+ }
64
+ }
65
+ /** Thrown when a filesystem write operation fails. */
66
+ export class DiskWriteError extends NonRecoverableErrorBase {
67
+ filePath;
68
+ cause;
69
+ code = 'DISK_WRITE_ERROR';
70
+ constructor(filePath, cause) {
71
+ super(`Disk write failed at ${filePath}: ${cause}`);
72
+ this.filePath = filePath;
73
+ this.cause = cause;
74
+ }
75
+ }
@@ -0,0 +1,5 @@
1
+ export type { ArtifactDescriptor } from './artifact-descriptors';
2
+ export { ARTIFACT_DESCRIPTORS, ARTIFACT_SCHEMA_MAP } from './artifact-descriptors';
3
+ export { acceptanceValidationContentSchema, agreementContentSchema, canonicalSpecificationContentSchema, clarificationAnswersContentSchema, codebaseContextContentSchema, escalationContextContentSchema, implementationContentSchema, intakeAnalysisContentSchema, intakeRequirementsContentSchema, judgeDecisionContentSchema, planContentSchema, releaseSummaryContentSchema, remediationPlanContentSchema, reviewContentSchema, reviewFindingsContentSchema, reviewReportContentSchema, runManifestContentSchema, testPlanContentSchema, testSuiteContentSchema, validatePlanStructure, verificationContentSchema, } from './artifact-content-schemas';
4
+ export { ArtifactNotFoundError, ChecksumMismatchError, DiskWriteError, ImmutabilityViolationError, InventoryCorruptionError, OwnershipViolationError, TypeValidationError, } from './errors';
5
+ export { AGREEMENT_ARTIFACT_TYPES, REVIEW_ARTIFACT_TYPES, VERDICT_ARTIFACT_TYPES, } from './constants';
@@ -0,0 +1,4 @@
1
+ export { ARTIFACT_DESCRIPTORS, ARTIFACT_SCHEMA_MAP } from './artifact-descriptors';
2
+ export { acceptanceValidationContentSchema, agreementContentSchema, canonicalSpecificationContentSchema, clarificationAnswersContentSchema, codebaseContextContentSchema, escalationContextContentSchema, implementationContentSchema, intakeAnalysisContentSchema, intakeRequirementsContentSchema, judgeDecisionContentSchema, planContentSchema, releaseSummaryContentSchema, remediationPlanContentSchema, reviewContentSchema, reviewFindingsContentSchema, reviewReportContentSchema, runManifestContentSchema, testPlanContentSchema, testSuiteContentSchema, validatePlanStructure, verificationContentSchema, } from './artifact-content-schemas';
3
+ export { ArtifactNotFoundError, ChecksumMismatchError, DiskWriteError, ImmutabilityViolationError, InventoryCorruptionError, OwnershipViolationError, TypeValidationError, } from './errors';
4
+ export { AGREEMENT_ARTIFACT_TYPES, REVIEW_ARTIFACT_TYPES, VERDICT_ARTIFACT_TYPES, } from './constants';
@@ -0,0 +1,9 @@
1
+ export type { ArtifactDescriptor } from './domain/artifact-system/index';
2
+ export { ARTIFACT_DESCRIPTORS, ARTIFACT_SCHEMA_MAP, acceptanceValidationContentSchema, agreementContentSchema, canonicalSpecificationContentSchema, clarificationAnswersContentSchema, codebaseContextContentSchema, escalationContextContentSchema, implementationContentSchema, intakeAnalysisContentSchema, intakeRequirementsContentSchema, judgeDecisionContentSchema, planContentSchema, releaseSummaryContentSchema, remediationPlanContentSchema, reviewContentSchema, reviewFindingsContentSchema, reviewReportContentSchema, runManifestContentSchema, testPlanContentSchema, testSuiteContentSchema, validatePlanStructure, verificationContentSchema, } from './domain/artifact-system/index';
3
+ export { ArtifactNotFoundError, ChecksumMismatchError, DiskWriteError, ImmutabilityViolationError, InventoryCorruptionError, OwnershipViolationError, TypeValidationError, } from './domain/artifact-system/index';
4
+ export { AGREEMENT_ARTIFACT_TYPES, REVIEW_ARTIFACT_TYPES, VERDICT_ARTIFACT_TYPES, } from './domain/artifact-system/index';
5
+ export { AgreementGateError, InvalidAgreementError } from './domain/agreement-artifacts/index';
6
+ export { buildOwnershipOverrides, FilesystemArtifactStore, DefaultOwnershipRegistry, DefaultArtifactTypeValidator, computeChecksum, verifyChecksum, safeJsonParse, parseTypedArtifactContent, parseFrontmatter, parseJson, parseYaml, parseArtifactContent, FRONTMATTER_REGEX, VersionManager, InventoryManager, } from './infrastructure/artifact-system/index';
7
+ export type { SafeParseResult } from './infrastructure/artifact-system/index';
8
+ export { DefaultAgreementGate, AgreementGenerator, DefaultAgreementValidator, } from './infrastructure/agreement-artifacts/index';
9
+ export { hashContent } from './infrastructure/shared/hash';
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { ARTIFACT_DESCRIPTORS, ARTIFACT_SCHEMA_MAP, acceptanceValidationContentSchema, agreementContentSchema, canonicalSpecificationContentSchema, clarificationAnswersContentSchema, codebaseContextContentSchema, escalationContextContentSchema, implementationContentSchema, intakeAnalysisContentSchema, intakeRequirementsContentSchema, judgeDecisionContentSchema, planContentSchema, releaseSummaryContentSchema, remediationPlanContentSchema, reviewContentSchema, reviewFindingsContentSchema, reviewReportContentSchema, runManifestContentSchema, testPlanContentSchema, testSuiteContentSchema, validatePlanStructure, verificationContentSchema, } from './domain/artifact-system/index';
2
+ export { ArtifactNotFoundError, ChecksumMismatchError, DiskWriteError, ImmutabilityViolationError, InventoryCorruptionError, OwnershipViolationError, TypeValidationError, } from './domain/artifact-system/index';
3
+ export { AGREEMENT_ARTIFACT_TYPES, REVIEW_ARTIFACT_TYPES, VERDICT_ARTIFACT_TYPES, } from './domain/artifact-system/index';
4
+ // Domain — Agreement Artifacts
5
+ export { AgreementGateError, InvalidAgreementError } from './domain/agreement-artifacts/index';
6
+ // Infrastructure — Artifact System
7
+ export { buildOwnershipOverrides, FilesystemArtifactStore, DefaultOwnershipRegistry, DefaultArtifactTypeValidator, computeChecksum, verifyChecksum, safeJsonParse, parseTypedArtifactContent, parseFrontmatter, parseJson, parseYaml, parseArtifactContent, FRONTMATTER_REGEX, VersionManager, InventoryManager, } from './infrastructure/artifact-system/index';
8
+ // Infrastructure — Agreement Artifacts
9
+ export { DefaultAgreementGate, AgreementGenerator, DefaultAgreementValidator, } from './infrastructure/agreement-artifacts/index';
10
+ // Infrastructure — Shared
11
+ export { hashContent } from './infrastructure/shared/hash';
@@ -0,0 +1,27 @@
1
+ import type { AgreementGate as AgreementGatePort, ArtifactStore } from '@ai-dev-orchestrator/ports';
2
+ import type { AgreementGateResult, AgreementType } from '@ai-dev-orchestrator/schemas';
3
+ /** Result of stage gating check. */
4
+ interface StageGatingResult {
5
+ readonly gated: boolean;
6
+ readonly requiredAgreement?: AgreementType;
7
+ readonly satisfied: boolean;
8
+ readonly reason: string;
9
+ }
10
+ /** Default agreement gate implementation with stage gating enforcement. */
11
+ export declare class DefaultAgreementGate implements AgreementGatePort {
12
+ private readonly artifactStore;
13
+ private readonly validator;
14
+ private readonly agreementCache;
15
+ constructor(artifactStore: ArtifactStore);
16
+ /** @inheritdoc */
17
+ register(type: AgreementType, result: AgreementGateResult): void;
18
+ /** @inheritdoc */
19
+ check(agreementType: AgreementType, _runId: string): AgreementGateResult;
20
+ /** Check if stage is gated and whether gate is satisfied. */
21
+ checkStageGating(stageId: string): StageGatingResult;
22
+ /** Get required agreement type for stage. */
23
+ getRequiredAgreement(stageId: string): AgreementType | null;
24
+ /** Async version for workflow engine internal use. */
25
+ checkAsync(artifactType: AgreementType, agreementType: AgreementType): Promise<AgreementGateResult>;
26
+ }
27
+ export {};
@@ -0,0 +1,105 @@
1
+ import { z } from 'zod';
2
+ import { safeJsonParse } from '../artifact-system/content-parser';
3
+ import { DefaultAgreementValidator } from './agreement-validator';
4
+ /** Maps workflow stages to required agreement types for gating. */
5
+ const STAGE_TO_REQUIRED_AGREEMENT = {
6
+ IMPLEMENTATION: 'planning_agreement',
7
+ VERIFICATION: 'implementation_agreement',
8
+ WRAP_UP: 'release_agreement',
9
+ };
10
+ /** Default agreement gate implementation with stage gating enforcement. */
11
+ export class DefaultAgreementGate {
12
+ artifactStore;
13
+ validator = new DefaultAgreementValidator();
14
+ agreementCache = new Map();
15
+ constructor(artifactStore) {
16
+ this.artifactStore = artifactStore;
17
+ }
18
+ /** @inheritdoc */
19
+ register(type, result) {
20
+ this.agreementCache.set(type, result);
21
+ }
22
+ /** @inheritdoc */
23
+ check(agreementType, _runId) {
24
+ const cached = this.agreementCache.get(agreementType);
25
+ if (cached) {
26
+ return cached;
27
+ }
28
+ return {
29
+ exists: false,
30
+ valid: false,
31
+ reason: `No ${agreementType} registered yet`,
32
+ };
33
+ }
34
+ /** Check if stage is gated and whether gate is satisfied. */
35
+ checkStageGating(stageId) {
36
+ const requiredAgreement = STAGE_TO_REQUIRED_AGREEMENT[stageId];
37
+ if (!requiredAgreement) {
38
+ return { gated: false, satisfied: true, reason: 'Stage has no agreement gate' };
39
+ }
40
+ const gateResult = this.check(requiredAgreement, '');
41
+ return {
42
+ gated: true,
43
+ requiredAgreement,
44
+ satisfied: gateResult.exists && gateResult.valid,
45
+ reason: gateResult.reason ??
46
+ (gateResult.valid ? 'Agreement gate satisfied' : 'Agreement gate not satisfied'),
47
+ };
48
+ }
49
+ /** Get required agreement type for stage. */
50
+ getRequiredAgreement(stageId) {
51
+ return STAGE_TO_REQUIRED_AGREEMENT[stageId] ?? null;
52
+ }
53
+ /** Async version for workflow engine internal use. */
54
+ async checkAsync(artifactType, agreementType) {
55
+ const latest = await this.artifactStore.getLatest(artifactType, agreementType);
56
+ if (!latest) {
57
+ return {
58
+ exists: false,
59
+ valid: false,
60
+ reason: `No ${agreementType} artifact found`,
61
+ };
62
+ }
63
+ const parseResult = safeJsonParse(latest.content, z.record(z.string(), z.unknown()));
64
+ if (!parseResult.success) {
65
+ return {
66
+ exists: true,
67
+ valid: false,
68
+ artifactRef: latest.ref,
69
+ reason: 'Agreement artifact content is not valid JSON',
70
+ };
71
+ }
72
+ const parsedAgreement = parseResult.data;
73
+ const agreement = {
74
+ type: agreementType,
75
+ runId: typeof parsedAgreement['runId'] === 'string' ? parsedAgreement['runId'] : '',
76
+ stageId: typeof parsedAgreement['stageId'] === 'string' ? parsedAgreement['stageId'] : '',
77
+ timestamp: typeof parsedAgreement['timestamp'] === 'string' ? parsedAgreement['timestamp'] : '',
78
+ participants: (Array.isArray(parsedAgreement['participants'])
79
+ ? parsedAgreement['participants']
80
+ : []),
81
+ reviewedArtifacts: (Array.isArray(parsedAgreement['reviewedArtifacts'])
82
+ ? parsedAgreement['reviewedArtifacts']
83
+ : []),
84
+ findings: (Array.isArray(parsedAgreement['findings'])
85
+ ? parsedAgreement['findings']
86
+ : []),
87
+ unresolvedFindings: (Array.isArray(parsedAgreement['unresolvedFindings'])
88
+ ? parsedAgreement['unresolvedFindings']
89
+ : []),
90
+ approvalStatus: (parsedAgreement['approvalStatus'] ?? 'rejected'),
91
+ approvalType: (parsedAgreement['approvalType'] ?? 'automated'),
92
+ conditions: typeof parsedAgreement['conditions'] === 'string'
93
+ ? parsedAgreement['conditions']
94
+ : undefined,
95
+ };
96
+ const validation = this.validator.validate(agreement);
97
+ return {
98
+ exists: true,
99
+ valid: validation.valid,
100
+ approvalStatus: agreement.approvalStatus,
101
+ artifactRef: latest.ref,
102
+ reason: validation.valid ? undefined : validation.errors.join('; '),
103
+ };
104
+ }
105
+ }
@@ -0,0 +1,28 @@
1
+ import type { AgreementArtifact, AgreementFinding, AgreementParticipant, AgreementType, ApprovalStatus, ApprovalType, ArtifactRef } from '@ai-dev-orchestrator/schemas';
2
+ /** Algorithm for computing approval from votes. */
3
+ type VerdictAlgorithm = 'unanimous' | 'majority' | 'quorum';
4
+ /** Quorum configuration for verdict computation. */
5
+ interface QuorumConfig {
6
+ readonly minimumApprovals: number;
7
+ }
8
+ /** Single reviewer's vote for verdict computation. */
9
+ export interface ReviewerVote {
10
+ readonly reviewerRole: string;
11
+ readonly vote: 'approve' | 'reject' | 'abstain';
12
+ }
13
+ /** Agreement artifact generator with verdict algorithms. */
14
+ export declare class AgreementGenerator {
15
+ /** Generate agreement artifact from review results. */
16
+ generate(type: AgreementType, runId: string, stageId: string, participants: readonly AgreementParticipant[], reviewedArtifacts: readonly ArtifactRef[], findings: readonly AgreementFinding[], approvalStatus: ApprovalStatus, approvalType: ApprovalType): AgreementArtifact;
17
+ /** Check whether any participant has reviewed or approved. */
18
+ hasApprovalParticipant(participants: readonly AgreementParticipant[]): ApprovalStatus;
19
+ /** Compute verdict using majority vote. */
20
+ computeMajorityVerdict(votes: readonly ReviewerVote[]): ApprovalStatus;
21
+ /** Compute verdict using quorum threshold. */
22
+ computeQuorumVerdict(votes: readonly ReviewerVote[], config: QuorumConfig): ApprovalStatus;
23
+ /** Compute verdict using specified algorithm. */
24
+ computeVerdict(algorithm: VerdictAlgorithm, votes: readonly ReviewerVote[], quorumConfig?: QuorumConfig): ApprovalStatus;
25
+ /** Serialize agreement to JSON matching the validation schema. */
26
+ serialize(agreement: AgreementArtifact): string;
27
+ }
28
+ export {};
@@ -0,0 +1,89 @@
1
+ /** Agreement artifact generator with verdict algorithms. */
2
+ export class AgreementGenerator {
3
+ /** Generate agreement artifact from review results. */
4
+ generate(type, runId, stageId, participants, reviewedArtifacts, findings, approvalStatus, approvalType) {
5
+ const unresolvedFindings = findings.filter((f) => f.status === 'open' || f.status === 'escalated');
6
+ return {
7
+ type,
8
+ runId,
9
+ stageId,
10
+ timestamp: new Date().toISOString(),
11
+ participants,
12
+ reviewedArtifacts,
13
+ findings,
14
+ unresolvedFindings,
15
+ approvalStatus,
16
+ approvalType,
17
+ };
18
+ }
19
+ /** Check whether any participant has reviewed or approved. */
20
+ hasApprovalParticipant(participants) {
21
+ const hasReviewerOrApprover = participants.some((p) => p.action === 'reviewed' || p.action === 'approved');
22
+ return hasReviewerOrApprover ? 'approved' : 'rejected';
23
+ }
24
+ /** Compute verdict using majority vote. */
25
+ computeMajorityVerdict(votes) {
26
+ const nonAbstaining = votes.filter((v) => v.vote !== 'abstain');
27
+ if (nonAbstaining.length === 0) {
28
+ return 'rejected';
29
+ }
30
+ const approvals = nonAbstaining.filter((v) => v.vote === 'approve').length;
31
+ const rejections = nonAbstaining.filter((v) => v.vote === 'reject').length;
32
+ if (approvals > rejections) {
33
+ return 'approved';
34
+ }
35
+ if (approvals === rejections) {
36
+ return 'conditionally_approved';
37
+ }
38
+ return 'rejected';
39
+ }
40
+ /** Compute verdict using quorum threshold. */
41
+ computeQuorumVerdict(votes, config) {
42
+ const approvals = votes.filter((v) => v.vote === 'approve').length;
43
+ const rejections = votes.filter((v) => v.vote === 'reject').length;
44
+ if (approvals >= config.minimumApprovals && rejections === 0) {
45
+ return 'approved';
46
+ }
47
+ if (approvals >= config.minimumApprovals && rejections > 0) {
48
+ return 'conditionally_approved';
49
+ }
50
+ return 'rejected';
51
+ }
52
+ /** Compute verdict using specified algorithm. */
53
+ computeVerdict(algorithm, votes, quorumConfig) {
54
+ switch (algorithm) {
55
+ case 'unanimous': {
56
+ const nonAbstaining = votes.filter((v) => v.vote !== 'abstain');
57
+ if (nonAbstaining.length === 0) {
58
+ return 'rejected';
59
+ }
60
+ const allApproved = nonAbstaining.every((v) => v.vote === 'approve');
61
+ return allApproved ? 'approved' : 'rejected';
62
+ }
63
+ case 'majority':
64
+ return this.computeMajorityVerdict(votes);
65
+ case 'quorum':
66
+ return this.computeQuorumVerdict(votes, quorumConfig ?? { minimumApprovals: 1 });
67
+ default: {
68
+ const _exhaustive = algorithm;
69
+ return _exhaustive;
70
+ }
71
+ }
72
+ }
73
+ /** Serialize agreement to JSON matching the validation schema. */
74
+ serialize(agreement) {
75
+ return JSON.stringify({
76
+ version: 1,
77
+ agreementType: agreement.type,
78
+ runId: agreement.runId,
79
+ stageId: agreement.stageId,
80
+ createdAt: agreement.timestamp,
81
+ participants: agreement.participants,
82
+ reviewedArtifacts: agreement.reviewedArtifacts,
83
+ findings: agreement.findings,
84
+ unresolvedFindings: agreement.unresolvedFindings,
85
+ approvalStatus: agreement.approvalStatus,
86
+ approvalType: agreement.approvalType,
87
+ }, null, 2);
88
+ }
89
+ }
@@ -0,0 +1,7 @@
1
+ import type { AgreementValidator as AgreementValidatorPort } from '@ai-dev-orchestrator/ports';
2
+ import type { AgreementArtifact, AgreementValidationResult } from '@ai-dev-orchestrator/schemas';
3
+ /** Validates agreement artifacts for structural and semantic correctness. */
4
+ export declare class DefaultAgreementValidator implements AgreementValidatorPort {
5
+ /** @inheritdoc */
6
+ validate(agreement: AgreementArtifact): AgreementValidationResult;
7
+ }
@@ -0,0 +1,38 @@
1
+ /** Validates agreement artifacts for structural and semantic correctness. */
2
+ export class DefaultAgreementValidator {
3
+ /** @inheritdoc */
4
+ validate(agreement) {
5
+ const errors = [];
6
+ const warnings = [];
7
+ if (agreement.participants.length === 0) {
8
+ errors.push('Agreement must have at least one participant');
9
+ }
10
+ const hasApprover = agreement.participants.some((p) => p.action === 'approved');
11
+ if (!hasApprover) {
12
+ errors.push('Agreement must have at least one participant with approved action');
13
+ }
14
+ if (agreement.reviewedArtifacts.length === 0) {
15
+ errors.push('Agreement must reference at least one reviewed artifact');
16
+ }
17
+ if (agreement.approvalStatus === 'approved' ||
18
+ agreement.approvalStatus === 'conditionally_approved') {
19
+ const criticalUnresolved = agreement.unresolvedFindings.filter((f) => f.severity === 'critical' || f.severity === 'high');
20
+ if (criticalUnresolved.length > 0) {
21
+ errors.push(`Cannot approve with ${String(criticalUnresolved.length)} critical/high unresolved findings`);
22
+ }
23
+ }
24
+ if (agreement.approvalStatus === 'conditionally_approved' && !agreement.conditions) {
25
+ errors.push('Conditionally approved agreements must specify conditions');
26
+ }
27
+ if (!agreement.runId) {
28
+ errors.push('Agreement must have a runId');
29
+ }
30
+ if (!agreement.stageId) {
31
+ errors.push('Agreement must have a stageId');
32
+ }
33
+ if (agreement.unresolvedFindings.length > 0 && agreement.approvalStatus === 'approved') {
34
+ warnings.push(`Agreement approved with ${String(agreement.unresolvedFindings.length)} unresolved findings`);
35
+ }
36
+ return { valid: errors.length === 0, errors, warnings };
37
+ }
38
+ }
@@ -0,0 +1,3 @@
1
+ export { DefaultAgreementGate } from './agreement-gate';
2
+ export { AgreementGenerator } from './agreement-generator';
3
+ export { DefaultAgreementValidator } from './agreement-validator';
@@ -0,0 +1,3 @@
1
+ export { DefaultAgreementGate } from './agreement-gate';
2
+ export { AgreementGenerator } from './agreement-generator';
3
+ export { DefaultAgreementValidator } from './agreement-validator';
@@ -0,0 +1,6 @@
1
+ import type { ArtifactTypeValidator, ArtifactValidationResult } from '@ai-dev-orchestrator/ports';
2
+ import type { ArtifactType } from '@ai-dev-orchestrator/schemas';
3
+ export declare class DefaultArtifactTypeValidator implements ArtifactTypeValidator {
4
+ validate(type: ArtifactType, content: string): ArtifactValidationResult;
5
+ getSchema(type: ArtifactType): unknown;
6
+ }
@@ -0,0 +1,38 @@
1
+ import { ARTIFACT_SCHEMA_MAP } from '../../domain/artifact-system/artifact-descriptors';
2
+ import { parseArtifactContent, parseYaml } from './content-parser';
3
+ export class DefaultArtifactTypeValidator {
4
+ validate(type, content) {
5
+ const schema = ARTIFACT_SCHEMA_MAP[type];
6
+ if (type === 'intake_requirements') {
7
+ return content.length > 0
8
+ ? { valid: true }
9
+ : { valid: false, errors: [{ path: '', message: 'Content must be non-empty' }] };
10
+ }
11
+ const data = type === 'run_manifest' ? parseYaml(content) : parseArtifactContent(content);
12
+ if (!data) {
13
+ return {
14
+ valid: false,
15
+ errors: [
16
+ {
17
+ path: '',
18
+ message: type === 'run_manifest'
19
+ ? 'Content is not valid YAML'
20
+ : 'Content is not valid frontmatter or JSON',
21
+ },
22
+ ],
23
+ };
24
+ }
25
+ const result = schema.safeParse(data);
26
+ if (result.success) {
27
+ return { valid: true };
28
+ }
29
+ const errors = result.error.issues.map((issue) => ({
30
+ path: '/' + issue.path.join('/'),
31
+ message: issue.message,
32
+ }));
33
+ return { valid: false, errors };
34
+ }
35
+ getSchema(type) {
36
+ return ARTIFACT_SCHEMA_MAP[type];
37
+ }
38
+ }
@@ -0,0 +1,4 @@
1
+ /** Compute a SHA-256 checksum of the given content. Returns `sha256:<hex>`. */
2
+ export declare function computeChecksum(content: string): string;
3
+ /** Verify that content matches the expected checksum. */
4
+ export declare function verifyChecksum(content: string, expected: string): boolean;
@@ -0,0 +1,9 @@
1
+ import { hashContent } from '../shared/hash';
2
+ /** Compute a SHA-256 checksum of the given content. Returns `sha256:<hex>`. */
3
+ export function computeChecksum(content) {
4
+ return hashContent(content);
5
+ }
6
+ /** Verify that content matches the expected checksum. */
7
+ export function verifyChecksum(content, expected) {
8
+ return computeChecksum(content) === expected;
9
+ }
@@ -0,0 +1,26 @@
1
+ import { type ZodType } from 'zod';
2
+ export declare const FRONTMATTER_REGEX: RegExp;
3
+ export type SafeParseResult<T> = {
4
+ readonly success: true;
5
+ readonly data: T;
6
+ } | {
7
+ readonly success: false;
8
+ readonly error: string;
9
+ };
10
+ /**
11
+ * Parse a JSON string and validate the result against a Zod schema.
12
+ * Returns a discriminated result instead of throwing.
13
+ */
14
+ export declare function safeJsonParse<T>(content: string, schema: ZodType<T>): SafeParseResult<T>;
15
+ export declare function parseFrontmatter(content: string): Record<string, unknown> | null;
16
+ export declare function parseJson(content: string): Record<string, unknown> | null;
17
+ export declare function parseYaml(content: string): Record<string, unknown> | null;
18
+ /** Parse artifact content trying frontmatter first, then JSON. */
19
+ export declare function parseArtifactContent(content: string): Record<string, unknown> | null;
20
+ /**
21
+ * Parse artifact content and validate against a Zod schema, returning the
22
+ * typed result or null if parsing/validation fails. Tries frontmatter first,
23
+ * then JSON — same extraction logic as parseArtifactContent but with schema
24
+ * validation on top.
25
+ */
26
+ export declare function parseTypedArtifactContent<T>(content: string, schema: ZodType<T>): T | null;
@@ -0,0 +1,64 @@
1
+ import { parse as parseYamlContent } from 'yaml';
2
+ import { z } from 'zod';
3
+ export const FRONTMATTER_REGEX = /^---\n([\s\S]*?)\n---/;
4
+ /**
5
+ * Parse a JSON string and validate the result against a Zod schema.
6
+ * Returns a discriminated result instead of throwing.
7
+ */
8
+ export function safeJsonParse(content, schema) {
9
+ let raw;
10
+ try {
11
+ raw = JSON.parse(content);
12
+ }
13
+ catch (e) {
14
+ return { success: false, error: e instanceof Error ? e.message : 'Invalid JSON' };
15
+ }
16
+ const result = schema.safeParse(raw);
17
+ if (result.success) {
18
+ return { success: true, data: result.data };
19
+ }
20
+ const message = result.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join('; ');
21
+ return { success: false, error: message };
22
+ }
23
+ export function parseFrontmatter(content) {
24
+ const match = FRONTMATTER_REGEX.exec(content);
25
+ if (!match?.[1]) {
26
+ return null;
27
+ }
28
+ try {
29
+ return parseYamlContent(match[1]);
30
+ }
31
+ catch {
32
+ return null;
33
+ }
34
+ }
35
+ export function parseJson(content) {
36
+ const result = safeJsonParse(content, z.record(z.string(), z.unknown()));
37
+ return result.success ? result.data : null;
38
+ }
39
+ export function parseYaml(content) {
40
+ try {
41
+ return parseYamlContent(content);
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ }
47
+ /** Parse artifact content trying frontmatter first, then JSON. */
48
+ export function parseArtifactContent(content) {
49
+ return parseFrontmatter(content) ?? parseJson(content);
50
+ }
51
+ /**
52
+ * Parse artifact content and validate against a Zod schema, returning the
53
+ * typed result or null if parsing/validation fails. Tries frontmatter first,
54
+ * then JSON — same extraction logic as parseArtifactContent but with schema
55
+ * validation on top.
56
+ */
57
+ export function parseTypedArtifactContent(content, schema) {
58
+ const raw = parseFrontmatter(content) ?? parseJson(content);
59
+ if (!raw) {
60
+ return null;
61
+ }
62
+ const result = schema.safeParse(raw);
63
+ return result.success ? result.data : null;
64
+ }
@@ -0,0 +1,14 @@
1
+ import type { OwnershipRegistry } from '@ai-dev-orchestrator/ports';
2
+ import type { ArtifactType, RoleContract } from '@ai-dev-orchestrator/schemas';
3
+ /**
4
+ * Builds an ownership override map from role contracts by collecting each role's
5
+ * declared `ownedArtifacts` into a map keyed by artifact type.
6
+ */
7
+ export declare function buildOwnershipOverrides(roles: readonly RoleContract[]): ReadonlyMap<ArtifactType, string[]>;
8
+ export declare class DefaultOwnershipRegistry implements OwnershipRegistry {
9
+ private readonly ownershipMap;
10
+ constructor(overrides?: ReadonlyMap<ArtifactType, string> | ReadonlyMap<ArtifactType, string[]>);
11
+ getOwner(type: ArtifactType): string | null;
12
+ isAuthorized(role: string, type: ArtifactType): boolean;
13
+ getOwnedTypes(role: string): ArtifactType[];
14
+ }