jev-agent-tools 0.1.4 → 0.3.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 (180) hide show
  1. package/CHANGELOG.md +106 -1
  2. package/CONTRIBUTING.md +43 -0
  3. package/README.md +58 -17
  4. package/SECURITY.md +43 -0
  5. package/dist/adapters/analysis-context.js +75 -0
  6. package/dist/adapters/ask-files.js +198 -0
  7. package/dist/adapters/ask-proof.js +200 -0
  8. package/dist/adapters/ask-syntax.js +385 -0
  9. package/dist/adapters/canonical-path.js +17 -0
  10. package/dist/adapters/command.js +234 -0
  11. package/dist/adapters/docs.js +192 -0
  12. package/dist/adapters/evidence-context.js +119 -0
  13. package/dist/adapters/exec.js +207 -0
  14. package/dist/adapters/files.js +418 -0
  15. package/dist/adapters/find.js +150 -0
  16. package/dist/adapters/git-base.js +32 -0
  17. package/dist/adapters/git-inventory.js +71 -0
  18. package/dist/adapters/git.js +483 -0
  19. package/dist/adapters/locate-file.js +197 -0
  20. package/dist/adapters/output-lines.js +46 -0
  21. package/dist/adapters/private-storage.js +106 -0
  22. package/dist/adapters/risk-callers.js +429 -0
  23. package/dist/adapters/runner-version.js +78 -0
  24. package/dist/adapters/shell.js +92 -0
  25. package/dist/adapters/syntax.js +187 -0
  26. package/dist/adapters/test-inventory.js +139 -0
  27. package/dist/adapters/usage.js +20 -0
  28. package/dist/adapters/utf8.js +47 -0
  29. package/dist/configuration.js +267 -0
  30. package/dist/constants.js +140 -0
  31. package/dist/core/ask-closure.js +282 -0
  32. package/dist/core/ask-proof.js +1 -0
  33. package/dist/core/ask-references.js +278 -0
  34. package/dist/core/asks.js +507 -0
  35. package/dist/core/batches.js +65 -0
  36. package/dist/core/command-output.js +224 -0
  37. package/dist/core/diff.js +178 -0
  38. package/dist/core/docs.js +302 -0
  39. package/dist/core/find.js +108 -0
  40. package/dist/core/git.js +1 -0
  41. package/dist/core/imports.js +550 -0
  42. package/dist/core/integrity.js +45 -0
  43. package/dist/core/lexical.js +132 -0
  44. package/dist/core/locate.js +169 -0
  45. package/dist/core/output.js +137 -0
  46. package/dist/core/pointer.js +29 -0
  47. package/dist/core/result-report.js +302 -0
  48. package/dist/core/risk-callers.js +851 -0
  49. package/dist/core/runner-version.js +45 -0
  50. package/dist/core/secret-path.js +34 -0
  51. package/dist/core/sections.js +230 -0
  52. package/dist/core/state.js +51 -0
  53. package/dist/core/syntax.js +1 -0
  54. package/dist/core/test-commands.js +334 -0
  55. package/dist/core/test-coverage.js +74 -0
  56. package/dist/core/test-discovery.js +1382 -0
  57. package/dist/core/test-evidence.js +527 -0
  58. package/dist/core/test-state.js +81 -0
  59. package/dist/core/truncate.js +12 -0
  60. package/dist/core/units.js +349 -0
  61. package/dist/describe.js +23 -0
  62. package/dist/guide.js +33 -0
  63. package/dist/host.js +24 -0
  64. package/dist/jev/client.js +456 -0
  65. package/dist/jev/pool.js +54 -0
  66. package/dist/jev/types.js +1 -0
  67. package/dist/mcp/main.js +124 -0
  68. package/dist/mcp/protocol.js +210 -0
  69. package/dist/mcp/tools.js +129 -0
  70. package/dist/presets/docs.js +62 -0
  71. package/dist/presets/risk.js +179 -0
  72. package/dist/presets/spec.js +81 -0
  73. package/dist/presets/witnesses.js +249 -0
  74. package/dist/render.js +114 -0
  75. package/dist/report-schema.js +1356 -0
  76. package/dist/result-types.js +1 -0
  77. package/dist/result.js +3 -0
  78. package/dist/runtime.js +1 -0
  79. package/dist/session.js +147 -0
  80. package/dist/texts/ask-files.js +3 -0
  81. package/dist/texts/ask.js +4 -0
  82. package/dist/texts/check-diff.js +20 -0
  83. package/dist/texts/configuration.js +1 -0
  84. package/dist/texts/find.js +19 -0
  85. package/dist/texts/guide.js +3 -0
  86. package/dist/texts/instructions.js +72 -0
  87. package/dist/texts/locate.js +15 -0
  88. package/dist/texts/select-tests.js +4 -0
  89. package/dist/tools/ask-files.js +450 -0
  90. package/dist/tools/ask-schema.js +70 -0
  91. package/dist/tools/ask.js +1147 -0
  92. package/dist/tools/check-diff.js +594 -0
  93. package/dist/tools/docs-check.js +408 -0
  94. package/dist/tools/find.js +682 -0
  95. package/dist/tools/locate.js +602 -0
  96. package/dist/tools/review-report.js +230 -0
  97. package/dist/tools/select-tests.js +821 -0
  98. package/dist/tools/spec-check.js +263 -0
  99. package/docs/adr/0001-strict-typescript-pure-core-offline-tests.md +31 -0
  100. package/docs/adr/0002-one-http-protocol-across-hosts.md +17 -0
  101. package/docs/adr/0003-explicit-scope-conservative-automation.md +19 -0
  102. package/docs/adr/0004-compiled-typed-intents.md +19 -0
  103. package/docs/adr/0005-evidence-construction-before-judgment.md +19 -0
  104. package/docs/adr/0006-visible-uncertainty-constrained-controls.md +21 -0
  105. package/docs/adr/0007-bounded-evidence-visible-limits.md +21 -0
  106. package/docs/adr/0008-static-test-discovery-conservative-plans.md +19 -0
  107. package/docs/adr/0009-session-cache-requested-model-identity.md +17 -0
  108. package/docs/adr/0010-mcp-server-thin-host.md +23 -0
  109. package/docs/agent-instructions.md +120 -0
  110. package/docs/design.md +16 -4
  111. package/docs/mcp.md +233 -0
  112. package/docs/tools/jev_ask.md +8 -5
  113. package/docs/tools/jev_ask_files.md +2 -1
  114. package/docs/tools/jev_check_diff.md +4 -1
  115. package/docs/tools/jev_find_files.md +2 -1
  116. package/docs/tools/jev_locate_in_file.md +5 -0
  117. package/docs/tools/jev_select_tests.md +4 -1
  118. package/package.json +19 -4
  119. package/rules/jev-ask.md +22 -1
  120. package/server.json +57 -0
  121. package/src/adapters/ask-files.ts +11 -3
  122. package/src/adapters/ask-proof.ts +69 -11
  123. package/src/adapters/canonical-path.ts +18 -0
  124. package/src/adapters/command.ts +102 -36
  125. package/src/adapters/docs.ts +33 -14
  126. package/src/adapters/evidence-context.ts +169 -0
  127. package/src/adapters/exec.ts +226 -0
  128. package/src/adapters/files.ts +146 -16
  129. package/src/adapters/find.ts +37 -7
  130. package/src/adapters/git-base.ts +7 -1
  131. package/src/adapters/git.ts +61 -8
  132. package/src/adapters/locate-file.ts +51 -9
  133. package/src/adapters/private-storage.ts +155 -0
  134. package/src/adapters/risk-callers.ts +7 -2
  135. package/src/adapters/shell.ts +113 -0
  136. package/src/adapters/test-inventory.ts +12 -4
  137. package/src/configuration.ts +55 -14
  138. package/src/constants.ts +37 -5
  139. package/src/core/ask-references.ts +262 -146
  140. package/src/core/asks.ts +79 -7
  141. package/src/core/command-output.ts +17 -1
  142. package/src/core/import-boundaries.ts +8 -3
  143. package/src/core/locate.ts +8 -5
  144. package/src/core/output.ts +34 -0
  145. package/src/core/result-report.ts +410 -0
  146. package/src/core/secret-path.ts +37 -0
  147. package/src/core/state.ts +8 -1
  148. package/src/core/units.ts +3 -2
  149. package/src/host.ts +11 -0
  150. package/src/index.ts +3 -0
  151. package/src/jev/client.ts +66 -16
  152. package/src/jev/types.ts +24 -3
  153. package/src/mcp/main.ts +135 -0
  154. package/src/mcp/protocol.ts +332 -0
  155. package/src/mcp/tools.ts +179 -0
  156. package/src/render.ts +109 -0
  157. package/src/report-schema.ts +1380 -0
  158. package/src/result-types.ts +234 -0
  159. package/src/result.ts +4 -1
  160. package/src/runtime.ts +6 -0
  161. package/src/session.ts +59 -0
  162. package/src/setup.ts +13 -5
  163. package/src/texts/ask-files.ts +4 -1
  164. package/src/texts/ask.ts +8 -1
  165. package/src/texts/check-diff.ts +7 -4
  166. package/src/texts/find.ts +8 -2
  167. package/src/texts/guide.ts +8 -16
  168. package/src/texts/instructions.ts +98 -0
  169. package/src/texts/locate.ts +8 -2
  170. package/src/texts/run-end.ts +2 -2
  171. package/src/texts/select-tests.ts +4 -1
  172. package/src/tools/ask-files.ts +311 -18
  173. package/src/tools/ask.ts +722 -95
  174. package/src/tools/check-diff.ts +337 -31
  175. package/src/tools/docs-check.ts +241 -38
  176. package/src/tools/find.ts +389 -29
  177. package/src/tools/locate.ts +387 -25
  178. package/src/tools/review-report.ts +308 -0
  179. package/src/tools/select-tests.ts +484 -23
  180. package/src/tools/spec-check.ts +194 -19
