@assertion-runtime/sdk-node 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 +6 -0
- package/dist/assertion-finding.schema.json +42 -0
- package/dist/cli.d.ts +18 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +78 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +273 -0
- package/dist/index.js.map +1 -0
- package/dist/sdk-diagnostic.schema.json +67 -0
- package/package.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "assr://schemas/assertion-finding/1.0.0",
|
|
4
|
+
"title": "AssertionFinding",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": [
|
|
7
|
+
"finding_id",
|
|
8
|
+
"output_excerpt",
|
|
9
|
+
"reason",
|
|
10
|
+
"created_at",
|
|
11
|
+
"emission_site"
|
|
12
|
+
],
|
|
13
|
+
"properties": {
|
|
14
|
+
"finding_id": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"format": "uuid"
|
|
17
|
+
},
|
|
18
|
+
"output_excerpt": {
|
|
19
|
+
"type": "string"
|
|
20
|
+
},
|
|
21
|
+
"reason": {
|
|
22
|
+
"type": "string"
|
|
23
|
+
},
|
|
24
|
+
"emission_site": {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"required": ["file", "line", "runtime", "stack_hash"],
|
|
27
|
+
"properties": {
|
|
28
|
+
"file": { "type": "string" },
|
|
29
|
+
"line": { "type": "number" },
|
|
30
|
+
"function": { "type": "string" },
|
|
31
|
+
"runtime": { "type": "string" },
|
|
32
|
+
"stack_hash": { "type": "string" }
|
|
33
|
+
},
|
|
34
|
+
"additionalProperties": false
|
|
35
|
+
},
|
|
36
|
+
"created_at": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"format": "date-time"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"additionalProperties": false
|
|
42
|
+
}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
type Finding = {
|
|
3
|
+
finding_id: string;
|
|
4
|
+
output_excerpt: string;
|
|
5
|
+
reason: string;
|
|
6
|
+
file_path?: string | null;
|
|
7
|
+
line_number?: number | null;
|
|
8
|
+
created_at?: string;
|
|
9
|
+
};
|
|
10
|
+
declare function formatEmissionSite(finding: Finding): string;
|
|
11
|
+
declare function formatCreatedAt(value?: string): string;
|
|
12
|
+
declare function parseArgs(argv: string[]): {
|
|
13
|
+
command: string | undefined;
|
|
14
|
+
json: boolean;
|
|
15
|
+
};
|
|
16
|
+
declare function fetchFindings(endpoint: string, apiKey?: string): Promise<Finding[]>;
|
|
17
|
+
declare function main(): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,KAAK,OAAO,GAAG;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,iBAAS,kBAAkB,CAAC,OAAO,EAAE,OAAO,UAM3C;AAED,iBAAS,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,UAUtC;AAED,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE;;;EAKhC;AAED,iBAAe,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,sBAa7D;AAED,iBAAe,IAAI,kBAoClB"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
function formatEmissionSite(finding) {
|
|
4
|
+
if (!finding.file_path)
|
|
5
|
+
return "-";
|
|
6
|
+
if (typeof finding.line_number === "number") {
|
|
7
|
+
return `${finding.file_path}:${finding.line_number}`;
|
|
8
|
+
}
|
|
9
|
+
return finding.file_path;
|
|
10
|
+
}
|
|
11
|
+
function formatCreatedAt(value) {
|
|
12
|
+
if (!value)
|
|
13
|
+
return "-";
|
|
14
|
+
const date = new Date(value);
|
|
15
|
+
if (Number.isNaN(date.getTime()))
|
|
16
|
+
return value;
|
|
17
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
18
|
+
month: "short",
|
|
19
|
+
day: "2-digit",
|
|
20
|
+
hour: "2-digit",
|
|
21
|
+
minute: "2-digit",
|
|
22
|
+
}).format(date);
|
|
23
|
+
}
|
|
24
|
+
function parseArgs(argv) {
|
|
25
|
+
const args = [...argv];
|
|
26
|
+
const command = args[0] && !args[0].startsWith("-") ? args.shift() : "lint";
|
|
27
|
+
const json = args.includes("--json");
|
|
28
|
+
return { command, json };
|
|
29
|
+
}
|
|
30
|
+
async function fetchFindings(endpoint, apiKey) {
|
|
31
|
+
const url = `${endpoint.replace(/\/$/, "")}/findings?limit=200&offset=0`;
|
|
32
|
+
const response = await fetch(url, {
|
|
33
|
+
headers: {
|
|
34
|
+
...(apiKey ? { authorization: `Bearer ${apiKey}` } : {}),
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const body = await response.text();
|
|
39
|
+
throw new Error(`Finding fetch failed (${response.status}): ${body}`);
|
|
40
|
+
}
|
|
41
|
+
const payload = (await response.json());
|
|
42
|
+
return Array.isArray(payload.findings) ? payload.findings : [];
|
|
43
|
+
}
|
|
44
|
+
async function main() {
|
|
45
|
+
const { command, json } = parseArgs(process.argv.slice(2));
|
|
46
|
+
if (command !== "lint") {
|
|
47
|
+
console.error("Usage: assertion-runtime lint [--json]");
|
|
48
|
+
process.exit(2);
|
|
49
|
+
}
|
|
50
|
+
const endpoint = process.env.ASSR_RUNTIME_API_URL || process.env.RUNTIME_API_URL || "http://localhost:4000";
|
|
51
|
+
const apiKey = process.env.ASSR_ADMIN_API_KEY || process.env.ASSR_API_KEY;
|
|
52
|
+
try {
|
|
53
|
+
const findings = await fetchFindings(endpoint, apiKey);
|
|
54
|
+
if (json) {
|
|
55
|
+
process.stdout.write(`${JSON.stringify({ findings }, null, 2)}\n`);
|
|
56
|
+
process.exit(findings.length > 0 ? 1 : 0);
|
|
57
|
+
}
|
|
58
|
+
if (findings.length === 0) {
|
|
59
|
+
console.log("No risky outputs detected.");
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
console.log(`${findings.length} risky outputs detected:`);
|
|
63
|
+
for (const finding of findings) {
|
|
64
|
+
console.log(`- ${finding.finding_id.slice(0, 8)} ${finding.output_excerpt}`);
|
|
65
|
+
console.log(` ${finding.reason}`);
|
|
66
|
+
console.log(` Emitted from: ${formatEmissionSite(finding)}`);
|
|
67
|
+
console.log(` Created: ${formatCreatedAt(finding.created_at)}`);
|
|
68
|
+
console.log("");
|
|
69
|
+
}
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error(error instanceof Error ? error.message : "CLI failed");
|
|
74
|
+
process.exit(2);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
void main();
|
|
78
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AAWA,SAAS,kBAAkB,CAAC,OAAgB;IAC1C,IAAI,CAAC,OAAO,CAAC,SAAS;QAAE,OAAO,GAAG,CAAC;IAC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,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,KAAK,IAAI,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export interface EmitOptions {
|
|
2
|
+
endpoint?: string;
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface EmissionSite {
|
|
6
|
+
file?: string;
|
|
7
|
+
line?: number;
|
|
8
|
+
function?: string;
|
|
9
|
+
runtime?: string;
|
|
10
|
+
stack_hash?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AssertionFinding {
|
|
13
|
+
finding_id: string;
|
|
14
|
+
output_excerpt: string;
|
|
15
|
+
reason: string;
|
|
16
|
+
emission_site?: EmissionSite;
|
|
17
|
+
created_at: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function lintOutput(output: string): {
|
|
20
|
+
reason: string;
|
|
21
|
+
} | null;
|
|
22
|
+
export declare function buildFinding(output: string): AssertionFinding | null;
|
|
23
|
+
export declare function emitFinding(output: string, options?: EmitOptions): Promise<unknown>;
|
|
24
|
+
export interface SdkDiagnosticEvent {
|
|
25
|
+
diagnostic_id: string;
|
|
26
|
+
project_id: string;
|
|
27
|
+
sdk: {
|
|
28
|
+
language: "node" | "python";
|
|
29
|
+
version: string;
|
|
30
|
+
runtime?: string;
|
|
31
|
+
platform?: string;
|
|
32
|
+
};
|
|
33
|
+
window: {
|
|
34
|
+
start: string;
|
|
35
|
+
end: string;
|
|
36
|
+
duration_sec?: number;
|
|
37
|
+
};
|
|
38
|
+
counters: Record<string, number>;
|
|
39
|
+
buffer: {
|
|
40
|
+
backend?: "file" | "sqlite" | "memory";
|
|
41
|
+
current_depth: number;
|
|
42
|
+
max_depth?: number;
|
|
43
|
+
oldest_event_age_sec?: number;
|
|
44
|
+
};
|
|
45
|
+
latency_ms?: Record<string, number>;
|
|
46
|
+
flags?: Record<string, boolean>;
|
|
47
|
+
timestamp: string;
|
|
48
|
+
schema_version: string;
|
|
49
|
+
extensions?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
export interface DiagnosticsOptions {
|
|
52
|
+
endpoint: string;
|
|
53
|
+
apiKey?: string;
|
|
54
|
+
projectId: string;
|
|
55
|
+
sdkVersion: string;
|
|
56
|
+
runtime?: string;
|
|
57
|
+
platform?: string;
|
|
58
|
+
schemaVersion?: string;
|
|
59
|
+
}
|
|
60
|
+
export declare class DiagnosticsEmitter {
|
|
61
|
+
private options;
|
|
62
|
+
private windowStart;
|
|
63
|
+
private counters;
|
|
64
|
+
private bufferState;
|
|
65
|
+
private latency;
|
|
66
|
+
private flags;
|
|
67
|
+
private flushInFlight;
|
|
68
|
+
private flushOnExitBound;
|
|
69
|
+
constructor(options: DiagnosticsOptions);
|
|
70
|
+
increment(counter: string, value?: number): void;
|
|
71
|
+
setBufferState(state: SdkDiagnosticEvent["buffer"]): void;
|
|
72
|
+
setLatency(metrics: Record<string, number>): void;
|
|
73
|
+
setFlags(flags: Record<string, boolean>): void;
|
|
74
|
+
emit(): Promise<unknown>;
|
|
75
|
+
registerShutdownHooks(): void;
|
|
76
|
+
unregisterShutdownHooks(): void;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAuBD,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB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AAC;CACtC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,kBAAkB;IASjB,OAAO,CAAC,OAAO;IAR3B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,WAAW,CAAwD;IAC3E,OAAO,CAAC,OAAO,CAAqC;IACpD,OAAO,CAAC,KAAK,CAAsC;IACnD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,gBAAgB,CAA6B;gBAEjC,OAAO,EAAE,kBAAkB;IAE/C,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAI;IAIpC,cAAc,CAAC,KAAK,EAAE,kBAAkB,CAAC,QAAQ,CAAC;IAIlD,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAI1C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIjC,IAAI;IAmDV,qBAAqB;IAYrB,uBAAuB;CAOxB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import Ajv from "ajv";
|
|
3
|
+
import addFormats from "ajv-formats";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const diagnosticSchemaPath = join(currentDir, "sdk-diagnostic.schema.json");
|
|
9
|
+
const findingSchemaPath = join(currentDir, "assertion-finding.schema.json");
|
|
10
|
+
const diagnosticSchema = JSON.parse(readFileSync(diagnosticSchemaPath, "utf-8"));
|
|
11
|
+
const findingSchema = JSON.parse(readFileSync(findingSchemaPath, "utf-8"));
|
|
12
|
+
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
13
|
+
addFormats(ajv);
|
|
14
|
+
const validateDiagnostic = ajv.compile(diagnosticSchema);
|
|
15
|
+
const validateFinding = ajv.compile(findingSchema);
|
|
16
|
+
function validateDiagnosticEvent(event) {
|
|
17
|
+
const ok = validateDiagnostic(event);
|
|
18
|
+
if (!ok) {
|
|
19
|
+
const error = new Error("invalid_diagnostic");
|
|
20
|
+
error.details = validateDiagnostic.errors ?? [];
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const seenFindings = new Set();
|
|
25
|
+
function validateFindingEvent(event) {
|
|
26
|
+
const ok = validateFinding(event);
|
|
27
|
+
if (!ok) {
|
|
28
|
+
const error = new Error("invalid_finding");
|
|
29
|
+
error.details = validateFinding.errors ?? [];
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function summarizeOutput(output, maxLength = 140) {
|
|
34
|
+
const trimmed = output.trim();
|
|
35
|
+
if (trimmed.length <= maxLength)
|
|
36
|
+
return trimmed;
|
|
37
|
+
return `${trimmed.slice(0, maxLength - 1)}…`;
|
|
38
|
+
}
|
|
39
|
+
function hashStackLocation(params) {
|
|
40
|
+
const payload = `${params.file}:${params.line}:${params.functionName ?? ""}`;
|
|
41
|
+
return crypto.createHash("sha256").update(payload).digest("hex");
|
|
42
|
+
}
|
|
43
|
+
function parseStackLine(line) {
|
|
44
|
+
const stripFileUrl = (value) => {
|
|
45
|
+
if (!value.startsWith("file://"))
|
|
46
|
+
return value;
|
|
47
|
+
try {
|
|
48
|
+
return fileURLToPath(value);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const withFunc = line.match(/^at\s+(?:async\s+)?(.+?)\s+\((.+):(\d+):(\d+)\)$/);
|
|
55
|
+
if (withFunc) {
|
|
56
|
+
return {
|
|
57
|
+
function: withFunc[1],
|
|
58
|
+
file: stripFileUrl(withFunc[2]),
|
|
59
|
+
line: Number(withFunc[3]),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const withoutFunc = line.match(/^at\s+(?:async\s+)?(.+):(\d+):(\d+)$/);
|
|
63
|
+
if (withoutFunc) {
|
|
64
|
+
return {
|
|
65
|
+
file: stripFileUrl(withoutFunc[1]),
|
|
66
|
+
line: Number(withoutFunc[2]),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
function captureEmissionSite() {
|
|
72
|
+
const stack = new Error().stack;
|
|
73
|
+
if (!stack)
|
|
74
|
+
return undefined;
|
|
75
|
+
const lines = stack.split("\n").map((line) => line.trim());
|
|
76
|
+
const skipPatterns = ["node:internal", "/node_modules/", "assr_sdk", "sdk-node", "internal/process"];
|
|
77
|
+
const candidate = lines
|
|
78
|
+
.slice(1)
|
|
79
|
+
.map((line) => ({ line, parsed: parseStackLine(line) }))
|
|
80
|
+
.find((entry) => entry.parsed && !skipPatterns.some((pattern) => entry.line.includes(pattern)));
|
|
81
|
+
if (!candidate?.parsed) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
file: candidate.parsed.file,
|
|
86
|
+
line: candidate.parsed.line,
|
|
87
|
+
function: candidate.parsed.function,
|
|
88
|
+
runtime: `node${process.version}`,
|
|
89
|
+
stack_hash: hashStackLocation({
|
|
90
|
+
file: candidate.parsed.file,
|
|
91
|
+
line: candidate.parsed.line,
|
|
92
|
+
functionName: candidate.parsed.function,
|
|
93
|
+
}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function hasQualifier(output) {
|
|
97
|
+
return /\b(estimate|approximately|approx|may|might|likely|suggests|early data|could)\b/i.test(output);
|
|
98
|
+
}
|
|
99
|
+
function isDebugLog(output) {
|
|
100
|
+
return /^(?:\s*\[?(?:debug|trace|info|warn|error)\]?:\s*|\s*(?:fetched|loaded|processing|queued|executed|query|cache|http)\b)/i.test(output);
|
|
101
|
+
}
|
|
102
|
+
function isForwardLooking(output) {
|
|
103
|
+
return /\b(q1|next quarter|will|predicts|expected)\b/i.test(output);
|
|
104
|
+
}
|
|
105
|
+
function isClaimCandidate(output) {
|
|
106
|
+
if (hasQualifier(output))
|
|
107
|
+
return false;
|
|
108
|
+
if (isDebugLog(output))
|
|
109
|
+
return false;
|
|
110
|
+
if (output.length <= 10)
|
|
111
|
+
return false;
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
function isDeclarative(output) {
|
|
115
|
+
return !hasQualifier(output);
|
|
116
|
+
}
|
|
117
|
+
export function lintOutput(output) {
|
|
118
|
+
const trimmed = output.trim();
|
|
119
|
+
if (!trimmed)
|
|
120
|
+
return null;
|
|
121
|
+
if (!isClaimCandidate(trimmed))
|
|
122
|
+
return null;
|
|
123
|
+
if (!isForwardLooking(trimmed))
|
|
124
|
+
return null;
|
|
125
|
+
if (!isDeclarative(trimmed))
|
|
126
|
+
return null;
|
|
127
|
+
return { reason: "Forward-looking claim without sufficient supporting context" };
|
|
128
|
+
}
|
|
129
|
+
export function buildFinding(output) {
|
|
130
|
+
const lint = lintOutput(output);
|
|
131
|
+
if (!lint)
|
|
132
|
+
return null;
|
|
133
|
+
const findingId = crypto.randomUUID();
|
|
134
|
+
const emissionSite = captureEmissionSite();
|
|
135
|
+
if (!emissionSite?.stack_hash || !emissionSite.file || typeof emissionSite.line !== "number")
|
|
136
|
+
return null;
|
|
137
|
+
return {
|
|
138
|
+
finding_id: findingId,
|
|
139
|
+
output_excerpt: summarizeOutput(output),
|
|
140
|
+
reason: lint.reason,
|
|
141
|
+
emission_site: emissionSite,
|
|
142
|
+
created_at: new Date().toISOString(),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export async function emitFinding(output, options = {}) {
|
|
146
|
+
const finding = buildFinding(output);
|
|
147
|
+
if (!finding) {
|
|
148
|
+
return { status: "skipped", reason: "not_risky" };
|
|
149
|
+
}
|
|
150
|
+
const stackHash = finding.emission_site?.stack_hash;
|
|
151
|
+
const key = stackHash ? `${stackHash}::${finding.output_excerpt}` : null;
|
|
152
|
+
if (key && seenFindings.has(key)) {
|
|
153
|
+
return { status: "skipped", reason: "deduped" };
|
|
154
|
+
}
|
|
155
|
+
if (key) {
|
|
156
|
+
seenFindings.add(key);
|
|
157
|
+
}
|
|
158
|
+
validateFindingEvent(finding);
|
|
159
|
+
if (!options.endpoint) {
|
|
160
|
+
throw new Error("Missing endpoint; provide endpoint.");
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const response = await fetch(`${options.endpoint}/findings`, {
|
|
164
|
+
method: "POST",
|
|
165
|
+
headers: {
|
|
166
|
+
"content-type": "application/json",
|
|
167
|
+
...(options.apiKey ? { authorization: `Bearer ${options.apiKey}` } : {}),
|
|
168
|
+
},
|
|
169
|
+
body: JSON.stringify(finding),
|
|
170
|
+
});
|
|
171
|
+
if (!response.ok) {
|
|
172
|
+
const body = await response.text();
|
|
173
|
+
return { status: "skipped", reason: "fail_open", error: `Finding emit failed (${response.status}): ${body}` };
|
|
174
|
+
}
|
|
175
|
+
return response.json();
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
return {
|
|
179
|
+
status: "skipped",
|
|
180
|
+
reason: "fail_open",
|
|
181
|
+
error: error instanceof Error ? error.message : "finding_emit_failed",
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
export class DiagnosticsEmitter {
|
|
186
|
+
constructor(options) {
|
|
187
|
+
this.options = options;
|
|
188
|
+
this.windowStart = new Date();
|
|
189
|
+
this.counters = {};
|
|
190
|
+
this.bufferState = { current_depth: 0 };
|
|
191
|
+
this.flushInFlight = false;
|
|
192
|
+
this.flushOnExitBound = null;
|
|
193
|
+
}
|
|
194
|
+
increment(counter, value = 1) {
|
|
195
|
+
this.counters[counter] = (this.counters[counter] ?? 0) + value;
|
|
196
|
+
}
|
|
197
|
+
setBufferState(state) {
|
|
198
|
+
this.bufferState = state;
|
|
199
|
+
}
|
|
200
|
+
setLatency(metrics) {
|
|
201
|
+
this.latency = metrics;
|
|
202
|
+
}
|
|
203
|
+
setFlags(flags) {
|
|
204
|
+
this.flags = flags;
|
|
205
|
+
}
|
|
206
|
+
async emit() {
|
|
207
|
+
if (this.flushInFlight) {
|
|
208
|
+
return { status: "skipped", reason: "in_flight" };
|
|
209
|
+
}
|
|
210
|
+
this.flushInFlight = true;
|
|
211
|
+
const windowEnd = new Date();
|
|
212
|
+
const payload = {
|
|
213
|
+
diagnostic_id: crypto.randomUUID(),
|
|
214
|
+
project_id: this.options.projectId,
|
|
215
|
+
sdk: {
|
|
216
|
+
language: "node",
|
|
217
|
+
version: this.options.sdkVersion,
|
|
218
|
+
runtime: this.options.runtime,
|
|
219
|
+
platform: this.options.platform,
|
|
220
|
+
},
|
|
221
|
+
window: {
|
|
222
|
+
start: this.windowStart.toISOString(),
|
|
223
|
+
end: windowEnd.toISOString(),
|
|
224
|
+
duration_sec: Math.max(1, Math.floor((windowEnd.getTime() - this.windowStart.getTime()) / 1000)),
|
|
225
|
+
},
|
|
226
|
+
counters: this.counters,
|
|
227
|
+
buffer: this.bufferState,
|
|
228
|
+
latency_ms: this.latency,
|
|
229
|
+
flags: this.flags,
|
|
230
|
+
timestamp: windowEnd.toISOString(),
|
|
231
|
+
schema_version: this.options.schemaVersion ?? "1.0.0",
|
|
232
|
+
};
|
|
233
|
+
validateDiagnosticEvent(payload);
|
|
234
|
+
const response = await fetch(`${this.options.endpoint}/sdk-diagnostics`, {
|
|
235
|
+
method: "POST",
|
|
236
|
+
headers: {
|
|
237
|
+
"content-type": "application/json",
|
|
238
|
+
...(this.options.apiKey ? { authorization: `Bearer ${this.options.apiKey}` } : {}),
|
|
239
|
+
},
|
|
240
|
+
body: JSON.stringify(payload),
|
|
241
|
+
});
|
|
242
|
+
if (!response.ok) {
|
|
243
|
+
const body = await response.text();
|
|
244
|
+
this.flushInFlight = false;
|
|
245
|
+
throw new Error(`Diagnostics emit failed (${response.status}): ${body}`);
|
|
246
|
+
}
|
|
247
|
+
this.windowStart = windowEnd;
|
|
248
|
+
this.counters = {};
|
|
249
|
+
this.flushInFlight = false;
|
|
250
|
+
return response.json();
|
|
251
|
+
}
|
|
252
|
+
registerShutdownHooks() {
|
|
253
|
+
if (this.flushOnExitBound)
|
|
254
|
+
return;
|
|
255
|
+
this.flushOnExitBound = () => {
|
|
256
|
+
void this.emit().catch(() => {
|
|
257
|
+
// Best-effort on shutdown; never throw.
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
process.on("beforeExit", this.flushOnExitBound);
|
|
261
|
+
process.on("SIGTERM", this.flushOnExitBound);
|
|
262
|
+
process.on("SIGINT", this.flushOnExitBound);
|
|
263
|
+
}
|
|
264
|
+
unregisterShutdownHooks() {
|
|
265
|
+
if (!this.flushOnExitBound)
|
|
266
|
+
return;
|
|
267
|
+
process.off("beforeExit", this.flushOnExitBound);
|
|
268
|
+
process.off("SIGTERM", this.flushOnExitBound);
|
|
269
|
+
process.off("SIGINT", this.flushOnExitBound);
|
|
270
|
+
this.flushOnExitBound = null;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,O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|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "SDK Diagnostic Event",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"required": [
|
|
6
|
+
"diagnostic_id",
|
|
7
|
+
"project_id",
|
|
8
|
+
"sdk",
|
|
9
|
+
"window",
|
|
10
|
+
"counters",
|
|
11
|
+
"buffer",
|
|
12
|
+
"timestamp",
|
|
13
|
+
"schema_version"
|
|
14
|
+
],
|
|
15
|
+
"properties": {
|
|
16
|
+
"diagnostic_id": { "type": "string", "format": "uuid" },
|
|
17
|
+
"project_id": { "type": "string", "format": "uuid" },
|
|
18
|
+
"sdk": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"required": ["language", "version"],
|
|
21
|
+
"properties": {
|
|
22
|
+
"language": { "enum": ["node", "python"] },
|
|
23
|
+
"version": { "type": "string" },
|
|
24
|
+
"runtime": { "type": "string" },
|
|
25
|
+
"platform": { "type": "string" }
|
|
26
|
+
},
|
|
27
|
+
"additionalProperties": false
|
|
28
|
+
},
|
|
29
|
+
"window": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"required": ["start", "end"],
|
|
32
|
+
"properties": {
|
|
33
|
+
"start": { "type": "string", "format": "date-time" },
|
|
34
|
+
"end": { "type": "string", "format": "date-time" },
|
|
35
|
+
"duration_sec": { "type": "number" }
|
|
36
|
+
},
|
|
37
|
+
"additionalProperties": false
|
|
38
|
+
},
|
|
39
|
+
"counters": {
|
|
40
|
+
"type": "object",
|
|
41
|
+
"additionalProperties": { "type": "number" }
|
|
42
|
+
},
|
|
43
|
+
"buffer": {
|
|
44
|
+
"type": "object",
|
|
45
|
+
"required": ["current_depth"],
|
|
46
|
+
"properties": {
|
|
47
|
+
"backend": { "enum": ["file", "sqlite", "memory"] },
|
|
48
|
+
"current_depth": { "type": "number" },
|
|
49
|
+
"max_depth": { "type": "number" },
|
|
50
|
+
"oldest_event_age_sec": { "type": "number" }
|
|
51
|
+
},
|
|
52
|
+
"additionalProperties": false
|
|
53
|
+
},
|
|
54
|
+
"latency_ms": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"additionalProperties": { "type": "number" }
|
|
57
|
+
},
|
|
58
|
+
"flags": {
|
|
59
|
+
"type": "object",
|
|
60
|
+
"additionalProperties": { "type": "boolean" }
|
|
61
|
+
},
|
|
62
|
+
"timestamp": { "type": "string", "format": "date-time" },
|
|
63
|
+
"schema_version": { "type": "string" },
|
|
64
|
+
"extensions": { "type": "object" }
|
|
65
|
+
},
|
|
66
|
+
"additionalProperties": false
|
|
67
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@assertion-runtime/sdk-node",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"assertion-runtime": "dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "rm -rf dist && tsc -p tsconfig.json && cp src/*.json dist/"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"ajv": "^8.17.1",
|
|
19
|
+
"ajv-formats": "^2.1.1"
|
|
20
|
+
}
|
|
21
|
+
}
|