zyntry-verdict 0.0.0-stage → 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.
- package/README.md +55 -2
- package/bin/zv.mjs +636 -0
- package/package.json +30 -3
package/README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# zyntry-verdict
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The hosted **AI courtroom** that verifies AI work — from your terminal.
|
|
4
|
+
|
|
5
|
+
You submit code; three adversarial AI agents investigate it, challenge every claim
|
|
6
|
+
with real executed tests, fix what's broken against a **sealed standard** you
|
|
7
|
+
control, and return one honest verdict: `resolved-verified` or `unresolved`.
|
|
8
|
+
|
|
9
|
+
Zero dependencies. Node >= 18.
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx zyntry-verdict signup # API key + $5 trial credits (no card)
|
|
15
|
+
npx zyntry-verdict provider meta --key <YOUR_MODEL_KEY> # BYOK: your model, your tokens
|
|
16
|
+
npx zyntry-verdict run multi-tenant-auth # watch the courtroom live
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The run streams the proceedings in your terminal — every proposal, APPROVED /
|
|
20
|
+
REJECTED rulings, claim transitions (`asserted → refuted → verified`) — and exits
|
|
21
|
+
`0` only when the verdict is `resolved-verified`, so it composes with scripts
|
|
22
|
+
and CI.
|
|
23
|
+
|
|
24
|
+
## Commands
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
signup create an API key with trial credits
|
|
28
|
+
balance credits + usage
|
|
29
|
+
topup <amount 5-500> pay via hosted checkout (card, bank transfer, mobile
|
|
30
|
+
money, crypto) — credits land automatically
|
|
31
|
+
provider [name] show or set YOUR model provider (meta | openai | ollama |
|
|
32
|
+
custom) — [--key <KEY>] or ZV_PROVIDER_KEY env
|
|
33
|
+
cases list available case packs
|
|
34
|
+
run <caseId> open the courtroom and stream the verdict live
|
|
35
|
+
[--mode route|courtroom] [--gateway <url>]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## How it works
|
|
39
|
+
|
|
40
|
+
1. **Route** — a cheap triage pass checks the work first ($0.03). If the sealed
|
|
41
|
+
standard passes, you're done. If it fails, the full courtroom opens ($0.75).
|
|
42
|
+
2. **Court** — an Investigigator builds the picture, a Challenger writes
|
|
43
|
+
exploit tests to break claims, a Proponent defends and fixes the code.
|
|
44
|
+
Claims are only `verified` when an executed test proves them.
|
|
45
|
+
3. **Verdict** — streamed live, stored forever, exportable as a markdown audit
|
|
46
|
+
report.
|
|
47
|
+
|
|
48
|
+
Bring your own model key (Meta, OpenAI, Ollama, or any OpenAI-compatible
|
|
49
|
+
endpoint). You pay your own token costs at cost — Zyntry charges only the
|
|
50
|
+
verdict fees.
|
|
51
|
+
|
|
52
|
+
## Links
|
|
53
|
+
|
|
54
|
+
- Gateway: https://verdict.zyntry.space
|
|
55
|
+
- MCP: same gateway, `/v1/mcp`
|
|
56
|
+
- GitHub Action: submit PRs to the courtroom from CI
|
package/bin/zv.mjs
ADDED
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// zyntry-verdict — thin client for the hosted Zyntry Verdict courtroom.
|
|
3
|
+
// Zero dependencies: fetch + filesystem + an SSE parser, nothing else.
|
|
4
|
+
//
|
|
5
|
+
// zyntry-verdict signup create an API key (trial credits)
|
|
6
|
+
// zyntry-verdict balance credits + usage
|
|
7
|
+
// zyntry-verdict run <caseId> [--mode route|courtroom]
|
|
8
|
+
// zyntry-verdict cases list available case packs
|
|
9
|
+
//
|
|
10
|
+
// Streams the live courtroom (Asserted → Disputed → Refuted → Verified) in
|
|
11
|
+
// ASCII and exits 0 only on resolved-verified.
|
|
12
|
+
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { chmodSync } from "node:fs";
|
|
16
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
17
|
+
|
|
18
|
+
const CONFIG_PATH = join(homedir(), ".zyntry", "config.json");
|
|
19
|
+
const DIM = (s) => `\x1b[2m${s}\x1b[0m`;
|
|
20
|
+
const BOLD = (s) => `\x1b[1m${s}\x1b[0m`;
|
|
21
|
+
const GREEN = (s) => `\x1b[32m${s}\x1b[0m`;
|
|
22
|
+
const RED = (s) => `\x1b[31m${s}\x1b[0m`;
|
|
23
|
+
const GOLD = (s) => `\x1b[33m${s}\x1b[0m`;
|
|
24
|
+
|
|
25
|
+
async function loadConfig() {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(await readFile(CONFIG_PATH, "utf8"));
|
|
28
|
+
} catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function saveConfig(config) {
|
|
34
|
+
await mkdir(join(homedir(), ".zyntry"), { recursive: true });
|
|
35
|
+
await writeFile(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
36
|
+
try {
|
|
37
|
+
chmodSync(CONFIG_PATH, 0o600); // owner-only — the key file must not be world-readable
|
|
38
|
+
} catch {
|
|
39
|
+
// some filesystems don't support chmod — the write still happened
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function gatewayUrl(flags) {
|
|
44
|
+
return flags.gateway ?? process.env.ZV_GATEWAY ?? "https://verdict.zyntry.space";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Auto-detect the caseId from the current repo's .zyntry.case.json */
|
|
48
|
+
async function detectCaseId(positional) {
|
|
49
|
+
if (positional[0]) return positional[0];
|
|
50
|
+
try {
|
|
51
|
+
const caseFile = await readFile(join(process.cwd(), ".zyntry.case.json"), "utf8");
|
|
52
|
+
const parsed = JSON.parse(caseFile);
|
|
53
|
+
if (typeof parsed.id === "string") return parsed.id;
|
|
54
|
+
} catch {
|
|
55
|
+
// no case file — caller must provide one
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function authHeaders(config) {
|
|
61
|
+
if (!config.key) {
|
|
62
|
+
console.error("Not signed up. Run: zyntry-verdict signup");
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
return { Authorization: `Bearer ${config.key}`, "Content-Type": "application/json" };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function api(config, flags, path, init) {
|
|
69
|
+
const res = await fetch(`${gatewayUrl(flags)}${path}`, init);
|
|
70
|
+
const body = await res.json().catch(() => ({}));
|
|
71
|
+
if (!res.ok) {
|
|
72
|
+
console.error(`${res.status}: ${body.error ?? res.statusText}`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
return body;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// --- SSE stream (fetch ReadableStream) --------------------------------------
|
|
79
|
+
|
|
80
|
+
async function* sseEvents(response) {
|
|
81
|
+
const reader = response.body.getReader();
|
|
82
|
+
const decoder = new TextDecoder();
|
|
83
|
+
let buffer = "";
|
|
84
|
+
while (true) {
|
|
85
|
+
const { done, value } = await reader.read();
|
|
86
|
+
if (done) break;
|
|
87
|
+
buffer += decoder.decode(value, { stream: true });
|
|
88
|
+
let index;
|
|
89
|
+
while ((index = buffer.indexOf("\n\n")) !== -1) {
|
|
90
|
+
const chunk = buffer.slice(0, index);
|
|
91
|
+
buffer = buffer.slice(index + 2);
|
|
92
|
+
const dataLines = chunk.split("\n").filter((l) => l.startsWith("data: "));
|
|
93
|
+
if (dataLines.length > 0) {
|
|
94
|
+
const data = dataLines.map((l) => l.slice(6)).join("\n");
|
|
95
|
+
try {
|
|
96
|
+
yield JSON.parse(data);
|
|
97
|
+
} catch {
|
|
98
|
+
// non-JSON event — ignore
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// --- NDJSON reader (hosted gateway streams raw JSON lines on submit) -------
|
|
106
|
+
|
|
107
|
+
async function* ndjsonLines(response) {
|
|
108
|
+
const reader = response.body.getReader();
|
|
109
|
+
const decoder = new TextDecoder();
|
|
110
|
+
let buffer = "";
|
|
111
|
+
while (true) {
|
|
112
|
+
const { done, value } = await reader.read();
|
|
113
|
+
if (done) break;
|
|
114
|
+
buffer += decoder.decode(value, { stream: true });
|
|
115
|
+
let index;
|
|
116
|
+
while ((index = buffer.indexOf("\n")) !== -1) {
|
|
117
|
+
const line = buffer.slice(0, index).trim();
|
|
118
|
+
buffer = buffer.slice(index + 1);
|
|
119
|
+
if (!line) continue;
|
|
120
|
+
try {
|
|
121
|
+
yield JSON.parse(line);
|
|
122
|
+
} catch {
|
|
123
|
+
// incomplete/partial line — skip
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// --- watch: auto-verdict on file change (the safety net) ------------------
|
|
130
|
+
|
|
131
|
+
async function cmdWatch(config, flags, positional) {
|
|
132
|
+
const caseId = positional[0];
|
|
133
|
+
const debounceMs = Number(flags.debounce ?? 30) * 1000; // seconds after last change
|
|
134
|
+
if (!caseId) {
|
|
135
|
+
console.error("usage: zyntry-verdict watch <caseId> [--debounce 30]");
|
|
136
|
+
console.error(" watches the current directory; when code changes, submits a verdict automatically");
|
|
137
|
+
process.exit(2);
|
|
138
|
+
}
|
|
139
|
+
const { watch } = await import("node:fs");
|
|
140
|
+
const path = await import("node:path");
|
|
141
|
+
const cwd = process.cwd();
|
|
142
|
+
const ignorePatterns = [/node_modules/, /\.git/, /out/, /dist/, /\.wrangler/, /gateway-data/];
|
|
143
|
+
|
|
144
|
+
console.log(GOLD("⚖ ZYNTRY VERDICT — watch mode"));
|
|
145
|
+
console.log(DIM(` case: ${caseId} · debounce: ${debounceMs / 1000}s · watching: ${cwd}`));
|
|
146
|
+
console.log(DIM(" code changes → verdict runs automatically. Ctrl+C to stop."));
|
|
147
|
+
console.log("");
|
|
148
|
+
|
|
149
|
+
let timer = null;
|
|
150
|
+
let running = false;
|
|
151
|
+
let changes = 0;
|
|
152
|
+
|
|
153
|
+
const submitVerdict = async (reason) => {
|
|
154
|
+
if (running) return;
|
|
155
|
+
running = true;
|
|
156
|
+
const timestamp = new Date().toISOString().slice(11, 19);
|
|
157
|
+
console.log(`\n${GOLD(`[${timestamp}]`)} ${changes} file change(s) detected (${reason}) — submitting verdict...`);
|
|
158
|
+
try {
|
|
159
|
+
const submitRes = await fetch(`${gatewayUrl(flags)}/v1/verdicts`, {
|
|
160
|
+
method: "POST",
|
|
161
|
+
headers: authHeaders(config),
|
|
162
|
+
body: JSON.stringify({ caseId, mode: "route" }),
|
|
163
|
+
});
|
|
164
|
+
if (submitRes.status === 402) {
|
|
165
|
+
console.error(RED(" credits exhausted — top up: zyntry-verdict topup 20"));
|
|
166
|
+
running = false;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (submitRes.status === 429) {
|
|
170
|
+
console.error(DIM(" rate limited — backing off 60s"));
|
|
171
|
+
await new Promise((r) => setTimeout(r, 60000));
|
|
172
|
+
running = false;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (!submitRes.ok) {
|
|
176
|
+
const body = await submitRes.json().catch(() => ({}));
|
|
177
|
+
console.error(RED(` submit failed: ${submitRes.status} ${body.error ?? ""}`));
|
|
178
|
+
running = false;
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const verdictId = submitRes.headers.get("x-verdict-id");
|
|
183
|
+
const contentType = submitRes.headers.get("content-type") ?? "";
|
|
184
|
+
let summary = null;
|
|
185
|
+
changes = 0;
|
|
186
|
+
|
|
187
|
+
if (contentType.includes("x-ndjson")) {
|
|
188
|
+
for await (const event of ndjsonLines(submitRes)) {
|
|
189
|
+
if (event.done !== undefined && event.summary) {
|
|
190
|
+
summary = { ...event.summary };
|
|
191
|
+
} else if (event.snapshot) {
|
|
192
|
+
const state = event.snapshot.state;
|
|
193
|
+
if (state) {
|
|
194
|
+
for (const claim of state.claims ?? []) {
|
|
195
|
+
const mark = claim.status === "verified" ? GREEN("✓") : claim.status === "refuted" ? RED("✗") : DIM("·");
|
|
196
|
+
console.log(` ${mark} ${claim.id}: ${claim.status}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (summary) {
|
|
204
|
+
const passed = summary.verdict === "resolved-verified";
|
|
205
|
+
console.log("");
|
|
206
|
+
console.log(
|
|
207
|
+
passed
|
|
208
|
+
? GREEN(` VERDICT: ${summary.verdict} (${summary.calls} calls)`)
|
|
209
|
+
: RED(` VERDICT: ${summary.verdict} — ${summary.verdictReason ?? "not done"} (${summary.calls} calls)`),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
} catch (error) {
|
|
213
|
+
console.error(DIM(` verdict error: ${error.message}`));
|
|
214
|
+
}
|
|
215
|
+
running = false;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
const watcher = watch(cwd, { recursive: true }, (eventType, filename) => {
|
|
220
|
+
const rel = String(filename ?? "").replace(/\\/g, "/");
|
|
221
|
+
if (ignorePatterns.some((p) => p.test(rel))) return;
|
|
222
|
+
changes += 1;
|
|
223
|
+
if (timer) clearTimeout(timer);
|
|
224
|
+
timer = setTimeout(() => submitVerdict(rel), debounceMs);
|
|
225
|
+
process.stdout.write(DIM(`\r change: ${rel}`));
|
|
226
|
+
});
|
|
227
|
+
process.on("SIGINT", () => {
|
|
228
|
+
watcher.close();
|
|
229
|
+
console.log("\n" + DIM("watch stopped"));
|
|
230
|
+
process.exit(0);
|
|
231
|
+
});
|
|
232
|
+
} catch (error) {
|
|
233
|
+
console.error(RED(`cannot watch ${cwd}: ${error.message}`));
|
|
234
|
+
process.exit(1);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// --- gate: one-shot for git hooks --------------------------------------------
|
|
239
|
+
|
|
240
|
+
async function cmdGate(config, flags, positional) {
|
|
241
|
+
const caseId = positional[0] ?? flags.case;
|
|
242
|
+
if (!caseId) {
|
|
243
|
+
console.error("usage: zyntry-verdict gate <caseId> (or --case <caseId>)");
|
|
244
|
+
console.error(" designed for git pre-commit hooks — exits 0 only on resolved-verified");
|
|
245
|
+
process.exit(2);
|
|
246
|
+
}
|
|
247
|
+
console.log(GOLD("⚖ ZYNTRY VERDICT — gate") + DIM(` case: ${caseId}`));
|
|
248
|
+
const submitRes = await fetch(`${gatewayUrl(flags)}/v1/verdicts`, {
|
|
249
|
+
method: "POST",
|
|
250
|
+
headers: authHeaders(config),
|
|
251
|
+
body: JSON.stringify({ caseId, mode: "route" }),
|
|
252
|
+
}).catch((e) => {
|
|
253
|
+
console.error(RED(`cannot reach gateway: ${e.message}`));
|
|
254
|
+
process.exit(1);
|
|
255
|
+
});
|
|
256
|
+
if (submitRes.status === 402) {
|
|
257
|
+
console.error(RED("insufficient credits — verdict not run, commit allowed (fail-open on billing)"));
|
|
258
|
+
process.exit(0); // billing must not block commits
|
|
259
|
+
}
|
|
260
|
+
if (!submitRes.ok) {
|
|
261
|
+
const body = await submitRes.json().catch(() => ({}));
|
|
262
|
+
console.error(RED(`verdict submit failed: ${submitRes.status} ${body.error ?? ""}`));
|
|
263
|
+
process.exit(0); // infra errors must not block commits
|
|
264
|
+
}
|
|
265
|
+
const contentType = submitRes.headers.get("content-type") ?? "";
|
|
266
|
+
let summary = null;
|
|
267
|
+
if (contentType.includes("x-ndjson")) {
|
|
268
|
+
for await (const event of ndjsonLines(submitRes)) {
|
|
269
|
+
if (event.done !== undefined && event.summary) summary = { ...event.summary };
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (!summary) {
|
|
273
|
+
console.error(RED("verdict did not complete — commit allowed"));
|
|
274
|
+
process.exit(0);
|
|
275
|
+
}
|
|
276
|
+
const passed = summary.verdict === "resolved-verified";
|
|
277
|
+
console.log(
|
|
278
|
+
passed
|
|
279
|
+
? GREEN(` ✓ ${summary.verdict} (${summary.calls} calls)`)
|
|
280
|
+
: RED(` ✗ ${summary.verdict} — ${summary.verdictReason ?? "not done"} (${summary.calls} calls)`),
|
|
281
|
+
);
|
|
282
|
+
process.exit(passed ? 0 : 1);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function cmdCertify(config, flags, positional) {
|
|
286
|
+
const verdictId = positional[0];
|
|
287
|
+
if (!verdictId) {
|
|
288
|
+
console.error("usage: zyntry-verdict certify <verdictId> [-o cert.json]");
|
|
289
|
+
process.exit(2);
|
|
290
|
+
}
|
|
291
|
+
const body = await api(config, flags, `/v1/verdicts/${verdictId}/certificate`, { headers: authHeaders(config) });
|
|
292
|
+
const outPath = flags.o;
|
|
293
|
+
if (outPath) {
|
|
294
|
+
const { writeFile: wf } = await import("node:fs/promises");
|
|
295
|
+
await wf(outPath, JSON.stringify(body, null, 2));
|
|
296
|
+
console.log(GREEN("✓ certificate written") + ` -> ${outPath}`);
|
|
297
|
+
} else {
|
|
298
|
+
console.log(JSON.stringify(body, null, 2));
|
|
299
|
+
}
|
|
300
|
+
if (body.hiddenStandardPass) {
|
|
301
|
+
console.log("");
|
|
302
|
+
console.log(GREEN(` Signed proof: ${body.caseId} was verified on ${body.verifiedAt}`));
|
|
303
|
+
console.log(DIM(` Signature: ${body.signature?.slice(0, 16)}...`));
|
|
304
|
+
} else {
|
|
305
|
+
console.log("");
|
|
306
|
+
console.log(RED(" ⚠ verdict was NOT resolved-verified — certificate records the failure"));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async function cmdStandards(config, flags, positional) {
|
|
311
|
+
const caseId = positional[0];
|
|
312
|
+
if (!caseId) {
|
|
313
|
+
console.error("usage: zyntry-verdict standards <caseId>");
|
|
314
|
+
process.exit(2);
|
|
315
|
+
}
|
|
316
|
+
const body = await api(config, flags, `/v1/cases/${caseId}/standards`, { headers: authHeaders(config) });
|
|
317
|
+
console.log(GOLD("⚖ STANDARDS GROWTH") + ` — ${caseId}`);
|
|
318
|
+
console.log("");
|
|
319
|
+
console.log(` base tests: ${BOLD(String(body.baseTests))}`);
|
|
320
|
+
console.log(` court-discovered: ${GREEN(String(body.courtTests))} (added by the challenger)`);
|
|
321
|
+
console.log(` total standard: ${BOLD(String(body.totalStandard))}`);
|
|
322
|
+
console.log("");
|
|
323
|
+
if (body.timeline.length > 0) {
|
|
324
|
+
console.log(DIM(" timeline:"));
|
|
325
|
+
console.log(DIM(" " + "─".repeat(70)));
|
|
326
|
+
for (const t of body.timeline) {
|
|
327
|
+
const source = t.source === "court" ? GREEN("court") : DIM("base ");
|
|
328
|
+
const date = t.addedAt?.slice(0, 10) ?? "?";
|
|
329
|
+
console.log(` ${DIM(date)} [${source}] ${t.testName}`);
|
|
330
|
+
if (t.note) console.log(` ${DIM(t.note.slice(0, 80))}`);
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
console.log(DIM(" no standard history yet — run a verdict first"));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// --- courtroom ASCII renderer -------------------------------------------------
|
|
338
|
+
|
|
339
|
+
function renderStream() {
|
|
340
|
+
let actionsSeen = 0;
|
|
341
|
+
const claimStatus = new Map();
|
|
342
|
+
return (snapshot) => {
|
|
343
|
+
const state = snapshot.state;
|
|
344
|
+
if (!state) return;
|
|
345
|
+
for (const action of state.actionLog.slice(actionsSeen)) {
|
|
346
|
+
actionsSeen += 1;
|
|
347
|
+
const p = action.proposal;
|
|
348
|
+
if (!p) {
|
|
349
|
+
const note = action.actor === "court" ? GOLD(`⚖ ${action.resultSummary ?? ""}`) : DIM(`${action.actor}: ${action.resultSummary ?? action.rejectionReason ?? "rests"}`);
|
|
350
|
+
console.log(` ${note}`);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
const decision = action.approved ? GREEN("APPROVED") : RED("REJECTED");
|
|
354
|
+
console.log(` [R${action.round}] ${p.agentId} ${BOLD(p.type.toUpperCase())} ${p.target} — ${decision}`);
|
|
355
|
+
if (p.why) console.log(` ${DIM(p.why.slice(0, 110))}`);
|
|
356
|
+
}
|
|
357
|
+
for (const claim of state.claims) {
|
|
358
|
+
const previous = claimStatus.get(claim.id);
|
|
359
|
+
if (previous === claim.status) continue;
|
|
360
|
+
claimStatus.set(claim.id, claim.status);
|
|
361
|
+
const color = { verified: GREEN, refuted: RED, disputed: GOLD }[claim.status] ?? ((s) => s);
|
|
362
|
+
const arrow = previous ? `${previous} → ` : "";
|
|
363
|
+
console.log(` ${color(`claim ${claim.id}: ${arrow}${claim.status}`)}`);
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// --- commands -----------------------------------------------------------------
|
|
369
|
+
|
|
370
|
+
async function cmdSignup(flags) {
|
|
371
|
+
const res = await fetch(`${gatewayUrl(flags)}/v1/keys`, {
|
|
372
|
+
method: "POST",
|
|
373
|
+
headers: { "Content-Type": "application/json" },
|
|
374
|
+
body: JSON.stringify({ label: "cli" }),
|
|
375
|
+
});
|
|
376
|
+
const body = await res.json();
|
|
377
|
+
if (!res.ok) {
|
|
378
|
+
console.error(`${res.status}: ${body.error ?? res.statusText}`);
|
|
379
|
+
process.exit(1);
|
|
380
|
+
}
|
|
381
|
+
await saveConfig({ ...((await loadConfig()) ?? {}), key: body.key, gateway: gatewayUrl(flags) });
|
|
382
|
+
console.log(GREEN("✓ key created") + ` — $${body.creditsUsd.toFixed(2)} trial credits`);
|
|
383
|
+
console.log(` stored at ${CONFIG_PATH}`);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
async function cmdBalance(config, flags) {
|
|
387
|
+
const summary = await api(config, flags, "/v1/keys/me", { headers: authHeaders(config) });
|
|
388
|
+
console.log(BOLD(`credits: $${summary.creditsUsd.toFixed(2)}`));
|
|
389
|
+
console.log(` spent: $${summary.spentUsd.toFixed(2)} · verdicts: ${summary.verdicts}`);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async function cmdProvider(config, flags, positional) {
|
|
393
|
+
const provider = positional[0];
|
|
394
|
+
if (!provider) {
|
|
395
|
+
const body = await api(config, flags, "/v1/keys/me/provider", { headers: authHeaders(config) });
|
|
396
|
+
console.log(BOLD(`provider: ${body.provider}`) + (body.keySet ? GREEN(" (key set)") : DIM(" (no key)")));
|
|
397
|
+
if (body.baseUrl) console.log(` baseUrl: ${body.baseUrl}`);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (!["mock", "meta", "openai", "ollama", "custom"].includes(provider)) {
|
|
401
|
+
console.error("provider must be: mock, meta, openai, ollama, or custom");
|
|
402
|
+
process.exit(2);
|
|
403
|
+
}
|
|
404
|
+
const apiKey = flags.key ?? process.env.ZV_PROVIDER_KEY ?? process.env.META_API_KEY ?? "";
|
|
405
|
+
if (provider !== "mock" && provider !== "ollama" && !apiKey) {
|
|
406
|
+
console.error("set the key via --key <KEY> or the ZV_PROVIDER_KEY env var (never as a plain shell arg in shared terminals)");
|
|
407
|
+
process.exit(2);
|
|
408
|
+
}
|
|
409
|
+
const body = await api(config, flags, "/v1/keys/me/provider", {
|
|
410
|
+
method: "POST",
|
|
411
|
+
headers: authHeaders(config),
|
|
412
|
+
body: JSON.stringify({ provider, ...(apiKey ? { apiKey } : {}), ...(flags.baseUrl ? { baseUrl: flags.baseUrl } : {}) }),
|
|
413
|
+
});
|
|
414
|
+
console.log(GREEN("✓ provider saved") + ` — ${body.provider}${body.keySet ? " (key stored encrypted)" : ""}`);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
async function cmdTopup(config, flags, positional) {
|
|
418
|
+
const amount = Number(positional[0]);
|
|
419
|
+
if (!Number.isFinite(amount) || amount < 5 || amount > 500) {
|
|
420
|
+
console.error("usage: zyntry-verdict topup <amount 5-500> — credit top-up via Bachs hosted checkout");
|
|
421
|
+
process.exit(2);
|
|
422
|
+
}
|
|
423
|
+
const body = await api(config, flags, "/v1/topups", {
|
|
424
|
+
method: "POST",
|
|
425
|
+
headers: authHeaders(config),
|
|
426
|
+
body: JSON.stringify({ amountUsd: amount }),
|
|
427
|
+
});
|
|
428
|
+
console.log(GREEN("✓ checkout created") + ` — $${amount.toFixed(2)} · reference ${body.reference}`);
|
|
429
|
+
console.log("");
|
|
430
|
+
console.log(BOLD("Open this link to pay (card, bank transfer, mobile money, crypto):"));
|
|
431
|
+
console.log(` ${GOLD(body.checkoutUrl)}`);
|
|
432
|
+
console.log("");
|
|
433
|
+
console.log(DIM("Credits land automatically once the payment confirms."));
|
|
434
|
+
console.log(DIM("Then check: zyntry-verdict balance"));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
async function cmdStats(config, flags, positional) {
|
|
438
|
+
const caseId = positional[0];
|
|
439
|
+
if (!caseId) {
|
|
440
|
+
console.error("usage: zyntry-verdict stats <caseId>");
|
|
441
|
+
process.exit(2);
|
|
442
|
+
}
|
|
443
|
+
const body = await api(config, flags, `/v1/cases/${caseId}/verdicts`, { headers: authHeaders(config) });
|
|
444
|
+
|
|
445
|
+
console.log(GOLD("⚖ ZYNTRY VERDICT") + ` — ${caseId}`);
|
|
446
|
+
console.log("");
|
|
447
|
+
console.log(` verdicts: ${BOLD(String(body.total))}`);
|
|
448
|
+
console.log(` wins: ${GREEN(String(body.wins))}/${body.total}`);
|
|
449
|
+
console.log(` win rate: ${body.winRate !== null ? (body.winRate * 100).toFixed(0) + "%" : "—"}`);
|
|
450
|
+
console.log(` escalation: ${body.escalationRate !== null ? (body.escalationRate * 100).toFixed(0) + "%" : "—"}`);
|
|
451
|
+
console.log(` median calls: ${body.medianCalls}`);
|
|
452
|
+
console.log(` total spend: $${body.totalSpend.toFixed(2)}`);
|
|
453
|
+
console.log("");
|
|
454
|
+
|
|
455
|
+
if (body.verdicts.length > 0) {
|
|
456
|
+
console.log(" " + DIM("recent verdicts:"));
|
|
457
|
+
console.log(" " + DIM("─".repeat(76)));
|
|
458
|
+
for (const v of body.verdicts.slice(0, 10)) {
|
|
459
|
+
const badge = v.verdict === "resolved-verified" ? GREEN("✓ verified") :
|
|
460
|
+
v.status === "error" ? RED("✗ error") :
|
|
461
|
+
v.status === "running" ? GOLD("● running") : RED("✗ unresolved");
|
|
462
|
+
const esc = v.escalated ? GOLD(" → court") : DIM(" (triage)");
|
|
463
|
+
console.log(
|
|
464
|
+
` ${DIM(v.startedAt.slice(0, 16))} ${badge.padEnd(14)}${esc} ${v.calls} calls $${v.spend.toFixed(2)}`,
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
if (body.total > 10) console.log(` ${DIM(`... ${body.total - 10} more`)}`);
|
|
468
|
+
} else {
|
|
469
|
+
console.log(DIM(" no verdicts yet — run one: zyntry-verdict run " + caseId));
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
async function cmdCases(config, flags) {
|
|
474
|
+
const body = await api(config, flags, "/v1/cases", { headers: authHeaders(config) });
|
|
475
|
+
for (const id of body.cases) console.log(` ${id}`);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
async function cmdRun(config, flags, positional) {
|
|
479
|
+
const caseId = await detectCaseId(positional);
|
|
480
|
+
if (!caseId) {
|
|
481
|
+
console.error("usage: zyntry-verdict run <caseId>");
|
|
482
|
+
console.error(" (or put a .zyntry.case.json in your repo root for auto-detection)");
|
|
483
|
+
process.exit(2);
|
|
484
|
+
}
|
|
485
|
+
const mode = flags.mode === "courtroom" ? "courtroom" : "route";
|
|
486
|
+
const gateway = gatewayUrl(flags);
|
|
487
|
+
const submitRes = await fetch(`${gateway}/v1/verdicts`, {
|
|
488
|
+
method: "POST",
|
|
489
|
+
headers: authHeaders(config),
|
|
490
|
+
body: JSON.stringify({ caseId, mode }),
|
|
491
|
+
});
|
|
492
|
+
if (!submitRes.ok) {
|
|
493
|
+
const body = await submitRes.json().catch(() => ({}));
|
|
494
|
+
console.error(`${submitRes.status}: ${body.error ?? submitRes.statusText}`);
|
|
495
|
+
process.exit(1);
|
|
496
|
+
}
|
|
497
|
+
const verdictId = submitRes.headers.get("x-verdict-id");
|
|
498
|
+
const contentType = submitRes.headers.get("content-type") ?? "";
|
|
499
|
+
console.log(GOLD("⚖ ZYNTRY VERDICT") + ` — ${caseId} (${mode}) — verdictId ${verdictId}`);
|
|
500
|
+
const credits = submitRes.headers.get("x-credits-remaining");
|
|
501
|
+
if (credits !== null) console.log(DIM(` credits remaining: $${Number(credits).toFixed(2)}`));
|
|
502
|
+
console.log("");
|
|
503
|
+
|
|
504
|
+
const render = renderStream();
|
|
505
|
+
let summary = null;
|
|
506
|
+
|
|
507
|
+
if (contentType.includes("x-ndjson")) {
|
|
508
|
+
// The hosted gateway streams the courtroom directly on submit.
|
|
509
|
+
for await (const event of ndjsonLines(submitRes)) {
|
|
510
|
+
if (event.done !== undefined && event.summary) {
|
|
511
|
+
summary = { ...event.summary };
|
|
512
|
+
} else if (event.snapshot) {
|
|
513
|
+
render(event.snapshot);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
} else {
|
|
517
|
+
// Older contract: 202 JSON with a separate SSE stream.
|
|
518
|
+
const submitted = await submitRes.json();
|
|
519
|
+
if (submitted.creditsRemainingUsd !== undefined) {
|
|
520
|
+
console.log(DIM(` credits remaining: $${Number(submitted.creditsRemainingUsd ?? 0).toFixed(2)}`));
|
|
521
|
+
}
|
|
522
|
+
const streamRes = await fetch(`${gateway}${submitted.stream}`, { headers: authHeaders(config) });
|
|
523
|
+
if (!streamRes.ok) {
|
|
524
|
+
console.error(`stream failed: ${streamRes.status}`);
|
|
525
|
+
process.exit(1);
|
|
526
|
+
}
|
|
527
|
+
for await (const event of sseEvents(streamRes)) {
|
|
528
|
+
if (event.verdictId !== undefined) {
|
|
529
|
+
summary = event;
|
|
530
|
+
} else {
|
|
531
|
+
render(event);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (!summary) {
|
|
537
|
+
const finalRes = await fetch(`${gateway}/v1/verdicts/${verdictId ?? ""}`, { headers: authHeaders(config) });
|
|
538
|
+
summary = await finalRes.json().catch(() => null);
|
|
539
|
+
}
|
|
540
|
+
printVerdict(summary);
|
|
541
|
+
const verdict = summary?.verdict ?? summary?.status;
|
|
542
|
+
process.exit(verdict === "resolved-verified" ? 0 : 1);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
function printVerdict(summary) {
|
|
546
|
+
console.log("");
|
|
547
|
+
console.log(" ┌──────────────────────────────────────────────");
|
|
548
|
+
console.log(` │ VERDICT: ${summary.verdict === "resolved-verified" ? GREEN(BOLD(summary.verdict)) : RED(BOLD(summary.verdict ?? summary.status ?? "error"))}`);
|
|
549
|
+
if (summary.verdictReason) console.log(` │ ${summary.verdictReason}`);
|
|
550
|
+
console.log(` │ calls: ${summary.calls} · rounds: ${summary.round} · spent: $${(summary.spentUsd?.trial ?? 0) + (summary.spentUsd?.escalation ?? 0)}`);
|
|
551
|
+
console.log(" └──────────────────────────────────────────────");
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// --- entry ----------------------------------------------------------------------
|
|
555
|
+
|
|
556
|
+
const argv = process.argv.slice(2);
|
|
557
|
+
const positional = [];
|
|
558
|
+
const flags = {};
|
|
559
|
+
let command = null;
|
|
560
|
+
for (let i = 0; i < argv.length; i++) {
|
|
561
|
+
if (argv[i].startsWith("--")) {
|
|
562
|
+
const name = argv[i].slice(2);
|
|
563
|
+
if (name === "gateway" || name === "mode" || name === "key" || name === "baseUrl" || name === "case" || name === "debounce") {
|
|
564
|
+
flags[name] = argv[i + 1];
|
|
565
|
+
i += 1;
|
|
566
|
+
} else {
|
|
567
|
+
flags[name] = true;
|
|
568
|
+
}
|
|
569
|
+
} else if (command === null) {
|
|
570
|
+
command = argv[i];
|
|
571
|
+
} else {
|
|
572
|
+
positional.push(argv[i]);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const config = await loadConfig();
|
|
577
|
+
switch (command) {
|
|
578
|
+
case "signup":
|
|
579
|
+
await cmdSignup(flags);
|
|
580
|
+
break;
|
|
581
|
+
case "balance":
|
|
582
|
+
await cmdBalance(config, flags);
|
|
583
|
+
break;
|
|
584
|
+
case "cases":
|
|
585
|
+
await cmdCases(config, flags);
|
|
586
|
+
break;
|
|
587
|
+
case "topup":
|
|
588
|
+
await cmdTopup(config, flags, positional);
|
|
589
|
+
break;
|
|
590
|
+
case "stats":
|
|
591
|
+
await cmdStats(config, flags, positional);
|
|
592
|
+
break;
|
|
593
|
+
case "certify":
|
|
594
|
+
await cmdCertify(config, flags, positional);
|
|
595
|
+
break;
|
|
596
|
+
case "standards":
|
|
597
|
+
await cmdStandards(config, flags, positional);
|
|
598
|
+
break;
|
|
599
|
+
case "watch":
|
|
600
|
+
await cmdWatch(config, flags, positional);
|
|
601
|
+
break;
|
|
602
|
+
case "gate":
|
|
603
|
+
await cmdGate(config, flags, positional);
|
|
604
|
+
break;
|
|
605
|
+
case "provider":
|
|
606
|
+
await cmdProvider(config, flags, positional);
|
|
607
|
+
break;
|
|
608
|
+
case "run":
|
|
609
|
+
await cmdRun(config, flags, positional);
|
|
610
|
+
break;
|
|
611
|
+
default:
|
|
612
|
+
console.log(`zyntry-verdict — the hosted courtroom, from your terminal
|
|
613
|
+
|
|
614
|
+
signup create an API key with trial credits
|
|
615
|
+
balance credits + usage
|
|
616
|
+
topup <amount 5-500> pay via Bachs hosted checkout (card, bank transfer,
|
|
617
|
+
mobile money, crypto) — credits land automatically
|
|
618
|
+
provider [name] show or set YOUR model provider (BYOK)
|
|
619
|
+
[--key <KEY>] [--baseUrl <url>] — or ZV_PROVIDER_KEY env
|
|
620
|
+
cases list available case packs
|
|
621
|
+
run [caseId] open the courtroom and stream the verdict live
|
|
622
|
+
(auto-detects .zyntry.case.json in your repo)
|
|
623
|
+
[--mode route|courtroom] [--gateway <url>]
|
|
624
|
+
watch [caseId] auto-verdict on file change (the safety net)
|
|
625
|
+
[--debounce 30] seconds after last change
|
|
626
|
+
gate [caseId] one-shot verdict for git pre-commit hooks
|
|
627
|
+
(exits 0 only on resolved-verified)
|
|
628
|
+
stats <caseId> per-repo dashboard: win rate, escalation rate, spend
|
|
629
|
+
certify <verdictId> export a signed verdict certificate (compliance proof)
|
|
630
|
+
standards <caseId> show the sealed standard's growth (visible moat)
|
|
631
|
+
|
|
632
|
+
git hook: zyntry-verdict gate --case my-case # in .git/hooks/pre-commit
|
|
633
|
+
|
|
634
|
+
env: ZV_GATEWAY (default https://verdict.zyntry.space)`);
|
|
635
|
+
process.exit(command ? 2 : 0);
|
|
636
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zyntry-verdict",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Thin client for the Zyntry Verdict hosted AI courtroom — submit code, watch the adversarial courtroom stream live, get a verdict that can withstand scrutiny.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"zyntry-verdict": "bin/zv.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/zv.mjs",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"ai",
|
|
15
|
+
"verification",
|
|
16
|
+
"code-review",
|
|
17
|
+
"ci",
|
|
18
|
+
"testing",
|
|
19
|
+
"adversarial",
|
|
20
|
+
"agent",
|
|
21
|
+
"mcp",
|
|
22
|
+
"courtroom",
|
|
23
|
+
"qa"
|
|
24
|
+
],
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/devspak-s8/zyntry-verdict.git"
|
|
28
|
+
},
|
|
29
|
+
"license": "UNLICENSED",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
}
|
|
6
33
|
}
|