@praxis.guard/auditor-cli 0.0.61 → 0.0.63
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/dist/approval/mcp-flow-create.d.ts +3 -0
- package/dist/approval/mcp-flow-create.d.ts.map +1 -0
- package/dist/approval/mcp-flow-create.js +76 -0
- package/dist/approval/mcp-flow-create.js.map +1 -0
- package/dist/approval/mcp-flow-existing.d.ts +14 -0
- package/dist/approval/mcp-flow-existing.d.ts.map +1 -0
- package/dist/approval/mcp-flow-existing.js +43 -0
- package/dist/approval/mcp-flow-existing.js.map +1 -0
- package/dist/approval/mcp-flow-outcome.d.ts +5 -0
- package/dist/approval/mcp-flow-outcome.d.ts.map +1 -0
- package/dist/approval/mcp-flow-outcome.js +19 -0
- package/dist/approval/mcp-flow-outcome.js.map +1 -0
- package/dist/approval/mcp-flow-pending.d.ts +7 -0
- package/dist/approval/mcp-flow-pending.d.ts.map +1 -0
- package/dist/approval/mcp-flow-pending.js +25 -0
- package/dist/approval/mcp-flow-pending.js.map +1 -0
- package/dist/approval/mcp-flow-redeem.d.ts +13 -0
- package/dist/approval/mcp-flow-redeem.d.ts.map +1 -0
- package/dist/approval/mcp-flow-redeem.js +20 -0
- package/dist/approval/mcp-flow-redeem.js.map +1 -0
- package/dist/approval/mcp-flow.d.ts +6 -28
- package/dist/approval/mcp-flow.d.ts.map +1 -1
- package/dist/approval/mcp-flow.js +21 -129
- package/dist/approval/mcp-flow.js.map +1 -1
- package/dist/approval/mcp-flow.types.d.ts +42 -0
- package/dist/approval/mcp-flow.types.d.ts.map +1 -0
- package/dist/approval/mcp-flow.types.js +2 -0
- package/dist/approval/mcp-flow.types.js.map +1 -0
- package/dist/cli/doctor-adapter-lines.d.ts +4 -0
- package/dist/cli/doctor-adapter-lines.d.ts.map +1 -0
- package/dist/cli/doctor-adapter-lines.js +47 -0
- package/dist/cli/doctor-adapter-lines.js.map +1 -0
- package/dist/cli/doctor-notifications.d.ts +5 -0
- package/dist/cli/doctor-notifications.d.ts.map +1 -0
- package/dist/cli/doctor-notifications.js +10 -0
- package/dist/cli/doctor-notifications.js.map +1 -0
- package/dist/cli/doctor-remote.d.ts +3 -0
- package/dist/cli/doctor-remote.d.ts.map +1 -0
- package/dist/cli/doctor-remote.js +48 -0
- package/dist/cli/doctor-remote.js.map +1 -0
- package/dist/cli/doctor.d.ts +1 -12
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +46 -111
- package/dist/cli/doctor.js.map +1 -1
- package/dist/mcp/evaluate-guard-approval.d.ts +47 -0
- package/dist/mcp/evaluate-guard-approval.d.ts.map +1 -0
- package/dist/mcp/evaluate-guard-approval.js +80 -0
- package/dist/mcp/evaluate-guard-approval.js.map +1 -0
- package/dist/mcp/evaluate-guard-policy.d.ts +3 -0
- package/dist/mcp/evaluate-guard-policy.d.ts.map +1 -0
- package/dist/mcp/evaluate-guard-policy.js +6 -0
- package/dist/mcp/evaluate-guard-policy.js.map +1 -0
- package/dist/mcp/evaluate-guard-proposal.d.ts +16 -0
- package/dist/mcp/evaluate-guard-proposal.d.ts.map +1 -0
- package/dist/mcp/evaluate-guard-proposal.js +57 -0
- package/dist/mcp/evaluate-guard-proposal.js.map +1 -0
- package/dist/mcp/evaluate-guard-run.d.ts +23 -0
- package/dist/mcp/evaluate-guard-run.d.ts.map +1 -0
- package/dist/mcp/evaluate-guard-run.js +75 -0
- package/dist/mcp/evaluate-guard-run.js.map +1 -0
- package/dist/mcp/evaluate-guard-telemetry.d.ts +22 -0
- package/dist/mcp/evaluate-guard-telemetry.d.ts.map +1 -0
- package/dist/mcp/evaluate-guard-telemetry.js +38 -0
- package/dist/mcp/evaluate-guard-telemetry.js.map +1 -0
- package/dist/mcp/evaluate-guard-tier.d.ts +18 -0
- package/dist/mcp/evaluate-guard-tier.d.ts.map +1 -0
- package/dist/mcp/evaluate-guard-tier.js +42 -0
- package/dist/mcp/evaluate-guard-tier.js.map +1 -0
- package/dist/mcp/evaluate-guard.d.ts +2 -5
- package/dist/mcp/evaluate-guard.d.ts.map +1 -1
- package/dist/mcp/evaluate-guard.js +18 -195
- package/dist/mcp/evaluate-guard.js.map +1 -1
- package/dist/mcp/gateway-call-handler.d.ts +9 -0
- package/dist/mcp/gateway-call-handler.d.ts.map +1 -0
- package/dist/mcp/gateway-call-handler.js +61 -0
- package/dist/mcp/gateway-call-handler.js.map +1 -0
- package/dist/mcp/gateway-call-results.d.ts +5 -0
- package/dist/mcp/gateway-call-results.d.ts.map +1 -0
- package/dist/mcp/gateway-call-results.js +14 -0
- package/dist/mcp/gateway-call-results.js.map +1 -0
- package/dist/mcp/gateway-connection-lib.d.ts +54 -0
- package/dist/mcp/gateway-connection-lib.d.ts.map +1 -0
- package/dist/mcp/gateway-connection-lib.js +39 -0
- package/dist/mcp/gateway-connection-lib.js.map +1 -0
- package/dist/mcp/gateway-connection.d.ts +16 -0
- package/dist/mcp/gateway-connection.d.ts.map +1 -0
- package/dist/mcp/gateway-connection.js +54 -0
- package/dist/mcp/gateway-connection.js.map +1 -0
- package/dist/mcp/gateway-log.d.ts +5 -0
- package/dist/mcp/gateway-log.d.ts.map +1 -0
- package/dist/mcp/gateway-log.js +9 -0
- package/dist/mcp/gateway-log.js.map +1 -0
- package/dist/mcp/gateway.d.ts +2 -20
- package/dist/mcp/gateway.d.ts.map +1 -1
- package/dist/mcp/gateway.js +18 -186
- package/dist/mcp/gateway.js.map +1 -1
- package/dist/policies.v1.json +6 -0
- package/native/darwin-amd64/praxis-guard-daemon +0 -0
- package/native/darwin-amd64/praxis-guard-hook +0 -0
- package/native/darwin-arm64/praxis-guard-daemon +0 -0
- package/native/darwin-arm64/praxis-guard-hook +0 -0
- package/native/linux-amd64/praxis-guard-daemon +0 -0
- package/native/linux-amd64/praxis-guard-hook +0 -0
- package/native/linux-arm64/praxis-guard-daemon +0 -0
- package/native/linux-arm64/praxis-guard-hook +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { evaluatePolicyWithDaemon } from "../daemon/client.js";
|
|
2
|
+
import { daemonModeEnabled } from "../daemon/paths.js";
|
|
3
|
+
import { evaluateMcpProposal, evaluateShellProposal } from "../shell/evaluate.js";
|
|
4
|
+
export function evaluateGuardProposal(input, policy) {
|
|
5
|
+
const shellCommand = input.proposal.kind === "shell"
|
|
6
|
+
? input.proposal.raw_command ?? input.proposal.argv.join(" ")
|
|
7
|
+
: null;
|
|
8
|
+
const shellResult = input.proposal.kind === "shell" && shellCommand
|
|
9
|
+
? evaluateShellProposal(policy, shellCommand)
|
|
10
|
+
: null;
|
|
11
|
+
const mcpResult = input.proposal.kind === "mcp"
|
|
12
|
+
? evaluateMcpProposal(policy, input.proposal.argv)
|
|
13
|
+
: null;
|
|
14
|
+
return {
|
|
15
|
+
skipped: shellResult?.skipped ?? mcpResult?.skipped ?? true,
|
|
16
|
+
evaluation: shellResult?.evaluation ?? mcpResult.evaluation,
|
|
17
|
+
analysis: shellResult?.analysis,
|
|
18
|
+
shellCommand,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export async function applyDaemonEvaluation(argv, evaluation) {
|
|
22
|
+
if (!daemonModeEnabled()) {
|
|
23
|
+
return { skipped: true, evaluation };
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const daemonEvaluation = await evaluatePolicyWithDaemon(argv);
|
|
27
|
+
return {
|
|
28
|
+
skipped: daemonEvaluation.skipped,
|
|
29
|
+
evaluation: {
|
|
30
|
+
...evaluation,
|
|
31
|
+
tier: daemonEvaluation.tier,
|
|
32
|
+
classification: daemonEvaluation.classification,
|
|
33
|
+
flags: daemonEvaluation.flags,
|
|
34
|
+
reasons: daemonEvaluation.skipped
|
|
35
|
+
? [{ code: "skipped", message: "No policy entry matched in the native daemon." }]
|
|
36
|
+
: [
|
|
37
|
+
{
|
|
38
|
+
code: "policy_match",
|
|
39
|
+
message: "Matched policy entry in the native daemon.",
|
|
40
|
+
details: {
|
|
41
|
+
tool: daemonEvaluation.classification.tool,
|
|
42
|
+
command_path: daemonEvaluation.classification.command_path,
|
|
43
|
+
verb: daemonEvaluation.classification.verb,
|
|
44
|
+
tier: daemonEvaluation.tier,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (process.env.PRAXIS_GUARD_SPAWN_FALLBACK !== "1")
|
|
53
|
+
throw error;
|
|
54
|
+
return { skipped: true, evaluation };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=evaluate-guard-proposal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate-guard-proposal.js","sourceRoot":"","sources":["../../src/mcp/evaluate-guard-proposal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAalF,MAAM,UAAU,qBAAqB,CACnC,KAAiB,EACjB,MAAkB;IAElB,MAAM,YAAY,GAChB,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,OAAO;QAC7B,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QAC7D,CAAC,CAAC,IAAI,CAAC;IACX,MAAM,WAAW,GACf,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,OAAO,IAAI,YAAY;QAC7C,CAAC,CAAC,qBAAqB,CAAC,MAAM,EAAE,YAAY,CAAC;QAC7C,CAAC,CAAC,IAAI,CAAC;IACX,MAAM,SAAS,GACb,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,KAAK;QAC3B,CAAC,CAAC,mBAAm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;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,GAAG;YAAE,MAAM,KAAK,CAAC;QACjE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IACvC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Tier } from "../policy/index.js";
|
|
2
|
+
import type { GuardEvaluation } from "../shell/guard-eval.js";
|
|
3
|
+
import type { ApprovalBlock } from "./guard-approval-block.js";
|
|
4
|
+
import type { GuardInput } from "./guard-schemas.js";
|
|
5
|
+
import { applyGuardMode, type GuardDecision } from "./guard-mode.js";
|
|
6
|
+
import { type PolicyState } from "./evaluate-guard-tier.js";
|
|
7
|
+
import { type GuardProposalEvaluation } from "./evaluate-guard-proposal.js";
|
|
8
|
+
export type GuardEvaluationResult = {
|
|
9
|
+
startedAt: number;
|
|
10
|
+
eventId: string;
|
|
11
|
+
proposal: GuardProposalEvaluation;
|
|
12
|
+
skipped: boolean;
|
|
13
|
+
evaluation: GuardEvaluation;
|
|
14
|
+
tier: Tier;
|
|
15
|
+
reasons: GuardEvaluation["reasons"];
|
|
16
|
+
decision: GuardDecision;
|
|
17
|
+
shadow: ReturnType<typeof applyGuardMode>["shadow"];
|
|
18
|
+
approvalBlock: ApprovalBlock;
|
|
19
|
+
approvalRequestId: string | null;
|
|
20
|
+
};
|
|
21
|
+
export declare function runGuardEvaluation(input: GuardInput, policyState: PolicyState): Promise<GuardEvaluationResult>;
|
|
22
|
+
export declare function buildGuardResponse(input: GuardInput, result: GuardEvaluationResult): Record<string, unknown>;
|
|
23
|
+
//# sourceMappingURL=evaluate-guard-run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate-guard-run.d.ts","sourceRoot":"","sources":["../../src/mcp/evaluate-guard-run.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,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+
import { daemonModeEnabled } from "../daemon/paths.js";
|
|
4
|
+
import { riskScore } from "./evaluate-guard-tier.js";
|
|
5
|
+
import { applyDaemonEvaluation, evaluateGuardProposal, } from "./evaluate-guard-proposal.js";
|
|
6
|
+
import { resolveGuardEnforcement, } from "./evaluate-guard-approval.js";
|
|
7
|
+
import { loadGuardPolicyState } from "./evaluate-guard-policy.js";
|
|
8
|
+
function rememberGuardWorkspace(input) {
|
|
9
|
+
const storageRoot = resolveGuardStorageRootFromHints({
|
|
10
|
+
cwd: input.proposal.cwd,
|
|
11
|
+
workspaceRoot: input.context?.workspace_root,
|
|
12
|
+
workspaceRoots: input.context?.workspace_roots,
|
|
13
|
+
});
|
|
14
|
+
rememberResolvedWorkspaceRoot(storageRoot);
|
|
15
|
+
return storageRoot;
|
|
16
|
+
}
|
|
17
|
+
export async function runGuardEvaluation(input, policyState) {
|
|
18
|
+
const startedAt = performance.now();
|
|
19
|
+
const eventId = uuidv4();
|
|
20
|
+
await loadGuardPolicyState(policyState);
|
|
21
|
+
const storageRoot = rememberGuardWorkspace(input);
|
|
22
|
+
const proposal = evaluateGuardProposal(input, policyState.policy);
|
|
23
|
+
let skipped = proposal.skipped;
|
|
24
|
+
let evaluation = proposal.evaluation;
|
|
25
|
+
if (daemonModeEnabled()) {
|
|
26
|
+
const daemon = await applyDaemonEvaluation(evaluation.argv, evaluation);
|
|
27
|
+
skipped = daemon.skipped;
|
|
28
|
+
evaluation = daemon.evaluation;
|
|
29
|
+
}
|
|
30
|
+
const tier = evaluation.tier;
|
|
31
|
+
const reasons = [...evaluation.reasons];
|
|
32
|
+
const enforcement = await resolveGuardEnforcement({
|
|
33
|
+
guardInput: input,
|
|
34
|
+
skipped,
|
|
35
|
+
tier,
|
|
36
|
+
reasons,
|
|
37
|
+
argv: evaluation.argv,
|
|
38
|
+
storageRoot,
|
|
39
|
+
eventId,
|
|
40
|
+
policyRevision: policyState.policyRevision,
|
|
41
|
+
analysis: proposal.analysis,
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
startedAt,
|
|
45
|
+
eventId,
|
|
46
|
+
proposal,
|
|
47
|
+
skipped,
|
|
48
|
+
evaluation,
|
|
49
|
+
tier,
|
|
50
|
+
reasons,
|
|
51
|
+
decision: enforcement.decision,
|
|
52
|
+
shadow: enforcement.shadow,
|
|
53
|
+
approvalBlock: enforcement.approvalBlock,
|
|
54
|
+
approvalRequestId: enforcement.approvalRequestId,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function buildGuardResponse(input, result) {
|
|
58
|
+
return {
|
|
59
|
+
mode: input.mode,
|
|
60
|
+
decision: result.decision,
|
|
61
|
+
skipped: result.skipped,
|
|
62
|
+
tier: result.tier,
|
|
63
|
+
risk_score: riskScore(result.skipped, result.tier),
|
|
64
|
+
reasons: result.reasons,
|
|
65
|
+
shadow: result.shadow,
|
|
66
|
+
approval: result.approvalBlock,
|
|
67
|
+
audit: {
|
|
68
|
+
event_id: result.eventId,
|
|
69
|
+
timestamp: new Date().toISOString(),
|
|
70
|
+
latency_ms: performance.now() - result.startedAt,
|
|
71
|
+
},
|
|
72
|
+
execution: { attempted: false, result: null },
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=evaluate-guard-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate-guard-run.js","sourceRoot":"","sources":["../../src/mcp/evaluate-guard-run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EACL,6BAA6B,EAC7B,gCAAgC,GACjC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAMvD,OAAO,EAAE,SAAS,EAAoB,MAAM,0BAA0B,CAAC;AACvE,OAAO,EACL,qBAAqB,EACrB,qBAAqB,GAEtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,uBAAuB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./guard-mode.js";
|
|
3
|
+
import type { GuardInput } from "./guard-schemas.js";
|
|
4
|
+
import type { PolicyState } from "./evaluate-guard-tier.js";
|
|
5
|
+
export declare function emitGuardEvaluationTelemetry(input: {
|
|
6
|
+
guardInput: GuardInput;
|
|
7
|
+
policyState: PolicyState;
|
|
8
|
+
startedAt: number;
|
|
9
|
+
eventId: string;
|
|
10
|
+
skipped: boolean;
|
|
11
|
+
tier: Tier;
|
|
12
|
+
decision: GuardDecision;
|
|
13
|
+
argv: string[];
|
|
14
|
+
shellCommand: string | null;
|
|
15
|
+
reasons: {
|
|
16
|
+
message?: string;
|
|
17
|
+
code?: string;
|
|
18
|
+
}[];
|
|
19
|
+
approvalRequestId: string | null;
|
|
20
|
+
invocationCount: number | null;
|
|
21
|
+
}): void;
|
|
22
|
+
//# sourceMappingURL=evaluate-guard-telemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate-guard-telemetry.d.ts","sourceRoot":"","sources":["../../src/mcp/evaluate-guard-telemetry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAc5D,wBAAgB,4BAA4B,CAAC,KAAK,EAAE;IAClD,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,aAAa,CAAC;IACxB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,OAAO,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC/C,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,GAAG,IAAI,CAyBP"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { sendGuardEvent } from "../telemetry/guard-events.js";
|
|
2
|
+
import { getInstallId } from "../cli/install-id.js";
|
|
3
|
+
import { resolveGuardAuditStatus } from "./guard-audit-status.js";
|
|
4
|
+
function firstPolicyReason(reasons) {
|
|
5
|
+
return (reasons.find((r) => typeof r?.message === "string")?.message ??
|
|
6
|
+
reasons.find((r) => typeof r?.code === "string")?.code ??
|
|
7
|
+
null);
|
|
8
|
+
}
|
|
9
|
+
function guardSkipReason(kind) {
|
|
10
|
+
return kind === "shell" ? "no_governed_invocation" : "mcp_policy_unmatched";
|
|
11
|
+
}
|
|
12
|
+
export function emitGuardEvaluationTelemetry(input) {
|
|
13
|
+
const status = resolveGuardAuditStatus({ skipped: input.skipped, decision: input.decision });
|
|
14
|
+
void sendGuardEvent({
|
|
15
|
+
ts: new Date().toISOString(),
|
|
16
|
+
status,
|
|
17
|
+
skipped: input.skipped,
|
|
18
|
+
...(input.skipped ? { skip_reason: guardSkipReason(input.guardInput.proposal.kind) } : {}),
|
|
19
|
+
tool: "auditor-mcp",
|
|
20
|
+
command_path: input.argv[0] ?? null,
|
|
21
|
+
verb: input.argv[1] ?? null,
|
|
22
|
+
resource: input.argv.length > 2 ? input.argv.slice(2).join(" ") : null,
|
|
23
|
+
reason: firstPolicyReason(input.reasons),
|
|
24
|
+
cmd: input.shellCommand ?? input.argv.join(" "),
|
|
25
|
+
tier: input.tier,
|
|
26
|
+
decision: input.decision,
|
|
27
|
+
latency_ms: performance.now() - input.startedAt,
|
|
28
|
+
event_id: input.eventId,
|
|
29
|
+
installId: getInstallId(),
|
|
30
|
+
kind: input.guardInput.proposal.kind,
|
|
31
|
+
...(input.policyState.policyRevision !== null
|
|
32
|
+
? { policy_revision: input.policyState.policyRevision }
|
|
33
|
+
: {}),
|
|
34
|
+
...(input.approvalRequestId ? { approval_request_id: input.approvalRequestId } : {}),
|
|
35
|
+
meta: { invocation_count: input.invocationCount },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=evaluate-guard-telemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate-guard-telemetry.js","sourceRoot":"","sources":["../../src/mcp/evaluate-guard-telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAKlE,SAAS,iBAAiB,CAAC,OAA8C;IACvE,OAAO,CACL,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,QAAQ,CAAC,EAAE,OAAO;QAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,KAAK,QAAQ,CAAC,EAAE,IAAI;QACtD,IAAI,CACL,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAoC;IAC3D,OAAO,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,sBAAsB,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,KAa5C;IACC,MAAM,MAAM,GAAG,uBAAuB,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7F,KAAK,cAAc,CAAC;QAClB,EAAE,EAAE,IAAI,IAA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AmB,EAAE,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpF,IAAI,EAAE,EAAE,gBAAgB,EAAE,KAAK,CAAC,eAAe,EAAE;KAClD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { loadPoliciesV1, type Tier } from "../policy/index.js";
|
|
2
|
+
import { type ApprovalBlock } from "./guard-approval-block.js";
|
|
3
|
+
import { type GuardDecision } from "./guard-mode.js";
|
|
4
|
+
import type { GuardInput } from "./guard-schemas.js";
|
|
5
|
+
export type PolicyState = {
|
|
6
|
+
policy: Awaited<ReturnType<typeof loadPoliciesV1>>;
|
|
7
|
+
policyRevision: number | null;
|
|
8
|
+
};
|
|
9
|
+
export declare function riskScore(skipped: boolean, tier: Tier): number;
|
|
10
|
+
export declare function resolveTierDecision(input: {
|
|
11
|
+
mode: GuardInput["mode"];
|
|
12
|
+
skipped: boolean;
|
|
13
|
+
tier: Tier;
|
|
14
|
+
}): {
|
|
15
|
+
enforceDecision: GuardDecision;
|
|
16
|
+
approvalBlock: ApprovalBlock;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=evaluate-guard-tier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate-guard-tier.d.ts","sourceRoot":"","sources":["../../src/mcp/evaluate-guard-tier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC;IACnD,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAEF,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAK9D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC;CACZ,GAAG;IAAE,eAAe,EAAE,aAAa,CAAC;IAAC,aAAa,EAAE,aAAa,CAAA;CAAE,CAgCnE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { defaultApprovalBlock } from "./guard-approval-block.js";
|
|
2
|
+
import { tierToPolicyDecision } from "./guard-mode.js";
|
|
3
|
+
export function riskScore(skipped, tier) {
|
|
4
|
+
if (skipped)
|
|
5
|
+
return 0;
|
|
6
|
+
if (tier === "READ")
|
|
7
|
+
return 0;
|
|
8
|
+
if (tier === "MUTATE")
|
|
9
|
+
return 60;
|
|
10
|
+
return 95;
|
|
11
|
+
}
|
|
12
|
+
export function resolveTierDecision(input) {
|
|
13
|
+
const { mode, skipped, tier } = input;
|
|
14
|
+
let enforceDecision = tierToPolicyDecision(tier, skipped);
|
|
15
|
+
const approvalBlock = defaultApprovalBlock();
|
|
16
|
+
if (skipped) {
|
|
17
|
+
return { enforceDecision: "allow", approvalBlock };
|
|
18
|
+
}
|
|
19
|
+
if (tier === "DESTRUCTIVE") {
|
|
20
|
+
return {
|
|
21
|
+
enforceDecision: "block",
|
|
22
|
+
approvalBlock: {
|
|
23
|
+
...approvalBlock,
|
|
24
|
+
instructions: "DESTRUCTIVE actions cannot be approved via guard. Escalate outside the agent loop.",
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (tier === "READ") {
|
|
29
|
+
return { enforceDecision: "allow", approvalBlock };
|
|
30
|
+
}
|
|
31
|
+
if (mode === "shadow") {
|
|
32
|
+
return {
|
|
33
|
+
enforceDecision: "require_approval",
|
|
34
|
+
approvalBlock: {
|
|
35
|
+
...approvalBlock,
|
|
36
|
+
instructions: "Shadow mode: no approval request created. Re-call with mode enforce to coordinate human approval.",
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return { enforceDecision, approvalBlock };
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=evaluate-guard-tier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate-guard-tier.js","sourceRoot":"","sources":["../../src/mcp/evaluate-guard-tier.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAsB,MAAM,iBAAiB,CAAC;AAQ3E,MAAM,UAAU,SAAS,CAAC,OAAgB,EAAE,IAAU;IACpD,IAAI,OAAO;QAAE,OAAO,CAAC,CAAC;IACtB,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,CAAC,CAAC;IAC9B,IAAI,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAInC;IACC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IACtC,IAAI,eAAe,GAAG,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1D,MAAM,aAAa,GAAG,oBAAoB,EAAE,CAAC;IAE7C,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IACrD,CAAC;IACD,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;QAC3B,OAAO;YACL,eAAe,EAAE,OAAO;YACxB,aAAa,EAAE;gBACb,GAAG,aAAa;gBAChB,YAAY,EACV,oFAAoF;aACvF;SACF,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IACrD,CAAC;IACD,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,OAAO;YACL,eAAe,EAAE,kBAAkB;YACnC,aAAa,EAAE;gBACb,GAAG,aAAa;gBAChB,YAAY,EACV,mGAAmG;aACtG;SACF,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC;AAC5C,CAAC"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { loadPoliciesV1 } from "../policy/index.js";
|
|
2
1
|
import type { GuardInput } from "./guard-schemas.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
policyRevision: number | null;
|
|
6
|
-
};
|
|
2
|
+
import type { PolicyState } from "./evaluate-guard-tier.js";
|
|
3
|
+
export type { PolicyState } from "./evaluate-guard-tier.js";
|
|
7
4
|
export declare function evaluateGuard(input: GuardInput, policyState: PolicyState): Promise<{
|
|
8
5
|
response: Record<string, unknown>;
|
|
9
6
|
startedAt: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate-guard.d.ts","sourceRoot":"","sources":["../../src/mcp/evaluate-guard.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evaluate-guard.d.ts","sourceRoot":"","sources":["../../src/mcp/evaluate-guard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAI5D,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,wBAAsB,aAAa,CACjC,KAAK,EAAE,UAAU,EACjB,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAmBnE"}
|
|
@@ -1,201 +1,24 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from "uuid";
|
|
2
|
-
import { loadPoliciesV1, readPoliciesV1Revision } from "../policy/index.js";
|
|
3
|
-
import { rememberResolvedWorkspaceRoot, resolveGuardStorageRootFromHints, } from "../bridge/guard-storage-root.js";
|
|
4
|
-
import { evaluateMcpProposal, evaluateShellProposal } from "../shell/evaluate.js";
|
|
5
|
-
import { sendGuardEvent } from "../telemetry/guard-events.js";
|
|
6
|
-
import { getInstallId } from "../cli/install-id.js";
|
|
7
|
-
import { evaluatePolicyWithDaemon } from "../daemon/client.js";
|
|
8
|
-
import { daemonModeEnabled } from "../daemon/paths.js";
|
|
9
|
-
import { resolveGuardAuditStatus } from "./guard-audit-status.js";
|
|
10
|
-
import { applyGuardMode, tierToPolicyDecision } from "./guard-mode.js";
|
|
11
1
|
import { resetHeartbeatIdle } from "./guard-heartbeat.js";
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
if (skipped)
|
|
15
|
-
return 0;
|
|
16
|
-
if (tier === "READ")
|
|
17
|
-
return 0;
|
|
18
|
-
if (tier === "MUTATE")
|
|
19
|
-
return 60;
|
|
20
|
-
return 95;
|
|
21
|
-
}
|
|
22
|
-
function resolveTierDecision(input) {
|
|
23
|
-
const { mode, skipped, tier } = input;
|
|
24
|
-
let enforceDecision = tierToPolicyDecision(tier, skipped);
|
|
25
|
-
const approvalBlock = defaultApprovalBlock();
|
|
26
|
-
if (skipped) {
|
|
27
|
-
return { enforceDecision: "allow", approvalBlock };
|
|
28
|
-
}
|
|
29
|
-
if (tier === "DESTRUCTIVE") {
|
|
30
|
-
return {
|
|
31
|
-
enforceDecision: "block",
|
|
32
|
-
approvalBlock: {
|
|
33
|
-
...approvalBlock,
|
|
34
|
-
instructions: "DESTRUCTIVE actions cannot be approved via guard. Escalate outside the agent loop.",
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
if (tier === "READ") {
|
|
39
|
-
return { enforceDecision: "allow", approvalBlock };
|
|
40
|
-
}
|
|
41
|
-
if (mode === "shadow") {
|
|
42
|
-
return {
|
|
43
|
-
enforceDecision: "require_approval",
|
|
44
|
-
approvalBlock: {
|
|
45
|
-
...approvalBlock,
|
|
46
|
-
instructions: "Shadow mode: no approval request created. Re-call with mode enforce to coordinate human approval.",
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return { enforceDecision, approvalBlock };
|
|
51
|
-
}
|
|
2
|
+
import { emitGuardEvaluationTelemetry } from "./evaluate-guard-telemetry.js";
|
|
3
|
+
import { buildGuardResponse, runGuardEvaluation } from "./evaluate-guard-run.js";
|
|
52
4
|
export async function evaluateGuard(input, policyState) {
|
|
53
|
-
const startedAt = performance.now();
|
|
54
|
-
const event_id = uuidv4();
|
|
55
5
|
resetHeartbeatIdle();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
:
|
|
70
|
-
|
|
71
|
-
? evaluateMcpProposal(policyState.policy, input.proposal.argv)
|
|
72
|
-
: null;
|
|
73
|
-
let skipped = shellResult?.skipped ?? mcpResult?.skipped ?? true;
|
|
74
|
-
let evaluation = shellResult?.evaluation ?? mcpResult.evaluation;
|
|
75
|
-
const analysis = shellResult?.analysis;
|
|
76
|
-
const argv = evaluation.argv;
|
|
77
|
-
if (daemonModeEnabled()) {
|
|
78
|
-
try {
|
|
79
|
-
const daemonEvaluation = await evaluatePolicyWithDaemon(argv);
|
|
80
|
-
skipped = daemonEvaluation.skipped;
|
|
81
|
-
evaluation = {
|
|
82
|
-
...evaluation,
|
|
83
|
-
tier: daemonEvaluation.tier,
|
|
84
|
-
classification: daemonEvaluation.classification,
|
|
85
|
-
flags: daemonEvaluation.flags,
|
|
86
|
-
reasons: daemonEvaluation.skipped
|
|
87
|
-
? [{ code: "skipped", message: "No policy entry matched in the native daemon." }]
|
|
88
|
-
: [
|
|
89
|
-
{
|
|
90
|
-
code: "policy_match",
|
|
91
|
-
message: "Matched policy entry in the native daemon.",
|
|
92
|
-
details: {
|
|
93
|
-
tool: daemonEvaluation.classification.tool,
|
|
94
|
-
command_path: daemonEvaluation.classification.command_path,
|
|
95
|
-
verb: daemonEvaluation.classification.verb,
|
|
96
|
-
tier: daemonEvaluation.tier,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
if (process.env.PRAXIS_GUARD_SPAWN_FALLBACK !== "1")
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const tier = evaluation.tier;
|
|
108
|
-
const reasons = [...evaluation.reasons];
|
|
109
|
-
const policyReasons = [...evaluation.reasons];
|
|
110
|
-
let { enforceDecision, approvalBlock } = resolveTierDecision({
|
|
111
|
-
mode: input.mode,
|
|
112
|
-
skipped,
|
|
113
|
-
tier,
|
|
114
|
-
});
|
|
115
|
-
let approvalRequestId = null;
|
|
116
|
-
const hookApprovalRequestId = input.context?.approval?.request_id?.trim() || null;
|
|
117
|
-
const hookWaitMs = input.context?.wait_ms ?? 0;
|
|
118
|
-
const redeemHookApproval = !skipped &&
|
|
119
|
-
tier !== "DESTRUCTIVE" &&
|
|
120
|
-
input.mode === "enforce" &&
|
|
121
|
-
hookApprovalRequestId !== null &&
|
|
122
|
-
hookWaitMs > 0;
|
|
123
|
-
if (redeemHookApproval ||
|
|
124
|
-
(!skipped && tier !== "DESTRUCTIVE" && tier !== "READ" && input.mode === "enforce")) {
|
|
125
|
-
const mutate = await resolveEnforceMutateApproval({
|
|
126
|
-
guardInput: input,
|
|
127
|
-
argv,
|
|
128
|
-
storageRoot,
|
|
129
|
-
eventId: event_id,
|
|
130
|
-
policyRevision: policyState.policyRevision,
|
|
131
|
-
reasons,
|
|
132
|
-
approval_fingerprint: analysis?.approval_fingerprint_payload ?? null,
|
|
133
|
-
});
|
|
134
|
-
enforceDecision = mutate.enforceDecision;
|
|
135
|
-
approvalBlock = mutate.approvalBlock;
|
|
136
|
-
approvalRequestId = mutate.approvalRequestId;
|
|
137
|
-
}
|
|
138
|
-
const { decision, shadow } = applyGuardMode({
|
|
139
|
-
mode: input.mode,
|
|
140
|
-
skipped,
|
|
141
|
-
tier,
|
|
142
|
-
policyReasons,
|
|
143
|
-
enforceDecision,
|
|
144
|
-
});
|
|
145
|
-
const response = {
|
|
146
|
-
mode: input.mode,
|
|
147
|
-
decision,
|
|
148
|
-
skipped,
|
|
149
|
-
tier,
|
|
150
|
-
risk_score: riskScore(skipped, tier),
|
|
151
|
-
reasons,
|
|
152
|
-
shadow,
|
|
153
|
-
approval: approvalBlock,
|
|
154
|
-
audit: {
|
|
155
|
-
event_id,
|
|
156
|
-
timestamp: new Date().toISOString(),
|
|
157
|
-
latency_ms: performance.now() - startedAt,
|
|
158
|
-
},
|
|
159
|
-
execution: {
|
|
160
|
-
attempted: false,
|
|
161
|
-
result: null,
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
const firstReason = reasons.find((r) => typeof r?.message === "string")?.message ??
|
|
165
|
-
reasons.find((r) => typeof r?.code === "string")?.code ??
|
|
166
|
-
null;
|
|
167
|
-
const actionVerb = argv[1] ?? null;
|
|
168
|
-
const actionResource = argv.length > 2 ? argv.slice(2).join(" ") : null;
|
|
169
|
-
const status = resolveGuardAuditStatus({ skipped, decision });
|
|
170
|
-
void sendGuardEvent({
|
|
171
|
-
ts: new Date().toISOString(),
|
|
172
|
-
status,
|
|
173
|
-
skipped,
|
|
174
|
-
...(skipped
|
|
175
|
-
? {
|
|
176
|
-
skip_reason: input.proposal.kind === "shell" ? "no_governed_invocation" : "mcp_policy_unmatched",
|
|
177
|
-
}
|
|
178
|
-
: {}),
|
|
179
|
-
tool: "auditor-mcp",
|
|
180
|
-
command_path: argv[0] ?? null,
|
|
181
|
-
verb: actionVerb,
|
|
182
|
-
resource: actionResource,
|
|
183
|
-
reason: firstReason,
|
|
184
|
-
cmd: shellCommand ?? argv.join(" "),
|
|
185
|
-
tier,
|
|
186
|
-
decision,
|
|
187
|
-
latency_ms: performance.now() - startedAt,
|
|
188
|
-
event_id,
|
|
189
|
-
installId: getInstallId(),
|
|
190
|
-
kind: input.proposal.kind,
|
|
191
|
-
...(policyState.policyRevision !== null
|
|
192
|
-
? { policy_revision: policyState.policyRevision }
|
|
193
|
-
: {}),
|
|
194
|
-
...(approvalRequestId ? { approval_request_id: approvalRequestId } : {}),
|
|
195
|
-
meta: {
|
|
196
|
-
invocation_count: analysis?.invocations.length ?? null,
|
|
197
|
-
},
|
|
6
|
+
const result = await runGuardEvaluation(input, policyState);
|
|
7
|
+
const response = buildGuardResponse(input, result);
|
|
8
|
+
emitGuardEvaluationTelemetry({
|
|
9
|
+
guardInput: input,
|
|
10
|
+
policyState,
|
|
11
|
+
startedAt: result.startedAt,
|
|
12
|
+
eventId: result.eventId,
|
|
13
|
+
skipped: result.skipped,
|
|
14
|
+
tier: result.tier,
|
|
15
|
+
decision: result.decision,
|
|
16
|
+
argv: result.evaluation.argv,
|
|
17
|
+
shellCommand: result.proposal.shellCommand,
|
|
18
|
+
reasons: result.reasons,
|
|
19
|
+
approvalRequestId: result.approvalRequestId,
|
|
20
|
+
invocationCount: result.proposal.analysis?.invocations.length ?? null,
|
|
198
21
|
});
|
|
199
|
-
return { response, startedAt };
|
|
22
|
+
return { response, startedAt: result.startedAt };
|
|
200
23
|
}
|
|
201
24
|
//# sourceMappingURL=evaluate-guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate-guard.js","sourceRoot":"","sources":["../../src/mcp/evaluate-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"evaluate-guard.js","sourceRoot":"","sources":["../../src/mcp/evaluate-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAIjF,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAAiB,EACjB,WAAwB;IAExB,kBAAkB,EAAE,CAAC;IACrB,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAG,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACnD,4BAA4B,CAAC;QAC3B,UAAU,EAAE,KAAK;QACjB,WAAW;QACX,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI;QAC5B,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,YAAY;QAC1C,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;QAC3C,eAAe,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,IAAI,IAAI;KACtE,CAAC,CAAC;IACH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import type { GatewayConnection } from "./gateway-connection.js";
|
|
3
|
+
export declare function handleGatewayCallTool(input: {
|
|
4
|
+
exposed: string;
|
|
5
|
+
args: Record<string, unknown>;
|
|
6
|
+
ids: string[];
|
|
7
|
+
byId: Map<string, GatewayConnection>;
|
|
8
|
+
}): Promise<CallToolResult>;
|
|
9
|
+
//# sourceMappingURL=gateway-call-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-call-handler.d.ts","sourceRoot":"","sources":["../../src/mcp/gateway-call-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAKzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAmCjE,wBAAsB,qBAAqB,CAAC,KAAK,EAAE;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;CACtC,GAAG,OAAO,CAAC,cAAc,CAAC,CAyC1B"}
|