semantic-atlas 0.1.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 (175) hide show
  1. package/.agents/skills/semantic-atlas/SKILL.md +172 -0
  2. package/.agents/skills/semantic-atlas/references/graph-patch.md +109 -0
  3. package/.agents/skills/semantic-atlas/references/result-routing.md +91 -0
  4. package/LICENSE +21 -0
  5. package/README.md +118 -0
  6. package/dist/business-flow/business-flow-derivation-service.d.ts +11 -0
  7. package/dist/business-flow/business-flow-derivation-service.d.ts.map +1 -0
  8. package/dist/business-flow/business-flow-derivation-service.js +151 -0
  9. package/dist/business-flow/business-flow-draft.d.ts +16 -0
  10. package/dist/business-flow/business-flow-draft.d.ts.map +1 -0
  11. package/dist/business-flow/business-flow-draft.js +150 -0
  12. package/dist/business-flow/framework-business-strategy.d.ts +7 -0
  13. package/dist/business-flow/framework-business-strategy.d.ts.map +1 -0
  14. package/dist/business-flow/framework-business-strategy.js +1 -0
  15. package/dist/business-flow/strategies/bullmq-business-strategy.d.ts +10 -0
  16. package/dist/business-flow/strategies/bullmq-business-strategy.d.ts.map +1 -0
  17. package/dist/business-flow/strategies/bullmq-business-strategy.js +79 -0
  18. package/dist/business-flow/strategies/called-operation-derivation.d.ts +13 -0
  19. package/dist/business-flow/strategies/called-operation-derivation.d.ts.map +1 -0
  20. package/dist/business-flow/strategies/called-operation-derivation.js +32 -0
  21. package/dist/business-flow/strategies/graphql-business-strategy.d.ts +8 -0
  22. package/dist/business-flow/strategies/graphql-business-strategy.d.ts.map +1 -0
  23. package/dist/business-flow/strategies/graphql-business-strategy.js +65 -0
  24. package/dist/business-flow/strategies/nestjs-business-strategy.d.ts +8 -0
  25. package/dist/business-flow/strategies/nestjs-business-strategy.d.ts.map +1 -0
  26. package/dist/business-flow/strategies/nestjs-business-strategy.js +72 -0
  27. package/dist/business-flow/strategies/strategy-helpers.d.ts +32 -0
  28. package/dist/business-flow/strategies/strategy-helpers.d.ts.map +1 -0
  29. package/dist/business-flow/strategies/strategy-helpers.js +49 -0
  30. package/dist/business-flow/strategies/typeorm-business-strategy.d.ts +10 -0
  31. package/dist/business-flow/strategies/typeorm-business-strategy.d.ts.map +1 -0
  32. package/dist/business-flow/strategies/typeorm-business-strategy.js +136 -0
  33. package/dist/business-flow/strategies/verified-invariant-strategy.d.ts +5 -0
  34. package/dist/business-flow/strategies/verified-invariant-strategy.d.ts.map +1 -0
  35. package/dist/business-flow/strategies/verified-invariant-strategy.js +38 -0
  36. package/dist/business-flow/strategies/verified-test-strategy.d.ts +5 -0
  37. package/dist/business-flow/strategies/verified-test-strategy.d.ts.map +1 -0
  38. package/dist/business-flow/strategies/verified-test-strategy.js +26 -0
  39. package/dist/business-flow/structural-flow-catalog.d.ts +21 -0
  40. package/dist/business-flow/structural-flow-catalog.d.ts.map +1 -0
  41. package/dist/business-flow/structural-flow-catalog.js +125 -0
  42. package/dist/business-flow/types.d.ts +51 -0
  43. package/dist/business-flow/types.d.ts.map +1 -0
  44. package/dist/business-flow/types.js +1 -0
  45. package/dist/cli/argument-parser.d.ts +3 -0
  46. package/dist/cli/argument-parser.d.ts.map +1 -0
  47. package/dist/cli/argument-parser.js +174 -0
  48. package/dist/cli/bin.d.ts +3 -0
  49. package/dist/cli/bin.d.ts.map +1 -0
  50. package/dist/cli/bin.js +23 -0
  51. package/dist/cli/cli-application.d.ts +38 -0
  52. package/dist/cli/cli-application.d.ts.map +1 -0
  53. package/dist/cli/cli-application.js +515 -0
  54. package/dist/cli/cli-error.d.ts +12 -0
  55. package/dist/cli/cli-error.d.ts.map +1 -0
  56. package/dist/cli/cli-error.js +44 -0
  57. package/dist/cli/cli-presenter.d.ts +14 -0
  58. package/dist/cli/cli-presenter.d.ts.map +1 -0
  59. package/dist/cli/cli-presenter.js +36 -0
  60. package/dist/cli/main.d.ts +3 -0
  61. package/dist/cli/main.d.ts.map +1 -0
  62. package/dist/cli/main.js +45 -0
  63. package/dist/cli/types.d.ts +46 -0
  64. package/dist/cli/types.d.ts.map +1 -0
  65. package/dist/cli/types.js +1 -0
  66. package/dist/contracts/cli.d.ts +2139 -0
  67. package/dist/contracts/cli.d.ts.map +1 -0
  68. package/dist/contracts/cli.js +232 -0
  69. package/dist/contracts/graph.d.ts +262 -0
  70. package/dist/contracts/graph.d.ts.map +1 -0
  71. package/dist/contracts/graph.js +182 -0
  72. package/dist/contracts/identifiers.d.ts +4 -0
  73. package/dist/contracts/identifiers.d.ts.map +1 -0
  74. package/dist/contracts/identifiers.js +7 -0
  75. package/dist/contracts/public-contracts.d.ts +4 -0
  76. package/dist/contracts/public-contracts.d.ts.map +1 -0
  77. package/dist/contracts/public-contracts.js +3 -0
  78. package/dist/evaluation/comparison.d.ts +30 -0
  79. package/dist/evaluation/comparison.d.ts.map +1 -0
  80. package/dist/evaluation/comparison.js +108 -0
  81. package/dist/evaluation/contracts.d.ts +204 -0
  82. package/dist/evaluation/contracts.d.ts.map +1 -0
  83. package/dist/evaluation/contracts.js +269 -0
  84. package/dist/graph/graph-store.d.ts +47 -0
  85. package/dist/graph/graph-store.d.ts.map +1 -0
  86. package/dist/graph/graph-store.js +719 -0
  87. package/dist/graph/types.d.ts +168 -0
  88. package/dist/graph/types.d.ts.map +1 -0
  89. package/dist/graph/types.js +1 -0
  90. package/dist/index.d.ts +19 -0
  91. package/dist/index.d.ts.map +1 -0
  92. package/dist/index.js +9 -0
  93. package/dist/knowledge/business-knowledge-service.d.ts +24 -0
  94. package/dist/knowledge/business-knowledge-service.d.ts.map +1 -0
  95. package/dist/knowledge/business-knowledge-service.js +200 -0
  96. package/dist/knowledge/graph-patch-conflict-error.d.ts +8 -0
  97. package/dist/knowledge/graph-patch-conflict-error.d.ts.map +1 -0
  98. package/dist/knowledge/graph-patch-conflict-error.js +12 -0
  99. package/dist/knowledge/structural-target-binding.d.ts +14 -0
  100. package/dist/knowledge/structural-target-binding.d.ts.map +1 -0
  101. package/dist/knowledge/structural-target-binding.js +11 -0
  102. package/dist/repository/git-command.d.ts +3 -0
  103. package/dist/repository/git-command.d.ts.map +1 -0
  104. package/dist/repository/git-command.js +25 -0
  105. package/dist/repository/repository-inspector.d.ts +7 -0
  106. package/dist/repository/repository-inspector.d.ts.map +1 -0
  107. package/dist/repository/repository-inspector.js +84 -0
  108. package/dist/repository/repository-language-support.d.ts +14 -0
  109. package/dist/repository/repository-language-support.d.ts.map +1 -0
  110. package/dist/repository/repository-language-support.js +64 -0
  111. package/dist/repository/types.d.ts +9 -0
  112. package/dist/repository/types.d.ts.map +1 -0
  113. package/dist/repository/types.js +1 -0
  114. package/dist/snapshots/repository-snapshot.d.ts +4 -0
  115. package/dist/snapshots/repository-snapshot.d.ts.map +1 -0
  116. package/dist/snapshots/repository-snapshot.js +119 -0
  117. package/dist/snapshots/types.d.ts +30 -0
  118. package/dist/snapshots/types.d.ts.map +1 -0
  119. package/dist/snapshots/types.js +1 -0
  120. package/dist/storage/atlas-database.d.ts +14 -0
  121. package/dist/storage/atlas-database.d.ts.map +1 -0
  122. package/dist/storage/atlas-database.js +552 -0
  123. package/dist/storage/snapshot-store.d.ts +19 -0
  124. package/dist/storage/snapshot-store.d.ts.map +1 -0
  125. package/dist/storage/snapshot-store.js +77 -0
  126. package/dist/structural-backend/codegraph-backend.d.ts +54 -0
  127. package/dist/structural-backend/codegraph-backend.d.ts.map +1 -0
  128. package/dist/structural-backend/codegraph-backend.js +1224 -0
  129. package/dist/structural-backend/codegraph-worker-client.d.ts +5 -0
  130. package/dist/structural-backend/codegraph-worker-client.d.ts.map +1 -0
  131. package/dist/structural-backend/codegraph-worker-client.js +118 -0
  132. package/dist/structural-backend/codegraph-worker-protocol.d.ts +35 -0
  133. package/dist/structural-backend/codegraph-worker-protocol.d.ts.map +1 -0
  134. package/dist/structural-backend/codegraph-worker-protocol.js +1 -0
  135. package/dist/structural-backend/codegraph-worker.d.ts +2 -0
  136. package/dist/structural-backend/codegraph-worker.d.ts.map +1 -0
  137. package/dist/structural-backend/codegraph-worker.js +131 -0
  138. package/dist/structural-backend/process-instance.d.ts +18 -0
  139. package/dist/structural-backend/process-instance.d.ts.map +1 -0
  140. package/dist/structural-backend/process-instance.js +207 -0
  141. package/dist/structural-backend/structural-fact-changes.d.ts +7 -0
  142. package/dist/structural-backend/structural-fact-changes.d.ts.map +1 -0
  143. package/dist/structural-backend/structural-fact-changes.js +78 -0
  144. package/dist/structural-backend/structural-publication.d.ts +12 -0
  145. package/dist/structural-backend/structural-publication.d.ts.map +1 -0
  146. package/dist/structural-backend/structural-publication.js +252 -0
  147. package/dist/structural-backend/structural-write-lock.d.ts +8 -0
  148. package/dist/structural-backend/structural-write-lock.d.ts.map +1 -0
  149. package/dist/structural-backend/structural-write-lock.js +415 -0
  150. package/dist/structural-backend/types.d.ts +144 -0
  151. package/dist/structural-backend/types.d.ts.map +1 -0
  152. package/dist/structural-backend/types.js +11 -0
  153. package/dist/world/types.d.ts +77 -0
  154. package/dist/world/types.d.ts.map +1 -0
  155. package/dist/world/types.js +1 -0
  156. package/dist/world/world-graph-query.d.ts +31 -0
  157. package/dist/world/world-graph-query.d.ts.map +1 -0
  158. package/dist/world/world-graph-query.js +453 -0
  159. package/dist/world/world-model-service.d.ts +21 -0
  160. package/dist/world/world-model-service.d.ts.map +1 -0
  161. package/dist/world/world-model-service.js +211 -0
  162. package/dist/world/world-snapshot-store.d.ts +40 -0
  163. package/dist/world/world-snapshot-store.d.ts.map +1 -0
  164. package/dist/world/world-snapshot-store.js +555 -0
  165. package/docs/architecture/codegraph-backend.md +193 -0
  166. package/docs/contracts/cli-v1.md +119 -0
  167. package/docs/contracts/graph-model.md +102 -0
  168. package/docs/contracts/graph-patch-v1.md +98 -0
  169. package/docs/evaluation.md +128 -0
  170. package/docs/product-contract.md +148 -0
  171. package/package.json +78 -0
  172. package/schemas/cli-envelope-v1.schema.json +1359 -0
  173. package/schemas/evaluation-plan-v1.schema.json +211 -0
  174. package/schemas/evaluation-run-v1.schema.json +365 -0
  175. package/schemas/graph-patch-v1.schema.json +392 -0
