archctx-contracts 0.16.0 → 0.17.0

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 (30) hide show
  1. package/fixtures/valid/archctx-capabilities.json +2 -2
  2. package/fixtures/valid/architecture-debt-delta.json +68 -0
  3. package/fixtures/valid/product-version-manifest.json +5 -5
  4. package/fixtures/valid/projection-slice.json +28 -0
  5. package/fixtures/valid/ref-impact-batch-request.json +11 -0
  6. package/fixtures/valid/ref-impact-batch.json +78 -0
  7. package/fixtures/valid/runtime-refactor-scan.json +2 -0
  8. package/fixtures/valid/runtime-verify.json +169 -0
  9. package/package.json +1 -1
  10. package/schemas/repo/constraint.schema.json +10 -1
  11. package/schemas/repo/refactor-decision.schema.json +5 -0
  12. package/schemas/runtime/archctx-capabilities.schema.json +1 -1
  13. package/schemas/runtime/architecture-debt-delta.schema.json +47 -0
  14. package/schemas/runtime/dependency-constraint-evaluation.schema.json +1 -0
  15. package/schemas/runtime/projection-slice.schema.json +147 -0
  16. package/schemas/runtime/ref-impact-batch-request.schema.json +26 -0
  17. package/schemas/runtime/ref-impact-batch.schema.json +38 -0
  18. package/schemas/runtime/runtime-recommendation-show.schema.json +5 -0
  19. package/schemas/runtime/runtime-refactor-scan.schema.json +18 -0
  20. package/schemas/runtime/runtime-verify.schema.json +131 -0
  21. package/src/architecture-debt.ts +18 -0
  22. package/src/architecture.ts +6 -4
  23. package/src/failure.ts +11 -0
  24. package/src/index.ts +1 -0
  25. package/src/ports.ts +2 -0
  26. package/src/product-version.ts +1 -1
  27. package/src/projection.ts +30 -0
  28. package/src/ref-impact.ts +33 -0
  29. package/src/refactor.ts +23 -1
  30. package/src/runtime-verify.ts +28 -0
