@shield-agent/kya 0.22.0 → 0.23.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/.mcp.json +1 -1
- package/README.md +72 -30
- package/amp/settings.example.json +1 -1
- package/claude/claude_desktop_config.example.json +1 -1
- package/cline/cline_mcp_settings.example.json +1 -1
- package/copilot/mcp-config.example.json +1 -1
- package/dist/certify/attest.js +5 -5
- package/dist/certify/catalog.d.ts +1 -1
- package/dist/certify/catalog.js +3 -3
- package/dist/certify/context.js +1 -1
- package/dist/certify/evaluate.d.ts +2 -2
- package/dist/certify/evaluate.js +12 -12
- package/dist/certify/live.js +2 -2
- package/dist/certify/render.d.ts +1 -1
- package/dist/certify/render.js +10 -10
- package/dist/cli.d.ts +2 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +49 -16
- package/dist/cli.js.map +1 -1
- package/dist/commands/certify.d.ts +1 -1
- package/dist/commands/certify.js +3 -3
- package/dist/commands/connect.d.ts +2 -2
- package/dist/commands/connect.js +22 -22
- package/dist/commands/dash.js +4 -4
- package/dist/commands/gate-serve.js +3 -3
- package/dist/commands/gate.d.ts +1 -1
- package/dist/commands/gate.js +16 -16
- package/dist/commands/hook.d.ts +1 -1
- package/dist/commands/hook.d.ts.map +1 -1
- package/dist/commands/hook.js +55 -18
- package/dist/commands/hook.js.map +1 -1
- package/dist/commands/import-traces.d.ts +16 -0
- package/dist/commands/import-traces.d.ts.map +1 -0
- package/dist/commands/import-traces.js +18 -0
- package/dist/commands/import-traces.js.map +1 -0
- package/dist/commands/init.js +1 -1
- package/dist/commands/investigate.d.ts +13 -0
- package/dist/commands/investigate.d.ts.map +1 -0
- package/dist/commands/investigate.js +22 -0
- package/dist/commands/investigate.js.map +1 -0
- package/dist/commands/notify-flush.d.ts +2 -0
- package/dist/commands/notify-flush.d.ts.map +1 -0
- package/dist/commands/notify-flush.js +47 -0
- package/dist/commands/notify-flush.js.map +1 -0
- package/dist/commands/orr.d.ts +3 -3
- package/dist/commands/orr.js +5 -5
- package/dist/commands/receipt-serve.d.ts +1 -1
- package/dist/commands/receipt-serve.js +1 -1
- package/dist/commands/serve-mcp.js +1 -1
- package/dist/commands/start.d.ts +2 -2
- package/dist/commands/start.js +20 -20
- package/dist/commands/stop.d.ts +1 -1
- package/dist/commands/stop.js +6 -6
- package/dist/commands/update.d.ts +19 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +96 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/wire-hooks.d.ts +1 -1
- package/dist/commands/wire-hooks.js +14 -14
- package/dist/commands/wrap.d.ts.map +1 -1
- package/dist/commands/wrap.js +12 -7
- package/dist/commands/wrap.js.map +1 -1
- package/dist/config.d.ts +4 -4
- package/dist/config.js +5 -5
- package/dist/dash/dash.d.ts +1 -1
- package/dist/dash/dash.js +3 -3
- package/dist/dash/entitlement.d.ts +1 -1
- package/dist/dash/entitlement.js +1 -1
- package/dist/dash/render.js +2 -2
- package/dist/dash/screens/enterprise.js +9 -9
- package/dist/dash/screens/free.js +5 -5
- package/dist/diff-preview.d.ts +1 -1
- package/dist/diff-preview.js +2 -2
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/fs-atomic.d.ts +1 -1
- package/dist/fs-atomic.js +2 -2
- package/dist/gate/binary.js +4 -4
- package/dist/gate/config-gen.d.ts +1 -1
- package/dist/gate/config-gen.js +7 -7
- package/dist/gate/config.d.ts +2 -2
- package/dist/gate/config.js +6 -6
- package/dist/gate/daemon.js +1 -1
- package/dist/gate/discover.d.ts +2 -2
- package/dist/gate/discover.js +7 -7
- package/dist/gate/hosted-sync.js +1 -1
- package/dist/gate/otlp-decode.d.ts +2 -2
- package/dist/gate/otlp-decode.js +2 -2
- package/dist/gate/otlp-receiver.d.ts +1 -1
- package/dist/gate/otlp-receiver.js +3 -3
- package/dist/host-reload.js +11 -11
- package/dist/host-tools.d.ts +1 -1
- package/dist/host-tools.js +1 -1
- package/dist/importers/formats.d.ts +26 -0
- package/dist/importers/formats.d.ts.map +1 -0
- package/dist/importers/formats.js +281 -0
- package/dist/importers/formats.js.map +1 -0
- package/dist/importers/index.d.ts +26 -0
- package/dist/importers/index.d.ts.map +1 -0
- package/dist/importers/index.js +122 -0
- package/dist/importers/index.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/investigate/detectors.d.ts +35 -0
- package/dist/investigate/detectors.d.ts.map +1 -0
- package/dist/investigate/detectors.js +277 -0
- package/dist/investigate/detectors.js.map +1 -0
- package/dist/investigate/fix-brief.d.ts +3 -0
- package/dist/investigate/fix-brief.d.ts.map +1 -0
- package/dist/investigate/fix-brief.js +88 -0
- package/dist/investigate/fix-brief.js.map +1 -0
- package/dist/investigate/incidents.d.ts +19 -0
- package/dist/investigate/incidents.d.ts.map +1 -0
- package/dist/investigate/incidents.js +84 -0
- package/dist/investigate/incidents.js.map +1 -0
- package/dist/investigate/index.d.ts +25 -0
- package/dist/investigate/index.d.ts.map +1 -0
- package/dist/investigate/index.js +46 -0
- package/dist/investigate/index.js.map +1 -0
- package/dist/mcp/protocol.d.ts +2 -2
- package/dist/mcp/protocol.d.ts.map +1 -1
- package/dist/mcp/protocol.js +39 -8
- package/dist/mcp/protocol.js.map +1 -1
- package/dist/mcp/stdio.d.ts +1 -1
- package/dist/mcp/stdio.js +2 -2
- package/dist/mcp-servers.d.ts +2 -2
- package/dist/mcp-servers.js +2 -2
- package/dist/node-upgrade.d.ts +2 -2
- package/dist/node-upgrade.js +9 -9
- package/dist/notify/dispatch.d.ts +20 -0
- package/dist/notify/dispatch.d.ts.map +1 -0
- package/dist/notify/dispatch.js +52 -0
- package/dist/notify/dispatch.js.map +1 -0
- package/dist/notify/index.d.ts +39 -0
- package/dist/notify/index.d.ts.map +1 -0
- package/dist/notify/index.js +119 -0
- package/dist/notify/index.js.map +1 -0
- package/dist/notify/sender.d.ts +56 -0
- package/dist/notify/sender.d.ts.map +1 -0
- package/dist/notify/sender.js +139 -0
- package/dist/notify/sender.js.map +1 -0
- package/dist/notify/templates.d.ts +33 -0
- package/dist/notify/templates.d.ts.map +1 -0
- package/dist/notify/templates.js +119 -0
- package/dist/notify/templates.js.map +1 -0
- package/dist/offline-evaluate.d.ts +2 -2
- package/dist/offline-evaluate.js +3 -3
- package/dist/orr/agentshield.d.ts +2 -2
- package/dist/orr/agentshield.js +4 -4
- package/dist/orr/scorecard.d.ts +1 -1
- package/dist/orr/scorecard.js +3 -3
- package/dist/otel/exporter.d.ts +64 -0
- package/dist/otel/exporter.d.ts.map +1 -0
- package/dist/otel/exporter.js +243 -0
- package/dist/otel/exporter.js.map +1 -0
- package/dist/parse-args.d.ts +1 -1
- package/dist/parse-args.js +1 -1
- package/dist/receipt/auto-open.d.ts +1 -1
- package/dist/receipt/auto-open.js +1 -1
- package/dist/receipt/daemon.d.ts +6 -6
- package/dist/receipt/daemon.js +15 -15
- package/dist/receipt/dashboard.d.ts +1 -1
- package/dist/receipt/dashboard.js +2 -2
- package/dist/receipt/embeddings.d.ts +15 -4
- package/dist/receipt/embeddings.d.ts.map +1 -1
- package/dist/receipt/embeddings.js +116 -35
- package/dist/receipt/embeddings.js.map +1 -1
- package/dist/receipt/enrich.d.ts +2 -2
- package/dist/receipt/enrich.js +5 -5
- package/dist/receipt/gate-card.d.ts +2 -2
- package/dist/receipt/gate-card.d.ts.map +1 -1
- package/dist/receipt/gate-card.js +3 -3
- package/dist/receipt/live-server.d.ts.map +1 -1
- package/dist/receipt/live-server.js +22 -8
- package/dist/receipt/live-server.js.map +1 -1
- package/dist/receipt/receipt-css.d.ts +1 -1
- package/dist/receipt/receipt-css.d.ts.map +1 -1
- package/dist/receipt/receipt-css.js +72 -11
- package/dist/receipt/receipt-css.js.map +1 -1
- package/dist/receipt/render-receipt.d.ts +1 -1
- package/dist/receipt/render-receipt.d.ts.map +1 -1
- package/dist/receipt/render-receipt.js +138 -87
- package/dist/receipt/render-receipt.js.map +1 -1
- package/dist/receipt/share.d.ts +2 -2
- package/dist/receipt/share.js +5 -5
- package/dist/sample-tools.d.ts +1 -1
- package/dist/sample-tools.js +1 -1
- package/dist/sandbox/mock-driver.d.ts +1 -1
- package/dist/sandbox/mock-driver.js +1 -1
- package/dist/sdk/a2a.d.ts +2 -2
- package/dist/sdk/a2a.js +1 -1
- package/dist/sdk/adapters/claude-agent.d.ts +1 -1
- package/dist/sdk/adapters/claude-agent.js +1 -1
- package/dist/sdk/adapters/langgraph.d.ts +1 -1
- package/dist/sdk/adapters/langgraph.js +1 -1
- package/dist/sdk/adapters/mastra.d.ts +1 -1
- package/dist/sdk/adapters/mastra.js +1 -1
- package/dist/sdk/adapters/openai-agents.d.ts +1 -1
- package/dist/sdk/adapters/openai-agents.js +1 -1
- package/dist/sdk/adapters/vercel-ai.d.ts +2 -2
- package/dist/sdk/adapters/vercel-ai.js +1 -1
- package/dist/sdk/govern.d.ts +2 -2
- package/dist/sdk/govern.js +3 -3
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/index.js +1 -1
- package/dist/showback/trail-usage.d.ts +30 -0
- package/dist/showback/trail-usage.d.ts.map +1 -0
- package/dist/showback/trail-usage.js +50 -0
- package/dist/showback/trail-usage.js.map +1 -0
- package/dist/sign/evidence-bundle.d.ts +6 -6
- package/dist/sign/evidence-bundle.js +5 -5
- package/dist/star-cta.d.ts +1 -1
- package/dist/star-cta.d.ts.map +1 -1
- package/dist/star-cta.js +3 -3
- package/dist/trail-summary.d.ts +1 -1
- package/dist/trail-summary.js +3 -3
- package/dist/trail.d.ts +8 -2
- package/dist/trail.d.ts.map +1 -1
- package/dist/trail.js +18 -5
- package/dist/trail.js.map +1 -1
- package/dist/update-check.d.ts +17 -0
- package/dist/update-check.d.ts.map +1 -0
- package/dist/update-check.js +134 -0
- package/dist/update-check.js.map +1 -0
- package/droid/README.md +1 -1
- package/droid/mcp.example.json +1 -1
- package/gemini/settings.example.json +1 -1
- package/grok/README.md +1 -1
- package/kilo/kilo.example.json +1 -1
- package/kimi/mcp.example.json +1 -1
- package/kiro/mcp.example.json +1 -1
- package/manifest.json +1 -1
- package/mastracode/mcp.example.json +1 -1
- package/mcp.json +1 -1
- package/openai/codex.config.example.toml +1 -1
- package/opencode/opencode.example.json +1 -1
- package/package.json +2 -2
- package/qwen/settings.example.json +1 -1
- package/server.json +2 -2
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort OTLP/HTTP export of KYA verdicts as GenAI spans. Opt-in:
|
|
3
|
+
* disabled unless an endpoint is configured (env KYA_OTLP_EXPORT_ENDPOINT or
|
|
4
|
+
* "otlpExport" in .kya/config.json). Fire-and-forget: export NEVER blocks,
|
|
5
|
+
* delays, or changes a verdict. Every failure is swallowed and counted
|
|
6
|
+
* in-memory for a future status surface.
|
|
7
|
+
*
|
|
8
|
+
* Privacy: only verdict metadata ships (tool id, verdict, reason code, mode,
|
|
9
|
+
* host, session id, token counts when known). Tool args, prompts, approval
|
|
10
|
+
* bodies, and API keys are never exported - same rule as docs/otlp.md.
|
|
11
|
+
*
|
|
12
|
+
* No new dependencies: one hand-built OTLP/JSON payload and the global fetch.
|
|
13
|
+
*/
|
|
14
|
+
import { randomBytes } from "node:crypto";
|
|
15
|
+
import { CLI_VERSION } from "../version.js";
|
|
16
|
+
const EXPORT_TIMEOUT_MS = 2_000;
|
|
17
|
+
const SERVICE_NAME = "shield-kya-cli";
|
|
18
|
+
const SCOPE_NAME = "shield-kya-cli";
|
|
19
|
+
const stats = { attempted: 0, exported: 0, failed: 0 };
|
|
20
|
+
/** In-memory counters for a future status command; process-local only. */
|
|
21
|
+
export function otlpExportStats() {
|
|
22
|
+
return { ...stats };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolve export config from env > parsed .kya/config.json. Accepts the parsed
|
|
26
|
+
* config object so callers that already read the file (resolveConfig) need no
|
|
27
|
+
* config.ts change. Returns undefined when disabled (no endpoint anywhere).
|
|
28
|
+
*/
|
|
29
|
+
export function resolveOtlpExportConfig(env = process.env, configJson) {
|
|
30
|
+
const file = readFileKey(configJson);
|
|
31
|
+
const endpoint = env.KYA_OTLP_EXPORT_ENDPOINT?.trim() || file?.endpoint;
|
|
32
|
+
if (!endpoint)
|
|
33
|
+
return undefined;
|
|
34
|
+
return {
|
|
35
|
+
endpoint,
|
|
36
|
+
...(file?.headers ? { headers: file.headers } : {}),
|
|
37
|
+
insecure: file?.insecure === true,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function readFileKey(configJson) {
|
|
41
|
+
if (!configJson || typeof configJson !== "object" || Array.isArray(configJson)) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const raw = configJson.otlpExport;
|
|
45
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
46
|
+
return undefined;
|
|
47
|
+
const key = raw;
|
|
48
|
+
const endpoint = typeof key.endpoint === "string" && key.endpoint.trim()
|
|
49
|
+
? key.endpoint.trim()
|
|
50
|
+
: undefined;
|
|
51
|
+
if (!endpoint)
|
|
52
|
+
return undefined;
|
|
53
|
+
let headers;
|
|
54
|
+
if (key.headers && typeof key.headers === "object" && !Array.isArray(key.headers)) {
|
|
55
|
+
headers = {};
|
|
56
|
+
for (const [k, v] of Object.entries(key.headers)) {
|
|
57
|
+
if (typeof v === "string" && k.trim())
|
|
58
|
+
headers[k.trim()] = v;
|
|
59
|
+
}
|
|
60
|
+
if (Object.keys(headers).length === 0)
|
|
61
|
+
headers = undefined;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
endpoint,
|
|
65
|
+
...(headers ? { headers } : {}),
|
|
66
|
+
insecure: key.insecure === true,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Loopback plaintext is fine; anything else over http requires insecure:true. */
|
|
70
|
+
function endpointAllowed(cfg) {
|
|
71
|
+
let url;
|
|
72
|
+
try {
|
|
73
|
+
url = new URL(cfg.endpoint);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (url.protocol === "https:")
|
|
79
|
+
return true;
|
|
80
|
+
if (url.protocol !== "http:")
|
|
81
|
+
return false;
|
|
82
|
+
if (cfg.insecure === true)
|
|
83
|
+
return true;
|
|
84
|
+
const host = url.hostname.toLowerCase();
|
|
85
|
+
return host === "127.0.0.1" || host === "::1" || host === "localhost";
|
|
86
|
+
}
|
|
87
|
+
function tracesUrl(cfg) {
|
|
88
|
+
const base = cfg.endpoint.replace(/\/+$/, "");
|
|
89
|
+
return base.endsWith("/v1/traces") ? base : `${base}/v1/traces`;
|
|
90
|
+
}
|
|
91
|
+
function hex(bytes) {
|
|
92
|
+
return randomBytes(bytes).toString("hex");
|
|
93
|
+
}
|
|
94
|
+
function nano(ts) {
|
|
95
|
+
const ms = ts ? Date.parse(ts) : Number.NaN;
|
|
96
|
+
const base = Number.isFinite(ms) ? ms : Date.now();
|
|
97
|
+
return (BigInt(Math.floor(base)) * 1000000n).toString();
|
|
98
|
+
}
|
|
99
|
+
function attr(key, value) {
|
|
100
|
+
return { key, value };
|
|
101
|
+
}
|
|
102
|
+
function strAttr(key, value) {
|
|
103
|
+
if (typeof value !== "string" || !value)
|
|
104
|
+
return undefined;
|
|
105
|
+
return attr(key, { stringValue: value });
|
|
106
|
+
}
|
|
107
|
+
function intAttr(key, value) {
|
|
108
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
|
|
109
|
+
return undefined;
|
|
110
|
+
return attr(key, { intValue: String(Math.floor(value)) });
|
|
111
|
+
}
|
|
112
|
+
/** One OTLP/JSON ExportTraceServiceRequest carrying exactly one verdict span. */
|
|
113
|
+
export function buildVerdictTracePayload(event) {
|
|
114
|
+
const start = nano(event.ts);
|
|
115
|
+
const attributes = [
|
|
116
|
+
strAttr("gen_ai.tool.name", event.toolId),
|
|
117
|
+
strAttr("kya.verdict", event.verdict),
|
|
118
|
+
strAttr("kya.reason_code", event.reasonCode),
|
|
119
|
+
strAttr("kya.mode", event.mode),
|
|
120
|
+
strAttr("kya.host", event.host),
|
|
121
|
+
strAttr("kya.session_id", event.sessionId),
|
|
122
|
+
intAttr("gen_ai.usage.input_tokens", event.tokensIn),
|
|
123
|
+
intAttr("gen_ai.usage.output_tokens", event.tokensOut),
|
|
124
|
+
].filter((a) => a !== undefined);
|
|
125
|
+
const denied = event.verdict === "DENY";
|
|
126
|
+
return {
|
|
127
|
+
resourceSpans: [
|
|
128
|
+
{
|
|
129
|
+
resource: {
|
|
130
|
+
attributes: [
|
|
131
|
+
attr("service.name", { stringValue: SERVICE_NAME }),
|
|
132
|
+
attr("service.version", { stringValue: CLI_VERSION }),
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
scopeSpans: [
|
|
136
|
+
{
|
|
137
|
+
scope: { name: SCOPE_NAME, version: CLI_VERSION },
|
|
138
|
+
spans: [
|
|
139
|
+
{
|
|
140
|
+
traceId: hex(16),
|
|
141
|
+
spanId: hex(8),
|
|
142
|
+
name: `kya.verdict ${event.toolId}`,
|
|
143
|
+
// SPAN_KIND_INTERNAL: the verdict is a local policy decision.
|
|
144
|
+
kind: 1,
|
|
145
|
+
startTimeUnixNano: start,
|
|
146
|
+
endTimeUnixNano: start,
|
|
147
|
+
attributes,
|
|
148
|
+
status: denied
|
|
149
|
+
? { code: 2, message: event.reasonCode || "DENY" }
|
|
150
|
+
: { code: 1 },
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Export one verdict span. Never throws, never blocks the caller beyond the
|
|
161
|
+
* 2s timeout budget, and never touches the verdict itself. No-op when the
|
|
162
|
+
* config is undefined (unconfigured) or the endpoint fails the scheme check.
|
|
163
|
+
*/
|
|
164
|
+
export async function exportVerdictSpan(event, config) {
|
|
165
|
+
if (!config || !endpointAllowed(config))
|
|
166
|
+
return;
|
|
167
|
+
stats.attempted += 1;
|
|
168
|
+
const controller = new AbortController();
|
|
169
|
+
const timer = setTimeout(() => controller.abort(), EXPORT_TIMEOUT_MS);
|
|
170
|
+
try {
|
|
171
|
+
const res = await fetch(tracesUrl(config), {
|
|
172
|
+
method: "POST",
|
|
173
|
+
headers: {
|
|
174
|
+
"content-type": "application/json",
|
|
175
|
+
...(config.headers ?? {}),
|
|
176
|
+
},
|
|
177
|
+
body: JSON.stringify(buildVerdictTracePayload(event)),
|
|
178
|
+
signal: controller.signal,
|
|
179
|
+
});
|
|
180
|
+
// Drain so the socket is released back to the pool.
|
|
181
|
+
await res.arrayBuffer().catch(() => new ArrayBuffer(0));
|
|
182
|
+
if (res.ok)
|
|
183
|
+
stats.exported += 1;
|
|
184
|
+
else
|
|
185
|
+
stats.failed += 1;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
stats.failed += 1;
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
clearTimeout(timer);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* CLI-invocable self-test: POST one synthetic span and report the outcome.
|
|
196
|
+
* Unlike exportVerdictSpan it reports failure detail instead of only counting
|
|
197
|
+
* it - still never throws.
|
|
198
|
+
*/
|
|
199
|
+
export async function otlpExportSelfTest(config) {
|
|
200
|
+
if (!config)
|
|
201
|
+
return { ok: false, detail: "otlpExport not configured (no endpoint)" };
|
|
202
|
+
if (!endpointAllowed(config)) {
|
|
203
|
+
return {
|
|
204
|
+
ok: false,
|
|
205
|
+
detail: `endpoint refused: non-https to a non-loopback host needs "insecure": true (${config.endpoint})`,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
const event = {
|
|
209
|
+
ts: new Date().toISOString(),
|
|
210
|
+
sessionId: "otlp-selftest",
|
|
211
|
+
toolId: "kya__selftest",
|
|
212
|
+
verdict: "ALLOW",
|
|
213
|
+
reasonCode: "SELFTEST",
|
|
214
|
+
mode: "observe",
|
|
215
|
+
host: "ide",
|
|
216
|
+
};
|
|
217
|
+
const controller = new AbortController();
|
|
218
|
+
const timer = setTimeout(() => controller.abort(), EXPORT_TIMEOUT_MS);
|
|
219
|
+
try {
|
|
220
|
+
const res = await fetch(tracesUrl(config), {
|
|
221
|
+
method: "POST",
|
|
222
|
+
headers: {
|
|
223
|
+
"content-type": "application/json",
|
|
224
|
+
...(config.headers ?? {}),
|
|
225
|
+
},
|
|
226
|
+
body: JSON.stringify(buildVerdictTracePayload(event)),
|
|
227
|
+
signal: controller.signal,
|
|
228
|
+
});
|
|
229
|
+
await res.arrayBuffer().catch(() => new ArrayBuffer(0));
|
|
230
|
+
if (res.ok) {
|
|
231
|
+
return { ok: true, detail: `span accepted (${res.status}) at ${tracesUrl(config)}` };
|
|
232
|
+
}
|
|
233
|
+
return { ok: false, detail: `endpoint returned HTTP ${res.status} at ${tracesUrl(config)}` };
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
237
|
+
return { ok: false, detail: `export failed: ${msg}` };
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
clearTimeout(timer);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=exporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exporter.js","sourceRoot":"","sources":["../../src/otel/exporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAChC,MAAM,YAAY,GAAG,gBAAgB,CAAC;AACtC,MAAM,UAAU,GAAG,gBAAgB,CAAC;AA8BpC,MAAM,KAAK,GAAG,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,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
|
|
9
9
|
* Write the latest receipt and optionally open it in the browser.
|
|
10
|
-
* @param force
|
|
10
|
+
* @param force - open even if already opened this cwd (use on DENY).
|
|
11
11
|
*/
|
|
12
12
|
export declare function autoOpenReceiptAfterWrap(config: ResolvedConfig, opts?: {
|
|
13
13
|
force?: boolean;
|
|
@@ -42,7 +42,7 @@ function openBrowser(target) {
|
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Write the latest receipt and optionally open it in the browser.
|
|
45
|
-
* @param force
|
|
45
|
+
* @param force - open even if already opened this cwd (use on DENY).
|
|
46
46
|
*/
|
|
47
47
|
export async function autoOpenReceiptAfterWrap(config, opts = {}) {
|
|
48
48
|
const env = opts.env ?? process.env;
|
package/dist/receipt/daemon.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare function writeDaemonState(cwd: string, state: ReceiptDaemonState)
|
|
|
18
18
|
/**
|
|
19
19
|
* Remove the state file. With expectedPid set (daemon shutdown), removal is
|
|
20
20
|
* skipped when the file was already replaced by a newer daemon (pid mismatch)
|
|
21
|
-
*
|
|
21
|
+
* - a dying daemon must not delete its successor's state. Read errors /
|
|
22
22
|
* missing / corrupt state still remove (we own the normal case).
|
|
23
23
|
*/
|
|
24
24
|
export declare function clearDaemonState(cwd: string, expectedPid?: number): void;
|
|
@@ -45,13 +45,13 @@ export interface DaemonProc {
|
|
|
45
45
|
*/
|
|
46
46
|
export declare function listOwnedProcesses(platform?: NodeJS.Platform): DaemonProc[];
|
|
47
47
|
/**
|
|
48
|
-
* Pids of running `cli.js receipt-serve` daemons
|
|
49
|
-
* cwd
|
|
48
|
+
* Pids of running `cli.js receipt-serve` daemons - any install path, any
|
|
49
|
+
* cwd - so `stop --all` can sweep orphans the cwd state file does not know
|
|
50
50
|
* about. Never matches this process. `receipt-serve` must appear as a
|
|
51
51
|
* standalone argv token (the daemon always spawns it as one), so an editor
|
|
52
52
|
* with `receipt-serve-notes.txt` open does not match. Residual risk,
|
|
53
53
|
* accepted: a same-uid process deliberately built to look like the daemon
|
|
54
|
-
* (`node cli.js receipt-serve`) still matches
|
|
54
|
+
* (`node cli.js receipt-serve`) still matches - but the sweep is scoped to
|
|
55
55
|
* the current user's processes and only ever sends SIGTERM, so the worst
|
|
56
56
|
* case is a graceful stop of a same-user lookalike.
|
|
57
57
|
*/
|
|
@@ -60,8 +60,8 @@ export declare function findReceiptDaemonPids(procs: readonly DaemonProc[]): num
|
|
|
60
60
|
* Reuse the running daemon only when its pid is alive, the stored loopback
|
|
61
61
|
* url answers the token handshake, AND the daemon reports this exact package
|
|
62
62
|
* version. A daemon from an older (or newer, or pre-version-handshake) build
|
|
63
|
-
* may serve a stale trail layout, so any mismatch
|
|
64
|
-
* unreadable version field
|
|
63
|
+
* may serve a stale trail layout, so any mismatch - including an absent or
|
|
64
|
+
* unreadable version field - stops it and spawns a fresh one. A wedged
|
|
65
65
|
* daemon that IS ours is stopped first so failed handshakes cannot leak
|
|
66
66
|
* orphans; a foreign pid is never signaled.
|
|
67
67
|
*/
|
package/dist/receipt/daemon.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Background live-receipt daemon: `kya start` spawns it detached and returns
|
|
3
3
|
* to the terminal. State (pid, url, token) lives in `.kya/receipt-server.json`
|
|
4
|
-
* (mode 0600
|
|
4
|
+
* (mode 0600 - it carries the loopback auth token); stdout/stderr go to
|
|
5
5
|
* `.kya/receipt-server.log`. The daemon child is the hidden `receipt-serve`
|
|
6
6
|
* command, which writes the state file once it is listening and removes it on
|
|
7
7
|
* shutdown.
|
|
@@ -33,7 +33,7 @@ export function readDaemonState(cwd) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
catch {
|
|
36
|
-
/* corrupt state
|
|
36
|
+
/* corrupt state - treat as absent */
|
|
37
37
|
}
|
|
38
38
|
return undefined;
|
|
39
39
|
}
|
|
@@ -58,13 +58,13 @@ function removeIfSymlink(path) {
|
|
|
58
58
|
rmSync(path, { force: true });
|
|
59
59
|
}
|
|
60
60
|
catch {
|
|
61
|
-
/* absent
|
|
61
|
+
/* absent - nothing to remove */
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* Remove the state file. With expectedPid set (daemon shutdown), removal is
|
|
66
66
|
* skipped when the file was already replaced by a newer daemon (pid mismatch)
|
|
67
|
-
*
|
|
67
|
+
* - a dying daemon must not delete its successor's state. Read errors /
|
|
68
68
|
* missing / corrupt state still remove (we own the normal case).
|
|
69
69
|
*/
|
|
70
70
|
export function clearDaemonState(cwd, expectedPid) {
|
|
@@ -83,7 +83,7 @@ export function pidAlive(pid) {
|
|
|
83
83
|
return true;
|
|
84
84
|
}
|
|
85
85
|
catch (err) {
|
|
86
|
-
// EPERM: process exists but owned by someone else
|
|
86
|
+
// EPERM: process exists but owned by someone else - still alive.
|
|
87
87
|
return err.code === "EPERM";
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -95,7 +95,7 @@ function cliJsPath() {
|
|
|
95
95
|
const built = fileURLToPath(new URL("../cli.js", import.meta.url));
|
|
96
96
|
if (existsSync(built))
|
|
97
97
|
return built;
|
|
98
|
-
// Running from src/ (vitest)
|
|
98
|
+
// Running from src/ (vitest) - spawn the built CLI.
|
|
99
99
|
return fileURLToPath(new URL("../../dist/cli.js", import.meta.url));
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
@@ -148,13 +148,13 @@ export function listOwnedProcesses(platform = process.platform) {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
|
-
* Pids of running `cli.js receipt-serve` daemons
|
|
152
|
-
* cwd
|
|
151
|
+
* Pids of running `cli.js receipt-serve` daemons - any install path, any
|
|
152
|
+
* cwd - so `stop --all` can sweep orphans the cwd state file does not know
|
|
153
153
|
* about. Never matches this process. `receipt-serve` must appear as a
|
|
154
154
|
* standalone argv token (the daemon always spawns it as one), so an editor
|
|
155
155
|
* with `receipt-serve-notes.txt` open does not match. Residual risk,
|
|
156
156
|
* accepted: a same-uid process deliberately built to look like the daemon
|
|
157
|
-
* (`node cli.js receipt-serve`) still matches
|
|
157
|
+
* (`node cli.js receipt-serve`) still matches - but the sweep is scoped to
|
|
158
158
|
* the current user's processes and only ever sends SIGTERM, so the worst
|
|
159
159
|
* case is a graceful stop of a same-user lookalike.
|
|
160
160
|
*/
|
|
@@ -171,7 +171,7 @@ export function findReceiptDaemonPids(procs) {
|
|
|
171
171
|
* server behind it answers a token-authenticated handshake with 200.
|
|
172
172
|
* Uses /healthz: O(1) and decoupled from render failures of the full page.
|
|
173
173
|
* Every failure mode (non-200, unreadable body, missing field) yields a
|
|
174
|
-
* probe without a version
|
|
174
|
+
* probe without a version - callers must treat that as "unknown version",
|
|
175
175
|
* never as a match.
|
|
176
176
|
*/
|
|
177
177
|
async function probeStoredDaemon(state) {
|
|
@@ -188,7 +188,7 @@ async function probeStoredDaemon(state) {
|
|
|
188
188
|
res.body?.cancel().catch(() => undefined);
|
|
189
189
|
return { ok: false };
|
|
190
190
|
}
|
|
191
|
-
// Handshake passed; the version may still be unreadable
|
|
191
|
+
// Handshake passed; the version may still be unreadable - pre-0.4.1
|
|
192
192
|
// daemons answer plain "ok\n". A parse failure is an unknown version,
|
|
193
193
|
// not a failed handshake.
|
|
194
194
|
let version;
|
|
@@ -222,8 +222,8 @@ async function stopOwnedDaemon(pid) {
|
|
|
222
222
|
* Reuse the running daemon only when its pid is alive, the stored loopback
|
|
223
223
|
* url answers the token handshake, AND the daemon reports this exact package
|
|
224
224
|
* version. A daemon from an older (or newer, or pre-version-handshake) build
|
|
225
|
-
* may serve a stale trail layout, so any mismatch
|
|
226
|
-
* unreadable version field
|
|
225
|
+
* may serve a stale trail layout, so any mismatch - including an absent or
|
|
226
|
+
* unreadable version field - stops it and spawns a fresh one. A wedged
|
|
227
227
|
* daemon that IS ours is stopped first so failed handshakes cannot leak
|
|
228
228
|
* orphans; a foreign pid is never signaled.
|
|
229
229
|
*/
|
|
@@ -235,7 +235,7 @@ export async function ensureReceiptDaemon(config, input) {
|
|
|
235
235
|
return { url: existing.url, pid: existing.pid, reused: true };
|
|
236
236
|
}
|
|
237
237
|
if (probe.ok) {
|
|
238
|
-
// Answered our token handshake with a stale/absent version
|
|
238
|
+
// Answered our token handshake with a stale/absent version - it is
|
|
239
239
|
// authenticated as a kya daemon even if an older install spawned it
|
|
240
240
|
// from a different cli.js path, so the args check would miss it.
|
|
241
241
|
await stopOwnedDaemon(existing.pid);
|
|
@@ -274,6 +274,6 @@ export async function ensureReceiptDaemon(config, input) {
|
|
|
274
274
|
break;
|
|
275
275
|
await sleep(100);
|
|
276
276
|
}
|
|
277
|
-
throw new KyaError(`receipt server failed to start
|
|
277
|
+
throw new KyaError(`receipt server failed to start - see ${daemonLogPath(config.cwd)}`, "RECEIPT_DAEMON_FAILED");
|
|
278
278
|
}
|
|
279
279
|
//# sourceMappingURL=daemon.js.map
|
|
@@ -55,7 +55,7 @@ export interface BucketWindowInput {
|
|
|
55
55
|
/**
|
|
56
56
|
* Zero-filled bucket window: from the earliest event's bucket up to the
|
|
57
57
|
* latest, capped to the most recent `cap` buckets, ascending chronologically.
|
|
58
|
-
* Candidates are deduped by start ms
|
|
58
|
+
* Candidates are deduped by start ms - stepping back across a spring-forward
|
|
59
59
|
* transition can map two steps to the same bucket start (duplicate column).
|
|
60
60
|
* Pure and exported so tests can feed the duplicate-start case directly.
|
|
61
61
|
*/
|
|
@@ -25,7 +25,7 @@ const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "
|
|
|
25
25
|
function hourLabel(startMs) {
|
|
26
26
|
return `${String(new Date(startMs).getHours()).padStart(2, "0")}:00`;
|
|
27
27
|
}
|
|
28
|
-
/** "Sep 16 14:00"
|
|
28
|
+
/** "Sep 16 14:00" - used when an hourly window crosses midnight. */
|
|
29
29
|
function hourDayLabel(startMs) {
|
|
30
30
|
const d = new Date(startMs);
|
|
31
31
|
return `${MONTHS[d.getMonth()]} ${d.getDate()} ${hourLabel(startMs)}`;
|
|
@@ -48,7 +48,7 @@ function stepBack(startMs, i, granularity) {
|
|
|
48
48
|
/**
|
|
49
49
|
* Zero-filled bucket window: from the earliest event's bucket up to the
|
|
50
50
|
* latest, capped to the most recent `cap` buckets, ascending chronologically.
|
|
51
|
-
* Candidates are deduped by start ms
|
|
51
|
+
* Candidates are deduped by start ms - stepping back across a spring-forward
|
|
52
52
|
* transition can map two steps to the same bucket start (duplicate column).
|
|
53
53
|
* Pure and exported so tests can feed the duplicate-start case directly.
|
|
54
54
|
*/
|
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
import type { TrailEvent } from "../trail.js";
|
|
2
2
|
export interface EmbeddingProvider {
|
|
3
3
|
embed(text: string): Promise<number[] | undefined>;
|
|
4
|
+
/** Optional batch embed. Providers that implement this can warm the index
|
|
5
|
+
* orders of magnitude faster than one-by-one calls. */
|
|
6
|
+
embedBatch?(texts: string[]): Promise<(number[] | undefined)[] | undefined>;
|
|
4
7
|
}
|
|
5
8
|
/** Local MiniLM provider via fastembed; loaded on first use. */
|
|
6
9
|
export declare class LocalMiniLmProvider implements EmbeddingProvider {
|
|
7
10
|
private readonly env;
|
|
8
|
-
private
|
|
9
|
-
private
|
|
11
|
+
private queryModel;
|
|
12
|
+
private batchModel;
|
|
13
|
+
private queryTried;
|
|
14
|
+
private batchTried;
|
|
15
|
+
/** fastembed model init is not re-entrant; serialize loadModel calls. */
|
|
16
|
+
private loadLock;
|
|
10
17
|
constructor(env?: NodeJS.ProcessEnv);
|
|
18
|
+
private withLoadLock;
|
|
19
|
+
private loadModel;
|
|
11
20
|
embed(text: string): Promise<number[] | undefined>;
|
|
21
|
+
embedBatch(texts: string[]): Promise<(number[] | undefined)[] | undefined>;
|
|
12
22
|
}
|
|
13
23
|
/** On-disk cache for event embeddings keyed by event id and document sha1. */
|
|
14
24
|
export declare class EventEmbeddingCache {
|
|
15
25
|
private data;
|
|
16
|
-
|
|
26
|
+
private readonly cacheFile;
|
|
27
|
+
constructor(cacheFile?: string);
|
|
17
28
|
private load;
|
|
18
29
|
private save;
|
|
19
30
|
getCached(eventId: string, textSha1: string): number[] | undefined;
|
|
@@ -28,7 +39,7 @@ export declare class EventEmbeddingCache {
|
|
|
28
39
|
/**
|
|
29
40
|
* Build a map of embeddings for the given events. Already-cached entries are
|
|
30
41
|
* returned without calling the provider; missing entries are embedded and
|
|
31
|
-
* written to the cache in
|
|
42
|
+
* written to the cache in chunks so the index warms incrementally.
|
|
32
43
|
*/
|
|
33
44
|
export declare function buildEventEmbeddings(events: readonly TrailEvent[], provider: EmbeddingProvider, cache: EventEmbeddingCache): Promise<Map<string, number[]>>;
|
|
34
45
|
//# sourceMappingURL=embeddings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embeddings.d.ts","sourceRoot":"","sources":["../../src/receipt/embeddings.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"embeddings.d.ts","sourceRoot":"","sources":["../../src/receipt/embeddings.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACnD;2DACuD;IACvD,UAAU,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC;CAC7E;AAsBD,gEAAgE;AAChE,qBAAa,mBAAoB,YAAW,iBAAiB;IAQ/C,OAAO,CAAC,QAAQ,CAAC,GAAG;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