@@ -0,0 +1,7 @@
1
+ import { z } from "zod";
2
+ export const contentIdentifierSchema = z
3
+ .string()
4
+ .regex(/^[a-f0-9]{64}$/, "Expected a SHA-256 identifier");
5
+ export const gitObjectIdSchema = z
6
+ .string()
7
+ .regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/, "Expected a Git object ID");
@@ -0,0 +1,4 @@
1
+ export * from "./cli.js";
2
+ export * from "./graph.js";
3
+ export * from "./identifiers.js";
4
+ //# sourceMappingURL=public-contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-contracts.d.ts","sourceRoot":"","sources":["../../src/contracts/public-contracts.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./cli.js";
2
+ export * from "./graph.js";
3
+ export * from "./identifiers.js";
@@ -0,0 +1,30 @@
1
+ import { type EvaluationRunSummary } from "./contracts.js";
2
+ export interface EvaluationPairSummary {
3
+ readonly caseId: string;
4
+ readonly noAtlas: EvaluationRunSummary;
5
+ readonly atlas: EvaluationRunSummary;
6
+ readonly noRegression: boolean;
7
+ }
8
+ export interface EvaluationComparison {
9
+ readonly pairs: readonly EvaluationPairSummary[];
10
+ readonly medians: {
11
+ readonly noAtlas: EvaluationUsageMedian;
12
+ readonly atlas: EvaluationUsageMedian;
13
+ };
14
+ readonly reductions: {
15
+ readonly openedFilePercent: number;
16
+ readonly sourceTokenPercent: number;
17
+ };
18
+ readonly gate: {
19
+ readonly noRegression: boolean;
20
+ readonly uncertaintyHandled: boolean;
21
+ readonly reductionThresholdMet: boolean;
22
+ readonly passed: boolean;
23
+ };
24
+ }
25
+ export interface EvaluationUsageMedian {
26
+ readonly openedFileCount: number;
27
+ readonly sourceTokens: number;
28
+ }
29
+ export declare function summarizeEvaluationComparison(rawPlan: unknown, rawRuns: readonly unknown[]): EvaluationComparison;
30
+ //# sourceMappingURL=comparison.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparison.d.ts","sourceRoot":"","sources":["../../src/evaluation/comparison.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,oBAAoB,EAC1B,MAAM,gBAAgB,CAAC;AAUxB,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;IACrC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,KAAK,EAAE,SAAS,qBAAqB,EAAE,CAAC;IACjD,QAAQ,CAAC,OAAO,EAAE;QAChB,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;QACxC,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC;KACvC,CAAC;IACF,QAAQ,CAAC,UAAU,EAAE;QACnB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;QACnC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;KACrC,CAAC;IACF,QAAQ,CAAC,IAAI,EAAE;QACb,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;QAC/B,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;QACrC,QAAQ,CAAC,qBAAqB,EAAE,OAAO,CAAC;QACxC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;KAC1B,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,SAAS,OAAO,EAAE,GAC1B,oBAAoB,CA2DtB"}
@@ -0,0 +1,108 @@
1
+ import { evaluationPlanSchema, evaluationRunSchema, summarizeEvaluationRun, } from "./contracts.js";
2
+ const REDUCTION_GATE_PERCENT = 30;
3
+ const UNCERTAINTY_FAILURES = new Set([
4
+ "stale-knowledge",
5
+ "hypothesis-mishandled",
6
+ "unknown-boundary-mishandled",
7
+ "unsupported-source",
8
+ ]);
9
+ export function summarizeEvaluationComparison(rawPlan, rawRuns) {
10
+ const plan = evaluationPlanSchema.parse(rawPlan);
11
+ const runs = rawRuns.map((run) => evaluationRunSchema.parse(run));
12
+ requireUniqueRunIds(runs);
13
+ const pairs = plan.cases.map((evaluationCase) => {
14
+ const caseRuns = runs.filter((run) => run.caseId === evaluationCase.id);
15
+ const noAtlas = requireModeRun(evaluationCase.id, caseRuns, "no-atlas");
16
+ const atlas = requireModeRun(evaluationCase.id, caseRuns, "atlas");
17
+ requireProtocolParity(noAtlas, atlas);
18
+ const noAtlasSummary = summarizeEvaluationRun(evaluationCase, noAtlas);
19
+ const atlasSummary = summarizeEvaluationRun(evaluationCase, atlas);
20
+ return {
21
+ caseId: evaluationCase.id,
22
+ noAtlas: noAtlasSummary,
23
+ atlas: atlasSummary,
24
+ noRegression: preservesOutcome(noAtlasSummary, atlasSummary),
25
+ };
26
+ });
27
+ const plannedCases = new Set(plan.cases.map((evaluationCase) => evaluationCase.id));
28
+ const unexpectedRun = runs.find((run) => !plannedCases.has(run.caseId));
29
+ if (unexpectedRun !== undefined) {
30
+ throw new Error(`Run ${unexpectedRun.runId} references unknown case ${unexpectedRun.caseId}`);
31
+ }
32
+ const medians = {
33
+ noAtlas: usageMedian(pairs.map((pair) => pair.noAtlas)),
34
+ atlas: usageMedian(pairs.map((pair) => pair.atlas)),
35
+ };
36
+ const reductions = {
37
+ openedFilePercent: reductionPercent(medians.noAtlas.openedFileCount, medians.atlas.openedFileCount),
38
+ sourceTokenPercent: reductionPercent(medians.noAtlas.sourceTokens, medians.atlas.sourceTokens),
39
+ };
40
+ const noRegression = pairs.every((pair) => pair.noRegression);
41
+ const uncertaintyHandled = pairs.every((pair) => (pair.atlas.failureClassifications.every((failure) => !UNCERTAINTY_FAILURES.has(failure))));
42
+ const reductionThresholdMet = reductions.openedFilePercent >= REDUCTION_GATE_PERCENT
43
+ || reductions.sourceTokenPercent >= REDUCTION_GATE_PERCENT;
44
+ return {
45
+ pairs,
46
+ medians,
47
+ reductions,
48
+ gate: {
49
+ noRegression,
50
+ uncertaintyHandled,
51
+ reductionThresholdMet,
52
+ passed: noRegression && uncertaintyHandled && reductionThresholdMet,
53
+ },
54
+ };
55
+ }
56
+ function requireUniqueRunIds(runs) {
57
+ const runIds = new Set();
58
+ for (const run of runs) {
59
+ if (runIds.has(run.runId)) {
60
+ throw new Error(`Evaluation run ID ${run.runId} is duplicated`);
61
+ }
62
+ runIds.add(run.runId);
63
+ }
64
+ }
65
+ function requireModeRun(caseId, runs, mode) {
66
+ const matches = runs.filter((run) => run.mode === mode);
67
+ if (matches.length !== 1 || runs.length !== 2) {
68
+ throw new Error(`Evaluation case ${caseId} requires exactly one no-atlas and one atlas run`);
69
+ }
70
+ return matches[0];
71
+ }
72
+ function requireProtocolParity(noAtlas, atlas) {
73
+ const comparable = [
74
+ noAtlas.agent.product === atlas.agent.product,
75
+ noAtlas.agent.model === atlas.agent.model,
76
+ noAtlas.protocol.fixtureCommit === atlas.protocol.fixtureCommit,
77
+ noAtlas.protocol.instructionsHash === atlas.protocol.instructionsHash,
78
+ noAtlas.protocol.toolPolicyHash === atlas.protocol.toolPolicyHash,
79
+ noAtlas.observations.sourceTokenMethod === atlas.observations.sourceTokenMethod,
80
+ ];
81
+ if (comparable.some((matches) => !matches)) {
82
+ throw new Error("Paired runs require the same agent product, model, fixture commit, instructions, "
83
+ + "tool policy, and source-token method");
84
+ }
85
+ }
86
+ function preservesOutcome(noAtlas, atlas) {
87
+ return Number(atlas.correct) >= Number(noAtlas.correct)
88
+ && atlas.requiredFileRecall >= noAtlas.requiredFileRecall
89
+ && atlas.requiredSymbolRecall >= noAtlas.requiredSymbolRecall;
90
+ }
91
+ function usageMedian(runs) {
92
+ return {
93
+ openedFileCount: median(runs.map((run) => run.openedFileCount)),
94
+ sourceTokens: median(runs.map((run) => run.sourceTokens)),
95
+ };
96
+ }
97
+ function median(values) {
98
+ const sorted = [...values].sort((left, right) => left - right);
99
+ const middle = Math.floor(sorted.length / 2);
100
+ return sorted.length % 2 === 0
101
+ ? (sorted[middle - 1] + sorted[middle]) / 2
102
+ : sorted[middle];
103
+ }
104
+ function reductionPercent(baseline, candidate) {
105
+ if (baseline === 0)
106
+ return candidate === 0 ? 0 : -100;
107
+ return Math.round(((baseline - candidate) / baseline) * 10_000) / 100;
108
+ }
@@ -0,0 +1,204 @@
1
+ import { z } from "zod";
2
+ export declare const evaluationCaseSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ title: z.ZodString;
5
+ category: z.ZodEnum<{
6
+ location: "location";
7
+ "dependency-impact": "dependency-impact";
8
+ }>;
9
+ frameworks: z.ZodArray<z.ZodEnum<{
10
+ nestjs: "nestjs";
11
+ graphql: "graphql";
12
+ typeorm: "typeorm";
13
+ bullmq: "bullmq";
14
+ }>>;
15
+ fixture: z.ZodDiscriminatedUnion<[z.ZodObject<{
16
+ kind: z.ZodLiteral<"synthetic">;
17
+ repository: z.ZodString;
18
+ revision: z.ZodString;
19
+ }, z.core.$strict>, z.ZodObject<{
20
+ kind: z.ZodLiteral<"private">;
21
+ repositoryAlias: z.ZodString;
22
+ revision: z.ZodString;
23
+ }, z.core.$strict>], "kind">;
24
+ prompt: z.ZodString;
25
+ oracle: z.ZodObject<{
26
+ acceptanceCriteria: z.ZodArray<z.ZodString>;
27
+ requiredFiles: z.ZodArray<z.ZodString>;
28
+ requiredSymbols: z.ZodArray<z.ZodObject<{
29
+ file: z.ZodString;
30
+ name: z.ZodString;
31
+ }, z.core.$strict>>;
32
+ }, z.core.$strict>;
33
+ }, z.core.$strict>;
34
+ export declare const evaluationPlanSchema: z.ZodObject<{
35
+ schemaVersion: z.ZodLiteral<1>;
36
+ cases: z.ZodArray<z.ZodObject<{
37
+ id: z.ZodString;
38
+ title: z.ZodString;
39
+ category: z.ZodEnum<{
40
+ location: "location";
41
+ "dependency-impact": "dependency-impact";
42
+ }>;
43
+ frameworks: z.ZodArray<z.ZodEnum<{
44
+ nestjs: "nestjs";
45
+ graphql: "graphql";
46
+ typeorm: "typeorm";
47
+ bullmq: "bullmq";
48
+ }>>;
49
+ fixture: z.ZodDiscriminatedUnion<[z.ZodObject<{
50
+ kind: z.ZodLiteral<"synthetic">;
51
+ repository: z.ZodString;
52
+ revision: z.ZodString;
53
+ }, z.core.$strict>, z.ZodObject<{
54
+ kind: z.ZodLiteral<"private">;
55
+ repositoryAlias: z.ZodString;
56
+ revision: z.ZodString;
57
+ }, z.core.$strict>], "kind">;
58
+ prompt: z.ZodString;
59
+ oracle: z.ZodObject<{
60
+ acceptanceCriteria: z.ZodArray<z.ZodString>;
61
+ requiredFiles: z.ZodArray<z.ZodString>;
62
+ requiredSymbols: z.ZodArray<z.ZodObject<{
63
+ file: z.ZodString;
64
+ name: z.ZodString;
65
+ }, z.core.$strict>>;
66
+ }, z.core.$strict>;
67
+ }, z.core.$strict>>;
68
+ }, z.core.$strict>;
69
+ export declare const baselineEvaluationPlanSchema: z.ZodObject<{
70
+ schemaVersion: z.ZodLiteral<1>;
71
+ cases: z.ZodArray<z.ZodObject<{
72
+ id: z.ZodString;
73
+ title: z.ZodString;
74
+ category: z.ZodEnum<{
75
+ location: "location";
76
+ "dependency-impact": "dependency-impact";
77
+ }>;
78
+ frameworks: z.ZodArray<z.ZodEnum<{
79
+ nestjs: "nestjs";
80
+ graphql: "graphql";
81
+ typeorm: "typeorm";
82
+ bullmq: "bullmq";
83
+ }>>;
84
+ fixture: z.ZodDiscriminatedUnion<[z.ZodObject<{
85
+ kind: z.ZodLiteral<"synthetic">;
86
+ repository: z.ZodString;
87
+ revision: z.ZodString;
88
+ }, z.core.$strict>, z.ZodObject<{
89
+ kind: z.ZodLiteral<"private">;
90
+ repositoryAlias: z.ZodString;
91
+ revision: z.ZodString;
92
+ }, z.core.$strict>], "kind">;
93
+ prompt: z.ZodString;
94
+ oracle: z.ZodObject<{
95
+ acceptanceCriteria: z.ZodArray<z.ZodString>;
96
+ requiredFiles: z.ZodArray<z.ZodString>;
97
+ requiredSymbols: z.ZodArray<z.ZodObject<{
98
+ file: z.ZodString;
99
+ name: z.ZodString;
100
+ }, z.core.$strict>>;
101
+ }, z.core.$strict>;
102
+ }, z.core.$strict>>;
103
+ }, z.core.$strict>;
104
+ export declare const evaluationFailureClassificationSchema: z.ZodEnum<{
105
+ "missed-dependency": "missed-dependency";
106
+ "incorrect-answer": "incorrect-answer";
107
+ "stale-knowledge": "stale-knowledge";
108
+ "hypothesis-mishandled": "hypothesis-mishandled";
109
+ "unknown-boundary-mishandled": "unknown-boundary-mishandled";
110
+ "unsupported-source": "unsupported-source";
111
+ "protocol-violation": "protocol-violation";
112
+ }>;
113
+ export declare const FRESH_AGENT_COMMAND_AUDIT_POLICY = "fresh-agent-shell-allowlist-v4";
114
+ export declare const evaluationRunSchema: z.ZodObject<{
115
+ schemaVersion: z.ZodLiteral<1>;
116
+ runId: z.ZodString;
117
+ caseId: z.ZodString;
118
+ mode: z.ZodEnum<{
119
+ "no-atlas": "no-atlas";
120
+ atlas: "atlas";
121
+ }>;
122
+ fixtureRevision: z.ZodString;
123
+ agent: z.ZodObject<{
124
+ product: z.ZodString;
125
+ model: z.ZodString;
126
+ freshContext: z.ZodLiteral<true>;
127
+ }, z.core.$strict>;
128
+ protocol: z.ZodObject<{
129
+ runnerVersion: z.ZodString;
130
+ fixtureCommit: z.ZodString;
131
+ instructionsHash: z.ZodString;
132
+ toolPolicyHash: z.ZodString;
133
+ oracleHidden: z.ZodLiteral<true>;
134
+ commandAuditPassed: z.ZodLiteral<true>;
135
+ commandAudit: z.ZodObject<{
136
+ policy: z.ZodLiteral<"fresh-agent-shell-allowlist-v4">;
137
+ commands: z.ZodArray<z.ZodString>;
138
+ }, z.core.$strict>;
139
+ }, z.core.$strict>;
140
+ startedAt: z.ZodISODateTime;
141
+ finishedAt: z.ZodISODateTime;
142
+ observations: z.ZodObject<{
143
+ sourceTokenMethod: z.ZodString;
144
+ sourceOpens: z.ZodArray<z.ZodObject<{
145
+ sequence: z.ZodNumber;
146
+ file: z.ZodString;
147
+ sourceTokens: z.ZodNumber;
148
+ }, z.core.$strict>>;
149
+ atlasCalls: z.ZodArray<z.ZodObject<{
150
+ sequence: z.ZodNumber;
151
+ command: z.ZodString;
152
+ }, z.core.$strict>>;
153
+ atlasHandling: z.ZodArray<z.ZodObject<{
154
+ sequence: z.ZodNumber;
155
+ classification: z.ZodEnum<{
156
+ hypothesis: "hypothesis";
157
+ stale: "stale";
158
+ unsupported: "unsupported";
159
+ unknown: "unknown";
160
+ partial: "partial";
161
+ insufficient: "insufficient";
162
+ }>;
163
+ action: z.ZodString;
164
+ }, z.core.$strict>>;
165
+ }, z.core.$strict>;
166
+ answer: z.ZodObject<{
167
+ response: z.ZodString;
168
+ reportedFiles: z.ZodArray<z.ZodString>;
169
+ reportedSymbols: z.ZodArray<z.ZodObject<{
170
+ file: z.ZodString;
171
+ name: z.ZodString;
172
+ }, z.core.$strict>>;
173
+ }, z.core.$strict>;
174
+ adjudication: z.ZodObject<{
175
+ correct: z.ZodBoolean;
176
+ notes: z.ZodString;
177
+ failureClassifications: z.ZodArray<z.ZodEnum<{
178
+ "missed-dependency": "missed-dependency";
179
+ "incorrect-answer": "incorrect-answer";
180
+ "stale-knowledge": "stale-knowledge";
181
+ "hypothesis-mishandled": "hypothesis-mishandled";
182
+ "unknown-boundary-mishandled": "unknown-boundary-mishandled";
183
+ "unsupported-source": "unsupported-source";
184
+ "protocol-violation": "protocol-violation";
185
+ }>>;
186
+ }, z.core.$strict>;
187
+ }, z.core.$strict>;
188
+ export type EvaluationCase = z.infer<typeof evaluationCaseSchema>;
189
+ export type EvaluationRun = z.infer<typeof evaluationRunSchema>;
190
+ export interface EvaluationRunSummary {
191
+ caseId: string;
192
+ runId: string;
193
+ mode: EvaluationRun["mode"];
194
+ correct: boolean;
195
+ requiredFileRecall: number;
196
+ requiredSymbolRecall: number;
197
+ openedFileCount: number;
198
+ sourceTokens: number;
199
+ atlasCallCount: number;
200
+ atlasHandlingCount: number;
201
+ failureClassifications: EvaluationRun["adjudication"]["failureClassifications"];
202
+ }
203
+ export declare function summarizeEvaluationRun(rawCase: unknown, rawRun: unknown): EvaluationRunSummary;
204
+ //# sourceMappingURL=contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/evaluation/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA8BxB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA0C7B,CAAC;AAEL,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAW7B,CAAC;AAEL,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA2CxC,CAAC;AA0BF,eAAO,MAAM,qCAAqC;;;;;;;;EAQhD,CAAC;AAIH,eAAO,MAAM,gCAAgC,mCAAmC,CAAC;AAEjF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAuF5B,CAAC;AAEL,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,sBAAsB,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC,wBAAwB,CAAC,CAAC;CACjF;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,OAAO,GACd,oBAAoB,CAgDtB"}
@@ -0,0 +1,269 @@
1
+ import { z } from "zod";
2
+ const relativeSourcePathSchema = z
3
+ .string()
4
+ .min(1)
5
+ .regex(/^(?!\/)(?!.*\\)(?!.*(?:^|\/)\.\.?(?:\/|$))(?!.*\/\/).+$/, "Expected a normalized repository-relative path");
6
+ const frameworkSchema = z.enum(["nestjs", "graphql", "typeorm", "bullmq"]);
7
+ const fixtureSchema = z.discriminatedUnion("kind", [
8
+ z.strictObject({
9
+ kind: z.literal("synthetic"),
10
+ repository: z.string().min(1),
11
+ revision: z.string().min(1),
12
+ }),
13
+ z.strictObject({
14
+ kind: z.literal("private"),
15
+ repositoryAlias: z.string().min(1),
16
+ revision: z.string().min(1),
17
+ }),
18
+ ]);
19
+ const symbolReferenceSchema = z.strictObject({
20
+ file: relativeSourcePathSchema,
21
+ name: z.string().min(1),
22
+ });
23
+ export const evaluationCaseSchema = z
24
+ .strictObject({
25
+ id: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
26
+ title: z.string().min(1),
27
+ category: z.enum(["location", "dependency-impact"]),
28
+ frameworks: z
29
+ .array(frameworkSchema)
30
+ .min(1)
31
+ .refine((frameworks) => new Set(frameworks).size === frameworks.length, { message: "frameworks must be unique" }),
32
+ fixture: fixtureSchema,
33
+ prompt: z.string().min(1),
34
+ oracle: z.strictObject({
35
+ acceptanceCriteria: z.array(z.string().min(1)).min(1),
36
+ requiredFiles: z.array(relativeSourcePathSchema).min(1),
37
+ requiredSymbols: z.array(symbolReferenceSchema).min(1),
38
+ }),
39
+ })
40
+ .superRefine((evaluationCase, context) => {
41
+ const { acceptanceCriteria, requiredFiles, requiredSymbols } = evaluationCase.oracle;
42
+ addUniqueValueIssue(acceptanceCriteria, context, [
43
+ "oracle",
44
+ "acceptanceCriteria",
45
+ ]);
46
+ addUniqueValueIssue(requiredFiles, context, ["oracle", "requiredFiles"]);
47
+ addUniqueValueIssue(requiredSymbols.map(toSymbolIdentity), context, ["oracle", "requiredSymbols"]);
48
+ const requiredFileSet = new Set(requiredFiles);
49
+ if (requiredSymbols.some((symbol) => !requiredFileSet.has(symbol.file))) {
50
+ context.addIssue({
51
+ code: "custom",
52
+ message: "Every required symbol file must also be a required file",
53
+ path: ["oracle", "requiredSymbols"],
54
+ });
55
+ }
56
+ });
57
+ export const evaluationPlanSchema = z
58
+ .strictObject({
59
+ schemaVersion: z.literal(1),
60
+ cases: z.array(evaluationCaseSchema).min(1),
61
+ })
62
+ .superRefine((plan, context) => {
63
+ addDuplicateIssues(plan.cases.map((evaluationCase) => evaluationCase.id), context, "cases");
64
+ });
65
+ export const baselineEvaluationPlanSchema = evaluationPlanSchema.superRefine((plan, context) => {
66
+ const locationCount = plan.cases.filter((evaluationCase) => evaluationCase.category === "location").length;
67
+ const impactCount = plan.cases.filter((evaluationCase) => evaluationCase.category === "dependency-impact").length;
68
+ if (locationCount !== 6 || impactCount !== 6) {
69
+ context.addIssue({
70
+ code: "custom",
71
+ message: "The baseline must contain six location and six dependency-impact cases",
72
+ path: ["cases"],
73
+ });
74
+ }
75
+ const coveredFrameworks = new Set(plan.cases.flatMap((evaluationCase) => evaluationCase.frameworks));
76
+ for (const framework of frameworkSchema.options) {
77
+ if (!coveredFrameworks.has(framework)) {
78
+ context.addIssue({
79
+ code: "custom",
80
+ message: `The baseline must cover ${framework}`,
81
+ path: ["cases"],
82
+ });
83
+ }
84
+ }
85
+ if (plan.cases.some((evaluationCase) => evaluationCase.fixture.kind !== "synthetic")) {
86
+ context.addIssue({
87
+ code: "custom",
88
+ message: "The published baseline may contain only synthetic fixtures",
89
+ path: ["cases"],
90
+ });
91
+ }
92
+ });
93
+ const sourceOpenSchema = z.strictObject({
94
+ sequence: z.number().int().positive(),
95
+ file: relativeSourcePathSchema,
96
+ sourceTokens: z.number().int().nonnegative(),
97
+ });
98
+ const atlasCallSchema = z.strictObject({
99
+ sequence: z.number().int().positive(),
100
+ command: z.string().min(1),
101
+ });
102
+ const atlasHandlingSchema = z.strictObject({
103
+ sequence: z.number().int().positive(),
104
+ classification: z.enum([
105
+ "stale",
106
+ "hypothesis",
107
+ "unknown",
108
+ "unsupported",
109
+ "partial",
110
+ "insufficient",
111
+ ]),
112
+ action: z.string().min(1),
113
+ });
114
+ export const evaluationFailureClassificationSchema = z.enum([
115
+ "missed-dependency",
116
+ "incorrect-answer",
117
+ "stale-knowledge",
118
+ "hypothesis-mishandled",
119
+ "unknown-boundary-mishandled",
120
+ "unsupported-source",
121
+ "protocol-violation",
122
+ ]);
123
+ const sha256Schema = z.string().regex(/^[a-f0-9]{64}$/);
124
+ export const FRESH_AGENT_COMMAND_AUDIT_POLICY = "fresh-agent-shell-allowlist-v4";
125
+ export const evaluationRunSchema = z
126
+ .strictObject({
127
+ schemaVersion: z.literal(1),
128
+ runId: z.string().min(1),
129
+ caseId: z.string().min(1),
130
+ mode: z.enum(["no-atlas", "atlas"]),
131
+ fixtureRevision: z.string().min(1),
132
+ agent: z.strictObject({
133
+ product: z.string().min(1),
134
+ model: z.string().min(1),
135
+ freshContext: z.literal(true),
136
+ }),
137
+ protocol: z.strictObject({
138
+ runnerVersion: z.string().min(1),
139
+ fixtureCommit: z.string().regex(/^[a-f0-9]{40}$/),
140
+ instructionsHash: sha256Schema,
141
+ toolPolicyHash: sha256Schema,
142
+ oracleHidden: z.literal(true),
143
+ commandAuditPassed: z.literal(true),
144
+ commandAudit: z.strictObject({
145
+ policy: z.literal(FRESH_AGENT_COMMAND_AUDIT_POLICY),
146
+ commands: z.array(z.string().min(1)).min(1),
147
+ }),
148
+ }),
149
+ startedAt: z.iso.datetime(),
150
+ finishedAt: z.iso.datetime(),
151
+ observations: z.strictObject({
152
+ sourceTokenMethod: z.string().min(1),
153
+ sourceOpens: z.array(sourceOpenSchema).min(1),
154
+ atlasCalls: z.array(atlasCallSchema),
155
+ atlasHandling: z.array(atlasHandlingSchema),
156
+ }),
157
+ answer: z.strictObject({
158
+ response: z.string().min(1),
159
+ reportedFiles: z.array(relativeSourcePathSchema),
160
+ reportedSymbols: z.array(symbolReferenceSchema),
161
+ }),
162
+ adjudication: z.strictObject({
163
+ correct: z.boolean(),
164
+ notes: z.string().min(1),
165
+ failureClassifications: z.array(evaluationFailureClassificationSchema),
166
+ }),
167
+ })
168
+ .superRefine((run, context) => {
169
+ if (run.mode === "no-atlas" && run.observations.atlasCalls.length > 0) {
170
+ context.addIssue({
171
+ code: "custom",
172
+ message: "A no-atlas run cannot contain Atlas calls",
173
+ path: ["observations", "atlasCalls"],
174
+ });
175
+ }
176
+ if (run.mode === "atlas" && run.observations.atlasCalls.length === 0) {
177
+ context.addIssue({
178
+ code: "custom",
179
+ message: "An Atlas-assisted run must contain at least one Atlas call",
180
+ path: ["observations", "atlasCalls"],
181
+ });
182
+ }
183
+ if (run.mode === "no-atlas" && run.observations.atlasHandling.length > 0) {
184
+ context.addIssue({
185
+ code: "custom",
186
+ message: "A no-atlas run cannot contain Atlas result handling",
187
+ path: ["observations", "atlasHandling"],
188
+ });
189
+ }
190
+ if (run.adjudication.correct === (run.adjudication.failureClassifications.length > 0)) {
191
+ context.addIssue({
192
+ code: "custom",
193
+ message: "Incorrect answers require failure classifications and correct answers require none",
194
+ path: ["adjudication", "failureClassifications"],
195
+ });
196
+ }
197
+ if (Date.parse(run.finishedAt) < Date.parse(run.startedAt)) {
198
+ context.addIssue({
199
+ code: "custom",
200
+ message: "finishedAt must not precede startedAt",
201
+ path: ["finishedAt"],
202
+ });
203
+ }
204
+ addSequenceIssues(run.observations.sourceOpens, context, "sourceOpens");
205
+ addSequenceIssues(run.observations.atlasCalls, context, "atlasCalls");
206
+ addSequenceIssues(run.observations.atlasHandling, context, "atlasHandling");
207
+ });
208
+ export function summarizeEvaluationRun(rawCase, rawRun) {
209
+ const evaluationCase = evaluationCaseSchema.parse(rawCase);
210
+ const run = evaluationRunSchema.parse(rawRun);
211
+ if (run.caseId !== evaluationCase.id) {
212
+ throw new Error(`Run case ${run.caseId} does not match evaluation case ${evaluationCase.id}`);
213
+ }
214
+ if (run.fixtureRevision !== evaluationCase.fixture.revision) {
215
+ throw new Error(`Run fixture revision ${run.fixtureRevision} does not match ${evaluationCase.fixture.revision}`);
216
+ }
217
+ const reportedFiles = new Set(run.answer.reportedFiles);
218
+ const reportedSymbols = new Set(run.answer.reportedSymbols.map(toSymbolIdentity));
219
+ const openedFiles = new Set(run.observations.sourceOpens.map((sourceOpen) => sourceOpen.file));
220
+ return {
221
+ caseId: evaluationCase.id,
222
+ runId: run.runId,
223
+ mode: run.mode,
224
+ correct: run.adjudication.correct,
225
+ requiredFileRecall: recall(evaluationCase.oracle.requiredFiles, reportedFiles, (file) => file),
226
+ requiredSymbolRecall: recall(evaluationCase.oracle.requiredSymbols, reportedSymbols, toSymbolIdentity),
227
+ openedFileCount: openedFiles.size,
228
+ sourceTokens: run.observations.sourceOpens.reduce((total, sourceOpen) => total + sourceOpen.sourceTokens, 0),
229
+ atlasCallCount: run.observations.atlasCalls.length,
230
+ atlasHandlingCount: run.observations.atlasHandling.length,
231
+ failureClassifications: [...run.adjudication.failureClassifications],
232
+ };
233
+ }
234
+ function recall(required, reported, key) {
235
+ const recalled = required.filter((value) => reported.has(key(value))).length;
236
+ return recalled / required.length;
237
+ }
238
+ function toSymbolIdentity(symbol) {
239
+ return `${symbol.file}#${symbol.name}`;
240
+ }
241
+ function addDuplicateIssues(values, context, path) {
242
+ if (new Set(values).size !== values.length) {
243
+ context.addIssue({
244
+ code: "custom",
245
+ message: `${path} must have unique identifiers`,
246
+ path: [path],
247
+ });
248
+ }
249
+ }
250
+ function addUniqueValueIssue(values, context, path) {
251
+ if (new Set(values).size !== values.length) {
252
+ context.addIssue({
253
+ code: "custom",
254
+ message: "Values must be unique",
255
+ path,
256
+ });
257
+ }
258
+ }
259
+ function addSequenceIssues(events, context, path) {
260
+ for (const [index, event] of events.entries()) {
261
+ if (index > 0 && event.sequence <= events[index - 1].sequence) {
262
+ context.addIssue({
263
+ code: "custom",
264
+ message: `${path} sequence values must be strictly increasing`,
265
+ path: ["observations", path, index, "sequence"],
266
+ });
267
+ }
268
+ }
269
+ }