@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
package/dist/commands/gate.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `kya gate`
|
|
2
|
+
* `kya gate` - local MCP gateway: govern + audit tool calls to any MCP server.
|
|
3
3
|
*
|
|
4
4
|
* init scaffold .kya/gateways.json (recipes for the well-known servers)
|
|
5
5
|
* setup install the pinned gateway binary to .kya/bin (only downloader)
|
|
@@ -36,7 +36,7 @@ export function runGateInit(env = process.env) {
|
|
|
36
36
|
created: r.created,
|
|
37
37
|
next: r.created
|
|
38
38
|
? "move a recipe into \"servers\" and fill its placeholders, then `kya gate setup && kya gate run`"
|
|
39
|
-
: "gateways.json already exists
|
|
39
|
+
: "gateways.json already exists - edit it, then `kya gate run`",
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
export async function runGateSetup(env = process.env) {
|
|
@@ -54,7 +54,7 @@ export function bindScopeFromYaml(env) {
|
|
|
54
54
|
yaml = readFileSync(gateYamlPath(env), "utf8");
|
|
55
55
|
}
|
|
56
56
|
catch {
|
|
57
|
-
return { loopbackOnly: false, detail: "no generated config yet
|
|
57
|
+
return { loopbackOnly: false, detail: "no generated config yet - `kya gate run` generates one" };
|
|
58
58
|
}
|
|
59
59
|
const hasRule = yaml.includes("networkAuthorization:") && yaml.includes("127.0.0.0/8") && yaml.includes("::1");
|
|
60
60
|
const listenersOff = yaml.includes('statsAddr: "off"') && yaml.includes('readinessAddr: "off"');
|
|
@@ -63,7 +63,7 @@ export function bindScopeFromYaml(env) {
|
|
|
63
63
|
loopbackOnly,
|
|
64
64
|
detail: loopbackOnly
|
|
65
65
|
? "loopback-only (L4 allowlist 127.0.0.0/8 + ::1; stats/readiness/admin listeners off)"
|
|
66
|
-
: "WARNING: generated config is missing the loopback allowlist or listener offs
|
|
66
|
+
: "WARNING: generated config is missing the loopback allowlist or listener offs - re-run `kya gate run`",
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
async function probeListener(state) {
|
|
@@ -102,7 +102,7 @@ export async function runGateDoctor(env = process.env) {
|
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* Generate the gateway YAML from gateways.json, then spawn the detached
|
|
105
|
-
* supervisor (OTLP receiver + gateway binary child). Requires the binary
|
|
105
|
+
* supervisor (OTLP receiver + gateway binary child). Requires the binary -
|
|
106
106
|
* never downloads; `kya gate setup` is the only downloader. Success is
|
|
107
107
|
* reported only after the listener actually answers.
|
|
108
108
|
*/
|
|
@@ -110,7 +110,7 @@ export async function runGateRun(config, input = {}) {
|
|
|
110
110
|
const env = input.env ?? process.env;
|
|
111
111
|
const bin = inspectGateBinary(env);
|
|
112
112
|
if (!bin.present) {
|
|
113
|
-
throw new KyaError(`gateway binary not installed
|
|
113
|
+
throw new KyaError(`gateway binary not installed - run \`kya gate setup\` first (expected at ${gateBinaryPath(env)})`, "GATE_BINARY_MISSING");
|
|
114
114
|
}
|
|
115
115
|
const gateways = readGateways(env);
|
|
116
116
|
const yaml = generateGatewayYaml(gateways);
|
|
@@ -127,7 +127,7 @@ export async function runGateRun(config, input = {}) {
|
|
|
127
127
|
};
|
|
128
128
|
const existing = readGateState(env);
|
|
129
129
|
if (existing && pidAlive(existing.pid) && isGateDaemonProcess(existing.pid)) {
|
|
130
|
-
// Never rewrite gate.yaml under a live process
|
|
130
|
+
// Never rewrite gate.yaml under a live process - the gateway watches the
|
|
131
131
|
// file. Compare and report drift instead.
|
|
132
132
|
let drift = false;
|
|
133
133
|
try {
|
|
@@ -153,8 +153,8 @@ export async function runGateRun(config, input = {}) {
|
|
|
153
153
|
reused: true,
|
|
154
154
|
...(drift ? { drift } : {}),
|
|
155
155
|
next: drift
|
|
156
|
-
? "config changed since gateway started
|
|
157
|
-
: "gateway already running
|
|
156
|
+
? "config changed since gateway started - `kya gate stop && kya gate run` to apply"
|
|
157
|
+
: "gateway already running - `kya gate stop` first to reload config",
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
160
|
clearGateState(env);
|
|
@@ -174,7 +174,7 @@ export async function runGateRun(config, input = {}) {
|
|
|
174
174
|
const fail = async () => {
|
|
175
175
|
await killGateProcessTree(pid, readGateState(env)?.childPid);
|
|
176
176
|
clearGateState(env);
|
|
177
|
-
throw new KyaError(`gateway failed to start
|
|
177
|
+
throw new KyaError(`gateway failed to start - see ${logPath}`, "GATE_START_FAILED");
|
|
178
178
|
};
|
|
179
179
|
let probingSince = -1;
|
|
180
180
|
for (let waited = 0; waited < 10_000; waited += 100) {
|
|
@@ -204,7 +204,7 @@ export async function runGateRun(config, input = {}) {
|
|
|
204
204
|
configPath: gateYamlPath(env),
|
|
205
205
|
logPath,
|
|
206
206
|
reused: false,
|
|
207
|
-
next: `point your host at ${state.url}/mcp (server key shield-kya-gate)
|
|
207
|
+
next: `point your host at ${state.url}/mcp (server key shield-kya-gate) - ` +
|
|
208
208
|
"`kya connect <host> --gate` wires it; `kya gate stop` stops everything.",
|
|
209
209
|
};
|
|
210
210
|
}
|
|
@@ -259,7 +259,7 @@ export async function runGateStop(env = process.env, input = {}) {
|
|
|
259
259
|
return { stopped: false };
|
|
260
260
|
}
|
|
261
261
|
if (pidAlive(state.pid) && !isGateDaemonProcess(state.pid)) {
|
|
262
|
-
// Planted or recycled pid
|
|
262
|
+
// Planted or recycled pid - never signal a foreign process.
|
|
263
263
|
clearGateState(env);
|
|
264
264
|
triggerHostedSyncFromEnv({ cwd: input.cwd ?? process.cwd(), env, state: "configured-stopped" });
|
|
265
265
|
return { stopped: false, pid: state.pid, stale: true };
|
|
@@ -287,12 +287,12 @@ export function formatGateDoctorHuman(r) {
|
|
|
287
287
|
"KYA gate doctor",
|
|
288
288
|
r.binary.present
|
|
289
289
|
? `binary: ${r.binary.path}${r.binary.version ? ` (${r.binary.version})` : ""}`
|
|
290
|
-
: `binary: missing
|
|
290
|
+
: `binary: missing - run \`kya gate setup\``,
|
|
291
291
|
`config: ${r.config.path} (${r.config.servers} server${r.config.servers === 1 ? "" : "s"})`,
|
|
292
292
|
`bind scope: ${r.bindScope.detail}`,
|
|
293
293
|
r.listener.running
|
|
294
294
|
? `listener: ${r.listener.url} (${r.listener.healthy ? "healthy" : "not answering"})`
|
|
295
|
-
: "listener: not running
|
|
295
|
+
: "listener: not running - `kya gate run`",
|
|
296
296
|
syncLine,
|
|
297
297
|
].join("\n");
|
|
298
298
|
}
|
|
@@ -300,13 +300,13 @@ function formatLastSync(last) {
|
|
|
300
300
|
if (!last)
|
|
301
301
|
return "";
|
|
302
302
|
const status = last.ok ? "ok" : "failed";
|
|
303
|
-
const detail = last.error ? `
|
|
303
|
+
const detail = last.error ? ` - ${last.error}` : "";
|
|
304
304
|
return ` (last sync: ${status}${detail})`;
|
|
305
305
|
}
|
|
306
306
|
export function gateSubcommand(parsed) {
|
|
307
307
|
const sub = parsed.positionals[0];
|
|
308
308
|
if (sub === "init" || sub === "setup" || sub === "doctor" || sub === "status" || sub === "run" || sub === "stop") {
|
|
309
|
-
// `status` is an alias for `doctor`
|
|
309
|
+
// `status` is an alias for `doctor` - same output, hosted sync line included.
|
|
310
310
|
return sub === "status" ? "doctor" : sub;
|
|
311
311
|
}
|
|
312
312
|
throw new UsageError("Usage: kya gate <init|setup|doctor|status|run|stop>");
|
package/dist/commands/hook.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface HookInput {
|
|
|
5
5
|
readonly stdinText: string;
|
|
6
6
|
readonly env: NodeJS.ProcessEnv;
|
|
7
7
|
readonly cwd: string;
|
|
8
|
-
/** Test seam
|
|
8
|
+
/** Test seam - defaults to the offline runEvalTool path. */
|
|
9
9
|
readonly evaluate?: (toolId: string, args: unknown) => Promise<PolicyEvaluateResponse>;
|
|
10
10
|
}
|
|
11
11
|
export interface HookResult {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/commands/hook.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/commands/hook.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAM3D,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAC;CACxF;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAwFD,wBAAsB,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAqEnE"}
|
package/dist/commands/hook.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* kya hook
|
|
2
|
+
* kya hook - PreToolUse interception for hosts with native hooks
|
|
3
3
|
* (Claude Code, Grok, Kimi Code). Offline local evaluate only: no network,
|
|
4
4
|
* sub-second, fail-open on any internal error. DENY (local never-list)
|
|
5
5
|
* blocks; REQUIRE_APPROVE records advisory unless --strict.
|
|
@@ -7,7 +7,27 @@
|
|
|
7
7
|
import { resolveConfig } from "../config.js";
|
|
8
8
|
import { runEvalTool } from "./eval-tool.js";
|
|
9
9
|
import { appendTrail, defaultSessionId, hostToProduct } from "../trail.js";
|
|
10
|
-
import {
|
|
10
|
+
import { deriveWireChangeFields } from "../diff-preview.js";
|
|
11
|
+
import { maybeSpawnNotifyFlush } from "../notify/dispatch.js";
|
|
12
|
+
function tokenCount(v) {
|
|
13
|
+
return typeof v === "number" && Number.isFinite(v) && v >= 0
|
|
14
|
+
? Math.floor(v)
|
|
15
|
+
: undefined;
|
|
16
|
+
}
|
|
17
|
+
/** Accept input_tokens/output_tokens (Claude/Kimi) and inputTokens/outputTokens. */
|
|
18
|
+
function readUsageShape(raw) {
|
|
19
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
20
|
+
return undefined;
|
|
21
|
+
const u = raw;
|
|
22
|
+
const tokensIn = tokenCount(u.input_tokens ?? u.inputTokens);
|
|
23
|
+
const tokensOut = tokenCount(u.output_tokens ?? u.outputTokens);
|
|
24
|
+
if (tokensIn === undefined && tokensOut === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
return {
|
|
27
|
+
...(tokensIn !== undefined ? { tokensIn } : {}),
|
|
28
|
+
...(tokensOut !== undefined ? { tokensOut } : {}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
11
31
|
/** Accept snake_case (Claude/Kimi) and camelCase (Grok) envelopes. */
|
|
12
32
|
function parsePayload(stdinText) {
|
|
13
33
|
let raw;
|
|
@@ -23,6 +43,11 @@ function parsePayload(stdinText) {
|
|
|
23
43
|
const event = (typeof p.hook_event_name === "string" && p.hook_event_name) ||
|
|
24
44
|
(typeof p.hookEventName === "string" && p.hookEventName) ||
|
|
25
45
|
undefined;
|
|
46
|
+
const toolResponse = p.tool_response && typeof p.tool_response === "object" && !Array.isArray(p.tool_response)
|
|
47
|
+
? p.tool_response
|
|
48
|
+
: p.toolResponse && typeof p.toolResponse === "object" && !Array.isArray(p.toolResponse)
|
|
49
|
+
? p.toolResponse
|
|
50
|
+
: undefined;
|
|
26
51
|
return {
|
|
27
52
|
event,
|
|
28
53
|
sessionId: (typeof p.session_id === "string" && p.session_id) ||
|
|
@@ -33,6 +58,7 @@ function parsePayload(stdinText) {
|
|
|
33
58
|
(typeof p.toolName === "string" && p.toolName) ||
|
|
34
59
|
undefined,
|
|
35
60
|
toolInput: p.tool_input ?? p.toolInput,
|
|
61
|
+
usage: readUsageShape(p.usage) ?? readUsageShape(toolResponse?.usage),
|
|
36
62
|
};
|
|
37
63
|
}
|
|
38
64
|
const ALLOW = { exitCode: 0, stdout: "", stderr: "" };
|
|
@@ -70,28 +96,39 @@ export async function runHook(input) {
|
|
|
70
96
|
(async (toolId, args) => (await runEvalTool(config, { toolId, args, offline: true })).response);
|
|
71
97
|
const response = await evaluate(payload.toolName, payload.toolInput ?? {});
|
|
72
98
|
// payload.cwd is host-supplied and only feeds the project-basename stamp;
|
|
73
|
-
// the trail path itself comes from env/KYA_HOME
|
|
99
|
+
// the trail path itself comes from env/KYA_HOME - no traversal risk.
|
|
74
100
|
const trailCwd = payload.cwd?.trim() || input.cwd;
|
|
75
|
-
|
|
101
|
+
// Wire change fields (summary, diffPreview, targetPath) feed the receipt's
|
|
102
|
+
// Changes tab; redaction + opt-out live inside deriveWireChangeFields.
|
|
103
|
+
const changeFields = deriveWireChangeFields(payload.toolName, payload.toolInput ?? {}, input.env);
|
|
104
|
+
const trailEvent = {
|
|
105
|
+
ts: new Date().toISOString(),
|
|
106
|
+
sessionId: payload.sessionId ?? defaultSessionId(input.env),
|
|
107
|
+
host: config.host,
|
|
108
|
+
product: hostToProduct(input.host),
|
|
109
|
+
toolId: response.toolId ?? payload.toolName,
|
|
110
|
+
verdict: response.verdict,
|
|
111
|
+
reasonCode: response.reasonCode ?? "",
|
|
112
|
+
mode: "offline",
|
|
113
|
+
neverEvent: response.reasonCode === "NEVER_EVENT",
|
|
114
|
+
argsHash: response.argsHash,
|
|
115
|
+
...(changeFields ?? {}),
|
|
116
|
+
...(payload.usage?.tokensIn !== undefined
|
|
117
|
+
? { tokensIn: payload.usage.tokensIn }
|
|
118
|
+
: {}),
|
|
119
|
+
...(payload.usage?.tokensOut !== undefined
|
|
120
|
+
? { tokensOut: payload.usage.tokensOut }
|
|
121
|
+
: {}),
|
|
122
|
+
};
|
|
76
123
|
try {
|
|
77
|
-
appendTrail(trailCwd,
|
|
78
|
-
ts: new Date().toISOString(),
|
|
79
|
-
sessionId: payload.sessionId ?? defaultSessionId(input.env),
|
|
80
|
-
host: config.host,
|
|
81
|
-
product: hostToProduct(input.host),
|
|
82
|
-
toolId: response.toolId ?? payload.toolName,
|
|
83
|
-
verdict: response.verdict,
|
|
84
|
-
reasonCode: response.reasonCode ?? "",
|
|
85
|
-
mode: "offline",
|
|
86
|
-
neverEvent: response.reasonCode === "NEVER_EVENT",
|
|
87
|
-
argsHash: response.argsHash,
|
|
88
|
-
summary: deriveTrailSummary(payload.toolName, payload.toolInput ?? {}),
|
|
89
|
-
...(targetPath ? { targetPath } : {}),
|
|
90
|
-
}, input.env);
|
|
124
|
+
appendTrail(trailCwd, trailEvent, input.env);
|
|
91
125
|
}
|
|
92
126
|
catch {
|
|
93
127
|
/* observe path never breaks the gate */
|
|
94
128
|
}
|
|
129
|
+
// Webhooks + OTLP export ride a detached helper; the hook never waits on
|
|
130
|
+
// the network. No-op unless a sink is configured.
|
|
131
|
+
maybeSpawnNotifyFlush({ env: input.env, cwd: trailCwd, event: trailEvent });
|
|
95
132
|
if (response.verdict === "DENY") {
|
|
96
133
|
return deny(`KYA denied ${payload.toolName}: ${response.reasonCode}`);
|
|
97
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../src/commands/hook.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EA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O,IAAI,CAAC,oBAAoB,OAAO,CAAC,QAAQ,uBAAuB,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC;QACjG,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC,CAAC,2DAA2D;IAC3E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kya import - convert foreign trace exports (LangSmith, Langfuse, Phoenix,
|
|
3
|
+
* OTel JSON) into local trail events so the receipt/certify sees them.
|
|
4
|
+
*/
|
|
5
|
+
import type { ParsedArgs } from "../parse-args.js";
|
|
6
|
+
import { type ImportSource } from "../importers/index.js";
|
|
7
|
+
export interface ImportCliOptions {
|
|
8
|
+
readonly from: ImportSource | undefined;
|
|
9
|
+
readonly file: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare function importOptionsFromArgs(parsed: ParsedArgs): ImportCliOptions;
|
|
12
|
+
export declare function runImport(opts: ImportCliOptions, io: {
|
|
13
|
+
log: (s: string) => void;
|
|
14
|
+
error: (s: string) => void;
|
|
15
|
+
}, cwd: string, env: NodeJS.ProcessEnv): Promise<number>;
|
|
16
|
+
//# sourceMappingURL=import-traces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-traces.d.ts","sourceRoot":"","sources":["../../src/commands/import-traces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAI/B,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,gBAAgB,CAI1E;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,gBAAgB,EACtB,EAAE,EAAE;IAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,EAC5D,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,CAAC,UAAU,GACrB,OAAO,CAAC,MAAM,CAAC,CAQjB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { flagString } from "../parse-args.js";
|
|
2
|
+
import { importTraces, renderImportSummary, } from "../importers/index.js";
|
|
3
|
+
const SOURCES = ["langsmith", "langfuse", "phoenix", "otel"];
|
|
4
|
+
export function importOptionsFromArgs(parsed) {
|
|
5
|
+
const rawFrom = flagString(parsed.flags, "from")?.toLowerCase();
|
|
6
|
+
const from = SOURCES.find((s) => s === rawFrom);
|
|
7
|
+
return { from, file: parsed.positionals[0] };
|
|
8
|
+
}
|
|
9
|
+
export async function runImport(opts, io, cwd, env) {
|
|
10
|
+
if (!opts.from || !opts.file) {
|
|
11
|
+
io.error("Usage: kya import --from <langsmith|langfuse|phoenix|otel> <file>");
|
|
12
|
+
return 2;
|
|
13
|
+
}
|
|
14
|
+
const result = await importTraces({ from: opts.from, file: opts.file, cwd, env });
|
|
15
|
+
io.log(renderImportSummary(result));
|
|
16
|
+
return result.imported === 0 && result.errors.length > 0 ? 1 : 0;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=import-traces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-traces.js","sourceRoot":"","sources":["../../src/commands/import-traces.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EACL,YAAY,EACZ,mBAAmB,GAEpB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,OAAO,GAA4B,CAAC,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;AAOtF,MAAM,UAAU,qBAAqB,CAAC,MAAkB;IACtD,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IAChE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC;IAChD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAsB,EACtB,EAA4D,EAC5D,GAAW,EACX,GAAsB;IAEtB,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAC7B,EAAE,CAAC,KAAK,CAAC,mEAAmE,CAAC,CAAC;QAC9E,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IAClF,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,QAAQ,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnE,CAAC"}
|
package/dist/commands/init.js
CHANGED
|
@@ -45,7 +45,7 @@ export function initFromArgs(parsed, cwd = process.cwd()) {
|
|
|
45
45
|
const force = parsed.flags["force"] === true || parsed.flags["force"] === "true";
|
|
46
46
|
return runInit({ cwd, baseUrl, host, force });
|
|
47
47
|
}
|
|
48
|
-
const ENV_EXAMPLE = `# Shield KYA light install
|
|
48
|
+
const ENV_EXAMPLE = `# Shield KYA light install - copy to .env (never commit secrets)
|
|
49
49
|
# Docs: docs/guides/kya-light-install.md
|
|
50
50
|
|
|
51
51
|
# Control plane origin (hosted or local free console)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kya investigate - deterministic detectors over the local trail: incident
|
|
3
|
+
* grouping plus markdown fix briefs shaped for coding agents. No LLM calls.
|
|
4
|
+
*/
|
|
5
|
+
import type { ParsedArgs } from "../parse-args.js";
|
|
6
|
+
export interface InvestigateCliOptions {
|
|
7
|
+
readonly json: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function investigateOptionsFromArgs(parsed: ParsedArgs): InvestigateCliOptions;
|
|
10
|
+
export declare function runInvestigate(opts: InvestigateCliOptions, io: {
|
|
11
|
+
log: (s: string) => void;
|
|
12
|
+
}, cwd: string, env: NodeJS.ProcessEnv): Promise<number>;
|
|
13
|
+
//# sourceMappingURL=investigate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"investigate.d.ts","sourceRoot":"","sources":["../../src/commands/investigate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAQnD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU,GAAG,qBAAqB,CAEpF;AAED,wBAAsB,cAAc,CAClC,IAAI,EAAE,qBAAqB,EAC3B,EAAE,EAAE;IAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,EAChC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,CAAC,UAAU,GACrB,OAAO,CAAC,MAAM,CAAC,CAmBjB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { flagBool } from "../parse-args.js";
|
|
2
|
+
import { readTrail } from "../trail.js";
|
|
3
|
+
import { investigateTrail, renderInvestigateReport, } from "../investigate/index.js";
|
|
4
|
+
export function investigateOptionsFromArgs(parsed) {
|
|
5
|
+
return { json: flagBool(parsed.flags, "json") };
|
|
6
|
+
}
|
|
7
|
+
export async function runInvestigate(opts, io, cwd, env) {
|
|
8
|
+
const events = readTrail(cwd, env);
|
|
9
|
+
const result = investigateTrail(events);
|
|
10
|
+
if (opts.json) {
|
|
11
|
+
io.log(JSON.stringify({
|
|
12
|
+
findings: result.findings,
|
|
13
|
+
incidents: result.incidents,
|
|
14
|
+
briefs: Object.fromEntries(result.briefs),
|
|
15
|
+
}, null, 2));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
io.log(renderInvestigateReport(result));
|
|
19
|
+
}
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=investigate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"investigate.js","sourceRoot":"","sources":["../../src/commands/investigate.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AAMjC,MAAM,UAAU,0BAA0B,CAAC,MAAkB;IAC3D,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAA2B,EAC3B,EAAgC,EAChC,GAAW,EACX,GAAsB;IAEtB,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACxC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,EAAE,CAAC,GAAG,CACJ,IAAI,CAAC,SAAS,CACZ;YACE,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC;SAC1C,EACD,IAAI,EACJ,CAAC,CACF,CACF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,EAAE,CAAC,GAAG,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notify-flush.d.ts","sourceRoot":"","sources":["../../src/commands/notify-flush.ts"],"names":[],"mappings":"AAWA,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,CAqCjB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kya notify-flush - internal helper spawned detached by hook/wrap (see
|
|
3
|
+
* src/notify/dispatch.ts). Delivers the event handed over in KYA_NOTIFY_EVENT
|
|
4
|
+
* to configured webhooks and the OTLP exporter, then exits. Never prints,
|
|
5
|
+
* never fails hard: it is a best-effort side channel.
|
|
6
|
+
*/
|
|
7
|
+
import { kyaHome, readFileConfig } from "../config.js";
|
|
8
|
+
import { notifyOnTrailEvent } from "../notify/index.js";
|
|
9
|
+
import { exportVerdictSpan, resolveOtlpExportConfig } from "../otel/exporter.js";
|
|
10
|
+
export async function runNotifyFlush(env, cwd) {
|
|
11
|
+
const raw = env.KYA_NOTIFY_EVENT;
|
|
12
|
+
if (!raw)
|
|
13
|
+
return 0;
|
|
14
|
+
let event;
|
|
15
|
+
try {
|
|
16
|
+
const parsed = JSON.parse(raw);
|
|
17
|
+
if (!parsed || typeof parsed.toolId !== "string" || typeof parsed.verdict !== "string") {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
event = parsed;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
// Project config wins over the global one (same precedence as resolveConfig).
|
|
26
|
+
const fileConfig = {
|
|
27
|
+
...readFileConfig(kyaHome(env)),
|
|
28
|
+
...readFileConfig(cwd),
|
|
29
|
+
};
|
|
30
|
+
await notifyOnTrailEvent(event, fileConfig, env).catch(() => undefined);
|
|
31
|
+
const otlp = resolveOtlpExportConfig(env, fileConfig);
|
|
32
|
+
if (otlp) {
|
|
33
|
+
await exportVerdictSpan({
|
|
34
|
+
ts: event.ts,
|
|
35
|
+
sessionId: event.sessionId,
|
|
36
|
+
toolId: event.toolId,
|
|
37
|
+
verdict: event.verdict,
|
|
38
|
+
reasonCode: event.reasonCode,
|
|
39
|
+
mode: event.mode,
|
|
40
|
+
...(event.host ? { host: event.host } : {}),
|
|
41
|
+
...(event.tokensIn !== undefined ? { tokensIn: event.tokensIn } : {}),
|
|
42
|
+
...(event.tokensOut !== undefined ? { tokensOut: event.tokensOut } : {}),
|
|
43
|
+
}, otlp).catch(() => undefined);
|
|
44
|
+
}
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=notify-flush.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notify-flush.js","sourceRoot":"","sources":["../../src/commands/notify-flush.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAyB,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,GAAsB,EACtB,GAAW;IAEX,MAAM,GAAG,GAAG,GAAG,CAAC,gBAAgB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K,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACrE,GAAG,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACzE,EACD,IAAI,CACL,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/commands/orr.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* kya orr run
|
|
2
|
+
* kya orr run - Phase O1 read-only ORR board emitter.
|
|
3
3
|
* Reporting orchestrator only: not a second PEP; never mints principals or allows side effects.
|
|
4
4
|
*/
|
|
5
5
|
import type { ParsedArgs } from "../parse-args.js";
|
|
@@ -72,9 +72,9 @@ export interface OrrRunOptions {
|
|
|
72
72
|
readonly failOn?: "no_go" | "conditional";
|
|
73
73
|
readonly quiet: boolean;
|
|
74
74
|
readonly jsonStdout: boolean;
|
|
75
|
-
/** Optional OpenSSF Scorecard / readiness JSON. Evidence only
|
|
75
|
+
/** Optional OpenSSF Scorecard / readiness JSON. Evidence only - not a PEP. */
|
|
76
76
|
readonly scorecardPath?: string;
|
|
77
|
-
/** Optional AgentShield SecurityReport JSON dump. Evidence only
|
|
77
|
+
/** Optional AgentShield SecurityReport JSON dump. Evidence only - not a PEP. */
|
|
78
78
|
readonly agentshieldJsonPath?: string;
|
|
79
79
|
/** Optional usage JSON (array). Observe-only showback. */
|
|
80
80
|
readonly usagePath?: string;
|
package/dist/commands/orr.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* kya orr run
|
|
2
|
+
* kya orr run - Phase O1 read-only ORR board emitter.
|
|
3
3
|
* Reporting orchestrator only: not a second PEP; never mints principals or allows side effects.
|
|
4
4
|
*/
|
|
5
5
|
import { existsSync, mkdirSync, readdirSync, readFileSync, lstatSync, realpathSync, statSync, writeFileSync, } from "node:fs";
|
|
@@ -218,7 +218,7 @@ export function readScorecardEvidence(scorecardPath) {
|
|
|
218
218
|
category: "enterprise_readiness",
|
|
219
219
|
severity: "info",
|
|
220
220
|
title: "Scorecard file not found",
|
|
221
|
-
detail: `${scorecardPath} was requested as an optional producer. Evidence only
|
|
221
|
+
detail: `${scorecardPath} was requested as an optional producer. Evidence only - not a PEP.`,
|
|
222
222
|
evidence: abs,
|
|
223
223
|
source_tool: "openssf.scorecard",
|
|
224
224
|
},
|
|
@@ -346,7 +346,7 @@ export function runSaFirstPartyProbes(root) {
|
|
|
346
346
|
category: "agent_factory_lifecycle",
|
|
347
347
|
severity: "high",
|
|
348
348
|
title: "Agent create path may be scope-auth only",
|
|
349
|
-
detail: "Factory doctrine: principal mint should be policy-gated (APPROVED). ORR reports only
|
|
349
|
+
detail: "Factory doctrine: principal mint should be policy-gated (APPROVED). ORR reports only - does not mint.",
|
|
350
350
|
evidence: "sa.first_party text probe",
|
|
351
351
|
});
|
|
352
352
|
}
|
|
@@ -361,7 +361,7 @@ export function runSaFirstPartyProbes(root) {
|
|
|
361
361
|
category: "cost_budget_gates",
|
|
362
362
|
severity: "info",
|
|
363
363
|
title: "No in-loop step/token/retry ceilings detected",
|
|
364
|
-
detail: "Look for max_steps, max_tokens, max_retries, or maxCost in the agent loop. Soft gate only
|
|
364
|
+
detail: "Look for max_steps, max_tokens, max_retries, or maxCost in the agent loop. Soft gate only - ORR does not kill spend.",
|
|
365
365
|
evidence: "sa.first_party text probe",
|
|
366
366
|
});
|
|
367
367
|
}
|
|
@@ -493,7 +493,7 @@ export function formatOrrMarkdown(report) {
|
|
|
493
493
|
.join("\n");
|
|
494
494
|
const showbackMd = formatShowbackMarkdown(report.showback);
|
|
495
495
|
const cards = report.scorecards
|
|
496
|
-
.map((s) => `- \`${s.category}\` / \`${s.name}\`: **${s.result}** (${s.hardness})${s.note ? `
|
|
496
|
+
.map((s) => `- \`${s.category}\` / \`${s.name}\`: **${s.result}** (${s.hardness})${s.note ? ` - ${s.note}` : ""}`)
|
|
497
497
|
.join("\n");
|
|
498
498
|
return `# ORR: ${report.target.name}
|
|
499
499
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hidden daemon entry: runs the live receipt server in the foreground and
|
|
3
3
|
* publishes `.kya/receipt-server.json` (pid, url, token) once listening.
|
|
4
|
-
* Spawned detached by `ensureReceiptDaemon`
|
|
4
|
+
* Spawned detached by `ensureReceiptDaemon` - never invoked by users directly.
|
|
5
5
|
*/
|
|
6
6
|
import type { ResolvedConfig } from "../config.js";
|
|
7
7
|
export declare function runReceiptServe(config: ResolvedConfig, input: {
|
|
@@ -17,7 +17,7 @@ export async function runReceiptServe(config, input) {
|
|
|
17
17
|
await live.waitUntilClosed;
|
|
18
18
|
}
|
|
19
19
|
finally {
|
|
20
|
-
// Only remove the state file if it is still ours
|
|
20
|
+
// Only remove the state file if it is still ours - a successor daemon
|
|
21
21
|
// spawned during our slow shutdown must not lose its state.
|
|
22
22
|
clearDaemonState(config.cwd, process.pid);
|
|
23
23
|
}
|
|
@@ -19,7 +19,7 @@ export async function runServeMcp(config, options, client) {
|
|
|
19
19
|
host: config.host,
|
|
20
20
|
agentId: config.agentId,
|
|
21
21
|
// Offline (KYA_OFFLINE=1, as `kya start`/`kya connect` wire for hosts):
|
|
22
|
-
// start keyless
|
|
22
|
+
// start keyless - initialize/tools/list work; tool calls still fail
|
|
23
23
|
// closed at call time without a key.
|
|
24
24
|
requireApiKey: !config.offline,
|
|
25
25
|
});
|
package/dist/commands/start.d.ts
CHANGED
|
@@ -45,8 +45,8 @@ export interface GateBootstrapDeps {
|
|
|
45
45
|
export declare function gateBootstrapEnabled(flag: boolean | undefined, env?: NodeJS.ProcessEnv): boolean;
|
|
46
46
|
/**
|
|
47
47
|
* Gate bootstrap for `kya start`: scaffold gateways.json, import third-party
|
|
48
|
-
* servers discovered in host configs, then
|
|
49
|
-
* govern
|
|
48
|
+
* servers discovered in host configs, then - only when there is something to
|
|
49
|
+
* govern - install the binary, start the supervisor, and route the source
|
|
50
50
|
* hosts through the gateway (direct entries removed, originals backed up
|
|
51
51
|
* under .kya/backups). Every step warns and continues: start never fails
|
|
52
52
|
* because of the gateway, and host configs are only touched once the
|