@@ -0,0 +1,230 @@
1
+ import { answerItemFromInput, buildResultReport, contextFromEvidence, known, unknown, } from "../core/result-report.js";
2
+ export function reportMetrics(envelope) {
3
+ const line = envelope.lines.find((line) => line.type === "yield");
4
+ if (line?.type !== "yield")
5
+ throw new Error("Report metrics missing from envelope");
6
+ return line.value;
7
+ }
8
+ export function controlsFor(id, judgment, witnessIds) {
9
+ const batches = judgment.batches?.filter((batch) => batch.questionIds.includes(id));
10
+ const responses = batches?.length
11
+ ? batches.map((batch) => batch.answers)
12
+ : [judgment.ok ? judgment.answers : {}];
13
+ return responses.flatMap((answers) => witnessIds.map((witnessId) => answers[witnessId] ?? {
14
+ type: "unjudged",
15
+ reason: "Required witness response unavailable",
16
+ }));
17
+ }
18
+ /** Producer-owned inventory: register before admission, retain negative answers too. */
19
+ export class ReviewReport {
20
+ items = new Map();
21
+ diagnostics = [];
22
+ actions = [];
23
+ inventories = [];
24
+ auxiliary = {
25
+ controls: { fresh: 0, cache: 0, notJudged: 0, static: 0 },
26
+ passages: { fresh: 0, cache: 0, notJudged: 0 },
27
+ };
28
+ refusal = false;
29
+ missingWork = false;
30
+ totalUnknown = false;
31
+ countControls(judgment, ids) {
32
+ const batches = judgment.batches ?? [
33
+ { answers: judgment.ok ? judgment.answers : {}, questionIds: ids },
34
+ ];
35
+ for (const batch of batches)
36
+ for (const id of ids) {
37
+ if (!batch.questionIds.includes(id) && judgment.batches)
38
+ continue;
39
+ const answer = batch.answers[id];
40
+ this.auxiliary.controls[answer && answer.type !== "unjudged" && answer.source
41
+ ? answer.source
42
+ : "notJudged"]++;
43
+ }
44
+ }
45
+ expect(id, label, kind, groupId = id) {
46
+ if (!this.items.has(id))
47
+ this.items.set(id, {
48
+ id,
49
+ label,
50
+ kind,
51
+ groupId,
52
+ evidence: [],
53
+ diagnosticIds: [],
54
+ actionIds: [],
55
+ treatment: "not_judged",
56
+ source: "none",
57
+ });
58
+ }
59
+ diagnose(cause, fact, target, itemIds = [], blocking = true, omittedMembers = []) {
60
+ const id = `diagnostic:${this.diagnostics.length}`;
61
+ const actionId = `action:${this.actions.length}`;
62
+ const scope = itemIds.length
63
+ ? { kind: "item", itemIds }
64
+ : { kind: "call" };
65
+ const code = cause === "invalid_root" || cause === "invalid_base"
66
+ ? "correct_context"
67
+ : cause === "not_configured"
68
+ ? "configure_client"
69
+ : cause === "service_unavailable" || cause === "transport_failure"
70
+ ? "recover_service"
71
+ : "inspect_native";
72
+ this.actions.push({
73
+ id: actionId,
74
+ code,
75
+ target: target === undefined
76
+ ? unknown("target not established")
77
+ : known(target),
78
+ scope,
79
+ condition: "Only after the named context, evidence, or service condition materially changes; otherwise use native inspection or the retained runner plan.",
80
+ instruction: code === "correct_context"
81
+ ? "Correct the named repository root or base if it does not match the intended comparison."
82
+ : code === "configure_client"
83
+ ? "Configure the required Jev endpoint before requesting judgment; use native inspection meanwhile."
84
+ : code === "recover_service"
85
+ ? "Establish service recovery before another useful judgment request; do not repeat the unchanged call."
86
+ : "Inspect the named evidence natively or execute the retained runner plan; preserve this limitation.",
87
+ repeatUnchanged: false,
88
+ });
89
+ this.diagnostics.push({
90
+ id,
91
+ cause,
92
+ fact,
93
+ target: target === undefined
94
+ ? unknown("target not established")
95
+ : known(target),
96
+ origin: cause === "control_failure"
97
+ ? "control"
98
+ : cause === "call_budget" || cause === "session_budget"
99
+ ? "budget"
100
+ : cause === "not_configured" ||
101
+ cause === "service_unavailable" ||
102
+ cause === "transport_failure" ||
103
+ cause === "invalid_response" ||
104
+ cause === "provider_context_refusal"
105
+ ? "provider"
106
+ : "collection",
107
+ scope,
108
+ effect: blocking ? "blocking" : "reservation",
109
+ material: true,
110
+ omittedMembers,
111
+ memberCount: known(omittedMembers.length),
112
+ actionIds: [actionId],
113
+ });
114
+ for (const itemId of itemIds) {
115
+ const item = this.items.get(itemId);
116
+ if (item) {
117
+ item.diagnosticIds.push(id);
118
+ item.actionIds.push(actionId);
119
+ }
120
+ }
121
+ }
122
+ static(id, reason, selected) {
123
+ const item = this.items.get(id);
124
+ if (!item)
125
+ throw new Error(`Unregistered review result ${id}`);
126
+ this.items.set(id, {
127
+ ...item,
128
+ treatment: "static",
129
+ source: "none",
130
+ staticReason: reason,
131
+ ...(selected === undefined ? {} : { selection: { selected, reason } }),
132
+ });
133
+ }
134
+ answer(id, answer, input = {}, controls = [], countControls = true) {
135
+ const item = this.items.get(id);
136
+ if (!item)
137
+ throw new Error(`Unregistered review result ${id}`);
138
+ const unavailable = !answer || answer.type === "unjudged" || !answer.source;
139
+ const missingControl = controls.some((control) => control.type === "unjudged" || !control.source);
140
+ if (countControls)
141
+ for (const control of controls)
142
+ this.auxiliary.controls[control.type === "unjudged" || !control.source
143
+ ? "notJudged"
144
+ : control.source]++;
145
+ if (unavailable || missingControl) {
146
+ this.diagnose(missingControl
147
+ ? "control_failure"
148
+ : answer?.type === "unjudged"
149
+ ? (answer.cause ?? "invalid_response")
150
+ : "invalid_response", missingControl
151
+ ? "Required control response is unavailable; the requested group has no admissible judgment."
152
+ : answer?.type === "unjudged"
153
+ ? answer.reason
154
+ : "Requested answer or its transport provenance is unavailable.", item.label, [id]);
155
+ return;
156
+ }
157
+ const valid = answer;
158
+ const rawValues = valid.type === "bool"
159
+ ? [{ label: "true", value: true, probability: known(valid.p) }]
160
+ : Object.entries(valid.probabilities).map(([label, p]) => ({
161
+ label,
162
+ value: label,
163
+ probability: known(p),
164
+ }));
165
+ this.items.set(id, answerItemFromInput(item, {
166
+ label: item.label,
167
+ answer: valid,
168
+ source: valid.source,
169
+ band: "verdict",
170
+ rawValues,
171
+ ...input,
172
+ reportControls: controls.map((control, index) => {
173
+ const source = control.source;
174
+ if (!source)
175
+ throw new Error("Admitted control lacks provenance");
176
+ return {
177
+ id: `${id}:control:${index}`,
178
+ kind: "integrity",
179
+ source,
180
+ outcome: control.type === "bool"
181
+ ? String(control.p)
182
+ : control.type === "choice"
183
+ ? control.choice
184
+ : control.type === "score"
185
+ ? String(control.score)
186
+ : control.reason,
187
+ rawValues: control.type === "choice" || control.type === "score"
188
+ ? Object.entries(control.probabilities).map(([label, p]) => ({
189
+ label,
190
+ value: label,
191
+ probability: known(p),
192
+ }))
193
+ : control.type === "bool"
194
+ ? [
195
+ {
196
+ label: "true",
197
+ value: true,
198
+ probability: known(control.p),
199
+ },
200
+ ]
201
+ : [],
202
+ };
203
+ }),
204
+ }));
205
+ }
206
+ failure(judgment, ids, cause) {
207
+ this.diagnose(cause ??
208
+ (!judgment.ok ? judgment.cause : undefined) ??
209
+ judgment.failureCause ??
210
+ "invalid_response", judgment.ok ? "Required responses unavailable" : judgment.error, undefined, ids);
211
+ }
212
+ build(tool, evidence, metrics) {
213
+ const context = contextFromEvidence(evidence);
214
+ context.inventories = this.inventories;
215
+ return buildResultReport({
216
+ tool,
217
+ context,
218
+ items: [...this.items.values()],
219
+ diagnostics: this.diagnostics,
220
+ actions: this.actions,
221
+ metrics,
222
+ auxiliary: this.auxiliary,
223
+ total: this.totalUnknown || (!this.inventories.length && !this.items.size)
224
+ ? unknown("Expected inventory was not completely enumerable")
225
+ : known(this.items.size),
226
+ refused: this.refusal,
227
+ missingWork: this.missingWork,
228
+ });
229
+ }
230
+ }