@danielblomma/cortex-mcp 1.7.1 → 2.0.2
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/bin/cortex.mjs +679 -32
- package/bin/style.mjs +349 -0
- package/package.json +4 -3
- package/scaffold/mcp/package-lock.json +834 -671
- package/scaffold/mcp/package.json +1 -1
- package/scaffold/mcp/src/cli/enterprise-setup.ts +124 -0
- package/scaffold/mcp/src/cli/govern.ts +987 -0
- package/scaffold/mcp/src/cli/run.ts +306 -0
- package/scaffold/mcp/src/cli/telemetry-test.ts +158 -0
- package/scaffold/mcp/src/cli/ungoverned-detector.ts +168 -0
- package/scaffold/mcp/src/core/audit/query.ts +81 -0
- package/scaffold/mcp/src/core/audit/writer.ts +68 -0
- package/scaffold/mcp/src/core/config.ts +329 -0
- package/scaffold/mcp/src/core/index.ts +34 -0
- package/scaffold/mcp/src/core/license.ts +202 -0
- package/scaffold/mcp/src/core/policy/enforce.ts +98 -0
- package/scaffold/mcp/src/core/policy/injection.ts +229 -0
- package/scaffold/mcp/src/core/policy/store.ts +197 -0
- package/scaffold/mcp/src/core/rbac/check.ts +40 -0
- package/scaffold/mcp/src/core/telemetry/collector.ts +234 -0
- package/scaffold/mcp/src/core/validators/builtins.ts +711 -0
- package/scaffold/mcp/src/core/validators/config.ts +47 -0
- package/scaffold/mcp/src/core/validators/engine.ts +199 -0
- package/scaffold/mcp/src/core/validators/evaluators/code_comments.ts +294 -0
- package/scaffold/mcp/src/core/validators/evaluators/regex.ts +144 -0
- package/scaffold/mcp/src/daemon/client.ts +155 -0
- package/scaffold/mcp/src/daemon/egress-proxy.ts +331 -0
- package/scaffold/mcp/src/daemon/heartbeat-pusher.ts +147 -0
- package/scaffold/mcp/src/daemon/heartbeat-tracker.ts +223 -0
- package/scaffold/mcp/src/daemon/host-events-pusher.ts +285 -0
- package/scaffold/mcp/src/daemon/main.ts +300 -0
- package/scaffold/mcp/src/daemon/paths.ts +41 -0
- package/scaffold/mcp/src/daemon/protocol.ts +101 -0
- package/scaffold/mcp/src/daemon/server.ts +227 -0
- package/scaffold/mcp/src/daemon/sync-checker.ts +213 -0
- package/scaffold/mcp/src/daemon/ungoverned-scanner.ts +149 -0
- package/scaffold/mcp/src/embed.ts +1 -1
- package/scaffold/mcp/src/embeddings.ts +1 -1
- package/scaffold/mcp/src/enterprise/audit/push.ts +84 -0
- package/scaffold/mcp/src/enterprise/index.ts +415 -0
- package/scaffold/mcp/src/enterprise/model/deploy.ts +33 -0
- package/scaffold/mcp/src/enterprise/policy/sync.ts +146 -0
- package/scaffold/mcp/src/enterprise/privacy/boundary.ts +212 -0
- package/scaffold/mcp/src/enterprise/reviews/push.ts +79 -0
- package/scaffold/mcp/src/enterprise/telemetry/sync.ts +72 -0
- package/scaffold/mcp/src/enterprise/tools/enterprise.ts +1031 -0
- package/scaffold/mcp/src/enterprise/tools/walk.ts +79 -0
- package/scaffold/mcp/src/enterprise/violations/push.ts +102 -0
- package/scaffold/mcp/src/enterprise/workflow/push.ts +60 -0
- package/scaffold/mcp/src/enterprise/workflow/state.ts +535 -0
- package/scaffold/mcp/src/hooks/pre-compact.ts +54 -0
- package/scaffold/mcp/src/hooks/pre-tool-use.ts +96 -0
- package/scaffold/mcp/src/hooks/session-end.ts +73 -0
- package/scaffold/mcp/src/hooks/session-start.ts +78 -0
- package/scaffold/mcp/src/hooks/shared.ts +134 -0
- package/scaffold/mcp/src/hooks/stop.ts +60 -0
- package/scaffold/mcp/src/hooks/user-prompt-submit.ts +64 -0
- package/scaffold/mcp/src/plugin.ts +150 -0
- package/scaffold/mcp/src/server.ts +218 -7
- package/scaffold/mcp/tests/copilot-shim.test.mjs +146 -0
- package/scaffold/mcp/tests/daemon-client.test.mjs +32 -0
- package/scaffold/mcp/tests/egress-proxy.test.mjs +239 -0
- package/scaffold/mcp/tests/enterprise-config.test.mjs +154 -0
- package/scaffold/mcp/tests/govern-install.test.mjs +320 -0
- package/scaffold/mcp/tests/govern-repair.test.mjs +157 -0
- package/scaffold/mcp/tests/govern-status.test.mjs +538 -0
- package/scaffold/mcp/tests/govern.test.mjs +74 -0
- package/scaffold/mcp/tests/heartbeat-pusher.test.mjs +154 -0
- package/scaffold/mcp/tests/heartbeat-tracker.test.mjs +237 -0
- package/scaffold/mcp/tests/host-events-pusher.test.mjs +347 -0
- package/scaffold/mcp/tests/policy-check.test.mjs +220 -0
- package/scaffold/mcp/tests/repo-name.test.mjs +134 -0
- package/scaffold/mcp/tests/run.test.mjs +109 -0
- package/scaffold/mcp/tests/sync-checker.test.mjs +188 -0
- package/scaffold/mcp/tests/ungoverned-detector.test.mjs +191 -0
- package/scaffold/mcp/tests/ungoverned-scanner.test.mjs +198 -0
- package/scaffold/scripts/bootstrap.sh +0 -11
- package/scaffold/scripts/doctor.sh +24 -4
- package/types.js +5 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { verifyLicense } from "../core/license.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One-liner enterprise onboarding.
|
|
7
|
+
*
|
|
8
|
+
* $ cortex enterprise <api-key> [--endpoint <url>]
|
|
9
|
+
*
|
|
10
|
+
* Replaces the manual `.context/enterprise.yml` editing flow that's been
|
|
11
|
+
* the friction point for new users. Validates the key against the
|
|
12
|
+
* license endpoint before writing config — so a typo'd key fails fast
|
|
13
|
+
* with a clear error rather than going silently into community-mode.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const DEFAULT_ENDPOINT = "https://cortex-web-rho.vercel.app";
|
|
17
|
+
|
|
18
|
+
export type EnterpriseSetupOptions = {
|
|
19
|
+
apiKey: string;
|
|
20
|
+
endpoint?: string;
|
|
21
|
+
cwd?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type EnterpriseSetupResult = {
|
|
25
|
+
ok: boolean;
|
|
26
|
+
message: string;
|
|
27
|
+
configPath?: string;
|
|
28
|
+
edition?: string;
|
|
29
|
+
expiresAt?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const API_KEY_RE = /^(?:ctx|ent)_[A-Za-z0-9._-]{8,}$/;
|
|
33
|
+
|
|
34
|
+
function buildEnterpriseYaml(baseUrl: string, apiKey: string): string {
|
|
35
|
+
const lines = [
|
|
36
|
+
"# Cortex enterprise configuration. Generated by `cortex enterprise <key>`.",
|
|
37
|
+
"# Single api_key is used for telemetry, policy, audit and govern services.",
|
|
38
|
+
"enterprise:",
|
|
39
|
+
` api_key: ${apiKey}`,
|
|
40
|
+
` base_url: ${baseUrl}`,
|
|
41
|
+
"",
|
|
42
|
+
"telemetry:",
|
|
43
|
+
" enabled: true",
|
|
44
|
+
" interval_minutes: 1",
|
|
45
|
+
"",
|
|
46
|
+
"compliance:",
|
|
47
|
+
" frameworks: [iso27001, iso42001, soc2]",
|
|
48
|
+
" eu_addons: false",
|
|
49
|
+
"",
|
|
50
|
+
"govern:",
|
|
51
|
+
" mode: off",
|
|
52
|
+
" sync_on_startup: true",
|
|
53
|
+
" sync_interval_minutes: 60",
|
|
54
|
+
" tier_claude: prevent",
|
|
55
|
+
" tier_codex: prevent",
|
|
56
|
+
" tier_copilot: wrap",
|
|
57
|
+
" detect_ungoverned: true",
|
|
58
|
+
"",
|
|
59
|
+
];
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function runEnterpriseSetup(
|
|
64
|
+
options: EnterpriseSetupOptions,
|
|
65
|
+
): Promise<EnterpriseSetupResult> {
|
|
66
|
+
const cwd = options.cwd ?? process.cwd();
|
|
67
|
+
const endpoint = (options.endpoint ?? DEFAULT_ENDPOINT).replace(/\/$/, "");
|
|
68
|
+
const apiKey = options.apiKey.trim();
|
|
69
|
+
|
|
70
|
+
if (!API_KEY_RE.test(apiKey)) {
|
|
71
|
+
return {
|
|
72
|
+
ok: false,
|
|
73
|
+
message:
|
|
74
|
+
"API key must start with 'ctx_' or 'ent_' followed by at least 8 alphanumeric/._- chars.",
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!/^https?:\/\//.test(endpoint)) {
|
|
79
|
+
return {
|
|
80
|
+
ok: false,
|
|
81
|
+
message: `Endpoint must be http(s) URL: ${endpoint}`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const contextDir = join(cwd, ".context");
|
|
86
|
+
if (!existsSync(contextDir)) {
|
|
87
|
+
return {
|
|
88
|
+
ok: false,
|
|
89
|
+
message: `No .context/ at ${cwd}. Run 'cortex init --bootstrap' first.`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Validate key BEFORE writing config — fail fast, no half-configured state.
|
|
94
|
+
const license = await verifyLicense(contextDir, endpoint, apiKey, {
|
|
95
|
+
client_version: process.env.CORTEX_VERSION,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (!license.valid) {
|
|
99
|
+
return {
|
|
100
|
+
ok: false,
|
|
101
|
+
message: `License rejected: ${license.reason} (source=${license.source}). Verify the API key and endpoint are correct.`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Write enterprise.yml.
|
|
106
|
+
const configPath = join(contextDir, "enterprise.yml");
|
|
107
|
+
try {
|
|
108
|
+
mkdirSync(contextDir, { recursive: true });
|
|
109
|
+
writeFileSync(configPath, buildEnterpriseYaml(endpoint, apiKey), "utf8");
|
|
110
|
+
} catch (err) {
|
|
111
|
+
return {
|
|
112
|
+
ok: false,
|
|
113
|
+
message: `Failed to write ${configPath}: ${err instanceof Error ? err.message : String(err)}`,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
ok: true,
|
|
119
|
+
message: "Enterprise configuration written.",
|
|
120
|
+
configPath,
|
|
121
|
+
edition: license.edition,
|
|
122
|
+
expiresAt: license.expires_at,
|
|
123
|
+
};
|
|
124
|
+
}
|