package/src/refactor.ts CHANGED
@@ -323,6 +323,8 @@ export interface ModuleDependencyV1 {
323
323
 
324
324
  export interface ModuleStatisticsSnapshotV1 {
325
325
  schemaVersion: typeof MODULE_STATISTICS_SCHEMA_VERSION;
326
+ /** When present, counts describe the requested files and their direct import neighbors. */
327
+ scope?: Exclude<RefactorScopeV1, { kind: "repository" }>;
326
328
  repository: ArchitectureRepositoryIdentityV1;
327
329
  worktree: ArchitectureWorktreeIdentityV1;
328
330
  modelDigest: string;
@@ -594,6 +596,11 @@ export function moduleStatisticsSnapshotDigest(snapshot: ModuleStatisticsSnapsho
594
596
  return digestJson(hashable as unknown as Json);
595
597
  }
596
598
 
599
+ /** Repository measurements have no scope digest. Scoped measurements can compare only to the same scope. */
600
+ export function refactorSnapshotScopeDigest(scope: ModuleStatisticsSnapshotV1["scope"]): string | undefined {
601
+ return scope === undefined ? undefined : digestJson(scope);
602
+ }
603
+
597
604
  export function refactorAssessmentDigest(assessment: RefactorAssessmentV1): string {
598
605
  const {
599
606
  assessmentDigest: _assessmentDigest,
@@ -1317,6 +1324,9 @@ export function refactorScanInvariantIssues(input: {
1317
1324
  if (input.assessment.statisticsSnapshotDigest !== input.snapshot.snapshotDigest) {
1318
1325
  issues.push("assessment.statisticsSnapshotDigest must reference the measured snapshot");
1319
1326
  }
1327
+ if (input.snapshot.scope !== undefined && digestJson(input.snapshot.scope) !== digestJson(input.assessment.requestedScope)) {
1328
+ issues.push("assessment.requestedScope must match the measured snapshot scope");
1329
+ }
1320
1330
  if (input.assessment.modelDigest !== input.snapshot.modelDigest) {
1321
1331
  issues.push("assessment.modelDigest must match the snapshot modelDigest");
1322
1332
  }
@@ -1587,6 +1597,8 @@ export interface RefactorDecisionV1 {
1587
1597
  status: RefactorDecisionStatus;
1588
1598
  /** The measurement the decision was taken against; `null` when the record carries none. */
1589
1599
  observationMetrics: Record<string, number | null> | null;
1600
+ /** Scope of the measured observation metrics. Absent for repository baselines. */
1601
+ observationScopeDigest?: string;
1590
1602
  reason: string;
1591
1603
  actor: { kind: ArchitectureActorKind; id: string };
1592
1604
  decidedAt: string;
@@ -1616,6 +1628,7 @@ const REFACTOR_DECISION_KEYS = [
1616
1628
  "status",
1617
1629
  "subject"
1618
1630
  ] as const;
1631
+ const REFACTOR_DECISION_OPTIONAL_KEYS = ["observationScopeDigest"] as const;
1619
1632
 
1620
1633
  export function isRefactorDecisionStatus(status: RecommendationStatus | string): status is RefactorDecisionStatus {
1621
1634
  return (REFACTOR_DECISION_STATUSES as readonly string[]).includes(status);
@@ -1671,6 +1684,7 @@ export function serializeRefactorDecision(decision: RefactorDecisionV1): string
1671
1684
  observationMetrics: decision.observationMetrics === null
1672
1685
  ? null
1673
1686
  : Object.fromEntries(Object.entries(decision.observationMetrics).sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))),
1687
+ ...(decision.observationScopeDigest === undefined ? {} : { observationScopeDigest: decision.observationScopeDigest }),
1674
1688
  reason: decision.reason,
1675
1689
  actor: { kind: decision.actor.kind, id: decision.actor.id },
1676
1690
  decidedAt: decision.decidedAt,
@@ -1692,7 +1706,8 @@ export function serializeRefactorDecision(decision: RefactorDecisionV1): string
1692
1706
  export function refactorDecisionInvariantIssues(value: unknown, prefix = "refactorDecision"): string[] {
1693
1707
  if (!isPlainObject(value)) return [`${prefix} must be an object`];
1694
1708
  const issues: string[] = [];
1695
- const unknownKeys = Object.keys(value).filter((key) => !(REFACTOR_DECISION_KEYS as readonly string[]).includes(key)).sort();
1709
+ const allowedKeys: readonly string[] = [...REFACTOR_DECISION_KEYS, ...REFACTOR_DECISION_OPTIONAL_KEYS];
1710
+ const unknownKeys = Object.keys(value).filter((key) => !allowedKeys.includes(key)).sort();
1696
1711
  if (unknownKeys.length > 0) issues.push(`${prefix} has unsupported key(s): ${unknownKeys.join(", ")}`);
1697
1712
  const missing = REFACTOR_DECISION_KEYS.filter((key) => !(key in value));
1698
1713
  if (missing.length > 0) issues.push(`${prefix} is missing key(s): ${missing.join(", ")}`);
@@ -1740,6 +1755,13 @@ export function refactorDecisionInvariantIssues(value: unknown, prefix = "refact
1740
1755
  issues.push(`${prefix}.observationMetrics must be null or a map of finite numbers and nulls`);
1741
1756
  }
1742
1757
  }
1758
+ if (decision.observationScopeDigest !== undefined) {
1759
+ if (typeof decision.observationScopeDigest === "string") issues.push(...digestIssues(`${prefix}.observationScopeDigest`, decision.observationScopeDigest));
1760
+ else issues.push(`${prefix}.observationScopeDigest must be a digest`);
1761
+ if (decision.category !== "structural_observation" || decision.observationMetrics === null) {
1762
+ issues.push(`${prefix}.observationScopeDigest requires measured observation metrics`);
1763
+ }
1764
+ }
1743
1765
  issues.push(...boundedLineIssues(`${prefix}.reason`, decision.reason, REFACTOR_DECISION_REASON_MAX_LENGTH));
1744
1766
  if (!isPlainObject(decision.actor) || Object.keys(decision.actor).sort().join(",") !== "id,kind") {
1745
1767
  issues.push(`${prefix}.actor must carry exactly kind and id`);
@@ -0,0 +1,28 @@
1
+ import type { ArchitectureDebtReportV1 } from "./architecture-debt";
2
+ import type { DependencyConstraintEvaluationV1 } from "./architecture";
3
+ import type { DocsAnchorsReportV1 } from "./docs-anchors";
4
+ import type { ModelValidationResult } from "./ports";
5
+ import type { ArchitectureFlowSelectorCheckV1 } from "./projection";
6
+ import type { ProjectionPrVerificationV1 } from "./projection-writer";
7
+ import type { ArchContextError } from "./schema";
8
+ import type { StateMachineCheckReportV1 } from "./state-machine";
9
+
10
+ export const RUNTIME_VERIFY_SCHEMA_VERSION = "archcontext.runtime-verify/v1" as const;
11
+
12
+ export type RuntimeVerifyCheck<T> = { ok: true; data: T } | { ok: false; error: ArchContextError };
13
+
14
+ export interface RuntimeVerifyV1 {
15
+ schemaVersion: typeof RUNTIME_VERIFY_SCHEMA_VERSION;
16
+ base: string;
17
+ baseSha: string;
18
+ headSha: string;
19
+ checks: {
20
+ validate: RuntimeVerifyCheck<ModelValidationResult>;
21
+ flows: RuntimeVerifyCheck<ArchitectureFlowSelectorCheckV1>;
22
+ "state-machines": RuntimeVerifyCheck<StateMachineCheckReportV1>;
23
+ constraints: RuntimeVerifyCheck<DependencyConstraintEvaluationV1 & { warnings: string[] }>;
24
+ docs: RuntimeVerifyCheck<DocsAnchorsReportV1>;
25
+ projection: RuntimeVerifyCheck<ProjectionPrVerificationV1>;
26
+ debt: RuntimeVerifyCheck<ArchitectureDebtReportV1>;
27
+ };
28
+ }