@theoklitosbam7/verdict-kit 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/LICENSE +21 -0
- package/README.md +625 -2
- package/config/routing/engineering.action-risk.consensus.v1.json +16 -0
- package/config/routing/engineering.task-route.cascade.v1.json +21 -0
- package/dist/action-policy.d.ts +104 -0
- package/dist/action-policy.js +173 -0
- package/dist/cache.d.ts +17 -0
- package/dist/cache.js +139 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +142 -0
- package/dist/concurrency.d.ts +12 -0
- package/dist/concurrency.js +110 -0
- package/dist/config.d.ts +61 -0
- package/dist/config.js +247 -0
- package/dist/decision.d.ts +75 -0
- package/dist/decision.js +278 -0
- package/dist/engine.d.ts +63 -0
- package/dist/engine.js +79 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +19 -0
- package/dist/http.d.ts +18 -0
- package/dist/http.js +140 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -0
- package/dist/package-info.d.ts +1 -0
- package/dist/package-info.js +5 -0
- package/dist/policy/evaluate.d.ts +7 -0
- package/dist/policy/evaluate.js +39 -0
- package/dist/policy/events.d.ts +32 -0
- package/dist/policy/events.js +31 -0
- package/dist/policy/payload.d.ts +6 -0
- package/dist/policy/payload.js +11 -0
- package/dist/policy/registry.d.ts +22 -0
- package/dist/policy/registry.js +89 -0
- package/dist/policy/schema.d.ts +198 -0
- package/dist/policy/schema.js +112 -0
- package/dist/policy/scope.d.ts +5 -0
- package/dist/policy/scope.js +120 -0
- package/dist/probability.d.ts +1 -0
- package/dist/probability.js +3 -0
- package/dist/providers/discovery.d.ts +10 -0
- package/dist/providers/discovery.js +113 -0
- package/dist/providers/index.d.ts +56 -0
- package/dist/providers/index.js +83 -0
- package/dist/providers/ollama.d.ts +12 -0
- package/dist/providers/ollama.js +93 -0
- package/dist/providers/opencode-go.d.ts +3 -0
- package/dist/providers/opencode-go.js +40 -0
- package/dist/providers/system-one.d.ts +21 -0
- package/dist/providers/system-one.js +44 -0
- package/dist/providers/typesafe.d.ts +3 -0
- package/dist/providers/typesafe.js +36 -0
- package/dist/public.d.ts +5 -0
- package/dist/public.js +5 -0
- package/dist/response.d.ts +6 -0
- package/dist/response.js +104 -0
- package/dist/routing/cascade.d.ts +112 -0
- package/dist/routing/cascade.js +220 -0
- package/dist/routing/consensus.d.ts +148 -0
- package/dist/routing/consensus.js +367 -0
- package/dist/routing/retry.d.ts +3 -0
- package/dist/routing/retry.js +47 -0
- package/dist/routing/router.d.ts +12 -0
- package/dist/routing/router.js +27 -0
- package/dist/schemas.d.ts +339 -0
- package/dist/schemas.js +283 -0
- package/dist/server.d.ts +42 -0
- package/dist/server.js +416 -0
- package/dist/telemetry/events.d.ts +15 -0
- package/dist/telemetry/events.js +87 -0
- package/dist/telemetry/sink.d.ts +7 -0
- package/dist/telemetry/sink.js +59 -0
- package/dist/templates/registry.d.ts +13 -0
- package/dist/templates/registry.js +100 -0
- package/dist/templates/schema.d.ts +115 -0
- package/dist/templates/schema.js +70 -0
- package/dist/types.d.ts +86 -0
- package/dist/types.js +2 -0
- package/package.json +77 -3
- package/policies/engineering-default.v1.json +36 -0
- package/policies/engineering-strict.v1.json +36 -0
- package/templates/engineering.action-risk.v1.json +32 -0
- package/templates/engineering.compatibility.v1.json +25 -0
- package/templates/engineering.pr-risk.v1.json +26 -0
- package/templates/engineering.security-sensitivity.v1.json +20 -0
- package/templates/engineering.task-route.v1.json +27 -0
- package/templates/engineering.test-depth.v1.json +26 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fromJsonSchema } from "@modelcontextprotocol/server";
|
|
4
|
+
import { DecisionError } from "../errors.js";
|
|
5
|
+
import { templateDefinitionSchema, } from "./schema.js";
|
|
6
|
+
function templateKey({ id, version }) {
|
|
7
|
+
return `${id}@${version}`;
|
|
8
|
+
}
|
|
9
|
+
export function createTemplateRegistry(definitions) {
|
|
10
|
+
const entries = new Map();
|
|
11
|
+
for (const candidate of definitions) {
|
|
12
|
+
const parsed = templateDefinitionSchema.safeParse(candidate);
|
|
13
|
+
if (!parsed.success) {
|
|
14
|
+
const path = parsed.error.issues[0]?.path.join(".") || "definition";
|
|
15
|
+
throw new DecisionError("configuration", `Invalid decision template at ${path}.`);
|
|
16
|
+
}
|
|
17
|
+
const definition = parsed.data;
|
|
18
|
+
const key = templateKey(definition);
|
|
19
|
+
if (entries.has(key)) {
|
|
20
|
+
throw new DecisionError("configuration", `Duplicate decision template ${key}.`);
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const stateValidator = definition.state_schema && fromJsonSchema(definition.state_schema);
|
|
24
|
+
entries.set(key, { definition, stateValidator });
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
throw new DecisionError("configuration", `Invalid state schema for decision template ${key}.`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function lookup(identity) {
|
|
31
|
+
const entry = entries.get(templateKey(identity));
|
|
32
|
+
if (!entry)
|
|
33
|
+
throw new DecisionError("invalid_request", "Unknown decision template ID and version.");
|
|
34
|
+
return entry;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
get(identity) {
|
|
38
|
+
return structuredClone(lookup(identity).definition);
|
|
39
|
+
},
|
|
40
|
+
list() {
|
|
41
|
+
return Array.from(entries.values(), ({ definition: { id, version, description } }) => ({
|
|
42
|
+
id,
|
|
43
|
+
version,
|
|
44
|
+
description,
|
|
45
|
+
uri: `decision-template://registry/${id}/${version}`,
|
|
46
|
+
})).sort((left, right) => left.id.localeCompare(right.id) || left.version - right.version);
|
|
47
|
+
},
|
|
48
|
+
async validateState(identity, state) {
|
|
49
|
+
const { stateValidator } = lookup(identity);
|
|
50
|
+
if (!stateValidator)
|
|
51
|
+
return true;
|
|
52
|
+
const result = await stateValidator["~standard"].validate(state);
|
|
53
|
+
return !result.issues;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const MAX_TEMPLATE_BYTES = 131_072;
|
|
58
|
+
const MAX_TEMPLATE_FILES = 64;
|
|
59
|
+
const bundledFiles = [
|
|
60
|
+
new URL("../../templates/engineering.action-risk.v1.json", import.meta.url),
|
|
61
|
+
new URL("../../templates/engineering.compatibility.v1.json", import.meta.url),
|
|
62
|
+
new URL("../../templates/engineering.pr-risk.v1.json", import.meta.url),
|
|
63
|
+
new URL("../../templates/engineering.security-sensitivity.v1.json", import.meta.url),
|
|
64
|
+
new URL("../../templates/engineering.task-route.v1.json", import.meta.url),
|
|
65
|
+
new URL("../../templates/engineering.test-depth.v1.json", import.meta.url),
|
|
66
|
+
];
|
|
67
|
+
function readJsonTemplate(file) {
|
|
68
|
+
try {
|
|
69
|
+
const stats = statSync(file);
|
|
70
|
+
if (stats.isFile() && stats.size <= MAX_TEMPLATE_BYTES) {
|
|
71
|
+
const bytes = readFileSync(file);
|
|
72
|
+
if (bytes.byteLength <= MAX_TEMPLATE_BYTES) {
|
|
73
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Keep file contents and system paths out of startup diagnostics.
|
|
79
|
+
}
|
|
80
|
+
throw new DecisionError("configuration", "Could not read a template as JSON of at most 128 KiB.");
|
|
81
|
+
}
|
|
82
|
+
export function loadTemplateRegistry(directory) {
|
|
83
|
+
const files = [...bundledFiles];
|
|
84
|
+
if (directory) {
|
|
85
|
+
let localFiles;
|
|
86
|
+
try {
|
|
87
|
+
localFiles = readdirSync(directory, { withFileTypes: true })
|
|
88
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith(".json"))
|
|
89
|
+
.map((entry) => join(directory, entry.name));
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
throw new DecisionError("configuration", "Could not read DECISION_TEMPLATE_DIR.");
|
|
93
|
+
}
|
|
94
|
+
if (files.length + localFiles.length > MAX_TEMPLATE_FILES) {
|
|
95
|
+
throw new DecisionError("configuration", "At most 64 template files may be loaded.");
|
|
96
|
+
}
|
|
97
|
+
files.push(...localFiles);
|
|
98
|
+
}
|
|
99
|
+
return createTemplateRegistry(files.map(readJsonTemplate));
|
|
100
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
export declare const templateIdentitySchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
version: z.ZodNumber;
|
|
5
|
+
}, z.core.$strict>;
|
|
6
|
+
type StateSchema = {
|
|
7
|
+
type: "string";
|
|
8
|
+
minLength?: number;
|
|
9
|
+
maxLength?: number;
|
|
10
|
+
} | {
|
|
11
|
+
type: "number" | "integer" | "boolean" | "null";
|
|
12
|
+
} | {
|
|
13
|
+
type: "array";
|
|
14
|
+
items: StateSchema;
|
|
15
|
+
maxItems?: number;
|
|
16
|
+
} | {
|
|
17
|
+
type: "object";
|
|
18
|
+
properties: Record<string, StateSchema>;
|
|
19
|
+
required?: string[];
|
|
20
|
+
additionalProperties?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare const templateDefinitionSchema: z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
version: z.ZodNumber;
|
|
25
|
+
description: z.ZodString;
|
|
26
|
+
state_schema: z.ZodOptional<z.ZodType<StateSchema, unknown, z.core.$ZodTypeInternals<StateSchema, unknown>>>;
|
|
27
|
+
questions: z.ZodPipe<z.ZodUnknown, z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
28
|
+
type: z.ZodLiteral<"choice">;
|
|
29
|
+
instructions: z.ZodString;
|
|
30
|
+
criteria: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>;
|
|
31
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
32
|
+
type: z.ZodLiteral<"noul">;
|
|
33
|
+
instructions: z.ZodString;
|
|
34
|
+
criteria: z.ZodOptional<z.ZodObject<{
|
|
35
|
+
true: z.ZodOptional<z.ZodString>;
|
|
36
|
+
false: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
39
|
+
type: z.ZodLiteral<"score">;
|
|
40
|
+
instructions: z.ZodString;
|
|
41
|
+
criteria: z.ZodArray<z.ZodString>;
|
|
42
|
+
}, z.core.$strip>], "type">>>;
|
|
43
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
|
|
44
|
+
}, z.core.$strict>;
|
|
45
|
+
export type TemplateIdentity = z.infer<typeof templateIdentitySchema>;
|
|
46
|
+
export type TemplateDefinition = z.infer<typeof templateDefinitionSchema>;
|
|
47
|
+
export declare const templateValidateInputSchema: z.ZodObject<{
|
|
48
|
+
template: z.ZodObject<{
|
|
49
|
+
id: z.ZodString;
|
|
50
|
+
version: z.ZodNumber;
|
|
51
|
+
}, z.core.$strict>;
|
|
52
|
+
state: z.ZodPipe<z.ZodUnknown, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
53
|
+
}, z.core.$strict>;
|
|
54
|
+
export declare const templateRunInputSchema: z.ZodObject<{
|
|
55
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
56
|
+
model: z.ZodOptional<z.ZodString>;
|
|
57
|
+
template: z.ZodObject<{
|
|
58
|
+
id: z.ZodString;
|
|
59
|
+
version: z.ZodNumber;
|
|
60
|
+
}, z.core.$strict>;
|
|
61
|
+
state: z.ZodPipe<z.ZodUnknown, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
62
|
+
}, z.core.$strict>;
|
|
63
|
+
export declare const templateValidateOutputSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
64
|
+
template: z.ZodObject<{
|
|
65
|
+
id: z.ZodString;
|
|
66
|
+
version: z.ZodNumber;
|
|
67
|
+
}, z.core.$strict>;
|
|
68
|
+
valid: z.ZodLiteral<true>;
|
|
69
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
70
|
+
template: z.ZodObject<{
|
|
71
|
+
id: z.ZodString;
|
|
72
|
+
version: z.ZodNumber;
|
|
73
|
+
}, z.core.$strict>;
|
|
74
|
+
valid: z.ZodLiteral<false>;
|
|
75
|
+
message: z.ZodString;
|
|
76
|
+
}, z.core.$strip>]>;
|
|
77
|
+
export declare const templateRunOutputSchema: z.ZodObject<{
|
|
78
|
+
template: z.ZodObject<{
|
|
79
|
+
id: z.ZodString;
|
|
80
|
+
version: z.ZodNumber;
|
|
81
|
+
}, z.core.$strict>;
|
|
82
|
+
result: z.ZodObject<{
|
|
83
|
+
provider: z.ZodString;
|
|
84
|
+
model: z.ZodOptional<z.ZodString>;
|
|
85
|
+
answers: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
86
|
+
confidence: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
probabilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
88
|
+
legend: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
89
|
+
type: z.ZodLiteral<"choice">;
|
|
90
|
+
choice: z.ZodString;
|
|
91
|
+
}, z.core.$catchall<z.ZodPipe<z.ZodUnknown, z.ZodJSONSchema>>>, z.ZodObject<{
|
|
92
|
+
confidence: z.ZodOptional<z.ZodNumber>;
|
|
93
|
+
probabilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
94
|
+
legend: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
95
|
+
type: z.ZodLiteral<"noul">;
|
|
96
|
+
noul: z.ZodNumber;
|
|
97
|
+
}, z.core.$catchall<z.ZodPipe<z.ZodUnknown, z.ZodJSONSchema>>>, z.ZodObject<{
|
|
98
|
+
confidence: z.ZodOptional<z.ZodNumber>;
|
|
99
|
+
probabilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
100
|
+
legend: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
101
|
+
type: z.ZodLiteral<"score">;
|
|
102
|
+
score: z.ZodNumber;
|
|
103
|
+
}, z.core.$catchall<z.ZodPipe<z.ZodUnknown, z.ZodJSONSchema>>>], "type">>;
|
|
104
|
+
usage: z.ZodOptional<z.ZodJSONSchema>;
|
|
105
|
+
}, z.core.$strip>;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
export declare const templateListOutputSchema: z.ZodObject<{
|
|
108
|
+
templates: z.ZodArray<z.ZodObject<{
|
|
109
|
+
id: z.ZodString;
|
|
110
|
+
version: z.ZodNumber;
|
|
111
|
+
description: z.ZodString;
|
|
112
|
+
uri: z.ZodString;
|
|
113
|
+
}, z.core.$strict>>;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import { decisionOutputSchema, jsonValueSchema, providerFields, questionsSchema, withinPayloadLimit, } from "../schemas.js";
|
|
3
|
+
export const templateIdentitySchema = z.strictObject({
|
|
4
|
+
id: z
|
|
5
|
+
.string()
|
|
6
|
+
.min(1)
|
|
7
|
+
.max(128)
|
|
8
|
+
.regex(/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)*$/),
|
|
9
|
+
version: z.number().int().min(1),
|
|
10
|
+
});
|
|
11
|
+
const propertyName = z.string().min(1).max(128);
|
|
12
|
+
const stateSchema = z.lazy(() => z.discriminatedUnion("type", [
|
|
13
|
+
z
|
|
14
|
+
.strictObject({
|
|
15
|
+
type: z.literal("string"),
|
|
16
|
+
minLength: z.number().int().min(0).max(32_768).optional(),
|
|
17
|
+
maxLength: z.number().int().min(0).max(32_768).optional(),
|
|
18
|
+
})
|
|
19
|
+
.refine(({ minLength = 0, maxLength = Infinity }) => minLength <= maxLength),
|
|
20
|
+
z.strictObject({ type: z.enum(["number", "integer", "boolean", "null"]) }),
|
|
21
|
+
z.strictObject({
|
|
22
|
+
type: z.literal("array"),
|
|
23
|
+
items: stateSchema,
|
|
24
|
+
maxItems: z.number().int().min(0).max(1_000).optional(),
|
|
25
|
+
}),
|
|
26
|
+
z
|
|
27
|
+
.strictObject({
|
|
28
|
+
type: z.literal("object"),
|
|
29
|
+
properties: z.record(propertyName, stateSchema),
|
|
30
|
+
required: z.array(propertyName).max(100).optional(),
|
|
31
|
+
additionalProperties: z.boolean().optional(),
|
|
32
|
+
})
|
|
33
|
+
.refine(({ properties, required = [] }) => Object.keys(properties).length <= 100 &&
|
|
34
|
+
new Set(required).size === required.length &&
|
|
35
|
+
required.every((key) => Object.hasOwn(properties, key))),
|
|
36
|
+
]));
|
|
37
|
+
export const templateDefinitionSchema = templateIdentitySchema.extend({
|
|
38
|
+
description: z.string().min(1).max(4_096),
|
|
39
|
+
state_schema: stateSchema.optional(),
|
|
40
|
+
questions: questionsSchema,
|
|
41
|
+
metadata: z.record(propertyName, z.json()).optional(),
|
|
42
|
+
});
|
|
43
|
+
const templateStateInput = z.strictObject({
|
|
44
|
+
template: templateIdentitySchema,
|
|
45
|
+
state: jsonValueSchema,
|
|
46
|
+
});
|
|
47
|
+
export const templateValidateInputSchema = templateStateInput.refine(withinPayloadLimit, {
|
|
48
|
+
message: "Request payload is too large.",
|
|
49
|
+
});
|
|
50
|
+
export const templateRunInputSchema = templateStateInput
|
|
51
|
+
.extend(providerFields)
|
|
52
|
+
.refine(withinPayloadLimit, {
|
|
53
|
+
message: "Request payload is too large.",
|
|
54
|
+
});
|
|
55
|
+
export const templateValidateOutputSchema = z
|
|
56
|
+
.union([
|
|
57
|
+
z.object({ template: templateIdentitySchema, valid: z.literal(true) }),
|
|
58
|
+
z.object({ template: templateIdentitySchema, valid: z.literal(false), message: z.string() }),
|
|
59
|
+
])
|
|
60
|
+
.meta({ type: "object" });
|
|
61
|
+
export const templateRunOutputSchema = z.object({
|
|
62
|
+
template: templateIdentitySchema,
|
|
63
|
+
result: decisionOutputSchema,
|
|
64
|
+
});
|
|
65
|
+
export const templateListOutputSchema = z.object({
|
|
66
|
+
templates: z.array(templateIdentitySchema.extend({
|
|
67
|
+
description: z.string(),
|
|
68
|
+
uri: z.string(),
|
|
69
|
+
})),
|
|
70
|
+
});
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { DecisionErrorCode } from "./errors.js";
|
|
2
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
export type ChoiceQuestion = {
|
|
6
|
+
type: "choice";
|
|
7
|
+
instructions: string;
|
|
8
|
+
criteria: Record<string, string | null>;
|
|
9
|
+
};
|
|
10
|
+
export type NoulQuestion = {
|
|
11
|
+
type: "noul";
|
|
12
|
+
instructions: string;
|
|
13
|
+
criteria?: {
|
|
14
|
+
true?: string;
|
|
15
|
+
false?: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type ScoreQuestion = {
|
|
19
|
+
type: "score";
|
|
20
|
+
instructions: string;
|
|
21
|
+
criteria: string[];
|
|
22
|
+
};
|
|
23
|
+
export type DecisionQuestion = ChoiceQuestion | NoulQuestion | ScoreQuestion;
|
|
24
|
+
export type DecisionQuestions = Record<string, DecisionQuestion>;
|
|
25
|
+
export type DecisionContext = Readonly<{
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
deadlineAt?: number;
|
|
28
|
+
onRouteAttempt?: (attempt: import("./routing/router.js").RouteAttempt) => void;
|
|
29
|
+
}>;
|
|
30
|
+
export interface DecisionRequest {
|
|
31
|
+
state: JsonValue;
|
|
32
|
+
questions: DecisionQuestions;
|
|
33
|
+
provider?: string;
|
|
34
|
+
model?: string;
|
|
35
|
+
context?: DecisionContext;
|
|
36
|
+
}
|
|
37
|
+
export type DecisionAnswer = Record<string, JsonValue> & ({
|
|
38
|
+
type: "choice";
|
|
39
|
+
choice: string;
|
|
40
|
+
} | {
|
|
41
|
+
type: "noul";
|
|
42
|
+
noul: number;
|
|
43
|
+
} | {
|
|
44
|
+
type: "score";
|
|
45
|
+
score: number;
|
|
46
|
+
});
|
|
47
|
+
export interface DecisionResponse {
|
|
48
|
+
provider: string;
|
|
49
|
+
model?: string;
|
|
50
|
+
answers: Record<string, DecisionAnswer>;
|
|
51
|
+
usage?: JsonValue;
|
|
52
|
+
}
|
|
53
|
+
export type ProviderReadiness = "ready" | "not_configured" | "unreachable" | "unauthenticated" | "model_missing" | "model_unsupported" | "unknown";
|
|
54
|
+
export type ModelReadiness = {
|
|
55
|
+
name: string;
|
|
56
|
+
default: boolean;
|
|
57
|
+
status: "ready" | "missing" | "unsupported" | "unknown";
|
|
58
|
+
locality: "local" | "non-local" | "unknown";
|
|
59
|
+
revision?: string;
|
|
60
|
+
};
|
|
61
|
+
export type ProviderStatus = {
|
|
62
|
+
ok: boolean;
|
|
63
|
+
detail?: string;
|
|
64
|
+
readiness?: ProviderReadiness;
|
|
65
|
+
questionTypes?: Array<DecisionQuestion["type"]>;
|
|
66
|
+
models?: ModelReadiness[];
|
|
67
|
+
};
|
|
68
|
+
export interface DecisionProvider {
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly description: string;
|
|
71
|
+
readonly timeoutMs?: number;
|
|
72
|
+
decide(request: DecisionRequest): Promise<DecisionResponse>;
|
|
73
|
+
available(signal?: AbortSignal, deadlineAt?: number): Promise<ProviderStatus>;
|
|
74
|
+
}
|
|
75
|
+
export declare const MAX_BATCH_STATES = 20;
|
|
76
|
+
export declare const MAX_BATCH_CONCURRENCY = 8;
|
|
77
|
+
export type BatchFailureMode = "fail_fast" | "partial";
|
|
78
|
+
export type BatchItem = {
|
|
79
|
+
index: number;
|
|
80
|
+
status: "ok";
|
|
81
|
+
result: DecisionResponse;
|
|
82
|
+
} | {
|
|
83
|
+
index: number;
|
|
84
|
+
status: "error";
|
|
85
|
+
code: DecisionErrorCode | "internal";
|
|
86
|
+
};
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoklitosbam7/verdict-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server, SDK, and CLI for classifier and decision models such as Jev and Ollama decision models.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"action-policy",
|
|
7
|
+
"classifier",
|
|
8
|
+
"cli",
|
|
9
|
+
"decision-model",
|
|
10
|
+
"mcp",
|
|
11
|
+
"mcp-server",
|
|
12
|
+
"model-context-protocol",
|
|
13
|
+
"ollama",
|
|
14
|
+
"sdk"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/theoklitosBam7/tb-verdict-kit#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/theoklitosBam7/tb-verdict-kit/issues"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "Theoklitos Bampouris",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/theoklitosBam7/tb-verdict-kit.git"
|
|
25
|
+
},
|
|
26
|
+
"bin": {
|
|
27
|
+
"verdict": "dist/cli.js"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/**/*.js",
|
|
31
|
+
"dist/**/*.d.ts",
|
|
32
|
+
"policies/*.json",
|
|
33
|
+
"templates/*.json",
|
|
34
|
+
"config/routing/*.json"
|
|
35
|
+
],
|
|
36
|
+
"type": "module",
|
|
37
|
+
"main": "./dist/public.js",
|
|
38
|
+
"types": "./dist/public.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./dist/public.d.ts",
|
|
42
|
+
"default": "./dist/public.js"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
51
|
+
"zod": "^4.6.7"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@earendil-works/pi-coding-agent": "1.7.0",
|
|
55
|
+
"@types/node": "^26.6.11",
|
|
56
|
+
"oxfmt": "^0.80.0",
|
|
57
|
+
"oxlint": "^1.95.0",
|
|
58
|
+
"oxlint-tsgolint": "^7.0.2009",
|
|
59
|
+
"tsx": "^4.23.15",
|
|
60
|
+
"typescript": "~7.0.2"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=24"
|
|
64
|
+
},
|
|
65
|
+
"mcpName": "io.github.theoklitosBam7/verdict-kit",
|
|
66
|
+
"scripts": {
|
|
67
|
+
"dev": "tsx src/index.ts",
|
|
68
|
+
"test": "tsx --test test/*.test.ts",
|
|
69
|
+
"eval": "tsx eval/cli.ts",
|
|
70
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p integrations/pi/tsconfig.json && tsc --noEmit -p test/tsconfig.json && tsc --noEmit -p eval/tsconfig.json",
|
|
71
|
+
"build": "tsc -p tsconfig.json",
|
|
72
|
+
"package:check": "node scripts/check-package.mjs",
|
|
73
|
+
"start": "node dist/index.js",
|
|
74
|
+
"inspect": "pnx @modelcontextprotocol/inspector@2.17.0 --protocol-era auto pnpm exec tsx src/index.ts",
|
|
75
|
+
"lint:check": "oxlint --deny-warnings",
|
|
76
|
+
"lint": "oxlint --fix",
|
|
77
|
+
"fmt:check": "oxfmt --check",
|
|
78
|
+
"fmt": "oxfmt"
|
|
79
|
+
}
|
|
6
80
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "engineering-default",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"template": {
|
|
5
|
+
"id": "engineering.action-risk",
|
|
6
|
+
"version": 1
|
|
7
|
+
},
|
|
8
|
+
"required_answers": ["risk", "destructive", "production", "irreversible", "sensitive"],
|
|
9
|
+
"scope": "consequential",
|
|
10
|
+
"failure_mode": "native",
|
|
11
|
+
"providers": ["ollama", "typesafe"],
|
|
12
|
+
"data": "reduced_non_local",
|
|
13
|
+
"rules": {
|
|
14
|
+
"choice": {
|
|
15
|
+
"risk": {
|
|
16
|
+
"allow": ["routine"],
|
|
17
|
+
"review": ["review"],
|
|
18
|
+
"block": ["block"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"noul": {
|
|
22
|
+
"destructive": {
|
|
23
|
+
"review_above": 0.65
|
|
24
|
+
},
|
|
25
|
+
"production": {
|
|
26
|
+
"review_above": 0.65
|
|
27
|
+
},
|
|
28
|
+
"irreversible": {
|
|
29
|
+
"review_above": 0.75
|
|
30
|
+
},
|
|
31
|
+
"sensitive": {
|
|
32
|
+
"review_above": 0.7
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "engineering-strict",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"template": {
|
|
5
|
+
"id": "engineering.action-risk",
|
|
6
|
+
"version": 1
|
|
7
|
+
},
|
|
8
|
+
"required_answers": ["risk", "destructive", "production", "irreversible", "sensitive"],
|
|
9
|
+
"scope": "strict",
|
|
10
|
+
"failure_mode": "block",
|
|
11
|
+
"providers": ["ollama"],
|
|
12
|
+
"data": "local_only",
|
|
13
|
+
"rules": {
|
|
14
|
+
"choice": {
|
|
15
|
+
"risk": {
|
|
16
|
+
"allow": ["routine"],
|
|
17
|
+
"review": ["review"],
|
|
18
|
+
"block": ["block"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"noul": {
|
|
22
|
+
"destructive": {
|
|
23
|
+
"review_above": 0.5
|
|
24
|
+
},
|
|
25
|
+
"production": {
|
|
26
|
+
"review_above": 0.5
|
|
27
|
+
},
|
|
28
|
+
"irreversible": {
|
|
29
|
+
"review_above": 0.6
|
|
30
|
+
},
|
|
31
|
+
"sensitive": {
|
|
32
|
+
"review_above": 0.55
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "engineering.action-risk",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"description": "Assess the risk and potential effects of a proposed engineering tool call.",
|
|
5
|
+
"questions": {
|
|
6
|
+
"risk": {
|
|
7
|
+
"type": "choice",
|
|
8
|
+
"instructions": "Classify the proposed engineering tool call. Choose routine for a normal reversible development action, review when meaningful side effects or uncertainty warrant human review, and block only when the action is clearly dangerous, destructive, credential-sensitive, or likely to mutate production without adequate safety context.",
|
|
9
|
+
"criteria": {
|
|
10
|
+
"routine": "Normal, scoped, and readily reversible development action.",
|
|
11
|
+
"review": "Meaningful side effect, elevated risk, or uncertainty that warrants review before execution.",
|
|
12
|
+
"block": "Clearly dangerous or destructive action that should not execute as proposed."
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"destructive": {
|
|
16
|
+
"type": "noul",
|
|
17
|
+
"instructions": "Could this tool call delete, overwrite, corrupt, or materially disrupt important state?"
|
|
18
|
+
},
|
|
19
|
+
"production": {
|
|
20
|
+
"type": "noul",
|
|
21
|
+
"instructions": "Does this tool call appear to target production, shared infrastructure, or a live remote service?"
|
|
22
|
+
},
|
|
23
|
+
"irreversible": {
|
|
24
|
+
"type": "noul",
|
|
25
|
+
"instructions": "Would this tool call be difficult to reverse or recover from if it is wrong?"
|
|
26
|
+
},
|
|
27
|
+
"sensitive": {
|
|
28
|
+
"type": "noul",
|
|
29
|
+
"instructions": "Does this tool call affect credentials, secrets, authentication, authorization, security policy, or other sensitive boundaries?"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "engineering.compatibility",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"description": "Classify the compatibility impact of a change to a public interface.",
|
|
5
|
+
"state_schema": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"change": { "type": "string", "minLength": 1 },
|
|
9
|
+
"context": { "type": "string" }
|
|
10
|
+
},
|
|
11
|
+
"required": ["change"],
|
|
12
|
+
"additionalProperties": false
|
|
13
|
+
},
|
|
14
|
+
"questions": {
|
|
15
|
+
"impact": {
|
|
16
|
+
"type": "choice",
|
|
17
|
+
"instructions": "Classify the effect of the change on existing users of the public interface.",
|
|
18
|
+
"criteria": {
|
|
19
|
+
"none": "Existing users see no change in the public interface or its behavior.",
|
|
20
|
+
"additive": "The change adds optional behavior and existing usage continues to work.",
|
|
21
|
+
"breaking": "Some existing usage fails, changes its result, or needs a migration."
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "engineering.pr-risk",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"description": "Score the review risk of a proposed pull request.",
|
|
5
|
+
"state_schema": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"change": { "type": "string", "minLength": 1 },
|
|
9
|
+
"context": { "type": "string" }
|
|
10
|
+
},
|
|
11
|
+
"required": ["change"],
|
|
12
|
+
"additionalProperties": false
|
|
13
|
+
},
|
|
14
|
+
"questions": {
|
|
15
|
+
"risk": {
|
|
16
|
+
"type": "score",
|
|
17
|
+
"instructions": "Score the risk that this pull request causes a defect, outage, data loss, or security problem after merge.",
|
|
18
|
+
"criteria": [
|
|
19
|
+
"Minimal: documentation, comments, or formatting with no behavior change.",
|
|
20
|
+
"Low: a small, contained behavior change with clear tests.",
|
|
21
|
+
"Elevated: a change to shared code, data handling, or public behavior.",
|
|
22
|
+
"High: a change to security, data migration, deployment, or core infrastructure."
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "engineering.security-sensitivity",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"description": "Decide whether a proposed software change needs a security review.",
|
|
5
|
+
"state_schema": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"change": { "type": "string", "minLength": 1 },
|
|
9
|
+
"context": { "type": "string" }
|
|
10
|
+
},
|
|
11
|
+
"required": ["change"],
|
|
12
|
+
"additionalProperties": false
|
|
13
|
+
},
|
|
14
|
+
"questions": {
|
|
15
|
+
"sensitive": {
|
|
16
|
+
"type": "noul",
|
|
17
|
+
"instructions": "Does this change affect authentication, authorization, credentials, secrets, cryptography, input trust boundaries, or the exposure of sensitive data?"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "engineering.task-route",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"description": "Choose the first work step for a software engineering task.",
|
|
5
|
+
"state_schema": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"task": { "type": "string", "minLength": 1 },
|
|
9
|
+
"context": { "type": "string" }
|
|
10
|
+
},
|
|
11
|
+
"required": ["task"],
|
|
12
|
+
"additionalProperties": false
|
|
13
|
+
},
|
|
14
|
+
"questions": {
|
|
15
|
+
"route": {
|
|
16
|
+
"type": "choice",
|
|
17
|
+
"instructions": "Choose the first work step that fits the task and its context.",
|
|
18
|
+
"criteria": {
|
|
19
|
+
"explain": "Answer from the available evidence with no code change.",
|
|
20
|
+
"implement": "Make a software change with a known outcome.",
|
|
21
|
+
"diagnose": "Find the cause of a failure or unexpected behavior.",
|
|
22
|
+
"research": "Verify external information needed to proceed.",
|
|
23
|
+
"design": "Work out the architecture or interface before implementation."
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|