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

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 (92) hide show
  1. package/README.md +23 -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/readStageContextExpectationFixtureV1.js +50 -0
  11. package/dist/src/evaluation/stageContextExpectations/readTypes.js +1 -0
  12. package/dist/src/evaluation/stageContextExpectations/types.js +1 -0
  13. package/dist/src/evaluation/stageContextExpectations/validation.js +568 -0
  14. package/dist/src/evaluation/stageContextMetrics/calculateArtifactStateMetrics.js +130 -0
  15. package/dist/src/evaluation/stageContextMetrics/calculateContextSizeMetrics.js +85 -0
  16. package/dist/src/evaluation/stageContextMetrics/calculateExpectationMetrics.js +103 -0
  17. package/dist/src/evaluation/stageContextMetrics/calculateResponsibilityMappingMetrics.js +36 -0
  18. package/dist/src/evaluation/stageContextMetrics/collectContextCapsuleEvidence.js +312 -0
  19. package/dist/src/evaluation/stageContextMetrics/collectRetrievalAuditEvidence.js +35 -0
  20. package/dist/src/evaluation/stageContextMetrics/collectWorkflowInstructionEvidence.js +137 -0
  21. package/dist/src/evaluation/stageContextMetrics/evaluateV043StageContextExecution.js +247 -0
  22. package/dist/src/evaluation/stageContextMetrics/index.js +10 -0
  23. package/dist/src/evaluation/stageContextMetrics/matchStageContextExpectations.js +38 -0
  24. package/dist/src/evaluation/stageContextMetrics/targetKeys.js +35 -0
  25. package/dist/src/evaluation/stageContextMetrics/types.js +1 -0
  26. package/dist/src/evaluation/stageContextSelectors/contextArtifactConsistency.js +79 -0
  27. package/dist/src/evaluation/stageContextSelectors/contextCapsuleSelectors.js +126 -0
  28. package/dist/src/evaluation/stageContextSelectors/index.js +4 -0
  29. package/dist/src/evaluation/stageContextSelectors/retrievalAuditRecordSelectors.js +54 -0
  30. package/dist/src/evaluation/stageContextSelectors/workflowInstructionPacketSelectors.js +51 -0
  31. package/dist/src/evaluation/targetImmutability/captureTargetSnapshot.js +208 -0
  32. package/dist/src/evaluation/targetImmutability/compareTargetSnapshots.js +56 -0
  33. package/dist/src/evaluation/targetImmutability/index.js +3 -0
  34. package/dist/src/evaluation/targetImmutability/types.js +1 -0
  35. package/dist/src/evaluation/targetImmutability/validateTargetImmutabilityConfig.js +130 -0
  36. package/dist/src/evaluation/upstreamArtifacts/artifactReadTypes.js +1 -0
  37. package/dist/src/evaluation/upstreamArtifacts/index.js +3 -0
  38. package/dist/src/evaluation/upstreamArtifacts/jsonTypes.js +1 -0
  39. package/dist/src/evaluation/upstreamArtifacts/myDevKitClassificationTypesV1.js +1 -0
  40. package/dist/src/evaluation/upstreamArtifacts/myDevKitContextArtifactsV1.js +1 -0
  41. package/dist/src/evaluation/upstreamArtifacts/myDevKitSemanticTypesV1.js +1 -0
  42. package/dist/src/evaluation/upstreamArtifacts/orchestratorWorkflowInstructionPacketV1.js +1 -0
  43. package/dist/src/evaluation/upstreamArtifacts/readJsonArtifact.js +53 -0
  44. package/dist/src/evaluation/upstreamArtifacts/readMyDevKitContextCapsuleV1.js +9 -0
  45. package/dist/src/evaluation/upstreamArtifacts/readMyDevKitRetrievalAuditRecordV1.js +9 -0
  46. package/dist/src/evaluation/upstreamArtifacts/readOrchestratorWorkflowInstructionPacketV1.js +9 -0
  47. package/dist/src/evaluation/upstreamArtifacts/runtimeValidation.js +131 -0
  48. package/dist/src/evaluation/upstreamArtifacts/schemaVersion.js +32 -0
  49. package/dist/src/evaluation/upstreamArtifacts/validateMyDevKitContextCapsuleV1.js +1208 -0
  50. package/dist/src/evaluation/upstreamArtifacts/validateMyDevKitRetrievalAuditRecordV1.js +105 -0
  51. package/dist/src/evaluation/upstreamArtifacts/validateOrchestratorWorkflowInstructionPacketV1.js +235 -0
  52. package/dist/src/experiments/plugins/contextStrategyComparison/executeV043StageContextStrategy.js +46 -0
  53. package/dist/src/experiments/plugins/contextStrategyComparison/index.js +9 -0
  54. package/dist/src/experiments/plugins/contextStrategyComparison/loadV043StrategyArtifacts.js +286 -0
  55. package/dist/src/experiments/plugins/contextStrategyComparison/plugin.js +39 -1
  56. package/dist/src/experiments/plugins/contextStrategyComparison/readV043FullWorkflowLibraryFixture.js +162 -0
  57. package/dist/src/experiments/plugins/contextStrategyComparison/resolveV043StrategyInputs.js +43 -0
  58. package/dist/src/experiments/plugins/contextStrategyComparison/resultMapping.js +3 -0
  59. package/dist/src/experiments/plugins/contextStrategyComparison/runV043StageContextStrategyWithAssurance.js +190 -0
  60. package/dist/src/experiments/plugins/contextStrategyComparison/v043FullWorkflowLibraryFixture.js +1 -0
  61. package/dist/src/experiments/plugins/contextStrategyComparison/v043RunAssuranceTypes.js +1 -0
  62. package/dist/src/experiments/plugins/contextStrategyComparison/v043StrategyExecutionTypes.js +1 -0
  63. package/dist/src/experiments/plugins/contextStrategyComparison/v043StrategyIds.js +13 -0
  64. package/dist/src/experiments/plugins/contextStrategyComparison/v043StrategyInputContracts.js +1 -0
  65. package/dist/src/experiments/plugins/contextStrategyComparison/validateV043RunAssuranceConfig.js +59 -0
  66. package/dist/src/experiments/plugins/contextStrategyComparison/validateV043StrategyInput.js +252 -0
  67. package/dist/src/report/experiments/buildContextStrategyComparisonV043Report.js +398 -0
  68. package/dist/src/report/experiments/buildPluginExperimentReport.js +21 -6
  69. package/dist/src/report/experiments/contextStrategyComparisonV043ReportModel.js +1 -0
  70. package/dist/src/report/experiments/index.js +4 -0
  71. package/dist/src/report/experiments/renderContextStrategyComparisonV043Html.js +234 -0
  72. package/dist/src/report/experiments/renderPluginExperimentReportHtml.js +3 -0
  73. package/dist/src/report/experiments/renderPluginExperimentReportText.js +225 -0
  74. package/dist/src/report/experiments/writePluginExperimentReports.js +3 -0
  75. package/dist/src/securityValidation/attackScenarios/scenarios/secretLeakageScenario.js +215 -9
  76. package/docs/METRICS.md +56 -10
  77. package/package.json +1 -1
  78. package/tests/fixtures/full-workflow-library/complete-v1.0.0.json +24 -0
  79. package/tests/fixtures/full-workflow-library/future-minor-v1.1.0-additive.json +25 -0
  80. package/tests/fixtures/stage-context-expectations/complete-v1.0.0.json +230 -0
  81. package/tests/fixtures/stage-context-expectations/future-minor-v1.1.0-additive.json +232 -0
  82. package/tests/fixtures/stage-context-expectations/invalid/malformed-json.txt +1 -0
  83. package/tests/fixtures/stage-context-expectations/invalid/non-object-root.json +1 -0
  84. package/tests/fixtures/stage-context-expectations/minimal-v1.0.0.json +18 -0
  85. package/tests/fixtures/upstream-artifacts/invalid/malformed-json.txt +1 -0
  86. package/tests/fixtures/upstream-artifacts/invalid/non-object-root.json +1 -0
  87. package/tests/fixtures/upstream-artifacts/my-dev-kit/1.10.2/context-capsule/complete-v1.0.0.json +504 -0
  88. package/tests/fixtures/upstream-artifacts/my-dev-kit/1.10.2/context-capsule/future-minor-v1.1.0-additive.json +955 -0
  89. package/tests/fixtures/upstream-artifacts/my-dev-kit/1.10.2/retrieval-audit-record/complete-v1.0.0.json +190 -0
  90. package/tests/fixtures/upstream-artifacts/my-dev-kit/1.10.2/retrieval-audit-record/future-minor-v1.1.0-additive.json +327 -0
  91. package/tests/fixtures/upstream-artifacts/my-dev-kit-orchestrator/1.2.1/workflow-instruction-packet/complete-v1.0.0.json +160 -0
  92. 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,130 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ function compareValue(sourceArtifact, sourceInstance, expectationFieldPath, artifactFieldPath, expected, actual, matched) {
3
+ return {
4
+ sourceArtifact,
5
+ sourceInstance,
6
+ expectationFieldPath,
7
+ artifactFieldPath,
8
+ availability: "available",
9
+ expected,
10
+ actual,
11
+ matched,
12
+ reason: null
13
+ };
14
+ }
15
+ function unavailableComparison(sourceArtifact, sourceInstance, expectationFieldPath, expected, reason) {
16
+ return {
17
+ sourceArtifact,
18
+ sourceInstance,
19
+ expectationFieldPath,
20
+ artifactFieldPath: null,
21
+ availability: "unavailable",
22
+ expected,
23
+ actual: null,
24
+ matched: null,
25
+ reason
26
+ };
27
+ }
28
+ export function compareExpectedContextCapsuleState(expected, artifact, sourceInstance) {
29
+ if (expected === undefined)
30
+ return [];
31
+ const comparisons = [];
32
+ const SA = "context-capsule";
33
+ if (expected.contextAdequacyStatus !== undefined) {
34
+ comparisons.push(compareValue(SA, sourceInstance, "contextAdequacyStatus", "contextAdequacy.status", expected.contextAdequacyStatus, artifact.contextAdequacy.status, artifact.contextAdequacy.status === expected.contextAdequacyStatus));
35
+ }
36
+ if (expected.roleAdequacyStatus !== undefined) {
37
+ comparisons.push(compareValue(SA, sourceInstance, "roleAdequacyStatus", "roleAdequacy.status", expected.roleAdequacyStatus, artifact.roleAdequacy.status, artifact.roleAdequacy.status === expected.roleAdequacyStatus));
38
+ }
39
+ if (expected.freshnessState !== undefined) {
40
+ comparisons.push(compareValue(SA, sourceInstance, "freshnessState", "freshness.state", expected.freshnessState, artifact.freshness.state, artifact.freshness.state === expected.freshnessState));
41
+ }
42
+ if (expected.truncated !== undefined) {
43
+ comparisons.push(compareValue(SA, sourceInstance, "truncated", "truncation.truncated", expected.truncated, artifact.truncation.truncated, artifact.truncation.truncated === expected.truncated));
44
+ }
45
+ if (expected.fullFileFallbackUsed !== undefined) {
46
+ comparisons.push(compareValue(SA, sourceInstance, "fullFileFallbackUsed", "fullFileFallback.used", expected.fullFileFallbackUsed, artifact.fullFileFallback.used, artifact.fullFileFallback.used === expected.fullFileFallbackUsed));
47
+ }
48
+ if (expected.unresolvedItemIds !== undefined) {
49
+ comparisons.push(unavailableComparison(SA, sourceInstance, "unresolvedItemIds", expected.unresolvedItemIds, "ContextCapsule unresolvedItems do not expose stable item IDs."));
50
+ }
51
+ if (expected.warningCount !== undefined) {
52
+ comparisons.push(compareValue(SA, sourceInstance, "warningCount", "warnings.length", expected.warningCount, artifact.warnings.length, artifact.warnings.length === expected.warningCount));
53
+ }
54
+ return comparisons;
55
+ }
56
+ export function compareExpectedRetrievalAuditState(expected, artifact, sourceInstance) {
57
+ if (expected === undefined)
58
+ return [];
59
+ const comparisons = [];
60
+ const SA = "retrieval-audit-record";
61
+ if (expected.contextAdequacyStatus !== undefined) {
62
+ comparisons.push(compareValue(SA, sourceInstance, "contextAdequacyStatus", "contextAdequacy.status", expected.contextAdequacyStatus, artifact.contextAdequacy.status, artifact.contextAdequacy.status === expected.contextAdequacyStatus));
63
+ }
64
+ if (expected.roleAdequacyStatus !== undefined) {
65
+ comparisons.push(compareValue(SA, sourceInstance, "roleAdequacyStatus", "roleAdequacy.status", expected.roleAdequacyStatus, artifact.roleAdequacy.status, artifact.roleAdequacy.status === expected.roleAdequacyStatus));
66
+ }
67
+ if (expected.freshnessState !== undefined) {
68
+ comparisons.push(compareValue(SA, sourceInstance, "freshnessState", "freshness.state", expected.freshnessState, artifact.freshness.state, artifact.freshness.state === expected.freshnessState));
69
+ }
70
+ if (expected.truncated !== undefined) {
71
+ comparisons.push(compareValue(SA, sourceInstance, "truncated", "truncation.truncated", expected.truncated, artifact.truncation.truncated, artifact.truncation.truncated === expected.truncated));
72
+ }
73
+ if (expected.fullFileFallbackUsed !== undefined) {
74
+ comparisons.push(compareValue(SA, sourceInstance, "fullFileFallbackUsed", "fullFileFallback.used", expected.fullFileFallbackUsed, artifact.fullFileFallback.used, artifact.fullFileFallback.used === expected.fullFileFallbackUsed));
75
+ }
76
+ if (expected.unresolvedItemIds !== undefined) {
77
+ comparisons.push(unavailableComparison(SA, sourceInstance, "unresolvedItemIds", expected.unresolvedItemIds, "RetrievalAuditRecord does not serialize unresolved item IDs."));
78
+ }
79
+ if (expected.warningCount !== undefined) {
80
+ comparisons.push(compareValue(SA, sourceInstance, "warningCount", "warnings.length", expected.warningCount, artifact.warnings.length, artifact.warnings.length === expected.warningCount));
81
+ }
82
+ return comparisons;
83
+ }
84
+ export function compareExpectedWorkflowInstructionPacketState(expected, artifact, sourceInstance) {
85
+ if (expected === undefined)
86
+ return [];
87
+ const comparisons = [];
88
+ const SA = "workflow-instruction-packet";
89
+ if (expected.adequacyStatus !== undefined) {
90
+ comparisons.push(compareValue(SA, sourceInstance, "adequacyStatus", "adequacy.status", expected.adequacyStatus, artifact.adequacy.status, artifact.adequacy.status === expected.adequacyStatus));
91
+ }
92
+ if (expected.truncated !== undefined) {
93
+ comparisons.push(compareValue(SA, sourceInstance, "truncated", "truncation.truncated", expected.truncated, artifact.truncation.truncated, artifact.truncation.truncated === expected.truncated));
94
+ }
95
+ if (expected.unresolvedReferences !== undefined) {
96
+ comparisons.push(compareValue(SA, sourceInstance, "unresolvedReferences", "unresolvedReferences", expected.unresolvedReferences, artifact.unresolvedReferences, isDeepStrictEqual(artifact.unresolvedReferences, expected.unresolvedReferences)));
97
+ }
98
+ if (expected.warningCount !== undefined) {
99
+ comparisons.push(compareValue(SA, sourceInstance, "warningCount", "warnings.length", expected.warningCount, artifact.warnings.length, artifact.warnings.length === expected.warningCount));
100
+ }
101
+ return comparisons;
102
+ }
103
+ export function compareExpectedTargetImmutabilityState(expected, targetImmutability) {
104
+ if (expected === undefined)
105
+ return [];
106
+ const SA = "target-immutability";
107
+ const expectationFieldPath = "expectedStates.targetImmutability.newMutationCount";
108
+ if (targetImmutability === undefined) {
109
+ return [
110
+ unavailableComparison(SA, "target", expectationFieldPath, expected.newMutationCount, "Target immutability configuration was not supplied for this strategy run.")
111
+ ];
112
+ }
113
+ if (targetImmutability.availability === "unavailable") {
114
+ return [unavailableComparison(SA, "target", expectationFieldPath, expected.newMutationCount, targetImmutability.reason)];
115
+ }
116
+ const comparison = targetImmutability.comparison;
117
+ return [
118
+ {
119
+ sourceArtifact: SA,
120
+ sourceInstance: "target",
121
+ expectationFieldPath,
122
+ artifactFieldPath: "targetImmutability.comparison.newMutationCount",
123
+ availability: "available",
124
+ expected: expected.newMutationCount,
125
+ actual: comparison.newMutationCount,
126
+ matched: expected.newMutationCount === comparison.newMutationCount,
127
+ reason: null
128
+ }
129
+ ];
130
+ }
@@ -0,0 +1,85 @@
1
+ function estimateTokens(characterCount) {
2
+ return Math.ceil(characterCount / 4);
3
+ }
4
+ function pairSources(pair, labelPrefix) {
5
+ const sources = [];
6
+ const capsuleCharacterCount = JSON.stringify(pair.contextCapsule).length;
7
+ sources.push({
8
+ sourceInstance: `${labelPrefix}.contextCapsule`,
9
+ sourceKind: "context-capsule",
10
+ characterCount: capsuleCharacterCount,
11
+ estimatedTokenCount: estimateTokens(capsuleCharacterCount)
12
+ });
13
+ if (pair.retrievalAuditRecord) {
14
+ const auditCharacterCount = JSON.stringify(pair.retrievalAuditRecord).length;
15
+ sources.push({
16
+ sourceInstance: `${labelPrefix}.retrievalAuditRecord`,
17
+ sourceKind: "retrieval-audit-record",
18
+ characterCount: auditCharacterCount,
19
+ estimatedTokenCount: estimateTokens(auditCharacterCount)
20
+ });
21
+ }
22
+ return sources;
23
+ }
24
+ export function calculateV043ExecutionContextSize(execution) {
25
+ const sources = [];
26
+ switch (execution.strategyId) {
27
+ case "architecture-context-only": {
28
+ const payload = execution.payload;
29
+ sources.push(...pairSources(payload.architecture, "architecture"));
30
+ break;
31
+ }
32
+ case "architecture-plus-implementation-refresh": {
33
+ const payload = execution.payload;
34
+ sources.push(...pairSources(payload.architecture, "architecture"));
35
+ sources.push(...pairSources(payload.implementation, "implementation"));
36
+ break;
37
+ }
38
+ case "architecture-plus-implementation-and-test-refresh": {
39
+ const payload = execution.payload;
40
+ sources.push(...pairSources(payload.architecture, "architecture"));
41
+ sources.push(...pairSources(payload.implementation, "implementation"));
42
+ sources.push(...pairSources(payload.testImplementation, "testImplementation"));
43
+ break;
44
+ }
45
+ case "full-workflow-library": {
46
+ const payload = execution.payload;
47
+ const characterCount = payload.fullWorkflowLibrary.rawText.length;
48
+ sources.push({
49
+ sourceInstance: "fullWorkflowLibrary.rawText",
50
+ sourceKind: "full-workflow-library-text",
51
+ characterCount,
52
+ estimatedTokenCount: estimateTokens(characterCount)
53
+ });
54
+ break;
55
+ }
56
+ case "bounded-workflow-instruction-packet": {
57
+ const payload = execution.payload;
58
+ const characterCount = JSON.stringify(payload.workflowInstructionPacket).length;
59
+ sources.push({
60
+ sourceInstance: "workflowInstructionPacket",
61
+ sourceKind: "workflow-instruction-packet",
62
+ characterCount,
63
+ estimatedTokenCount: estimateTokens(characterCount)
64
+ });
65
+ break;
66
+ }
67
+ case "combined-bounded-stage-context": {
68
+ const payload = execution.payload;
69
+ payload.contextArtifacts.forEach((pair, index) => {
70
+ sources.push(...pairSources(pair, `contextArtifacts[${index}]`));
71
+ });
72
+ const characterCount = JSON.stringify(payload.workflowInstructionPacket).length;
73
+ sources.push({
74
+ sourceInstance: "workflowInstructionPacket",
75
+ sourceKind: "workflow-instruction-packet",
76
+ characterCount,
77
+ estimatedTokenCount: estimateTokens(characterCount)
78
+ });
79
+ break;
80
+ }
81
+ }
82
+ const totalCharacterCount = sources.reduce((sum, source) => sum + source.characterCount, 0);
83
+ const totalEstimatedTokenCount = sources.reduce((sum, source) => sum + source.estimatedTokenCount, 0);
84
+ return { availability: "available", sources, totalCharacterCount, totalEstimatedTokenCount };
85
+ }
@@ -0,0 +1,103 @@
1
+ import { buildStageContextExpectationTargetKey } from "./targetKeys.js";
2
+ const INSTRUCTION_CATEGORIES = ["workflow", "stage", "command", "rule", "report-contract"];
3
+ function buildRatioMetric(filtered, targetOutcome, notApplicableReason) {
4
+ if (filtered.length === 0) {
5
+ return {
6
+ availability: "not-applicable",
7
+ numerator: null,
8
+ denominator: null,
9
+ rate: null,
10
+ matchedExpectationIds: [],
11
+ missingExpectationIds: [],
12
+ reason: notApplicableReason
13
+ };
14
+ }
15
+ const matchedExpectationIds = [];
16
+ const missingExpectationIds = [];
17
+ for (const match of filtered) {
18
+ if (match.outcome === targetOutcome) {
19
+ matchedExpectationIds.push(match.expectationId);
20
+ }
21
+ else {
22
+ missingExpectationIds.push(match.expectationId);
23
+ }
24
+ }
25
+ return {
26
+ availability: "available",
27
+ numerator: matchedExpectationIds.length,
28
+ denominator: filtered.length,
29
+ rate: matchedExpectationIds.length / filtered.length,
30
+ matchedExpectationIds,
31
+ missingExpectationIds,
32
+ reason: null
33
+ };
34
+ }
35
+ export function calculateRequiredEvidenceRecall(matches) {
36
+ const filtered = matches.filter((match) => match.inclusion === "required");
37
+ return buildRatioMetric(filtered, "matched", "The expectation fixture contains no required evidence items.");
38
+ }
39
+ export function calculateAllowedEvidenceCoverage(matches) {
40
+ const filtered = matches.filter((match) => match.inclusion === "allowed");
41
+ return buildRatioMetric(filtered, "matched", "The expectation fixture contains no allowed evidence items.");
42
+ }
43
+ export function calculateForbiddenEvidenceInclusion(matches) {
44
+ const filtered = matches.filter((match) => match.inclusion === "forbidden");
45
+ return buildRatioMetric(filtered, "violated", "The expectation fixture contains no forbidden evidence items.");
46
+ }
47
+ export function calculateRequiredProvenanceRecall(matches) {
48
+ const filtered = matches.filter((match) => match.inclusion === "required" && match.category === "provenance");
49
+ return buildRatioMetric(filtered, "matched", "The expectation fixture contains no required provenance items.");
50
+ }
51
+ export function calculateIrrelevantFileInclusion(expectations, observedEvidence) {
52
+ const fileEvidence = observedEvidence.filter((evidence) => evidence.sourceArtifact === "context-capsule" && evidence.category === "file");
53
+ if (fileEvidence.length === 0) {
54
+ return {
55
+ availability: "not-applicable",
56
+ count: null,
57
+ evidenceKeys: [],
58
+ reason: "The completed strategy contains no context-capsule file evidence."
59
+ };
60
+ }
61
+ const coveredKeys = new Set(expectations.expectedEvidence
62
+ .filter((item) => item.sourceArtifact === "context-capsule" &&
63
+ item.category === "file" &&
64
+ (item.inclusion === "required" || item.inclusion === "allowed"))
65
+ .map((item) => buildStageContextExpectationTargetKey(item)));
66
+ const seen = new Set();
67
+ const evidenceKeys = [];
68
+ for (const evidence of fileEvidence) {
69
+ if (coveredKeys.has(evidence.targetKey))
70
+ continue;
71
+ if (seen.has(evidence.targetKey))
72
+ continue;
73
+ seen.add(evidence.targetKey);
74
+ evidenceKeys.push(evidence.targetKey);
75
+ }
76
+ return { availability: "available", count: evidenceKeys.length, evidenceKeys, reason: null };
77
+ }
78
+ export function calculateIrrelevantInstructionInclusion(expectations, observedEvidence) {
79
+ const instructionEvidence = observedEvidence.filter((evidence) => (evidence.sourceArtifact === "workflow-instruction-packet" || evidence.sourceArtifact === "full-workflow-library") &&
80
+ INSTRUCTION_CATEGORIES.includes(evidence.category));
81
+ if (instructionEvidence.length === 0) {
82
+ return {
83
+ availability: "not-applicable",
84
+ count: null,
85
+ evidenceKeys: [],
86
+ reason: "The completed strategy contains no workflow instruction evidence."
87
+ };
88
+ }
89
+ const coveredKeys = new Set(expectations.expectedEvidence
90
+ .filter((item) => INSTRUCTION_CATEGORIES.includes(item.category) && (item.inclusion === "required" || item.inclusion === "allowed"))
91
+ .map((item) => buildStageContextExpectationTargetKey(item)));
92
+ const seen = new Set();
93
+ const evidenceKeys = [];
94
+ for (const evidence of instructionEvidence) {
95
+ if (coveredKeys.has(evidence.targetKey))
96
+ continue;
97
+ if (seen.has(evidence.targetKey))
98
+ continue;
99
+ seen.add(evidence.targetKey);
100
+ evidenceKeys.push(evidence.targetKey);
101
+ }
102
+ return { availability: "available", count: evidenceKeys.length, evidenceKeys, reason: null };
103
+ }
@@ -0,0 +1,36 @@
1
+ function buildMetric(sourceArtifact, sourceInstance, requested, operational, mappings) {
2
+ let mappedCount = 0;
3
+ let partiallyMappedCount = 0;
4
+ let unmappedCount = 0;
5
+ let notApplicableCount = 0;
6
+ for (const mapping of mappings) {
7
+ if (mapping.mappingStatus === "mapped")
8
+ mappedCount += 1;
9
+ else if (mapping.mappingStatus === "partially-mapped")
10
+ partiallyMappedCount += 1;
11
+ else if (mapping.mappingStatus === "unmapped")
12
+ unmappedCount += 1;
13
+ else if (mapping.mappingStatus === "not-applicable")
14
+ notApplicableCount += 1;
15
+ }
16
+ const denominator = mappedCount + partiallyMappedCount + unmappedCount;
17
+ const mappedRate = denominator > 0 ? mappedCount / denominator : null;
18
+ return {
19
+ sourceArtifact,
20
+ sourceInstance,
21
+ requested,
22
+ operational,
23
+ mappedCount,
24
+ partiallyMappedCount,
25
+ unmappedCount,
26
+ notApplicableCount,
27
+ denominator,
28
+ mappedRate
29
+ };
30
+ }
31
+ export function calculateContextCapsuleResponsibilityMappingMetric(artifact, sourceInstance) {
32
+ return buildMetric("context-capsule", sourceInstance, artifact.responsibilityMappings.requested, artifact.responsibilityMappings.operational, artifact.responsibilityMappings.mappings);
33
+ }
34
+ export function calculateRetrievalAuditResponsibilityMappingMetric(artifact, sourceInstance) {
35
+ return buildMetric("retrieval-audit-record", sourceInstance, artifact.responsibilityMappings.requested, artifact.responsibilityMappings.operational, artifact.responsibilityMappings.mappings);
36
+ }
@@ -0,0 +1,312 @@
1
+ const SOURCE_ARTIFACT = "context-capsule";
2
+ function pathKey(category, path) {
3
+ return `${SOURCE_ARTIFACT}|${category}|path:${path}`;
4
+ }
5
+ function symbolKey(category, symbolId) {
6
+ return `${SOURCE_ARTIFACT}|${category}|symbolId:${symbolId}`;
7
+ }
8
+ function sourceRangeKey(filePath, startLine, endLine) {
9
+ return `context-capsule|source-range|filePath:${filePath}|startLine:${startLine}|endLine:${endLine}`;
10
+ }
11
+ function responsibilityKey(responsibilityId) {
12
+ return `${SOURCE_ARTIFACT}|production-responsibility|responsibilityId:${responsibilityId}`;
13
+ }
14
+ function packageScriptKey(name) {
15
+ return `context-capsule|package-script|name:${name}`;
16
+ }
17
+ function testCommandKey(commandText) {
18
+ return `context-capsule|test-command|commandText:${commandText}`;
19
+ }
20
+ function provenanceKey(evidenceId) {
21
+ return `${SOURCE_ARTIFACT}|provenance|evidenceId:${evidenceId}`;
22
+ }
23
+ function pushFileEvidenceFromRefs(records, items, fieldPrefix, category, sourceInstance) {
24
+ items.forEach((item, index) => {
25
+ if (item.path !== undefined) {
26
+ records.push({
27
+ sourceArtifact: SOURCE_ARTIFACT,
28
+ sourceInstance,
29
+ category,
30
+ targetKey: pathKey(category, item.path),
31
+ sourceFieldPath: `${fieldPrefix}[${index}].path`
32
+ });
33
+ }
34
+ if (item.sourceLocation?.filePath !== undefined) {
35
+ records.push({
36
+ sourceArtifact: SOURCE_ARTIFACT,
37
+ sourceInstance,
38
+ category,
39
+ targetKey: pathKey(category, item.sourceLocation.filePath),
40
+ sourceFieldPath: `${fieldPrefix}[${index}].sourceLocation.filePath`
41
+ });
42
+ }
43
+ });
44
+ }
45
+ function pushSymbolEvidenceFromRefs(records, items, fieldPrefix, category, sourceInstance) {
46
+ items.forEach((item, index) => {
47
+ if (item.symbolId !== undefined) {
48
+ records.push({
49
+ sourceArtifact: SOURCE_ARTIFACT,
50
+ sourceInstance,
51
+ category,
52
+ targetKey: symbolKey(category, item.symbolId),
53
+ sourceFieldPath: `${fieldPrefix}[${index}].symbolId`
54
+ });
55
+ }
56
+ if (item.nodeId !== undefined) {
57
+ records.push({
58
+ sourceArtifact: SOURCE_ARTIFACT,
59
+ sourceInstance,
60
+ category,
61
+ targetKey: symbolKey(category, item.nodeId),
62
+ sourceFieldPath: `${fieldPrefix}[${index}].nodeId`
63
+ });
64
+ }
65
+ });
66
+ }
67
+ function dedupeEvidence(records) {
68
+ const seen = new Set();
69
+ const result = [];
70
+ for (const record of records) {
71
+ const key = `${record.sourceInstance} ${record.category} ${record.targetKey}`;
72
+ if (seen.has(key))
73
+ continue;
74
+ seen.add(key);
75
+ result.push(record);
76
+ }
77
+ return result;
78
+ }
79
+ export function collectContextCapsuleEvidence(artifact, sourceInstance) {
80
+ const records = [];
81
+ // Section 25: general file evidence
82
+ artifact.candidateFiles.forEach((candidate, index) => {
83
+ if (candidate.retained) {
84
+ records.push({
85
+ sourceArtifact: SOURCE_ARTIFACT,
86
+ sourceInstance,
87
+ category: "file",
88
+ targetKey: pathKey("file", candidate.path),
89
+ sourceFieldPath: `candidateFiles[${index}].path`
90
+ });
91
+ }
92
+ });
93
+ artifact.selectedGraph.nodes.forEach((node, index) => {
94
+ if (node.filePath !== undefined) {
95
+ records.push({
96
+ sourceArtifact: SOURCE_ARTIFACT,
97
+ sourceInstance,
98
+ category: "file",
99
+ targetKey: pathKey("file", node.filePath),
100
+ sourceFieldPath: `selectedGraph.nodes[${index}].filePath`
101
+ });
102
+ }
103
+ });
104
+ artifact.selectedSource.slices.forEach((slice, index) => {
105
+ records.push({
106
+ sourceArtifact: SOURCE_ARTIFACT,
107
+ sourceInstance,
108
+ category: "file",
109
+ targetKey: pathKey("file", slice.filePath),
110
+ sourceFieldPath: `selectedSource.slices[${index}].filePath`
111
+ });
112
+ });
113
+ artifact.selectedSourceBundles.bundles.forEach((bundle, bundleIndex) => {
114
+ bundle.blocks.forEach((block, blockIndex) => {
115
+ records.push({
116
+ sourceArtifact: SOURCE_ARTIFACT,
117
+ sourceInstance,
118
+ category: "file",
119
+ targetKey: pathKey("file", block.filePath),
120
+ sourceFieldPath: `selectedSourceBundles.bundles[${bundleIndex}].blocks[${blockIndex}].filePath`
121
+ });
122
+ });
123
+ });
124
+ artifact.roleContext.changedSurface.files.forEach((file, index) => {
125
+ records.push({
126
+ sourceArtifact: SOURCE_ARTIFACT,
127
+ sourceInstance,
128
+ category: "file",
129
+ targetKey: pathKey("file", file.path),
130
+ sourceFieldPath: `roleContext.changedSurface.files[${index}].path`
131
+ });
132
+ });
133
+ artifact.evidenceGroups.forEach((group, groupIndex) => {
134
+ pushFileEvidenceFromRefs(records, group.items, `evidenceGroups[${groupIndex}].items`, "file", sourceInstance);
135
+ });
136
+ pushFileEvidenceFromRefs(records, artifact.selectedOwners, "selectedOwners", "file", sourceInstance);
137
+ pushFileEvidenceFromRefs(records, artifact.selectedContracts, "selectedContracts", "file", sourceInstance);
138
+ pushFileEvidenceFromRefs(records, artifact.selectedTests, "selectedTests", "file", sourceInstance);
139
+ pushFileEvidenceFromRefs(records, artifact.testInfrastructure.relatedTests, "testInfrastructure.relatedTests", "file", sourceInstance);
140
+ pushFileEvidenceFromRefs(records, artifact.testInfrastructure.fixtures, "testInfrastructure.fixtures", "file", sourceInstance);
141
+ pushFileEvidenceFromRefs(records, artifact.testInfrastructure.factories, "testInfrastructure.factories", "file", sourceInstance);
142
+ pushFileEvidenceFromRefs(records, artifact.testInfrastructure.mocks, "testInfrastructure.mocks", "file", sourceInstance);
143
+ pushFileEvidenceFromRefs(records, artifact.testInfrastructure.setupFiles, "testInfrastructure.setupFiles", "file", sourceInstance);
144
+ artifact.testInfrastructure.testConfigurations.forEach((config, index) => {
145
+ records.push({
146
+ sourceArtifact: SOURCE_ARTIFACT,
147
+ sourceInstance,
148
+ category: "file",
149
+ targetKey: pathKey("file", config.path),
150
+ sourceFieldPath: `testInfrastructure.testConfigurations[${index}].path`
151
+ });
152
+ });
153
+ artifact.testInfrastructure.packageScripts.forEach((script, index) => {
154
+ records.push({
155
+ sourceArtifact: SOURCE_ARTIFACT,
156
+ sourceInstance,
157
+ category: "file",
158
+ targetKey: pathKey("file", script.packageJsonPath),
159
+ sourceFieldPath: `testInfrastructure.packageScripts[${index}].packageJsonPath`
160
+ });
161
+ });
162
+ artifact.testInfrastructure.testCommands.forEach((command, commandIndex) => {
163
+ command.testFiles.forEach((testFile, fileIndex) => {
164
+ records.push({
165
+ sourceArtifact: SOURCE_ARTIFACT,
166
+ sourceInstance,
167
+ category: "file",
168
+ targetKey: pathKey("file", testFile),
169
+ sourceFieldPath: `testInfrastructure.testCommands[${commandIndex}].testFiles[${fileIndex}]`
170
+ });
171
+ });
172
+ });
173
+ // Section 26: specific path-category evidence
174
+ pushFileEvidenceFromRefs(records, artifact.selectedTests, "selectedTests", "test-file", sourceInstance);
175
+ pushFileEvidenceFromRefs(records, artifact.testInfrastructure.relatedTests, "testInfrastructure.relatedTests", "test-file", sourceInstance);
176
+ artifact.testInfrastructure.testCommands.forEach((command, commandIndex) => {
177
+ command.testFiles.forEach((testFile, fileIndex) => {
178
+ records.push({
179
+ sourceArtifact: SOURCE_ARTIFACT,
180
+ sourceInstance,
181
+ category: "test-file",
182
+ targetKey: pathKey("test-file", testFile),
183
+ sourceFieldPath: `testInfrastructure.testCommands[${commandIndex}].testFiles[${fileIndex}]`
184
+ });
185
+ });
186
+ });
187
+ pushFileEvidenceFromRefs(records, artifact.testInfrastructure.fixtures, "testInfrastructure.fixtures", "fixture", sourceInstance);
188
+ pushFileEvidenceFromRefs(records, artifact.testInfrastructure.factories, "testInfrastructure.factories", "factory", sourceInstance);
189
+ pushFileEvidenceFromRefs(records, artifact.testInfrastructure.mocks, "testInfrastructure.mocks", "mock", sourceInstance);
190
+ pushFileEvidenceFromRefs(records, artifact.testInfrastructure.setupFiles, "testInfrastructure.setupFiles", "setup-file", sourceInstance);
191
+ artifact.testInfrastructure.testConfigurations.forEach((config, index) => {
192
+ records.push({
193
+ sourceArtifact: SOURCE_ARTIFACT,
194
+ sourceInstance,
195
+ category: "test-configuration",
196
+ targetKey: pathKey("test-configuration", config.path),
197
+ sourceFieldPath: `testInfrastructure.testConfigurations[${index}].path`
198
+ });
199
+ });
200
+ // Section 27: symbol and symbol-subtype evidence
201
+ artifact.candidateNodes.forEach((node, index) => {
202
+ if (node.retained) {
203
+ records.push({
204
+ sourceArtifact: SOURCE_ARTIFACT,
205
+ sourceInstance,
206
+ category: "symbol",
207
+ targetKey: symbolKey("symbol", node.nodeId),
208
+ sourceFieldPath: `candidateNodes[${index}].nodeId`
209
+ });
210
+ }
211
+ });
212
+ artifact.selectedGraph.nodes.forEach((node, index) => {
213
+ records.push({
214
+ sourceArtifact: SOURCE_ARTIFACT,
215
+ sourceInstance,
216
+ category: "symbol",
217
+ targetKey: symbolKey("symbol", node.nodeId),
218
+ sourceFieldPath: `selectedGraph.nodes[${index}].nodeId`
219
+ });
220
+ });
221
+ artifact.evidenceGroups.forEach((group, groupIndex) => {
222
+ pushSymbolEvidenceFromRefs(records, group.items, `evidenceGroups[${groupIndex}].items`, "symbol", sourceInstance);
223
+ });
224
+ pushSymbolEvidenceFromRefs(records, artifact.selectedOwners, "selectedOwners", "symbol", sourceInstance);
225
+ pushSymbolEvidenceFromRefs(records, artifact.selectedContracts, "selectedContracts", "symbol", sourceInstance);
226
+ pushSymbolEvidenceFromRefs(records, artifact.selectedTests, "selectedTests", "symbol", sourceInstance);
227
+ pushSymbolEvidenceFromRefs(records, artifact.testInfrastructure.relatedTests, "testInfrastructure.relatedTests", "symbol", sourceInstance);
228
+ pushSymbolEvidenceFromRefs(records, artifact.testInfrastructure.fixtures, "testInfrastructure.fixtures", "symbol", sourceInstance);
229
+ pushSymbolEvidenceFromRefs(records, artifact.testInfrastructure.factories, "testInfrastructure.factories", "symbol", sourceInstance);
230
+ pushSymbolEvidenceFromRefs(records, artifact.testInfrastructure.mocks, "testInfrastructure.mocks", "symbol", sourceInstance);
231
+ pushSymbolEvidenceFromRefs(records, artifact.testInfrastructure.setupFiles, "testInfrastructure.setupFiles", "symbol", sourceInstance);
232
+ pushSymbolEvidenceFromRefs(records, artifact.selectedContracts, "selectedContracts", "contract", sourceInstance);
233
+ artifact.responsibilityMappings.mappings.forEach((mapping, mappingIndex) => {
234
+ pushSymbolEvidenceFromRefs(records, mapping.contracts, `responsibilityMappings.mappings[${mappingIndex}].contracts`, "contract", sourceInstance);
235
+ });
236
+ artifact.responsibilityMappings.mappings.forEach((mapping, mappingIndex) => {
237
+ pushSymbolEvidenceFromRefs(records, mapping.validators, `responsibilityMappings.mappings[${mappingIndex}].validators`, "validator", sourceInstance);
238
+ });
239
+ artifact.responsibilityMappings.mappings.forEach((mapping, mappingIndex) => {
240
+ pushSymbolEvidenceFromRefs(records, mapping.constants, `responsibilityMappings.mappings[${mappingIndex}].constants`, "constant", sourceInstance);
241
+ });
242
+ artifact.responsibilityMappings.mappings.forEach((mapping, mappingIndex) => {
243
+ pushSymbolEvidenceFromRefs(records, mapping.errors, `responsibilityMappings.mappings[${mappingIndex}].errors`, "error", sourceInstance);
244
+ });
245
+ pushSymbolEvidenceFromRefs(records, artifact.selectedContracts, "selectedContracts", "schema-or-serializer", sourceInstance);
246
+ artifact.responsibilityMappings.mappings.forEach((mapping, mappingIndex) => {
247
+ pushSymbolEvidenceFromRefs(records, mapping.contracts, `responsibilityMappings.mappings[${mappingIndex}].contracts`, "schema-or-serializer", sourceInstance);
248
+ });
249
+ // Section 28: source-range evidence
250
+ artifact.selectedSource.slices.forEach((slice, index) => {
251
+ records.push({
252
+ sourceArtifact: SOURCE_ARTIFACT,
253
+ sourceInstance,
254
+ category: "source-range",
255
+ targetKey: sourceRangeKey(slice.filePath, slice.startLine, slice.endLine),
256
+ sourceFieldPath: `selectedSource.slices[${index}]`
257
+ });
258
+ });
259
+ artifact.selectedSourceBundles.bundles.forEach((bundle, bundleIndex) => {
260
+ bundle.blocks.forEach((block, blockIndex) => {
261
+ records.push({
262
+ sourceArtifact: SOURCE_ARTIFACT,
263
+ sourceInstance,
264
+ category: "source-range",
265
+ targetKey: sourceRangeKey(block.filePath, block.startLine, block.endLine),
266
+ sourceFieldPath: `selectedSourceBundles.bundles[${bundleIndex}].blocks[${blockIndex}]`
267
+ });
268
+ });
269
+ });
270
+ // Section 29: production-responsibility evidence
271
+ artifact.responsibilityMappings.mappings.forEach((mapping, index) => {
272
+ records.push({
273
+ sourceArtifact: SOURCE_ARTIFACT,
274
+ sourceInstance,
275
+ category: "production-responsibility",
276
+ targetKey: responsibilityKey(mapping.responsibilityId),
277
+ sourceFieldPath: `responsibilityMappings.mappings[${index}].responsibilityId`
278
+ });
279
+ });
280
+ // Section 30: package-script and test-command evidence
281
+ artifact.testInfrastructure.packageScripts.forEach((script, index) => {
282
+ records.push({
283
+ sourceArtifact: SOURCE_ARTIFACT,
284
+ sourceInstance,
285
+ category: "package-script",
286
+ targetKey: packageScriptKey(script.name),
287
+ sourceFieldPath: `testInfrastructure.packageScripts[${index}].name`
288
+ });
289
+ });
290
+ artifact.testInfrastructure.testCommands.forEach((command, index) => {
291
+ if (command.commandText !== null) {
292
+ records.push({
293
+ sourceArtifact: SOURCE_ARTIFACT,
294
+ sourceInstance,
295
+ category: "test-command",
296
+ targetKey: testCommandKey(command.commandText),
297
+ sourceFieldPath: `testInfrastructure.testCommands[${index}].commandText`
298
+ });
299
+ }
300
+ });
301
+ // Section 31: context-capsule provenance evidence
302
+ artifact.provenance.forEach((provenanceRecord, index) => {
303
+ records.push({
304
+ sourceArtifact: SOURCE_ARTIFACT,
305
+ sourceInstance,
306
+ category: "provenance",
307
+ targetKey: provenanceKey(provenanceRecord.evidenceId),
308
+ sourceFieldPath: `provenance[${index}].evidenceId`
309
+ });
310
+ });
311
+ return dedupeEvidence(records);
312
+ }