@dailephd/my-dev-kit-lab 0.4.2 → 0.4.4

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 (113) hide show
  1. package/README.md +28 -113
  2. package/benchmarks/contracts/todo-behavior.md +1 -1
  3. package/benchmarks/projects/task-analytics-large-mixed/README.md +2 -0
  4. package/benchmarks/projects/task-workflow-medium-ts/README.md +3 -1
  5. package/dist/src/evaluation/stageContextDeterminism/calculateStageContextDeterminism.js +52 -0
  6. package/dist/src/evaluation/stageContextDeterminism/canonicalizeStageContextRun.js +53 -0
  7. package/dist/src/evaluation/stageContextDeterminism/index.js +2 -0
  8. package/dist/src/evaluation/stageContextDeterminism/types.js +1 -0
  9. package/dist/src/evaluation/stageContextExpectations/index.js +2 -0
  10. package/dist/src/evaluation/stageContextExpectations/producerReadinessExpectationTypes.js +8 -0
  11. package/dist/src/evaluation/stageContextExpectations/readStageContextExpectationFixtureV1.js +50 -0
  12. package/dist/src/evaluation/stageContextExpectations/readTypes.js +1 -0
  13. package/dist/src/evaluation/stageContextExpectations/types.js +1 -0
  14. package/dist/src/evaluation/stageContextExpectations/validation.js +768 -0
  15. package/dist/src/evaluation/stageContextMetrics/calculateAllocationMetrics.js +96 -0
  16. package/dist/src/evaluation/stageContextMetrics/calculateArtifactStateMetrics.js +130 -0
  17. package/dist/src/evaluation/stageContextMetrics/calculateContextSizeMetrics.js +85 -0
  18. package/dist/src/evaluation/stageContextMetrics/calculateCriticalityMetrics.js +112 -0
  19. package/dist/src/evaluation/stageContextMetrics/calculateExpectationMetrics.js +103 -0
  20. package/dist/src/evaluation/stageContextMetrics/calculateOwnerMetrics.js +84 -0
  21. package/dist/src/evaluation/stageContextMetrics/calculateReadinessAgreement.js +152 -0
  22. package/dist/src/evaluation/stageContextMetrics/calculateResponsibilityMappingMetrics.js +36 -0
  23. package/dist/src/evaluation/stageContextMetrics/calculateSupplementalRawAgreement.js +50 -0
  24. package/dist/src/evaluation/stageContextMetrics/calculateTruncationClassification.js +44 -0
  25. package/dist/src/evaluation/stageContextMetrics/collectContextCapsuleEvidence.js +312 -0
  26. package/dist/src/evaluation/stageContextMetrics/collectRetrievalAuditEvidence.js +35 -0
  27. package/dist/src/evaluation/stageContextMetrics/collectWorkflowInstructionEvidence.js +137 -0
  28. package/dist/src/evaluation/stageContextMetrics/evaluateProducerReadinessBridge.js +127 -0
  29. package/dist/src/evaluation/stageContextMetrics/evaluateV043StageContextExecution.js +247 -0
  30. package/dist/src/evaluation/stageContextMetrics/index.js +17 -0
  31. package/dist/src/evaluation/stageContextMetrics/matchStageContextExpectations.js +38 -0
  32. package/dist/src/evaluation/stageContextMetrics/producerReadinessMetricTypes.js +1 -0
  33. package/dist/src/evaluation/stageContextMetrics/targetKeys.js +35 -0
  34. package/dist/src/evaluation/stageContextMetrics/types.js +1 -0
  35. package/dist/src/evaluation/stageContextSelectors/contextArtifactConsistency.js +89 -0
  36. package/dist/src/evaluation/stageContextSelectors/contextCapsuleSelectors.js +126 -0
  37. package/dist/src/evaluation/stageContextSelectors/index.js +4 -0
  38. package/dist/src/evaluation/stageContextSelectors/retrievalAuditRecordSelectors.js +54 -0
  39. package/dist/src/evaluation/stageContextSelectors/workflowInstructionPacketSelectors.js +51 -0
  40. package/dist/src/evaluation/targetImmutability/captureTargetSnapshot.js +208 -0
  41. package/dist/src/evaluation/targetImmutability/compareTargetSnapshots.js +56 -0
  42. package/dist/src/evaluation/targetImmutability/index.js +3 -0
  43. package/dist/src/evaluation/targetImmutability/types.js +1 -0
  44. package/dist/src/evaluation/targetImmutability/validateTargetImmutabilityConfig.js +130 -0
  45. package/dist/src/evaluation/upstreamArtifacts/artifactReadTypes.js +1 -0
  46. package/dist/src/evaluation/upstreamArtifacts/index.js +9 -0
  47. package/dist/src/evaluation/upstreamArtifacts/jsonTypes.js +1 -0
  48. package/dist/src/evaluation/upstreamArtifacts/myDevKitClassificationTypesV1.js +1 -0
  49. package/dist/src/evaluation/upstreamArtifacts/myDevKitContextArtifactsV1.js +1 -0
  50. package/dist/src/evaluation/upstreamArtifacts/myDevKitSemanticTypesV1.js +1 -0
  51. package/dist/src/evaluation/upstreamArtifacts/orchestratorContextReadinessResultV1.js +247 -0
  52. package/dist/src/evaluation/upstreamArtifacts/orchestratorWorkflowInstructionPacketV1.js +1 -0
  53. package/dist/src/evaluation/upstreamArtifacts/readImplementationContextPacketV1.js +9 -0
  54. package/dist/src/evaluation/upstreamArtifacts/readImplementationContextRetrievalReportV1.js +9 -0
  55. package/dist/src/evaluation/upstreamArtifacts/readJsonArtifact.js +53 -0
  56. package/dist/src/evaluation/upstreamArtifacts/readMyDevKitContextCapsuleV1.js +9 -0
  57. package/dist/src/evaluation/upstreamArtifacts/readMyDevKitRetrievalAuditRecordV1.js +9 -0
  58. package/dist/src/evaluation/upstreamArtifacts/readOrchestratorWorkflowInstructionPacketV1.js +9 -0
  59. package/dist/src/evaluation/upstreamArtifacts/readSupplementalContextTextFile.js +29 -0
  60. package/dist/src/evaluation/upstreamArtifacts/readTestContextPacketV1.js +9 -0
  61. package/dist/src/evaluation/upstreamArtifacts/readTestContextRetrievalReportV1.js +9 -0
  62. package/dist/src/evaluation/upstreamArtifacts/runtimeValidation.js +131 -0
  63. package/dist/src/evaluation/upstreamArtifacts/schemaVersion.js +32 -0
  64. package/dist/src/evaluation/upstreamArtifacts/supplementalContextTextParser.js +75 -0
  65. package/dist/src/evaluation/upstreamArtifacts/supplementalContextTypes.js +152 -0
  66. package/dist/src/evaluation/upstreamArtifacts/validateMyDevKitContextCapsuleV1.js +1208 -0
  67. package/dist/src/evaluation/upstreamArtifacts/validateMyDevKitRetrievalAuditRecordV1.js +112 -0
  68. package/dist/src/evaluation/upstreamArtifacts/validateOrchestratorWorkflowInstructionPacketV1.js +235 -0
  69. package/dist/src/evaluation/upstreamArtifacts/validateSupplementalContextDocumentV1.js +148 -0
  70. package/dist/src/experiments/plugins/contextStrategyComparison/executeV043StageContextStrategy.js +46 -0
  71. package/dist/src/experiments/plugins/contextStrategyComparison/index.js +9 -0
  72. package/dist/src/experiments/plugins/contextStrategyComparison/loadV043StrategyArtifacts.js +397 -0
  73. package/dist/src/experiments/plugins/contextStrategyComparison/plugin.js +39 -1
  74. package/dist/src/experiments/plugins/contextStrategyComparison/readV043FullWorkflowLibraryFixture.js +162 -0
  75. package/dist/src/experiments/plugins/contextStrategyComparison/resolveV043StrategyInputs.js +43 -0
  76. package/dist/src/experiments/plugins/contextStrategyComparison/resultMapping.js +3 -0
  77. package/dist/src/experiments/plugins/contextStrategyComparison/runV043StageContextStrategyWithAssurance.js +205 -0
  78. package/dist/src/experiments/plugins/contextStrategyComparison/v043FullWorkflowLibraryFixture.js +1 -0
  79. package/dist/src/experiments/plugins/contextStrategyComparison/v043RunAssuranceTypes.js +1 -0
  80. package/dist/src/experiments/plugins/contextStrategyComparison/v043StrategyExecutionTypes.js +1 -0
  81. package/dist/src/experiments/plugins/contextStrategyComparison/v043StrategyIds.js +13 -0
  82. package/dist/src/experiments/plugins/contextStrategyComparison/v043StrategyInputContracts.js +1 -0
  83. package/dist/src/experiments/plugins/contextStrategyComparison/validateV043RunAssuranceConfig.js +59 -0
  84. package/dist/src/experiments/plugins/contextStrategyComparison/validateV043StrategyInput.js +266 -0
  85. package/dist/src/report/experiments/buildContextStrategyComparisonV043Report.js +520 -0
  86. package/dist/src/report/experiments/buildPluginExperimentReport.js +21 -6
  87. package/dist/src/report/experiments/contextStrategyComparisonV043ReportModel.js +1 -0
  88. package/dist/src/report/experiments/index.js +4 -0
  89. package/dist/src/report/experiments/renderContextStrategyComparisonV043Html.js +296 -0
  90. package/dist/src/report/experiments/renderPluginExperimentReportHtml.js +3 -0
  91. package/dist/src/report/experiments/renderPluginExperimentReportText.js +292 -0
  92. package/dist/src/report/experiments/writePluginExperimentReports.js +3 -0
  93. package/dist/src/securityValidation/attackScenarios/scenarios/secretLeakageScenario.js +215 -9
  94. package/docs/METRICS.md +84 -10
  95. package/package.json +2 -2
  96. package/tests/fixtures/full-workflow-library/complete-v1.0.0.json +24 -0
  97. package/tests/fixtures/full-workflow-library/future-minor-v1.1.0-additive.json +25 -0
  98. package/tests/fixtures/stage-context-expectations/complete-v1.0.0.json +230 -0
  99. package/tests/fixtures/stage-context-expectations/future-minor-v1.1.0-additive.json +232 -0
  100. package/tests/fixtures/stage-context-expectations/invalid/malformed-json.txt +1 -0
  101. package/tests/fixtures/stage-context-expectations/invalid/non-object-root.json +1 -0
  102. package/tests/fixtures/stage-context-expectations/minimal-v1.0.0.json +18 -0
  103. package/tests/fixtures/upstream-artifacts/invalid/malformed-json.txt +1 -0
  104. package/tests/fixtures/upstream-artifacts/invalid/non-object-root.json +1 -0
  105. package/tests/fixtures/upstream-artifacts/my-dev-kit/1.10.2/context-capsule/complete-v1.0.0.json +504 -0
  106. package/tests/fixtures/upstream-artifacts/my-dev-kit/1.10.2/context-capsule/future-minor-v1.1.0-additive.json +955 -0
  107. package/tests/fixtures/upstream-artifacts/my-dev-kit/1.10.2/retrieval-audit-record/complete-v1.0.0.json +190 -0
  108. package/tests/fixtures/upstream-artifacts/my-dev-kit/1.10.2/retrieval-audit-record/future-minor-v1.1.0-additive.json +327 -0
  109. package/tests/fixtures/upstream-artifacts/my-dev-kit-1.10.2-identity/PROVENANCE.txt +13 -0
  110. package/tests/fixtures/upstream-artifacts/my-dev-kit-1.10.2-identity/context-capsule.json +7874 -0
  111. package/tests/fixtures/upstream-artifacts/my-dev-kit-1.10.2-identity/retrieval-audit-record.json +1076 -0
  112. package/tests/fixtures/upstream-artifacts/my-dev-kit-orchestrator/1.2.1/workflow-instruction-packet/complete-v1.0.0.json +160 -0
  113. package/tests/fixtures/upstream-artifacts/my-dev-kit-orchestrator/1.2.1/workflow-instruction-packet/future-minor-v1.1.0-additive.json +186 -0
