@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,130 @@
1
+ const ALLOWED_KEYS = ["targetRootPath", "relativeFilePaths"];
2
+ const MAX_RELATIVE_FILES = 100;
3
+ function isPlainObject(value) {
4
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5
+ }
6
+ function isAbsolutePathLike(value) {
7
+ if (value.startsWith("/") || value.startsWith("\\"))
8
+ return true;
9
+ if (/^[A-Za-z]:[\\/]/.test(value))
10
+ return true;
11
+ return false;
12
+ }
13
+ function hasTraversalSegment(value) {
14
+ return value.split(/[\\/]/).includes("..");
15
+ }
16
+ export function validateTargetImmutabilityConfig(value) {
17
+ if (!isPlainObject(value)) {
18
+ return {
19
+ ok: false,
20
+ issues: [{ code: "NON_OBJECT_CONFIG", fieldPath: "", message: "Target immutability config must be an object." }]
21
+ };
22
+ }
23
+ const root = value;
24
+ const issues = [];
25
+ for (const key of Object.keys(root)) {
26
+ if (!ALLOWED_KEYS.includes(key)) {
27
+ issues.push({ code: "UNKNOWN_CONFIG_FIELD", fieldPath: key, message: `"${key}" is not a recognized field.` });
28
+ }
29
+ }
30
+ if (root.targetRootPath === undefined) {
31
+ issues.push({ code: "MISSING_REQUIRED_FIELD", fieldPath: "targetRootPath", message: "targetRootPath is required." });
32
+ }
33
+ if (root.relativeFilePaths === undefined) {
34
+ issues.push({ code: "MISSING_REQUIRED_FIELD", fieldPath: "relativeFilePaths", message: "relativeFilePaths is required." });
35
+ }
36
+ const targetRootPathIsString = root.targetRootPath !== undefined && typeof root.targetRootPath === "string";
37
+ if (root.targetRootPath !== undefined && !targetRootPathIsString) {
38
+ issues.push({ code: "INVALID_FIELD_TYPE", fieldPath: "targetRootPath", message: "targetRootPath must be a string." });
39
+ }
40
+ const relativeFilePathsIsArray = root.relativeFilePaths !== undefined && Array.isArray(root.relativeFilePaths);
41
+ if (root.relativeFilePaths !== undefined && !relativeFilePathsIsArray) {
42
+ issues.push({ code: "INVALID_FIELD_TYPE", fieldPath: "relativeFilePaths", message: "relativeFilePaths must be an array." });
43
+ }
44
+ if (targetRootPathIsString && root.targetRootPath.trim().length === 0) {
45
+ issues.push({ code: "EMPTY_TARGET_ROOT_PATH", fieldPath: "targetRootPath", message: "targetRootPath must be a nonempty string." });
46
+ }
47
+ let pathsArray = [];
48
+ if (relativeFilePathsIsArray) {
49
+ pathsArray = root.relativeFilePaths;
50
+ if (pathsArray.length === 0) {
51
+ issues.push({
52
+ code: "EMPTY_RELATIVE_FILE_SET",
53
+ fieldPath: "relativeFilePaths",
54
+ message: "relativeFilePaths must contain at least one entry."
55
+ });
56
+ }
57
+ else if (pathsArray.length > MAX_RELATIVE_FILES) {
58
+ issues.push({
59
+ code: "TOO_MANY_RELATIVE_FILES",
60
+ fieldPath: "relativeFilePaths",
61
+ message: `relativeFilePaths must contain at most ${MAX_RELATIVE_FILES} entries.`
62
+ });
63
+ }
64
+ }
65
+ const validStringPaths = [];
66
+ if (relativeFilePathsIsArray) {
67
+ pathsArray.forEach((entry, index) => {
68
+ if (typeof entry !== "string") {
69
+ issues.push({
70
+ code: "INVALID_FIELD_TYPE",
71
+ fieldPath: `relativeFilePaths[${index}]`,
72
+ message: `relativeFilePaths[${index}] must be a string.`
73
+ });
74
+ validStringPaths.push(null);
75
+ }
76
+ else if (entry.trim().length === 0) {
77
+ issues.push({
78
+ code: "EMPTY_RELATIVE_FILE_PATH",
79
+ fieldPath: `relativeFilePaths[${index}]`,
80
+ message: `relativeFilePaths[${index}] must be a nonempty string.`
81
+ });
82
+ validStringPaths.push(null);
83
+ }
84
+ else {
85
+ validStringPaths.push(entry);
86
+ }
87
+ });
88
+ }
89
+ if (relativeFilePathsIsArray) {
90
+ validStringPaths.forEach((entry, index) => {
91
+ if (entry !== null && isAbsolutePathLike(entry)) {
92
+ issues.push({
93
+ code: "ABSOLUTE_RELATIVE_FILE_PATH",
94
+ fieldPath: `relativeFilePaths[${index}]`,
95
+ message: `relativeFilePaths[${index}] must be a relative path.`
96
+ });
97
+ }
98
+ });
99
+ }
100
+ if (relativeFilePathsIsArray) {
101
+ validStringPaths.forEach((entry, index) => {
102
+ if (entry !== null && hasTraversalSegment(entry)) {
103
+ issues.push({
104
+ code: "RELATIVE_FILE_PATH_TRAVERSAL",
105
+ fieldPath: `relativeFilePaths[${index}]`,
106
+ message: `relativeFilePaths[${index}] must not contain a ".." path segment.`
107
+ });
108
+ }
109
+ });
110
+ }
111
+ if (relativeFilePathsIsArray) {
112
+ const seen = new Set();
113
+ validStringPaths.forEach((entry, index) => {
114
+ if (entry === null)
115
+ return;
116
+ if (seen.has(entry)) {
117
+ issues.push({
118
+ code: "DUPLICATE_RELATIVE_FILE_PATH",
119
+ fieldPath: `relativeFilePaths[${index}]`,
120
+ message: `relativeFilePaths[${index}] duplicates an earlier entry.`
121
+ });
122
+ }
123
+ seen.add(entry);
124
+ });
125
+ }
126
+ if (issues.length > 0) {
127
+ return { ok: false, issues };
128
+ }
129
+ return { ok: true, config: value };
130
+ }
@@ -0,0 +1,9 @@
1
+ export { readMyDevKitContextCapsuleV1 } from "./readMyDevKitContextCapsuleV1.js";
2
+ export { readMyDevKitRetrievalAuditRecordV1 } from "./readMyDevKitRetrievalAuditRecordV1.js";
3
+ export { readOrchestratorWorkflowInstructionPacketV1 } from "./readOrchestratorWorkflowInstructionPacketV1.js";
4
+ export { ROLE_BY_DOCUMENT_KIND, REQUIRED_METADATA_BY_DOCUMENT_KIND, REQUIRED_SECTIONS_BY_DOCUMENT_KIND, VALID_REPOSITORY_SCOPES, VALID_DECLARED_STATUSES, VALID_FRESHNESS_VALUES, VALID_ADEQUACY_VALUES, VALID_TRUNCATION_VALUES } from "./supplementalContextTypes.js";
5
+ export { readImplementationContextPacketV1 } from "./readImplementationContextPacketV1.js";
6
+ export { readImplementationContextRetrievalReportV1 } from "./readImplementationContextRetrievalReportV1.js";
7
+ export { readTestContextPacketV1 } from "./readTestContextPacketV1.js";
8
+ export { readTestContextRetrievalReportV1 } from "./readTestContextRetrievalReportV1.js";
9
+ export { READINESS_DECISIONS, READINESS_CLASSIFICATIONS, validateOrchestratorContextReadinessResultV1, checkSupplementalReadinessIdentityConsistency } from "./orchestratorContextReadinessResultV1.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,247 @@
1
+ // Lab-owned bounded plain-object adapter for the frozen my-dev-kit-orchestrator
2
+ // ContextReadinessResult (commit bc08a05d3b52a629e7e4504372af199c324c4ae4,
3
+ // src/instructions/contextReadiness.ts). At the frozen commit, readiness is never
4
+ // serialized to a stable file artifact -- `check`/`export` only render it as formatted
5
+ // text (src/commands/check.ts, src/commands/export.ts). This adapter therefore
6
+ // validates and normalizes a plain object (as constructed by a caller that already has
7
+ // an in-memory readiness result -- e.g. a future integration or a test fixture), rather
8
+ // than parsing a file. It never imports orchestrator runtime code and never
9
+ // recomputes/reevaluates readiness, producer parity, or issue prioritization -- it only
10
+ // preserves what is already declared on the object.
11
+ import { makeFailure } from "./runtimeValidation.js";
12
+ import { VALID_ADEQUACY_VALUES, VALID_FRESHNESS_VALUES, VALID_TRUNCATION_VALUES } from "./supplementalContextTypes.js";
13
+ const ARTIFACT_KIND = "orchestrator-context-readiness-result-v1";
14
+ export const READINESS_DECISIONS = ["not-required", "ready", "refresh-required"];
15
+ export const READINESS_CLASSIFICATIONS = [
16
+ "not-required",
17
+ "ready",
18
+ "missing",
19
+ "template",
20
+ "partial",
21
+ "malformed",
22
+ "unsupported-schema",
23
+ "incompatible",
24
+ "source-reference-missing",
25
+ "source-reference-unreadable",
26
+ "source-evidence-malformed",
27
+ "source-evidence-unsupported-schema",
28
+ "role-mismatch",
29
+ "repository-scope-mismatch",
30
+ "repository-identity-incomplete",
31
+ "index-identity-incomplete",
32
+ "index-identity-mismatch",
33
+ "freshness-unknown",
34
+ "stale",
35
+ "adequacy-unknown",
36
+ "inadequate",
37
+ "conflict",
38
+ "required-evidence-truncated",
39
+ "required-evidence-incomplete",
40
+ "provenance-missing",
41
+ "test-strategy-missing",
42
+ "test-responsibility-invalid",
43
+ "test-responsibility-criticality-unknown",
44
+ "responsibility-mappings-truncated",
45
+ "critical-responsibilities-unmapped"
46
+ ];
47
+ function isPlainObject(value) {
48
+ return typeof value === "object" && value !== null && !Array.isArray(value);
49
+ }
50
+ function fail(sourceLabel, code, message, fieldPath) {
51
+ return makeFailure(ARTIFACT_KIND, sourceLabel, code, message, fieldPath);
52
+ }
53
+ function requireEnum(value, allowed, fieldPath, sourceLabel, errorCode) {
54
+ if (typeof value !== "string" || !allowed.includes(value)) {
55
+ return fail(sourceLabel, errorCode, `Field "${fieldPath}" must be one of: ${allowed.join(", ")}. Received: ${JSON.stringify(value)}.`, fieldPath);
56
+ }
57
+ return value;
58
+ }
59
+ function isReadinessIssue(value) {
60
+ if (!isPlainObject(value))
61
+ return false;
62
+ return (typeof value.code === "string" &&
63
+ (value.severity === "error" || value.severity === "warning") &&
64
+ typeof value.message === "string" &&
65
+ typeof value.priority === "number" &&
66
+ typeof value.correctiveAction === "string" &&
67
+ typeof value.evidenceTarget === "string" &&
68
+ typeof value.stageId === "string" &&
69
+ (value.contextKind === "implementation" || value.contextKind === "test"));
70
+ }
71
+ function isBlockerSummary(value) {
72
+ if (!isPlainObject(value))
73
+ return false;
74
+ return ((value.contextKind === "implementation" || value.contextKind === "test") &&
75
+ typeof value.primaryCode === "string" &&
76
+ typeof value.primaryReason === "string" &&
77
+ typeof value.correctiveAction === "string" &&
78
+ typeof value.evidenceTarget === "string" &&
79
+ Array.isArray(value.blockingIssueCodes) &&
80
+ value.blockingIssueCodes.every((c) => typeof c === "string") &&
81
+ Array.isArray(value.supportingIssueCodes) &&
82
+ value.supportingIssueCodes.every((c) => typeof c === "string"));
83
+ }
84
+ export function validateOrchestratorContextReadinessResultV1(input, sourceLabel) {
85
+ if (!isPlainObject(input)) {
86
+ return fail(sourceLabel, "MALFORMED_TEXT_ARTIFACT", `Readiness input at "${sourceLabel}" must be a plain object.`);
87
+ }
88
+ const schemaVersion = input["schemaVersion"];
89
+ if (typeof schemaVersion !== "string" || schemaVersion.length === 0) {
90
+ return fail(sourceLabel, "MISSING_REQUIRED_FIELD", `Readiness input at "${sourceLabel}" is missing "schemaVersion".`, "schemaVersion");
91
+ }
92
+ const kind = requireEnum(input["kind"], ["implementation", "test"], "kind", sourceLabel, "MISSING_REQUIRED_FIELD");
93
+ if (typeof kind !== "string")
94
+ return kind;
95
+ const roleAllowed = ["implementation", "test-implementation"];
96
+ const role = requireEnum(input["role"], roleAllowed, "role", sourceLabel, "MISSING_REQUIRED_FIELD");
97
+ if (typeof role !== "string")
98
+ return role;
99
+ const expectedRole = kind === "implementation" ? "implementation" : "test-implementation";
100
+ if (role !== expectedRole) {
101
+ return fail(sourceLabel, "DOCUMENT_ROLE_MISMATCH", `Readiness input at "${sourceLabel}" declares kind "${kind}" with role "${role}", but role must be "${expectedRole}" for that kind.`, "role");
102
+ }
103
+ const decision = requireEnum(input["decision"], READINESS_DECISIONS, "decision", sourceLabel, "UNKNOWN_READINESS_DECISION");
104
+ if (typeof decision !== "string")
105
+ return decision;
106
+ const classification = requireEnum(input["classification"], READINESS_CLASSIFICATIONS, "classification", sourceLabel, "INVALID_LITERAL_VALUE");
107
+ if (typeof classification !== "string")
108
+ return classification;
109
+ const stageId = input["stageId"];
110
+ if (typeof stageId !== "string" || stageId.length === 0) {
111
+ return fail(sourceLabel, "MISSING_REQUIRED_FIELD", `Readiness input at "${sourceLabel}" is missing "stageId".`, "stageId");
112
+ }
113
+ const packetPath = input["packetPath"];
114
+ const reportPath = input["reportPath"];
115
+ if (typeof packetPath !== "string" || typeof reportPath !== "string") {
116
+ return fail(sourceLabel, "MISSING_REQUIRED_FIELD", `Readiness input at "${sourceLabel}" must declare string "packetPath" and "reportPath".`);
117
+ }
118
+ const issuesRaw = input["issues"];
119
+ if (!Array.isArray(issuesRaw) || !issuesRaw.every(isReadinessIssue)) {
120
+ return fail(sourceLabel, "MALFORMED_ISSUE_STRUCTURE", `Readiness input at "${sourceLabel}" has a malformed "issues" array.`, "issues");
121
+ }
122
+ const issues = issuesRaw;
123
+ const warningsRaw = input["warnings"];
124
+ if (!Array.isArray(warningsRaw) || !warningsRaw.every((w) => typeof w === "string")) {
125
+ return fail(sourceLabel, "INVALID_FIELD_TYPE", `Readiness input at "${sourceLabel}" must declare a string array "warnings".`, "warnings");
126
+ }
127
+ const blockingIssueCodesRaw = input["blockingIssueCodes"];
128
+ if (!Array.isArray(blockingIssueCodesRaw) || !blockingIssueCodesRaw.every((c) => typeof c === "string")) {
129
+ return fail(sourceLabel, "INVALID_FIELD_TYPE", `Readiness input at "${sourceLabel}" must declare a string array "blockingIssueCodes".`, "blockingIssueCodes");
130
+ }
131
+ let primaryIssue;
132
+ if (input["primaryIssue"] !== undefined) {
133
+ if (!isReadinessIssue(input["primaryIssue"])) {
134
+ return fail(sourceLabel, "MALFORMED_ISSUE_STRUCTURE", `Readiness input at "${sourceLabel}" has a malformed "primaryIssue".`, "primaryIssue");
135
+ }
136
+ primaryIssue = input["primaryIssue"];
137
+ }
138
+ let blockerSummary;
139
+ if (input["blockerSummary"] !== undefined) {
140
+ if (!isBlockerSummary(input["blockerSummary"])) {
141
+ return fail(sourceLabel, "MALFORMED_ISSUE_STRUCTURE", `Readiness input at "${sourceLabel}" has a malformed "blockerSummary".`, "blockerSummary");
142
+ }
143
+ blockerSummary = input["blockerSummary"];
144
+ }
145
+ const affectedResponsibilityIdsRaw = input["affectedResponsibilityIds"];
146
+ if (!Array.isArray(affectedResponsibilityIdsRaw) || !affectedResponsibilityIdsRaw.every((id) => typeof id === "string")) {
147
+ return fail(sourceLabel, "INVALID_FIELD_TYPE", `Readiness input at "${sourceLabel}" must declare a string array "affectedResponsibilityIds".`, "affectedResponsibilityIds");
148
+ }
149
+ const evaluatedFreshness = requireEnum(input["evaluatedFreshness"], VALID_FRESHNESS_VALUES, "evaluatedFreshness", sourceLabel, "MISSING_REQUIRED_FIELD");
150
+ if (typeof evaluatedFreshness !== "string")
151
+ return evaluatedFreshness;
152
+ const evaluatedAdequacy = requireEnum(input["evaluatedAdequacy"], VALID_ADEQUACY_VALUES, "evaluatedAdequacy", sourceLabel, "MISSING_REQUIRED_FIELD");
153
+ if (typeof evaluatedAdequacy !== "string")
154
+ return evaluatedAdequacy;
155
+ const requiredEvidenceTruncated = requireEnum(input["requiredEvidenceTruncated"], VALID_TRUNCATION_VALUES, "requiredEvidenceTruncated", sourceLabel, "MISSING_REQUIRED_FIELD");
156
+ if (typeof requiredEvidenceTruncated !== "string")
157
+ return requiredEvidenceTruncated;
158
+ let declaredFreshness;
159
+ if (input["declaredFreshness"] !== undefined) {
160
+ const v = requireEnum(input["declaredFreshness"], VALID_FRESHNESS_VALUES, "declaredFreshness", sourceLabel, "INVALID_LITERAL_VALUE");
161
+ if (typeof v !== "string")
162
+ return v;
163
+ declaredFreshness = v;
164
+ }
165
+ let declaredAdequacy;
166
+ if (input["declaredAdequacy"] !== undefined) {
167
+ const v = requireEnum(input["declaredAdequacy"], VALID_ADEQUACY_VALUES, "declaredAdequacy", sourceLabel, "INVALID_LITERAL_VALUE");
168
+ if (typeof v !== "string")
169
+ return v;
170
+ declaredAdequacy = v;
171
+ }
172
+ let responsibilityMappingsTruncated;
173
+ if (input["responsibilityMappingsTruncated"] !== undefined) {
174
+ const v = requireEnum(input["responsibilityMappingsTruncated"], VALID_TRUNCATION_VALUES, "responsibilityMappingsTruncated", sourceLabel, "INVALID_LITERAL_VALUE");
175
+ if (typeof v !== "string")
176
+ return v;
177
+ responsibilityMappingsTruncated = v;
178
+ }
179
+ const readyWithAssumptions = input["readyWithAssumptions"];
180
+ if (typeof readyWithAssumptions !== "boolean") {
181
+ return fail(sourceLabel, "INVALID_FIELD_TYPE", `Readiness input at "${sourceLabel}" must declare boolean "readyWithAssumptions".`, "readyWithAssumptions");
182
+ }
183
+ const provenanceSummary = input["provenanceSummary"];
184
+ if (typeof provenanceSummary !== "string") {
185
+ return fail(sourceLabel, "MISSING_REQUIRED_FIELD", `Readiness input at "${sourceLabel}" is missing string "provenanceSummary".`, "provenanceSummary");
186
+ }
187
+ const indexIdentity = input["indexIdentity"];
188
+ if (indexIdentity !== undefined && (typeof indexIdentity !== "string" || indexIdentity.length === 0)) {
189
+ return fail(sourceLabel, "MISSING_CANONICAL_IDENTITY", `Readiness input at "${sourceLabel}" declares a non-string or empty "indexIdentity".`, "indexIdentity");
190
+ }
191
+ const sourceCapsulePath = input["sourceCapsulePath"];
192
+ const sourceAuditPath = input["sourceAuditPath"];
193
+ if (sourceCapsulePath !== undefined && typeof sourceCapsulePath !== "string") {
194
+ return fail(sourceLabel, "INVALID_FIELD_TYPE", `Readiness input at "${sourceLabel}" has non-string "sourceCapsulePath".`, "sourceCapsulePath");
195
+ }
196
+ if (sourceAuditPath !== undefined && typeof sourceAuditPath !== "string") {
197
+ return fail(sourceLabel, "INVALID_FIELD_TYPE", `Readiness input at "${sourceLabel}" has non-string "sourceAuditPath".`, "sourceAuditPath");
198
+ }
199
+ const artifact = {
200
+ schemaVersion,
201
+ kind,
202
+ role,
203
+ decision,
204
+ classification,
205
+ stageId,
206
+ packetPath,
207
+ reportPath,
208
+ sourceCapsulePath: sourceCapsulePath,
209
+ sourceAuditPath: sourceAuditPath,
210
+ issues,
211
+ warnings: warningsRaw,
212
+ blockingIssueCodes: blockingIssueCodesRaw,
213
+ primaryIssue,
214
+ blockerSummary,
215
+ affectedResponsibilityIds: affectedResponsibilityIdsRaw,
216
+ declaredFreshness,
217
+ evaluatedFreshness,
218
+ declaredAdequacy,
219
+ evaluatedAdequacy,
220
+ requiredEvidenceTruncated,
221
+ responsibilityMappingsTruncated,
222
+ indexIdentity: indexIdentity,
223
+ readyWithAssumptions,
224
+ provenanceSummary
225
+ };
226
+ return {
227
+ ok: true,
228
+ artifactKind: ARTIFACT_KIND,
229
+ sourcePath: sourceLabel,
230
+ schemaVersion,
231
+ schemaMajor: 1,
232
+ artifact,
233
+ rawArtifact: input
234
+ };
235
+ }
236
+ export function checkSupplementalReadinessIdentityConsistency(document, readiness) {
237
+ if (readiness.indexIdentity === undefined)
238
+ return null;
239
+ if (document.indexIdentity === readiness.indexIdentity)
240
+ return null;
241
+ return {
242
+ code: "INCOMPATIBLE_ARTIFACT_IDENTITY",
243
+ message: `Supplemental document index identity "${document.indexIdentity}" does not match readiness result index identity "${readiness.indexIdentity}".`,
244
+ documentIndexIdentity: document.indexIdentity,
245
+ readinessIndexIdentity: readiness.indexIdentity
246
+ };
247
+ }
@@ -0,0 +1,9 @@
1
+ import { readTextArtifactFile } from "./readSupplementalContextTextFile.js";
2
+ import { validateSupplementalContextDocumentV1 } from "./validateSupplementalContextDocumentV1.js";
3
+ const ARTIFACT_KIND = "orchestrator-implementation-context-packet-v1";
4
+ export async function readImplementationContextPacketV1(sourcePath) {
5
+ const loaded = await readTextArtifactFile(ARTIFACT_KIND, sourcePath);
6
+ if (!loaded.ok)
7
+ return loaded;
8
+ return validateSupplementalContextDocumentV1(ARTIFACT_KIND, "implementation-context-packet", loaded.text, loaded.sourcePath);
9
+ }
@@ -0,0 +1,9 @@
1
+ import { readTextArtifactFile } from "./readSupplementalContextTextFile.js";
2
+ import { validateSupplementalContextDocumentV1 } from "./validateSupplementalContextDocumentV1.js";
3
+ const ARTIFACT_KIND = "orchestrator-implementation-context-retrieval-report-v1";
4
+ export async function readImplementationContextRetrievalReportV1(sourcePath) {
5
+ const loaded = await readTextArtifactFile(ARTIFACT_KIND, sourcePath);
6
+ if (!loaded.ok)
7
+ return loaded;
8
+ return validateSupplementalContextDocumentV1(ARTIFACT_KIND, "implementation-context-retrieval-report", loaded.text, loaded.sourcePath);
9
+ }
@@ -0,0 +1,53 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ export async function readJsonArtifactFile(artifactKind, sourcePathInput) {
4
+ const sourcePath = path.resolve(sourcePathInput);
5
+ let raw;
6
+ try {
7
+ raw = await readFile(sourcePath, "utf8");
8
+ }
9
+ catch (error) {
10
+ const code = error.code;
11
+ if (code === "ENOENT") {
12
+ return {
13
+ ok: false,
14
+ artifactKind,
15
+ sourcePath,
16
+ code: "FILE_NOT_FOUND",
17
+ message: `Artifact "${artifactKind}" file was not found at "${sourcePath}".`
18
+ };
19
+ }
20
+ return {
21
+ ok: false,
22
+ artifactKind,
23
+ sourcePath,
24
+ code: "UNREADABLE_FILE",
25
+ message: `Artifact "${artifactKind}" file at "${sourcePath}" could not be read: ${error.message}`
26
+ };
27
+ }
28
+ let parsed;
29
+ try {
30
+ parsed = JSON.parse(raw);
31
+ }
32
+ catch (error) {
33
+ return {
34
+ ok: false,
35
+ artifactKind,
36
+ sourcePath,
37
+ code: "MALFORMED_JSON",
38
+ message: `Artifact "${artifactKind}" file at "${sourcePath}" is not valid JSON: ${error.message}`
39
+ };
40
+ }
41
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
42
+ return {
43
+ ok: false,
44
+ artifactKind,
45
+ sourcePath,
46
+ code: "NON_OBJECT_ROOT",
47
+ message: `Artifact "${artifactKind}" file at "${sourcePath}" must parse to a JSON object at the root.`,
48
+ expected: "object",
49
+ actual: parsed
50
+ };
51
+ }
52
+ return { ok: true, sourcePath, value: parsed };
53
+ }
@@ -0,0 +1,9 @@
1
+ import { readJsonArtifactFile } from "./readJsonArtifact.js";
2
+ import { validateMyDevKitContextCapsuleV1 } from "./validateMyDevKitContextCapsuleV1.js";
3
+ const ARTIFACT_KIND = "my-dev-kit-context-capsule-v1";
4
+ export async function readMyDevKitContextCapsuleV1(sourcePath) {
5
+ const loaded = await readJsonArtifactFile(ARTIFACT_KIND, sourcePath);
6
+ if (!loaded.ok)
7
+ return loaded;
8
+ return validateMyDevKitContextCapsuleV1(loaded.value, loaded.sourcePath);
9
+ }
@@ -0,0 +1,9 @@
1
+ import { readJsonArtifactFile } from "./readJsonArtifact.js";
2
+ import { validateMyDevKitRetrievalAuditRecordV1 } from "./validateMyDevKitRetrievalAuditRecordV1.js";
3
+ const ARTIFACT_KIND = "my-dev-kit-retrieval-audit-record-v1";
4
+ export async function readMyDevKitRetrievalAuditRecordV1(sourcePath) {
5
+ const loaded = await readJsonArtifactFile(ARTIFACT_KIND, sourcePath);
6
+ if (!loaded.ok)
7
+ return loaded;
8
+ return validateMyDevKitRetrievalAuditRecordV1(loaded.value, loaded.sourcePath);
9
+ }
@@ -0,0 +1,9 @@
1
+ import { readJsonArtifactFile } from "./readJsonArtifact.js";
2
+ import { validateOrchestratorWorkflowInstructionPacketV1 } from "./validateOrchestratorWorkflowInstructionPacketV1.js";
3
+ const ARTIFACT_KIND = "orchestrator-workflow-instruction-packet-v1";
4
+ export async function readOrchestratorWorkflowInstructionPacketV1(sourcePath) {
5
+ const loaded = await readJsonArtifactFile(ARTIFACT_KIND, sourcePath);
6
+ if (!loaded.ok)
7
+ return loaded;
8
+ return validateOrchestratorWorkflowInstructionPacketV1(loaded.value, loaded.sourcePath);
9
+ }
@@ -0,0 +1,29 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ export async function readTextArtifactFile(artifactKind, sourcePathInput) {
4
+ const sourcePath = path.resolve(sourcePathInput);
5
+ let text;
6
+ try {
7
+ text = await readFile(sourcePath, "utf8");
8
+ }
9
+ catch (error) {
10
+ const code = error.code;
11
+ if (code === "ENOENT") {
12
+ return {
13
+ ok: false,
14
+ artifactKind,
15
+ sourcePath,
16
+ code: "FILE_NOT_FOUND",
17
+ message: `Artifact "${artifactKind}" file was not found at "${sourcePath}".`
18
+ };
19
+ }
20
+ return {
21
+ ok: false,
22
+ artifactKind,
23
+ sourcePath,
24
+ code: "UNREADABLE_FILE",
25
+ message: `Artifact "${artifactKind}" file at "${sourcePath}" could not be read: ${error.message}`
26
+ };
27
+ }
28
+ return { ok: true, sourcePath, text };
29
+ }
@@ -0,0 +1,9 @@
1
+ import { readTextArtifactFile } from "./readSupplementalContextTextFile.js";
2
+ import { validateSupplementalContextDocumentV1 } from "./validateSupplementalContextDocumentV1.js";
3
+ const ARTIFACT_KIND = "orchestrator-test-context-packet-v1";
4
+ export async function readTestContextPacketV1(sourcePath) {
5
+ const loaded = await readTextArtifactFile(ARTIFACT_KIND, sourcePath);
6
+ if (!loaded.ok)
7
+ return loaded;
8
+ return validateSupplementalContextDocumentV1(ARTIFACT_KIND, "test-context-packet", loaded.text, loaded.sourcePath);
9
+ }
@@ -0,0 +1,9 @@
1
+ import { readTextArtifactFile } from "./readSupplementalContextTextFile.js";
2
+ import { validateSupplementalContextDocumentV1 } from "./validateSupplementalContextDocumentV1.js";
3
+ const ARTIFACT_KIND = "orchestrator-test-context-retrieval-report-v1";
4
+ export async function readTestContextRetrievalReportV1(sourcePath) {
5
+ const loaded = await readTextArtifactFile(ARTIFACT_KIND, sourcePath);
6
+ if (!loaded.ok)
7
+ return loaded;
8
+ return validateSupplementalContextDocumentV1(ARTIFACT_KIND, "test-context-retrieval-report", loaded.text, loaded.sourcePath);
9
+ }