-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathaltimate-core-check.ts
More file actions
80 lines (72 loc) · 2.68 KB
/
altimate-core-check.ts
File metadata and controls
80 lines (72 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import z from "zod"
import { Tool } from "../../tool/tool"
import { Dispatcher } from "../native"
export const AltimateCoreCheckTool = Tool.define("altimate_core_check", {
description:
"Run full analysis pipeline: validate + lint + safety scan + PII check. Single call for comprehensive SQL analysis. Provide schema_context or schema_path for accurate table/column resolution.",
parameters: z.object({
sql: z.string().describe("SQL query to analyze"),
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
}),
async execute(args, ctx) {
try {
const result = await Dispatcher.call("altimate_core.check", {
sql: args.sql,
schema_path: args.schema_path ?? "",
schema_context: args.schema_context,
})
const data = result.data as Record<string, any>
return {
title: `Check: ${formatCheckTitle(data)}`,
metadata: { success: result.success },
output: formatCheck(data),
}
} catch (e) {
const msg = e instanceof Error ? e.message : String(e)
return { title: "Check: ERROR", metadata: { success: false }, output: `Failed: ${msg}` }
}
},
})
function formatCheckTitle(data: Record<string, any>): string {
const parts: string[] = []
if (!data.validation?.valid) parts.push("validation errors")
if (!data.lint?.clean) parts.push(`${data.lint?.findings?.length ?? 0} lint findings`)
if (!data.safety?.safe) parts.push("safety threats")
if (data.pii?.findings?.length) parts.push("PII detected")
return parts.length ? parts.join(", ") : "PASS"
}
function formatCheck(data: Record<string, any>): string {
const lines: string[] = []
lines.push("=== Validation ===")
if (data.validation?.valid) {
lines.push("Valid SQL.")
} else {
lines.push(`Invalid: ${data.validation?.errors?.map((e: any) => e.message).join("; ") ?? "unknown"}`)
}
lines.push("\n=== Lint ===")
if (data.lint?.clean) {
lines.push("No lint findings.")
} else {
for (const f of data.lint?.findings ?? []) {
lines.push(` [${f.severity}] ${f.rule}: ${f.message}`)
}
}
lines.push("\n=== Safety ===")
if (data.safety?.safe) {
lines.push("Safe — no threats.")
} else {
for (const t of data.safety?.threats ?? []) {
lines.push(` [${t.severity}] ${t.type}: ${t.description}`)
}
}
lines.push("\n=== PII ===")
if (!data.pii?.findings?.length) {
lines.push("No PII detected.")
} else {
for (const p of data.pii?.findings ?? []) {
lines.push(` ${p.column}: ${p.category} (${p.confidence} confidence)`)
}
}
return lines.join("\n")
}