@@ -0,0 +1,137 @@
1
+ function dedupeEvidence(records) {
2
+ const seen = new Set();
3
+ const result = [];
4
+ for (const record of records) {
5
+ const key = `${record.sourceInstance} ${record.category} ${record.targetKey}`;
6
+ if (seen.has(key))
7
+ continue;
8
+ seen.add(key);
9
+ result.push(record);
10
+ }
11
+ return result;
12
+ }
13
+ function workflowStableIdKey(sourceArtifact, category, id) {
14
+ return `${sourceArtifact}|${category}|id:${id}`;
15
+ }
16
+ function provenanceKey(sourceArtifact, evidenceId) {
17
+ return `${sourceArtifact}|provenance|evidenceId:${evidenceId}`;
18
+ }
19
+ export function collectWorkflowInstructionPacketEvidence(artifact, sourceInstance) {
20
+ const SOURCE_ARTIFACT = "workflow-instruction-packet";
21
+ const records = [];
22
+ records.push({
23
+ sourceArtifact: SOURCE_ARTIFACT,
24
+ sourceInstance,
25
+ category: "workflow",
26
+ targetKey: workflowStableIdKey(SOURCE_ARTIFACT, "workflow", artifact.workflowId),
27
+ sourceFieldPath: "workflowId"
28
+ });
29
+ records.push({
30
+ sourceArtifact: SOURCE_ARTIFACT,
31
+ sourceInstance,
32
+ category: "stage",
33
+ targetKey: workflowStableIdKey(SOURCE_ARTIFACT, "stage", artifact.stageId),
34
+ sourceFieldPath: "stageId"
35
+ });
36
+ artifact.resolvedCommands.forEach((command, index) => {
37
+ records.push({
38
+ sourceArtifact: SOURCE_ARTIFACT,
39
+ sourceInstance,
40
+ category: "command",
41
+ targetKey: workflowStableIdKey(SOURCE_ARTIFACT, "command", command.id),
42
+ sourceFieldPath: `resolvedCommands[${index}].id`
43
+ });
44
+ });
45
+ artifact.resolvedRules.forEach((rule, index) => {
46
+ records.push({
47
+ sourceArtifact: SOURCE_ARTIFACT,
48
+ sourceInstance,
49
+ category: "rule",
50
+ targetKey: workflowStableIdKey(SOURCE_ARTIFACT, "rule", rule.id),
51
+ sourceFieldPath: `resolvedRules[${index}].id`
52
+ });
53
+ });
54
+ records.push({
55
+ sourceArtifact: SOURCE_ARTIFACT,
56
+ sourceInstance,
57
+ category: "report-contract",
58
+ targetKey: workflowStableIdKey(SOURCE_ARTIFACT, "report-contract", artifact.reportContract.id),
59
+ sourceFieldPath: "reportContract.id"
60
+ });
61
+ artifact.resolutionProvenance.forEach((entry, index) => {
62
+ records.push({
63
+ sourceArtifact: SOURCE_ARTIFACT,
64
+ sourceInstance,
65
+ category: "provenance",
66
+ targetKey: provenanceKey(SOURCE_ARTIFACT, entry.sourceEntryId),
67
+ sourceFieldPath: `resolutionProvenance[${index}].sourceEntryId`
68
+ });
69
+ records.push({
70
+ sourceArtifact: SOURCE_ARTIFACT,
71
+ sourceInstance,
72
+ category: "provenance",
73
+ targetKey: provenanceKey(SOURCE_ARTIFACT, entry.referencedEntryId),
74
+ sourceFieldPath: `resolutionProvenance[${index}].referencedEntryId`
75
+ });
76
+ });
77
+ return dedupeEvidence(records);
78
+ }
79
+ export function collectFullWorkflowLibraryEvidence(fixture, sourceInstance) {
80
+ const SOURCE_ARTIFACT = "full-workflow-library";
81
+ const records = [];
82
+ fixture.workflowIds.forEach((id, index) => {
83
+ records.push({
84
+ sourceArtifact: SOURCE_ARTIFACT,
85
+ sourceInstance,
86
+ category: "workflow",
87
+ targetKey: workflowStableIdKey(SOURCE_ARTIFACT, "workflow", id),
88
+ sourceFieldPath: `workflowIds[${index}]`
89
+ });
90
+ });
91
+ fixture.stageIds.forEach((id, index) => {
92
+ records.push({
93
+ sourceArtifact: SOURCE_ARTIFACT,
94
+ sourceInstance,
95
+ category: "stage",
96
+ targetKey: workflowStableIdKey(SOURCE_ARTIFACT, "stage", id),
97
+ sourceFieldPath: `stageIds[${index}]`
98
+ });
99
+ });
100
+ fixture.commandIds.forEach((id, index) => {
101
+ records.push({
102
+ sourceArtifact: SOURCE_ARTIFACT,
103
+ sourceInstance,
104
+ category: "command",
105
+ targetKey: workflowStableIdKey(SOURCE_ARTIFACT, "command", id),
106
+ sourceFieldPath: `commandIds[${index}]`
107
+ });
108
+ });
109
+ fixture.ruleIds.forEach((id, index) => {
110
+ records.push({
111
+ sourceArtifact: SOURCE_ARTIFACT,
112
+ sourceInstance,
113
+ category: "rule",
114
+ targetKey: workflowStableIdKey(SOURCE_ARTIFACT, "rule", id),
115
+ sourceFieldPath: `ruleIds[${index}]`
116
+ });
117
+ });
118
+ fixture.reportContractIds.forEach((id, index) => {
119
+ records.push({
120
+ sourceArtifact: SOURCE_ARTIFACT,
121
+ sourceInstance,
122
+ category: "report-contract",
123
+ targetKey: workflowStableIdKey(SOURCE_ARTIFACT, "report-contract", id),
124
+ sourceFieldPath: `reportContractIds[${index}]`
125
+ });
126
+ });
127
+ fixture.provenanceEvidenceIds.forEach((id, index) => {
128
+ records.push({
129
+ sourceArtifact: SOURCE_ARTIFACT,
130
+ sourceInstance,
131
+ category: "provenance",
132
+ targetKey: provenanceKey(SOURCE_ARTIFACT, id),
133
+ sourceFieldPath: `provenanceEvidenceIds[${index}]`
134
+ });
135
+ });
136
+ return dedupeEvidence(records);
137
+ }
@@ -0,0 +1,127 @@
1
+ import { collectSelectedOwnerEvidence, calculateOwnerMetrics } from "./calculateOwnerMetrics.js";
2
+ import { calculateAllocationFactsForGroups } from "./calculateAllocationMetrics.js";
3
+ import { classifyTruncationRecords } from "./calculateTruncationClassification.js";
4
+ import { calculateSupplementalRawAgreement } from "./calculateSupplementalRawAgreement.js";
5
+ import { calculateReadinessAgreementMetrics } from "./calculateReadinessAgreement.js";
6
+ import { calculateCriticalityMetrics } from "./calculateCriticalityMetrics.js";
7
+ function ownerExpectationsFor(expectations, sourceArtifact) {
8
+ return expectations?.ownerExpectations?.filter((e) => e.sourceArtifact === sourceArtifact);
9
+ }
10
+ function evaluateSide(input, expectations) {
11
+ const producerExpectations = expectations?.producerReadinessExpectations;
12
+ // Owner-selection and allocation-group evidence only exist on ContextCapsule (Batch 1
13
+ // contract-lock evidence: RetrievalAuditRecord has no selectedOwners/evidenceGroups
14
+ // fields). Truncation and responsibility-mapping evidence exist on both.
15
+ const capsule = input.contextCapsule;
16
+ const truncationArtifact = input.contextCapsule ?? input.retrievalAuditRecord;
17
+ const rawForAgreement = input.contextCapsule ?? input.retrievalAuditRecord;
18
+ const selectedOwnerEvidence = capsule ? collectSelectedOwnerEvidence(capsule.selectedOwners, "context-capsule", input.role) : undefined;
19
+ const ownerEvaluation = calculateOwnerMetrics(selectedOwnerEvidence, ownerExpectationsFor(producerExpectations, "context-capsule"));
20
+ const allocationFacts = capsule
21
+ ? calculateAllocationFactsForGroups(capsule.evidenceGroups, "context-capsule", input.role)
22
+ : { requiredGroupCapacity: [], usedReservation: [], borrowedCapacity: [], unusedCapacity: [] };
23
+ const allocationEvaluation = {
24
+ ...allocationFacts,
25
+ requiredEvidenceOmitted: {
26
+ availability: "not-applicable",
27
+ count: null,
28
+ evidenceKeys: [],
29
+ reason: "Batch 3 bridge evaluation derives omission from truncation records, not expectation matches; see truncationEvaluation."
30
+ },
31
+ requiredEvidenceOmittedEntries: []
32
+ };
33
+ const truncationSourceArtifact = input.contextCapsule ? "context-capsule" : "retrieval-audit-record";
34
+ const truncationEvaluation = truncationArtifact
35
+ ? classifyTruncationRecords(truncationArtifact.truncation.records, truncationSourceArtifact, input.role)
36
+ : [];
37
+ const packetAgreement = input.packet !== undefined || rawForAgreement !== undefined ? calculateSupplementalRawAgreement(input.packet, rawForAgreement) : null;
38
+ const reportAgreement = input.report !== undefined || rawForAgreement !== undefined ? calculateSupplementalRawAgreement(input.report, rawForAgreement) : null;
39
+ return { ownerEvaluation, allocationEvaluation, truncationEvaluation, packetAgreement, reportAgreement };
40
+ }
41
+ // Builds bridge-evaluator input from an already-loaded combined-bounded-stage-context
42
+ // execution payload (Batch 3 section 12.1: "accept already-read raw, supplemental,
43
+ // readiness, and expectation inputs"). Never reads a file itself.
44
+ export function buildProducerReadinessBridgeInputFromCombinedPayload(payload, expectations) {
45
+ const implementationPair = payload.contextArtifacts.find((p) => p.role === "implementation");
46
+ const testPair = payload.contextArtifacts.find((p) => p.role === "test-implementation");
47
+ const hasImplementationSide = implementationPair !== undefined || payload.implementationContextPacket !== undefined || payload.implementationContextRetrievalReport !== undefined;
48
+ const hasTestSide = testPair !== undefined || payload.testContextPacket !== undefined || payload.testContextRetrievalReport !== undefined;
49
+ return {
50
+ implementation: hasImplementationSide
51
+ ? {
52
+ role: "implementation",
53
+ contextCapsule: implementationPair?.contextCapsule,
54
+ retrievalAuditRecord: implementationPair?.retrievalAuditRecord,
55
+ packet: payload.implementationContextPacket,
56
+ packetSourcePath: payload.implementationContextPacketSourcePath,
57
+ report: payload.implementationContextRetrievalReport
58
+ }
59
+ : undefined,
60
+ testImplementation: hasTestSide
61
+ ? {
62
+ role: "test-implementation",
63
+ contextCapsule: testPair?.contextCapsule,
64
+ retrievalAuditRecord: testPair?.retrievalAuditRecord,
65
+ packet: payload.testContextPacket,
66
+ packetSourcePath: payload.testContextPacketSourcePath,
67
+ report: payload.testContextRetrievalReport
68
+ }
69
+ : undefined,
70
+ readiness: payload.readiness,
71
+ expectations
72
+ };
73
+ }
74
+ export function evaluateProducerReadinessBridge(input) {
75
+ const hasAnyInput = input.implementation !== undefined || input.testImplementation !== undefined || input.readiness !== undefined;
76
+ if (!hasAnyInput) {
77
+ return {
78
+ status: "not-applicable",
79
+ reason: "No producer-readiness bridge inputs (supplemental artifacts or readiness result) were supplied.",
80
+ implementation: null,
81
+ testImplementation: null,
82
+ readinessAgreement: null,
83
+ criticalityEvaluation: null,
84
+ warnings: [],
85
+ evidenceReferences: []
86
+ };
87
+ }
88
+ const evidenceReferences = [];
89
+ const warnings = [];
90
+ let implementation = null;
91
+ if (input.implementation !== undefined) {
92
+ const evaluated = evaluateSide(input.implementation, input.expectations);
93
+ implementation = { role: "implementation", ...evaluated };
94
+ if (input.implementation.packetSourcePath)
95
+ evidenceReferences.push(input.implementation.packetSourcePath);
96
+ }
97
+ let testImplementation = null;
98
+ if (input.testImplementation !== undefined) {
99
+ const evaluated = evaluateSide(input.testImplementation, input.expectations);
100
+ testImplementation = { role: "test-implementation", ...evaluated };
101
+ if (input.testImplementation.packetSourcePath)
102
+ evidenceReferences.push(input.testImplementation.packetSourcePath);
103
+ }
104
+ let readinessAgreement = null;
105
+ if (input.readiness !== undefined) {
106
+ const readinessExpectations = input.expectations.producerReadinessExpectations?.readinessExpectations;
107
+ const matchingExpectation = readinessExpectations?.find((e) => e.kind === input.readiness.kind);
108
+ const relevantPacket = input.readiness.kind === "implementation" ? input.implementation?.packet : input.testImplementation?.packet;
109
+ const relevantPacketPath = input.readiness.kind === "implementation" ? input.implementation?.packetSourcePath : input.testImplementation?.packetSourcePath;
110
+ readinessAgreement = calculateReadinessAgreementMetrics(input.readiness, matchingExpectation, relevantPacket, relevantPacketPath);
111
+ }
112
+ const criticalityMappings = input.testImplementation?.retrievalAuditRecord?.responsibilityMappings.mappings ??
113
+ input.testImplementation?.contextCapsule?.responsibilityMappings.mappings ??
114
+ input.implementation?.retrievalAuditRecord?.responsibilityMappings.mappings ??
115
+ input.implementation?.contextCapsule?.responsibilityMappings.mappings;
116
+ const criticalityEvaluation = calculateCriticalityMetrics(criticalityMappings, input.expectations.producerReadinessExpectations?.criticalityExpectations);
117
+ return {
118
+ status: "evaluated",
119
+ reason: null,
120
+ implementation,
121
+ testImplementation,
122
+ readinessAgreement,
123
+ criticalityEvaluation,
124
+ warnings,
125
+ evidenceReferences
126
+ };
127
+ }
@@ -0,0 +1,247 @@
1
+ import { collectContextCapsuleEvidence } from "./collectContextCapsuleEvidence.js";
2
+ import { collectRetrievalAuditEvidence } from "./collectRetrievalAuditEvidence.js";
3
+ import { collectFullWorkflowLibraryEvidence, collectWorkflowInstructionPacketEvidence } from "./collectWorkflowInstructionEvidence.js";
4
+ import { matchStageContextExpectations } from "./matchStageContextExpectations.js";
5
+ import { calculateAllowedEvidenceCoverage, calculateForbiddenEvidenceInclusion, calculateIrrelevantFileInclusion, calculateIrrelevantInstructionInclusion, calculateRequiredEvidenceRecall, calculateRequiredProvenanceRecall } from "./calculateExpectationMetrics.js";
6
+ import { calculateContextCapsuleResponsibilityMappingMetric, calculateRetrievalAuditResponsibilityMappingMetric } from "./calculateResponsibilityMappingMetrics.js";
7
+ import { compareExpectedContextCapsuleState, compareExpectedRetrievalAuditState, compareExpectedTargetImmutabilityState, compareExpectedWorkflowInstructionPacketState } from "./calculateArtifactStateMetrics.js";
8
+ import { calculateV043ExecutionContextSize } from "./calculateContextSizeMetrics.js";
9
+ function collectExecutionEvidence(execution) {
10
+ const evidence = [];
11
+ function pushPairEvidence(pair, labelPrefix) {
12
+ evidence.push(...collectContextCapsuleEvidence(pair.contextCapsule, `${labelPrefix}.contextCapsule`));
13
+ if (pair.retrievalAuditRecord) {
14
+ evidence.push(...collectRetrievalAuditEvidence(pair.retrievalAuditRecord, `${labelPrefix}.retrievalAuditRecord`));
15
+ }
16
+ }
17
+ switch (execution.strategyId) {
18
+ case "architecture-context-only": {
19
+ const payload = execution.payload;
20
+ pushPairEvidence(payload.architecture, "architecture");
21
+ break;
22
+ }
23
+ case "architecture-plus-implementation-refresh": {
24
+ const payload = execution.payload;
25
+ pushPairEvidence(payload.architecture, "architecture");
26
+ pushPairEvidence(payload.implementation, "implementation");
27
+ break;
28
+ }
29
+ case "architecture-plus-implementation-and-test-refresh": {
30
+ const payload = execution.payload;
31
+ pushPairEvidence(payload.architecture, "architecture");
32
+ pushPairEvidence(payload.implementation, "implementation");
33
+ pushPairEvidence(payload.testImplementation, "testImplementation");
34
+ break;
35
+ }
36
+ case "full-workflow-library": {
37
+ const payload = execution.payload;
38
+ evidence.push(...collectFullWorkflowLibraryEvidence(payload.fullWorkflowLibrary, "fullWorkflowLibrary"));
39
+ break;
40
+ }
41
+ case "bounded-workflow-instruction-packet": {
42
+ const payload = execution.payload;
43
+ evidence.push(...collectWorkflowInstructionPacketEvidence(payload.workflowInstructionPacket, "workflowInstructionPacket"));
44
+ break;
45
+ }
46
+ case "combined-bounded-stage-context": {
47
+ const payload = execution.payload;
48
+ payload.contextArtifacts.forEach((pair, index) => {
49
+ pushPairEvidence(pair, `contextArtifacts[${index}]`);
50
+ });
51
+ evidence.push(...collectWorkflowInstructionPacketEvidence(payload.workflowInstructionPacket, "workflowInstructionPacket"));
52
+ break;
53
+ }
54
+ }
55
+ return evidence;
56
+ }
57
+ function collectResponsibilityMetrics(execution) {
58
+ const metrics = [];
59
+ function pushPairMetrics(pair, labelPrefix) {
60
+ metrics.push(calculateContextCapsuleResponsibilityMappingMetric(pair.contextCapsule, `${labelPrefix}.contextCapsule`));
61
+ if (pair.retrievalAuditRecord) {
62
+ metrics.push(calculateRetrievalAuditResponsibilityMappingMetric(pair.retrievalAuditRecord, `${labelPrefix}.retrievalAuditRecord`));
63
+ }
64
+ }
65
+ switch (execution.strategyId) {
66
+ case "architecture-context-only": {
67
+ const payload = execution.payload;
68
+ pushPairMetrics(payload.architecture, "architecture");
69
+ break;
70
+ }
71
+ case "architecture-plus-implementation-refresh": {
72
+ const payload = execution.payload;
73
+ pushPairMetrics(payload.architecture, "architecture");
74
+ pushPairMetrics(payload.implementation, "implementation");
75
+ break;
76
+ }
77
+ case "architecture-plus-implementation-and-test-refresh": {
78
+ const payload = execution.payload;
79
+ pushPairMetrics(payload.architecture, "architecture");
80
+ pushPairMetrics(payload.implementation, "implementation");
81
+ pushPairMetrics(payload.testImplementation, "testImplementation");
82
+ break;
83
+ }
84
+ case "combined-bounded-stage-context": {
85
+ const payload = execution.payload;
86
+ payload.contextArtifacts.forEach((pair, index) => {
87
+ pushPairMetrics(pair, `contextArtifacts[${index}]`);
88
+ });
89
+ break;
90
+ }
91
+ case "full-workflow-library":
92
+ case "bounded-workflow-instruction-packet":
93
+ break;
94
+ }
95
+ return metrics;
96
+ }
97
+ function buildTargetImmutabilityMetric(targetImmutability) {
98
+ if (targetImmutability === undefined) {
99
+ return {
100
+ availability: "unavailable",
101
+ count: null,
102
+ evidenceKeys: [],
103
+ reason: "Target immutability configuration was not supplied for this strategy run."
104
+ };
105
+ }
106
+ if (targetImmutability.availability === "unavailable") {
107
+ return {
108
+ availability: "unavailable",
109
+ count: null,
110
+ evidenceKeys: [],
111
+ reason: targetImmutability.reason
112
+ };
113
+ }
114
+ return {
115
+ availability: "available",
116
+ count: targetImmutability.comparison.newMutationCount,
117
+ evidenceKeys: targetImmutability.comparison.mutations.map((mutation) => mutation.id),
118
+ reason: null
119
+ };
120
+ }
121
+ function collectStateComparisons(execution, targetImmutability) {
122
+ const expectedStates = execution.expectations.expectedStates;
123
+ const comparisons = [];
124
+ function pushPairComparisons(pair, labelPrefix) {
125
+ comparisons.push(...compareExpectedContextCapsuleState(expectedStates.contextCapsule, pair.contextCapsule, `${labelPrefix}.contextCapsule`));
126
+ if (pair.retrievalAuditRecord) {
127
+ comparisons.push(...compareExpectedRetrievalAuditState(expectedStates.retrievalAuditRecord, pair.retrievalAuditRecord, `${labelPrefix}.retrievalAuditRecord`));
128
+ }
129
+ }
130
+ switch (execution.strategyId) {
131
+ case "architecture-context-only": {
132
+ const payload = execution.payload;
133
+ pushPairComparisons(payload.architecture, "architecture");
134
+ break;
135
+ }
136
+ case "architecture-plus-implementation-refresh": {
137
+ const payload = execution.payload;
138
+ pushPairComparisons(payload.architecture, "architecture");
139
+ pushPairComparisons(payload.implementation, "implementation");
140
+ break;
141
+ }
142
+ case "architecture-plus-implementation-and-test-refresh": {
143
+ const payload = execution.payload;
144
+ pushPairComparisons(payload.architecture, "architecture");
145
+ pushPairComparisons(payload.implementation, "implementation");
146
+ pushPairComparisons(payload.testImplementation, "testImplementation");
147
+ break;
148
+ }
149
+ case "full-workflow-library":
150
+ break;
151
+ case "bounded-workflow-instruction-packet": {
152
+ const payload = execution.payload;
153
+ comparisons.push(...compareExpectedWorkflowInstructionPacketState(expectedStates.workflowInstructionPacket, payload.workflowInstructionPacket, "workflowInstructionPacket"));
154
+ break;
155
+ }
156
+ case "combined-bounded-stage-context": {
157
+ const payload = execution.payload;
158
+ payload.contextArtifacts.forEach((pair, index) => {
159
+ pushPairComparisons(pair, `contextArtifacts[${index}]`);
160
+ });
161
+ comparisons.push(...compareExpectedWorkflowInstructionPacketState(expectedStates.workflowInstructionPacket, payload.workflowInstructionPacket, "workflowInstructionPacket"));
162
+ break;
163
+ }
164
+ }
165
+ comparisons.push(...compareExpectedTargetImmutabilityState(expectedStates.targetImmutability, targetImmutability));
166
+ return comparisons;
167
+ }
168
+ export function evaluateV043StageContextExecution(execution, context) {
169
+ try {
170
+ if (execution.status === "invalid-input") {
171
+ return {
172
+ status: "not-applicable",
173
+ strategyId: execution.strategyId,
174
+ executionStatus: "invalid-input",
175
+ reason: "Metrics are not applicable because strategy input validation failed."
176
+ };
177
+ }
178
+ if (execution.status === "failed") {
179
+ return {
180
+ status: "not-applicable",
181
+ strategyId: execution.strategyId,
182
+ executionStatus: "failed",
183
+ reason: "Metrics are not applicable because strategy execution failed."
184
+ };
185
+ }
186
+ const status = execution.status;
187
+ if (status === "unavailable") {
188
+ return {
189
+ status: "not-applicable",
190
+ strategyId: execution.strategyId,
191
+ executionStatus: "unavailable",
192
+ reason: "Metrics are not applicable because strategy execution is unavailable."
193
+ };
194
+ }
195
+ if (status === "not-applicable") {
196
+ return {
197
+ status: "not-applicable",
198
+ strategyId: execution.strategyId,
199
+ executionStatus: "not-applicable",
200
+ reason: "Metrics are not applicable to this strategy execution."
201
+ };
202
+ }
203
+ const observedEvidence = collectExecutionEvidence(execution);
204
+ const expectationMatches = matchStageContextExpectations(execution.expectations, observedEvidence);
205
+ const metrics = {
206
+ requiredEvidenceRecall: calculateRequiredEvidenceRecall(expectationMatches),
207
+ allowedEvidenceCoverage: calculateAllowedEvidenceCoverage(expectationMatches),
208
+ forbiddenEvidenceInclusion: calculateForbiddenEvidenceInclusion(expectationMatches),
209
+ irrelevantFileInclusion: calculateIrrelevantFileInclusion(execution.expectations, observedEvidence),
210
+ irrelevantInstructionInclusion: calculateIrrelevantInstructionInclusion(execution.expectations, observedEvidence),
211
+ requiredProvenanceRecall: calculateRequiredProvenanceRecall(expectationMatches),
212
+ responsibilityMappingCompleteness: collectResponsibilityMetrics(execution),
213
+ stateComparisons: collectStateComparisons(execution, context?.targetImmutability),
214
+ contextSize: calculateV043ExecutionContextSize(execution),
215
+ consideredButUnselectedReads: {
216
+ availability: "unavailable",
217
+ count: null,
218
+ evidenceKeys: [],
219
+ reason: "The published upstream artifacts do not expose considered-but-unselected reads."
220
+ },
221
+ unnecessaryReads: {
222
+ availability: "unavailable",
223
+ count: null,
224
+ evidenceKeys: [],
225
+ reason: "The published upstream artifacts do not expose unnecessary-read evidence."
226
+ },
227
+ targetImmutability: buildTargetImmutabilityMetric(context?.targetImmutability)
228
+ };
229
+ return {
230
+ status: "completed",
231
+ strategyId: execution.strategyId,
232
+ executionStatus: "completed",
233
+ expectationMatches,
234
+ observedEvidence,
235
+ metrics,
236
+ warnings: []
237
+ };
238
+ }
239
+ catch {
240
+ return {
241
+ status: "failed",
242
+ strategyId: execution.strategyId,
243
+ executionStatus: execution.status,
244
+ reason: "Unexpected v0.4.3 stage-context metric evaluation failure."
245
+ };
246
+ }
247
+ }
@@ -0,0 +1,17 @@
1
+ export { buildStageContextExpectationTargetKey } from "./targetKeys.js";
2
+ export { collectContextCapsuleEvidence } from "./collectContextCapsuleEvidence.js";
3
+ export { collectRetrievalAuditEvidence } from "./collectRetrievalAuditEvidence.js";
4
+ export { collectFullWorkflowLibraryEvidence, collectWorkflowInstructionPacketEvidence } from "./collectWorkflowInstructionEvidence.js";
5
+ export { matchStageContextExpectations } from "./matchStageContextExpectations.js";
6
+ export { calculateAllowedEvidenceCoverage, calculateForbiddenEvidenceInclusion, calculateIrrelevantFileInclusion, calculateIrrelevantInstructionInclusion, calculateRequiredEvidenceRecall, calculateRequiredProvenanceRecall } from "./calculateExpectationMetrics.js";
7
+ export { compareExpectedContextCapsuleState, compareExpectedRetrievalAuditState, compareExpectedTargetImmutabilityState, compareExpectedWorkflowInstructionPacketState } from "./calculateArtifactStateMetrics.js";
8
+ export { calculateContextCapsuleResponsibilityMappingMetric, calculateRetrievalAuditResponsibilityMappingMetric } from "./calculateResponsibilityMappingMetrics.js";
9
+ export { calculateV043ExecutionContextSize } from "./calculateContextSizeMetrics.js";
10
+ export { evaluateV043StageContextExecution } from "./evaluateV043StageContextExecution.js";
11
+ export { collectSelectedOwnerEvidence, calculateOwnerMetrics } from "./calculateOwnerMetrics.js";
12
+ export { calculateAllocationFactsForGroups, calculateRequiredEvidenceOmitted, findAllocationExpectationForGroup } from "./calculateAllocationMetrics.js";
13
+ export { classifyTruncationRecord, classifyTruncationRecords } from "./calculateTruncationClassification.js";
14
+ export { calculateSupplementalRawAgreement } from "./calculateSupplementalRawAgreement.js";
15
+ export { calculateReadinessStructuralAgreement, calculateReadinessDecisionAgreement, calculateInvalidReady, calculateValidBlocked, calculateReadinessAgreementMetrics } from "./calculateReadinessAgreement.js";
16
+ export { calculateCriticalityMetrics } from "./calculateCriticalityMetrics.js";
17
+ export { evaluateProducerReadinessBridge, buildProducerReadinessBridgeInputFromCombinedPayload } from "./evaluateProducerReadinessBridge.js";
@@ -0,0 +1,38 @@
1
+ import { buildStageContextExpectationTargetKey } from "./targetKeys.js";
2
+ function dedupeStrings(values) {
3
+ const seen = new Set();
4
+ const result = [];
5
+ for (const value of values) {
6
+ if (seen.has(value))
7
+ continue;
8
+ seen.add(value);
9
+ result.push(value);
10
+ }
11
+ return result;
12
+ }
13
+ export function matchStageContextExpectations(expectations, observedEvidence) {
14
+ return expectations.expectedEvidence.map((item) => {
15
+ const targetKey = buildStageContextExpectationTargetKey(item);
16
+ const observedMatches = observedEvidence.filter((evidence) => evidence.sourceArtifact === item.sourceArtifact && evidence.category === item.category && evidence.targetKey === targetKey);
17
+ const matchedSourceInstances = dedupeStrings(observedMatches.map((evidence) => evidence.sourceInstance));
18
+ const matchedSourceFieldPaths = dedupeStrings(observedMatches.map((evidence) => evidence.sourceFieldPath));
19
+ const hasMatch = observedMatches.length > 0;
20
+ let outcome;
21
+ if (item.inclusion === "forbidden") {
22
+ outcome = hasMatch ? "violated" : "matched";
23
+ }
24
+ else {
25
+ outcome = hasMatch ? "matched" : "missing";
26
+ }
27
+ return {
28
+ expectationId: item.expectationId,
29
+ inclusion: item.inclusion,
30
+ sourceArtifact: item.sourceArtifact,
31
+ category: item.category,
32
+ targetKey,
33
+ outcome,
34
+ matchedSourceInstances,
35
+ matchedSourceFieldPaths
36
+ };
37
+ });
38
+ }
@@ -0,0 +1,35 @@
1
+ export function buildStageContextExpectationTargetKey(item) {
2
+ switch (item.category) {
3
+ case "file":
4
+ case "test-file":
5
+ case "fixture":
6
+ case "factory":
7
+ case "mock":
8
+ case "setup-file":
9
+ case "test-configuration":
10
+ return `${item.sourceArtifact}|${item.category}|path:${item.match.path}`;
11
+ case "symbol":
12
+ case "contract":
13
+ case "validator":
14
+ case "constant":
15
+ case "error":
16
+ case "schema-or-serializer":
17
+ return `${item.sourceArtifact}|${item.category}|symbolId:${item.match.symbolId}`;
18
+ case "source-range":
19
+ return `context-capsule|source-range|filePath:${item.match.filePath}|startLine:${item.match.startLine}|endLine:${item.match.endLine}`;
20
+ case "production-responsibility":
21
+ return `${item.sourceArtifact}|production-responsibility|responsibilityId:${item.match.responsibilityId}`;
22
+ case "package-script":
23
+ return `context-capsule|package-script|name:${item.match.name}`;
24
+ case "test-command":
25
+ return `context-capsule|test-command|commandText:${item.match.commandText}`;
26
+ case "workflow":
27
+ case "stage":
28
+ case "command":
29
+ case "rule":
30
+ case "report-contract":
31
+ return `${item.sourceArtifact}|${item.category}|id:${item.match.id}`;
32
+ case "provenance":
33
+ return `${item.sourceArtifact}|provenance|evidenceId:${item.match.evidenceId}`;
34
+ }
35
+ }
@@ -0,0 +1 @@
1
+ export {};