mergen-server 1.4.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/LICENSE +57 -0
- package/README.md +96 -0
- package/dist/__stubs__/calibration.js +471 -0
- package/dist/__stubs__/causal.js +601 -0
- package/dist/__stubs__/closed-source.js +150 -0
- package/dist/__stubs__/license.js +35 -0
- package/dist/__stubs__/plans.js +197 -0
- package/dist/app.js +467 -0
- package/dist/cli.js +250 -0
- package/dist/commands/agent-identity.js +79 -0
- package/dist/commands/gate.js +107 -0
- package/dist/commands/github.js +632 -0
- package/dist/commands/incident.js +644 -0
- package/dist/commands/policy.js +710 -0
- package/dist/commands/scan.js +243 -0
- package/dist/commands/setup.js +1218 -0
- package/dist/commands/shared.js +109 -0
- package/dist/commands/team.js +809 -0
- package/dist/datadog/blame-attribution.js +228 -0
- package/dist/datadog/client.js +159 -0
- package/dist/datadog/compactor.js +169 -0
- package/dist/datadog/fingerprinter.js +34 -0
- package/dist/datadog/incident-state.js +21 -0
- package/dist/datadog/line-matcher.js +56 -0
- package/dist/datadog/memory-store.js +399 -0
- package/dist/datadog/otel-trace.js +67 -0
- package/dist/index.js +505 -0
- package/dist/intelligence/action-risk.js +132 -0
- package/dist/intelligence/activity-feed.js +40 -0
- package/dist/intelligence/agent-identity.js +115 -0
- package/dist/intelligence/agent-pipeline.js +329 -0
- package/dist/intelligence/agent-profiles.js +81 -0
- package/dist/intelligence/ai-commit.js +16 -0
- package/dist/intelligence/approval-analytics.js +42 -0
- package/dist/intelligence/approval-events.js +5 -0
- package/dist/intelligence/arch-boundaries.js +94 -0
- package/dist/intelligence/arch-graph.js +117 -0
- package/dist/intelligence/autonomy.js +397 -0
- package/dist/intelligence/azure-broker.js +57 -0
- package/dist/intelligence/azure-proxy-sessions.js +49 -0
- package/dist/intelligence/baseline.js +1 -0
- package/dist/intelligence/behavior-baseline.js +134 -0
- package/dist/intelligence/billing.js +1 -0
- package/dist/intelligence/blast-radius.js +224 -0
- package/dist/intelligence/bypass.js +157 -0
- package/dist/intelligence/calibration-classifier.js +77 -0
- package/dist/intelligence/calibration-git-sync.js +74 -0
- package/dist/intelligence/calibration.js +1 -0
- package/dist/intelligence/cascade-detector.js +58 -0
- package/dist/intelligence/case-study-generator.js +126 -0
- package/dist/intelligence/causal-graph.js +126 -0
- package/dist/intelligence/causal.js +1 -0
- package/dist/intelligence/change-risk.js +102 -0
- package/dist/intelligence/compliance-report.js +134 -0
- package/dist/intelligence/confidence-report.js +85 -0
- package/dist/intelligence/corpus-to-policy.js +140 -0
- package/dist/intelligence/credential-broker.js +112 -0
- package/dist/intelligence/credential-misuse.js +39 -0
- package/dist/intelligence/debug-sessions.js +108 -0
- package/dist/intelligence/decision-escalation.js +36 -0
- package/dist/intelligence/decision-memory.js +47 -0
- package/dist/intelligence/decision-similarity.js +85 -0
- package/dist/intelligence/default-safety-tests.js +53 -0
- package/dist/intelligence/degradation-watcher.js +108 -0
- package/dist/intelligence/detector-plugins.js +70 -0
- package/dist/intelligence/detectors.js +1 -0
- package/dist/intelligence/device-auth.js +138 -0
- package/dist/intelligence/diff-size.js +42 -0
- package/dist/intelligence/ebpf-verify.js +45 -0
- package/dist/intelligence/enterprise-policy-engine.js +1122 -0
- package/dist/intelligence/error-fingerprint.js +1 -0
- package/dist/intelligence/execution-gate.js +100 -0
- package/dist/intelligence/execution-mode.js +22 -0
- package/dist/intelligence/gate-analytics.js +256 -0
- package/dist/intelligence/gate-decision.js +64 -0
- package/dist/intelligence/gcp-broker.js +50 -0
- package/dist/intelligence/git-adr-sync.js +207 -0
- package/dist/intelligence/hitl-hold.js +460 -0
- package/dist/intelligence/hypothesis-history.js +93 -0
- package/dist/intelligence/idp-identity.js +83 -0
- package/dist/intelligence/impl-critic.js +216 -0
- package/dist/intelligence/incident-autopilot.js +622 -0
- package/dist/intelligence/incident-replay.js +162 -0
- package/dist/intelligence/incident-result-cache.js +33 -0
- package/dist/intelligence/incident-similarity.js +58 -0
- package/dist/intelligence/infra-detectors.js +312 -0
- package/dist/intelligence/license.js +185 -0
- package/dist/intelligence/llm-spokesperson.js +62 -0
- package/dist/intelligence/mcp-prompts.js +320 -0
- package/dist/intelligence/mcp-resources.js +171 -0
- package/dist/intelligence/normalize.js +108 -0
- package/dist/intelligence/notifications.js +83 -0
- package/dist/intelligence/oidc-issuer.js +87 -0
- package/dist/intelligence/override-corpus.js +597 -0
- package/dist/intelligence/planning-gate.js +84 -0
- package/dist/intelligence/plans.js +223 -0
- package/dist/intelligence/platt-scaling.js +164 -0
- package/dist/intelligence/policy-proposals.js +84 -0
- package/dist/intelligence/policy-suggester.js +161 -0
- package/dist/intelligence/policy-sync.js +103 -0
- package/dist/intelligence/policy-test-runner.js +35 -0
- package/dist/intelligence/postmortem-parser.js +181 -0
- package/dist/intelligence/postmortem-retrieval.js +224 -0
- package/dist/intelligence/postmortem-store.js +596 -0
- package/dist/intelligence/pr-commenter.js +81 -0
- package/dist/intelligence/pr-policy-gate.js +38 -0
- package/dist/intelligence/pr-shadow-analyzer.js +229 -0
- package/dist/intelligence/process-tree.js +108 -0
- package/dist/intelligence/prompts.js +1 -0
- package/dist/intelligence/replay.js +38 -0
- package/dist/intelligence/repro-steps.js +1 -0
- package/dist/intelligence/resource-extractors.js +0 -0
- package/dist/intelligence/resource-file-context.js +138 -0
- package/dist/intelligence/risk-score.js +22 -0
- package/dist/intelligence/rollback.js +137 -0
- package/dist/intelligence/runbook-updater.js +143 -0
- package/dist/intelligence/sandbox.js +194 -0
- package/dist/intelligence/script-trust.js +104 -0
- package/dist/intelligence/session-metrics.js +67 -0
- package/dist/intelligence/session-threat-tracker.js +231 -0
- package/dist/intelligence/shadow-digest-cron.js +81 -0
- package/dist/intelligence/shadow-log.js +284 -0
- package/dist/intelligence/shell-ast.js +145 -0
- package/dist/intelligence/siem-forward.js +104 -0
- package/dist/intelligence/slack-digest.js +151 -0
- package/dist/intelligence/slack-override-loop.js +217 -0
- package/dist/intelligence/slack-routing.js +67 -0
- package/dist/intelligence/slack.js +900 -0
- package/dist/intelligence/sql-ast.js +31 -0
- package/dist/intelligence/team.js +1 -0
- package/dist/intelligence/telemetry.js +76 -0
- package/dist/intelligence/threshold-optimizer.js +75 -0
- package/dist/intelligence/token-budget.js +66 -0
- package/dist/intelligence/tool-guard.js +708 -0
- package/dist/intelligence/tool-manifest 2.js +74 -0
- package/dist/intelligence/tool-manifest.js +125 -0
- package/dist/intelligence/tools-analysis.js +857 -0
- package/dist/intelligence/tools-arch.js +152 -0
- package/dist/intelligence/tools-autonomy.js +495 -0
- package/dist/intelligence/tools-blast-radius.js +140 -0
- package/dist/intelligence/tools-browser.js +431 -0
- package/dist/intelligence/tools-change-timeline.js +154 -0
- package/dist/intelligence/tools-credentials.js +117 -0
- package/dist/intelligence/tools-datadog.js +233 -0
- package/dist/intelligence/tools-debug-sessions.js +209 -0
- package/dist/intelligence/tools-discovery.js +284 -0
- package/dist/intelligence/tools-infra.js +612 -0
- package/dist/intelligence/tools-intent.js +128 -0
- package/dist/intelligence/tools-memory.js +514 -0
- package/dist/intelligence/tools-runbook.js +951 -0
- package/dist/intelligence/tools-sessions.js +107 -0
- package/dist/intelligence/tools-state.js +232 -0
- package/dist/intelligence/tools-utility.js +430 -0
- package/dist/intelligence/tools-validate.js +215 -0
- package/dist/intelligence/tools.js +1 -0
- package/dist/intelligence/trace-context.js +11 -0
- package/dist/intelligence/unclassified-clusters.js +87 -0
- package/dist/intelligence/usage.js +195 -0
- package/dist/routes/active-authors.js +63 -0
- package/dist/routes/activity-feed.js +21 -0
- package/dist/routes/adr.js +117 -0
- package/dist/routes/agent-activity.js +184 -0
- package/dist/routes/agent-blunders.js +163 -0
- package/dist/routes/agents.js +175 -0
- package/dist/routes/api-keys.js +65 -0
- package/dist/routes/arch.js +75 -0
- package/dist/routes/audit-export.js +93 -0
- package/dist/routes/billing-dashboard.js +158 -0
- package/dist/routes/billing-outcome.js +77 -0
- package/dist/routes/calibration.js +305 -0
- package/dist/routes/ci-gate-history.js +20 -0
- package/dist/routes/ci-gate.js +232 -0
- package/dist/routes/ci.js +293 -0
- package/dist/routes/compliance-report.js +24 -0
- package/dist/routes/confidence.js +30 -0
- package/dist/routes/credentials.js +119 -0
- package/dist/routes/dashboard.js +1407 -0
- package/dist/routes/decision-memory.js +42 -0
- package/dist/routes/demo.js +844 -0
- package/dist/routes/device-auth-stub.js +173 -0
- package/dist/routes/explain-why.js +39 -0
- package/dist/routes/gate-analytics.js +213 -0
- package/dist/routes/gate.js +28 -0
- package/dist/routes/github-webhook.js +364 -0
- package/dist/routes/habituation.js +30 -0
- package/dist/routes/health-integrations.js +243 -0
- package/dist/routes/heartbeats.js +45 -0
- package/dist/routes/hitl.js +364 -0
- package/dist/routes/impact-report.js +645 -0
- package/dist/routes/incident-webhook.js +63 -0
- package/dist/routes/incidents.js +366 -0
- package/dist/routes/layers.js +62 -0
- package/dist/routes/license.js +187 -0
- package/dist/routes/oidc-issuer.js +30 -0
- package/dist/routes/onboarding.js +170 -0
- package/dist/routes/otel.js +67 -0
- package/dist/routes/otlp-receiver.js +179 -0
- package/dist/routes/overrides.js +241 -0
- package/dist/routes/pagerduty.js +258 -0
- package/dist/routes/policies.js +809 -0
- package/dist/routes/policy-nl.js +169 -0
- package/dist/routes/postmortem.js +102 -0
- package/dist/routes/pr-shadow.js +47 -0
- package/dist/routes/rbac.js +61 -0
- package/dist/routes/replay.js +17 -0
- package/dist/routes/risk-report.js +164 -0
- package/dist/routes/runbooks.js +125 -0
- package/dist/routes/safety-test.js +174 -0
- package/dist/routes/sdk.js +222 -0
- package/dist/routes/sensor.js +819 -0
- package/dist/routes/sentry.js +140 -0
- package/dist/routes/sessions.js +43 -0
- package/dist/routes/setup-ui.js +594 -0
- package/dist/routes/shadow-report.js +107 -0
- package/dist/routes/slack-routing.js +171 -0
- package/dist/routes/team-usage.js +71 -0
- package/dist/routes/telemetry.js +28 -0
- package/dist/routes/tenants.js +199 -0
- package/dist/routes/tickets.js +167 -0
- package/dist/routes/validate.js +13 -0
- package/dist/routes/war-room.js +113 -0
- package/dist/scripts/check-arch.js +22 -0
- package/dist/seeds/community-corpus.js +176 -0
- package/dist/seeds/corpus.js +1224 -0
- package/dist/sensor/action-ledger.js +327 -0
- package/dist/sensor/adr-store.js +140 -0
- package/dist/sensor/agent-blunder-store.js +370 -0
- package/dist/sensor/agent-context-store.js +225 -0
- package/dist/sensor/agent-memory-store.js +231 -0
- package/dist/sensor/audit-fetch.js +23 -0
- package/dist/sensor/audit-log.js +273 -0
- package/dist/sensor/buffer-schemas.js +225 -0
- package/dist/sensor/buffer.js +599 -0
- package/dist/sensor/bypass-tracker.js +93 -0
- package/dist/sensor/ci-gate-history.js +70 -0
- package/dist/sensor/cloud-auth.js +183 -0
- package/dist/sensor/commit-context-store.js +235 -0
- package/dist/sensor/docker-log-stream.js +164 -0
- package/dist/sensor/docker-monitor.js +122 -0
- package/dist/sensor/extended-buffer.js +46 -0
- package/dist/sensor/feedback-token.js +41 -0
- package/dist/sensor/file-lock.js +6 -0
- package/dist/sensor/fs-watcher.js +106 -0
- package/dist/sensor/gate-heartbeat.js +122 -0
- package/dist/sensor/git-suspect.js +136 -0
- package/dist/sensor/habituation-store.js +77 -0
- package/dist/sensor/heartbeat-monitor.js +133 -0
- package/dist/sensor/incident-store.js +340 -0
- package/dist/sensor/infra-normalizer.js +513 -0
- package/dist/sensor/ingest.js +339 -0
- package/dist/sensor/jest-reporter.js +52 -0
- package/dist/sensor/k8s-events.js +132 -0
- package/dist/sensor/layer2-store.js +111 -0
- package/dist/sensor/layer3-store.js +230 -0
- package/dist/sensor/layer4-store.js +147 -0
- package/dist/sensor/logger.js +13 -0
- package/dist/sensor/otel-exporter.js +161 -0
- package/dist/sensor/paths.js +71 -0
- package/dist/sensor/policy-history.js +147 -0
- package/dist/sensor/pr-shadow-store.js +83 -0
- package/dist/sensor/process-watcher.js +162 -0
- package/dist/sensor/rbac.js +92 -0
- package/dist/sensor/redact.js +114 -0
- package/dist/sensor/redis-store.js +191 -0
- package/dist/sensor/route-reachability.js +64 -0
- package/dist/sensor/security-utils.js +18 -0
- package/dist/sensor/service-graph.js +170 -0
- package/dist/sensor/service-topology.js +227 -0
- package/dist/sensor/session-history.js +74 -0
- package/dist/sensor/session-persist.js +38 -0
- package/dist/sensor/shadow-promote.js +122 -0
- package/dist/sensor/sourcemap.js +281 -0
- package/dist/sensor/sqlite-store.js +205 -0
- package/dist/sensor/sso.js +164 -0
- package/dist/sensor/vitest-reporter.js +65 -0
- package/dist/sensor/watcher.js +48 -0
- package/dist/storage/interfaces.js +0 -0
- package/dist/storage/pg/pg-action-ledger.js +138 -0
- package/dist/storage/pg/pg-approval-store.js +107 -0
- package/dist/storage/pg/pg-blunder-store.js +193 -0
- package/dist/storage/pg/pg-ci-gate-history.js +83 -0
- package/dist/storage/pg/pg-client.js +24 -0
- package/dist/storage/pg/pg-event-store.js +63 -0
- package/dist/storage/pg/pg-incident-store.js +190 -0
- package/dist/storage/pg/pg-migrations.js +26 -0
- package/dist/storage/pg/pg-override-corpus.js +447 -0
- package/dist/storage/pg/pg-shadow-log.js +129 -0
- package/dist/storage/sqlite/sqlite-action-ledger.js +18 -0
- package/dist/storage/sqlite/sqlite-approval-store.js +37 -0
- package/dist/storage/sqlite/sqlite-blunder-store.js +27 -0
- package/dist/storage/sqlite/sqlite-ci-gate-history.js +19 -0
- package/dist/storage/sqlite/sqlite-event-store.js +29 -0
- package/dist/storage/sqlite/sqlite-incident-store.js +34 -0
- package/dist/storage/sqlite/sqlite-override-corpus.js +75 -0
- package/dist/storage/sqlite/sqlite-shadow-log.js +36 -0
- package/dist/storage/store-factory.js +55 -0
- package/dist/storage/store-registry.js +31 -0
- package/dist/update-checker.js +107 -0
- package/dist/workers/autopilot-worker.js +28 -0
- package/dist/workers/notification-worker.js +28 -0
- package/dist/workers/queues.js +58 -0
- package/dist/workers/validation-worker.js +24 -0
- package/dist/workers/worker-registry.js +18 -0
- package/package.json +123 -0
- package/sdk/mergen-inject.js +260 -0
- package/sdk/node.js +313 -0
- package/sdk/vite-plugin.ts +57 -0
- package/sdk/webpack-plugin.js +106 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { listSessionMetas, loadSessionsByTimeRange } from "../sensor/session-history.js";
|
|
3
|
+
import { getAuditLog } from "../sensor/audit-log.js";
|
|
4
|
+
import { trackCall, withTierGate } from "./tools-state.js";
|
|
5
|
+
import { getTierForTool } from "./tool-manifest.js";
|
|
6
|
+
function registerSessionTools(server) {
|
|
7
|
+
server.registerTool(
|
|
8
|
+
"get_session_replay",
|
|
9
|
+
{
|
|
10
|
+
description: 'Retrieves events from past debugging sessions archived to disk. Use when you need historical context: "what errors happened yesterday at 3pm?", "show me the session from this morning", "compare error counts across sessions". Sessions are auto-saved when the buffer is cleared or the server restarts. Tip: call with list_only:true first to see what sessions are available.',
|
|
11
|
+
inputSchema: {
|
|
12
|
+
since: z.number().int().optional().describe("Start of time window as Unix ms timestamp (default: 24 h ago)"),
|
|
13
|
+
until: z.number().int().optional().describe("End of time window as Unix ms timestamp (default: now)"),
|
|
14
|
+
limit: z.number().int().min(1).max(500).optional().describe("Max events to return (default 200)"),
|
|
15
|
+
list_only: z.boolean().optional().describe("Return only session metadata without loading events (fast)")
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
async ({ since, until, limit = 200, list_only = false }) => {
|
|
19
|
+
trackCall("get_session_replay");
|
|
20
|
+
const metas = listSessionMetas();
|
|
21
|
+
if (metas.length === 0) {
|
|
22
|
+
return { content: [{ type: "text", text: "No past sessions found. Sessions are auto-saved on buffer clear and server restart. Capture some events first." }] };
|
|
23
|
+
}
|
|
24
|
+
if (list_only) {
|
|
25
|
+
const lines2 = [
|
|
26
|
+
`## Past Sessions (${metas.length} total)`,
|
|
27
|
+
"",
|
|
28
|
+
...metas.slice(0, 20).map(
|
|
29
|
+
(m) => `- **${new Date(m.savedAt).toISOString()}** \u2014 ${m.eventCount} events \xB7 _${m.label}_`
|
|
30
|
+
)
|
|
31
|
+
];
|
|
32
|
+
if (metas.length > 20) lines2.push(`_\u2026and ${metas.length - 20} more_`);
|
|
33
|
+
return { content: [{ type: "text", text: lines2.join("\n") }] };
|
|
34
|
+
}
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
const sinceMs = since ?? now - 24 * 60 * 60 * 1e3;
|
|
37
|
+
const untilMs = until ?? now;
|
|
38
|
+
const events = loadSessionsByTimeRange(sinceMs, untilMs).slice(0, limit);
|
|
39
|
+
if (events.length === 0) {
|
|
40
|
+
const rangeStr = `${new Date(sinceMs).toISOString()} \u2192 ${new Date(untilMs).toISOString()}`;
|
|
41
|
+
const available = metas.slice(0, 5).map((m) => ` ${new Date(m.savedAt).toISOString()} (${m.eventCount} events)`).join("\n");
|
|
42
|
+
return { content: [{ type: "text", text: `No events found in range ${rangeStr}.
|
|
43
|
+
|
|
44
|
+
Most recent sessions:
|
|
45
|
+
${available}` }] };
|
|
46
|
+
}
|
|
47
|
+
const errors = events.filter((e) => e.type === "console" && e.level === "error");
|
|
48
|
+
const netFails = events.filter((e) => e.type === "network" && (e.status ?? 0) >= 400);
|
|
49
|
+
const lines = [
|
|
50
|
+
`## Session Replay`,
|
|
51
|
+
"",
|
|
52
|
+
`**Range:** ${new Date(sinceMs).toISOString()} \u2192 ${new Date(untilMs).toISOString()}`,
|
|
53
|
+
`**Events:** ${events.length} returned \xB7 ${errors.length} errors \xB7 ${netFails.length} network failures`,
|
|
54
|
+
"",
|
|
55
|
+
"### Console Errors"
|
|
56
|
+
];
|
|
57
|
+
if (errors.length === 0) {
|
|
58
|
+
lines.push("No errors in this window.");
|
|
59
|
+
} else {
|
|
60
|
+
for (const e of errors.slice(0, 20)) {
|
|
61
|
+
const args = e.args ?? [];
|
|
62
|
+
const msg = args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ").slice(0, 200);
|
|
63
|
+
lines.push(`- ${new Date(e.timestamp).toISOString()} \u2014 ${msg}`);
|
|
64
|
+
}
|
|
65
|
+
if (errors.length > 20) lines.push(`_\u2026${errors.length - 20} more errors_`);
|
|
66
|
+
}
|
|
67
|
+
lines.push("", "### Network Failures");
|
|
68
|
+
if (netFails.length === 0) {
|
|
69
|
+
lines.push("No network failures in this window.");
|
|
70
|
+
} else {
|
|
71
|
+
for (const e of netFails.slice(0, 20)) {
|
|
72
|
+
const n = e;
|
|
73
|
+
lines.push(`- ${new Date(e.timestamp).toISOString()} \u2014 ${n.method ?? "GET"} ${n.url} \u2192 ${n.status} (${n.duration}ms)`);
|
|
74
|
+
}
|
|
75
|
+
if (netFails.length > 20) lines.push(`_\u2026${netFails.length - 20} more failures_`);
|
|
76
|
+
}
|
|
77
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
server.registerTool(
|
|
81
|
+
"get_audit_log",
|
|
82
|
+
{
|
|
83
|
+
description: "Returns the enterprise audit log \u2014 a record of all API calls made to this Mergen instance. Each entry shows: timestamp, actor identity, HTTP method + path, response status, and duration. Use for security reviews, compliance audits, or investigating unexpected access patterns.",
|
|
84
|
+
inputSchema: {
|
|
85
|
+
limit: z.number().int().min(1).max(500).optional().describe("Max entries to return, newest first (default 100)")
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
withTierGate(getTierForTool("get_audit_log"), async ({ limit = 100 }) => {
|
|
89
|
+
trackCall("get_audit_log");
|
|
90
|
+
const entries = getAuditLog(limit);
|
|
91
|
+
if (entries.length === 0) {
|
|
92
|
+
return { content: [{ type: "text", text: "Audit log is empty. Entries are written for all non-trivial API requests." }] };
|
|
93
|
+
}
|
|
94
|
+
const lines = [
|
|
95
|
+
`## Audit Log (last ${entries.length} entries)`,
|
|
96
|
+
"",
|
|
97
|
+
...entries.map(
|
|
98
|
+
(e) => `${e.ts} ${e.actor.padEnd(20)} ${e.method.padEnd(6)} ${e.path.padEnd(35)} ${e.status} ${e.durationMs}ms`
|
|
99
|
+
)
|
|
100
|
+
];
|
|
101
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
registerSessionTools
|
|
107
|
+
};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { planAllowsGate, minPlanForGate, getPlan, describeEntitlement, estimateToolCallOverageCents, estimateSeatOverageCents } from "./plans.js";
|
|
2
|
+
import { getActivePlanId } from "./license.js";
|
|
3
|
+
import { getToolCallCounts as getGateMediatedToolCallCounts } from "./gate-analytics.js";
|
|
4
|
+
import { listMembers } from "../sensor/rbac.js";
|
|
5
|
+
function entitlementLines() {
|
|
6
|
+
const { unlocked, upgradeLines } = describeEntitlement(getActivePlanId());
|
|
7
|
+
const out = [];
|
|
8
|
+
if (unlocked.length > 0) {
|
|
9
|
+
out.push("", "**Governance unlocked:**");
|
|
10
|
+
for (const cap of unlocked) out.push(` \u2022 ${cap}`);
|
|
11
|
+
}
|
|
12
|
+
if (upgradeLines.length > 0) out.push("", ...upgradeLines);
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
function executionUsageLines() {
|
|
16
|
+
const planId = getActivePlanId();
|
|
17
|
+
const plan = getPlan(planId);
|
|
18
|
+
let toolCallsThisMonth = 0;
|
|
19
|
+
for (const count of getGateMediatedToolCallCounts().values()) toolCallsThisMonth += count;
|
|
20
|
+
const activeSeats = listMembers().length;
|
|
21
|
+
const includedCalls = plan.includedToolCallsPerMonth;
|
|
22
|
+
const seatCap = plan.seatCap;
|
|
23
|
+
const toolCallOverageCents = estimateToolCallOverageCents(planId, toolCallsThisMonth);
|
|
24
|
+
const seatOverageCents = estimateSeatOverageCents(planId, activeSeats);
|
|
25
|
+
const out = ["", "**Execution volume (mediated tool-calls):**"];
|
|
26
|
+
out.push(includedCalls === 0 ? ` \u2022 ${toolCallsThisMonth} tool-call(s) this month (unlimited plan)` : ` \u2022 ${toolCallsThisMonth} / ${includedCalls} tool-call(s) this month`);
|
|
27
|
+
if (toolCallOverageCents > 0) {
|
|
28
|
+
out.push(` \u2022 Estimated overage: $${(toolCallOverageCents / 100).toFixed(2)}`);
|
|
29
|
+
}
|
|
30
|
+
if (isFinite(seatCap)) {
|
|
31
|
+
out.push(` \u2022 Seats: ${activeSeats} / ${seatCap} included`);
|
|
32
|
+
if (seatOverageCents > 0) {
|
|
33
|
+
out.push(` \u2022 Seat overage: $${(seatOverageCents / 100).toFixed(2)}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
const KNOWN_TOOLS = /* @__PURE__ */ new Set([
|
|
39
|
+
// Analysis
|
|
40
|
+
"quick_check",
|
|
41
|
+
"explain_warning",
|
|
42
|
+
"session_summary",
|
|
43
|
+
"analyze_runtime",
|
|
44
|
+
"reconstruct_context",
|
|
45
|
+
"explain_why",
|
|
46
|
+
"get_change_timeline",
|
|
47
|
+
"get_error_frequency",
|
|
48
|
+
"get_anomaly_baseline",
|
|
49
|
+
"get_regression_start",
|
|
50
|
+
"get_repro_steps",
|
|
51
|
+
"get_causal_graph",
|
|
52
|
+
// Buffer reads
|
|
53
|
+
"get_recent_logs",
|
|
54
|
+
"get_network_activity",
|
|
55
|
+
"get_dom_context",
|
|
56
|
+
"get_component_tree",
|
|
57
|
+
"get_diagnostics",
|
|
58
|
+
"get_test_results",
|
|
59
|
+
"get_snapshots",
|
|
60
|
+
"get_websocket_activity",
|
|
61
|
+
"get_sse_activity",
|
|
62
|
+
"get_service_topology",
|
|
63
|
+
// Backend / infra
|
|
64
|
+
"get_process_logs",
|
|
65
|
+
"get_backend_logs",
|
|
66
|
+
"get_backend_spans",
|
|
67
|
+
"get_correlated_trace",
|
|
68
|
+
"get_ci_results",
|
|
69
|
+
"get_deployments",
|
|
70
|
+
"get_unified_timeline",
|
|
71
|
+
"get_service_graph",
|
|
72
|
+
// Blast radius
|
|
73
|
+
"get_blast_radius",
|
|
74
|
+
"get_code_owners",
|
|
75
|
+
"get_attribution_accuracy",
|
|
76
|
+
// Incidents
|
|
77
|
+
"triage_incident",
|
|
78
|
+
"execute_fix",
|
|
79
|
+
"validate_fix",
|
|
80
|
+
"get_incident_history",
|
|
81
|
+
"list_open_incidents",
|
|
82
|
+
// Datadog
|
|
83
|
+
"get_incident_context",
|
|
84
|
+
"get_datadog_trace",
|
|
85
|
+
"get_datadog_logs",
|
|
86
|
+
// Debug sessions
|
|
87
|
+
"inject_logpoint",
|
|
88
|
+
"remove_logpoint",
|
|
89
|
+
"start_debug_session",
|
|
90
|
+
"checkpoint_debug_session",
|
|
91
|
+
"end_debug_session",
|
|
92
|
+
// Runbook / postmortem
|
|
93
|
+
"create_postmortem",
|
|
94
|
+
"list_postmortems",
|
|
95
|
+
"check_fix_history",
|
|
96
|
+
"explain_service",
|
|
97
|
+
"generate_runbook",
|
|
98
|
+
"search_postmortems",
|
|
99
|
+
"draft_postmortem",
|
|
100
|
+
"start_runbook",
|
|
101
|
+
"suggest_followups",
|
|
102
|
+
"find_similar_incidents",
|
|
103
|
+
// Sessions / audit
|
|
104
|
+
"get_session_replay",
|
|
105
|
+
"get_audit_log",
|
|
106
|
+
// Memory
|
|
107
|
+
"store_agent_memory",
|
|
108
|
+
"recall_agent_memory",
|
|
109
|
+
"get_override_patterns",
|
|
110
|
+
"get_detector_calibration",
|
|
111
|
+
"check_staged_changes",
|
|
112
|
+
// Intent
|
|
113
|
+
"create_ticket",
|
|
114
|
+
// Cloud credential broker
|
|
115
|
+
"request_credential",
|
|
116
|
+
// Utility
|
|
117
|
+
"clear_buffer",
|
|
118
|
+
"get_status",
|
|
119
|
+
"mark_capture_start",
|
|
120
|
+
"export_session",
|
|
121
|
+
"suggest_logging_locations",
|
|
122
|
+
"watch_for_fix",
|
|
123
|
+
"stop_file_watch",
|
|
124
|
+
// ADR / discovery / agent workflow
|
|
125
|
+
"search_adrs",
|
|
126
|
+
"discover_repo_context",
|
|
127
|
+
"report_confidence",
|
|
128
|
+
"plan_rollback",
|
|
129
|
+
"get_buffer_schema",
|
|
130
|
+
"get_behavior_map",
|
|
131
|
+
// Architectural governance
|
|
132
|
+
"check_arch_violations",
|
|
133
|
+
"score_change_risk",
|
|
134
|
+
"query_arch_graph",
|
|
135
|
+
"critique_implementation",
|
|
136
|
+
// Discovery and environment
|
|
137
|
+
"get_system_status",
|
|
138
|
+
"get_env_snapshot",
|
|
139
|
+
"get_diff_from_baseline"
|
|
140
|
+
]);
|
|
141
|
+
const toolCallCounts = {};
|
|
142
|
+
let lastMcpCallAt = null;
|
|
143
|
+
let firstAnalyzeAt = null;
|
|
144
|
+
let lastTimeToFirstAnalysisMs = null;
|
|
145
|
+
let _lastClearAt = Date.now();
|
|
146
|
+
let humanCallCount = 0;
|
|
147
|
+
let agentCallCount = 0;
|
|
148
|
+
const AGENT_BURST_WINDOW_MS = 1e4;
|
|
149
|
+
const AGENT_BURST_THRESHOLD = 5;
|
|
150
|
+
const _recentCallTs = [];
|
|
151
|
+
function getAgentCallRatio() {
|
|
152
|
+
const total = humanCallCount + agentCallCount;
|
|
153
|
+
return total > 0 ? agentCallCount / total : 0;
|
|
154
|
+
}
|
|
155
|
+
function trackCall(tool) {
|
|
156
|
+
if (!KNOWN_TOOLS.has(tool)) return;
|
|
157
|
+
const now = Date.now();
|
|
158
|
+
lastMcpCallAt = now;
|
|
159
|
+
toolCallCounts[tool] = (toolCallCounts[tool] ?? 0) + 1;
|
|
160
|
+
_recentCallTs.push(now);
|
|
161
|
+
while (_recentCallTs.length > 0 && now - _recentCallTs[0] > AGENT_BURST_WINDOW_MS) {
|
|
162
|
+
_recentCallTs.shift();
|
|
163
|
+
}
|
|
164
|
+
if (_recentCallTs.length >= AGENT_BURST_THRESHOLD) {
|
|
165
|
+
agentCallCount++;
|
|
166
|
+
} else {
|
|
167
|
+
humanCallCount++;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function buildCreditBar(used, total) {
|
|
171
|
+
const pct = Math.min(1, used / total);
|
|
172
|
+
const filled = Math.round(pct * 10);
|
|
173
|
+
return `[${"\u2588".repeat(filled)}${"\u2591".repeat(10 - filled)}] ${Math.round(pct * 100)}%`;
|
|
174
|
+
}
|
|
175
|
+
function setFirstAnalyzeAt(ts) {
|
|
176
|
+
firstAnalyzeAt = ts;
|
|
177
|
+
}
|
|
178
|
+
function setLastTimeToFirstAnalysisMs(ms) {
|
|
179
|
+
lastTimeToFirstAnalysisMs = ms;
|
|
180
|
+
}
|
|
181
|
+
function setLastClearAt(ts) {
|
|
182
|
+
_lastClearAt = ts;
|
|
183
|
+
}
|
|
184
|
+
function getLastClearAt() {
|
|
185
|
+
return _lastClearAt;
|
|
186
|
+
}
|
|
187
|
+
function withTierGate(gate, handler) {
|
|
188
|
+
if (gate === "free" || gate === "all") return handler;
|
|
189
|
+
return async (...args) => {
|
|
190
|
+
const planId = getActivePlanId();
|
|
191
|
+
if (!planAllowsGate(planId, gate)) {
|
|
192
|
+
const currentPlan = getPlan(planId);
|
|
193
|
+
const requiredPlan = getPlan(minPlanForGate(gate));
|
|
194
|
+
return {
|
|
195
|
+
content: [{
|
|
196
|
+
type: "text",
|
|
197
|
+
text: [
|
|
198
|
+
`## Tool requires the ${requiredPlan.name} plan`,
|
|
199
|
+
"",
|
|
200
|
+
`You are on **${currentPlan.name}**. This tool unlocks on **${requiredPlan.name}** (${requiredPlan.priceDescription}) and above.`,
|
|
201
|
+
"",
|
|
202
|
+
`**Upgrade at:** ${requiredPlan.ctaUrl}`,
|
|
203
|
+
"",
|
|
204
|
+
"To check your current plan: call `get_status`.",
|
|
205
|
+
'To activate a license key: `POST /license { "key": "..." }`'
|
|
206
|
+
].join("\n")
|
|
207
|
+
}]
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
return handler(...args);
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
export {
|
|
214
|
+
KNOWN_TOOLS,
|
|
215
|
+
agentCallCount,
|
|
216
|
+
buildCreditBar,
|
|
217
|
+
entitlementLines,
|
|
218
|
+
executionUsageLines,
|
|
219
|
+
firstAnalyzeAt,
|
|
220
|
+
getActivePlanId,
|
|
221
|
+
getAgentCallRatio,
|
|
222
|
+
getLastClearAt,
|
|
223
|
+
humanCallCount,
|
|
224
|
+
lastMcpCallAt,
|
|
225
|
+
lastTimeToFirstAnalysisMs,
|
|
226
|
+
setFirstAnalyzeAt,
|
|
227
|
+
setLastClearAt,
|
|
228
|
+
setLastTimeToFirstAnalysisMs,
|
|
229
|
+
toolCallCounts,
|
|
230
|
+
trackCall,
|
|
231
|
+
withTierGate
|
|
232
|
+
};
|