@opentrust/cli 7.1.0 → 7.2.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/README.md +1 -1
- package/dist/commands/init.js +63 -44
- package/dist/commands/setup.js +118 -46
- package/dist/lib/paths.d.ts +7 -0
- package/dist/lib/paths.js +56 -18
- package/dist/lib/process-manager.d.ts +1 -0
- package/dist/lib/process-manager.js +88 -36
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @opentrust/cli
|
|
2
2
|
|
|
3
|
-
CLI tool to manage [OpenTrust](https://github.com/opentrust
|
|
3
|
+
CLI tool to manage [OpenTrust](https://github.com/opentrust/opentrust) — an open-source AI Agent Runtime Security Platform.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
package/dist/commands/init.js
CHANGED
|
@@ -1,20 +1,51 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
const
|
|
4
|
+
const SCAFFOLD_PKG = {
|
|
5
|
+
name: "opentrust-project",
|
|
6
|
+
version: "1.0.0",
|
|
7
|
+
private: true,
|
|
8
|
+
description: "OpenTrust local deployment",
|
|
9
|
+
scripts: {
|
|
10
|
+
setup: "opentrust setup",
|
|
11
|
+
start: "opentrust start",
|
|
12
|
+
stop: "opentrust stop",
|
|
13
|
+
status: "opentrust status",
|
|
14
|
+
},
|
|
15
|
+
dependencies: {
|
|
16
|
+
"@opentrust/core": "^7.2.0",
|
|
17
|
+
"@opentrust/gateway": "^7.2.0",
|
|
18
|
+
"@opentrust/dashboard": "^7.2.0",
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const ENV_TEMPLATE = `# OpenTrust Configuration
|
|
22
|
+
|
|
23
|
+
# Dashboard
|
|
24
|
+
DEV_MODE=true
|
|
25
|
+
DASHBOARD_MODE=embedded
|
|
26
|
+
DASHBOARD_DATA_DIR=./data
|
|
27
|
+
|
|
28
|
+
# Core
|
|
29
|
+
CORE_PORT=53666
|
|
30
|
+
|
|
31
|
+
# Gateway
|
|
32
|
+
GATEWAY_PORT=8900
|
|
33
|
+
# ANTHROPIC_API_KEY=sk-ant-xxx
|
|
34
|
+
# OPENAI_API_KEY=sk-xxx
|
|
35
|
+
# GEMINI_API_KEY=xxx
|
|
36
|
+
`;
|
|
5
37
|
export function registerInitCommand(program) {
|
|
6
38
|
program
|
|
7
39
|
.command("init")
|
|
8
|
-
.description("Initialize OpenTrust project (
|
|
9
|
-
.option("--
|
|
10
|
-
.option("--branch <name>", "Git branch to clone", "main")
|
|
40
|
+
.description("Initialize an OpenTrust project (install packages via npm)")
|
|
41
|
+
.option("--registry <url>", "npm registry URL")
|
|
11
42
|
.action(async (options) => {
|
|
12
43
|
const cwd = process.cwd();
|
|
13
44
|
const pkgPath = path.join(cwd, "package.json");
|
|
14
45
|
if (fs.existsSync(pkgPath)) {
|
|
15
46
|
try {
|
|
16
47
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
17
|
-
if (pkg.name === "opentrust") {
|
|
48
|
+
if (pkg.name === "opentrust" || pkg.name === "opentrust-project") {
|
|
18
49
|
console.log("OpenTrust project already exists in current directory.");
|
|
19
50
|
console.log("Run 'opentrust setup' to install dependencies.");
|
|
20
51
|
return;
|
|
@@ -22,54 +53,42 @@ export function registerInitCommand(program) {
|
|
|
22
53
|
}
|
|
23
54
|
catch { }
|
|
24
55
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
56
|
+
console.log("Initializing OpenTrust project...\n");
|
|
57
|
+
// Write package.json
|
|
58
|
+
fs.writeFileSync(pkgPath, JSON.stringify(SCAFFOLD_PKG, null, 2) + "\n", "utf-8");
|
|
59
|
+
console.log(" Created package.json");
|
|
60
|
+
// Write .env
|
|
61
|
+
const envPath = path.join(cwd, ".env");
|
|
62
|
+
if (!fs.existsSync(envPath)) {
|
|
63
|
+
fs.writeFileSync(envPath, ENV_TEMPLATE, "utf-8");
|
|
64
|
+
console.log(" Created .env");
|
|
31
65
|
}
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
|
|
36
|
-
console.
|
|
37
|
-
process.exit(1);
|
|
66
|
+
// Create data directory
|
|
67
|
+
const dataDir = path.join(cwd, "data");
|
|
68
|
+
if (!fs.existsSync(dataDir)) {
|
|
69
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
70
|
+
console.log(" Created data/");
|
|
38
71
|
}
|
|
39
|
-
|
|
40
|
-
console.log(
|
|
41
|
-
|
|
42
|
-
console.log(` Target: ${targetDir}\n`);
|
|
72
|
+
// Install dependencies
|
|
73
|
+
console.log("\nInstalling packages...\n");
|
|
74
|
+
const registryArg = options.registry ? ` --registry ${options.registry}` : "";
|
|
43
75
|
try {
|
|
44
|
-
|
|
45
|
-
execSync(`git clone --depth 1 --branch ${options.branch} ${options.repo} .`, { cwd, stdio: "inherit" });
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
execSync(`git clone --depth 1 --branch ${options.branch} ${options.repo} opentrust`, { cwd, stdio: "inherit" });
|
|
49
|
-
}
|
|
76
|
+
execSync(`npm install${registryArg}`, { cwd, stdio: "inherit" });
|
|
50
77
|
}
|
|
51
78
|
catch {
|
|
52
|
-
console.error("\
|
|
79
|
+
console.error("\nnpm install failed. Check the output above for details.");
|
|
53
80
|
process.exit(1);
|
|
54
81
|
}
|
|
55
82
|
console.log("\n-------------------------------------------");
|
|
56
83
|
console.log("OpenTrust project initialized!");
|
|
57
84
|
console.log("-------------------------------------------\n");
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
console.log("Next steps:");
|
|
67
|
-
console.log(" cd opentrust");
|
|
68
|
-
console.log(" opentrust setup # Install dependencies (local mode)");
|
|
69
|
-
console.log(" opentrust start # Start all services\n");
|
|
70
|
-
console.log("Or use Docker:");
|
|
71
|
-
console.log(" cd opentrust");
|
|
72
|
-
console.log(" opentrust start --docker # Start via Docker Compose");
|
|
73
|
-
}
|
|
85
|
+
console.log("Next steps:");
|
|
86
|
+
console.log(" opentrust setup # Run database migrations");
|
|
87
|
+
console.log(" opentrust start # Start all services");
|
|
88
|
+
console.log(" opentrust status # Check service health\n");
|
|
89
|
+
console.log("Services:");
|
|
90
|
+
console.log(" Core http://localhost:53666");
|
|
91
|
+
console.log(" Dashboard http://localhost:53667/dashboard/");
|
|
92
|
+
console.log(" Gateway http://localhost:8900");
|
|
74
93
|
});
|
|
75
94
|
}
|
package/dist/commands/setup.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
-
import
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { paths, requireProject, projectMode, projectRoot } from "../lib/paths.js";
|
|
4
5
|
import { dockerSetup } from "../lib/docker-manager.js";
|
|
5
6
|
export function registerSetupCommand(program) {
|
|
6
7
|
program
|
|
@@ -14,52 +15,123 @@ export function registerSetupCommand(program) {
|
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
17
|
requireProject();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
18
|
+
if (projectMode === "npm") {
|
|
19
|
+
runNpmSetup();
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
runMonorepoSetup();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function runMonorepoSetup() {
|
|
27
|
+
console.log("OpenTrust Setup (monorepo)\n");
|
|
28
|
+
const steps = [
|
|
29
|
+
{
|
|
30
|
+
label: "Core",
|
|
31
|
+
cwd: paths.core,
|
|
32
|
+
commands: ["npm install"],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
label: "Dashboard",
|
|
36
|
+
cwd: paths.dashboard,
|
|
37
|
+
commands: [
|
|
38
|
+
"pnpm install",
|
|
39
|
+
"pnpm build",
|
|
40
|
+
"pnpm db:generate",
|
|
41
|
+
"pnpm db:migrate",
|
|
42
|
+
"pnpm db:seed",
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
label: "Gateway",
|
|
47
|
+
cwd: paths.gateway,
|
|
48
|
+
commands: ["npm install"],
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
for (const step of steps) {
|
|
52
|
+
if (!fs.existsSync(step.cwd)) {
|
|
53
|
+
console.log(` ⚠ ${step.label}: directory not found, skipping`);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
console.log(`Setting up ${step.label}...`);
|
|
57
|
+
for (const cmd of step.commands) {
|
|
58
|
+
try {
|
|
59
|
+
console.log(` $ ${cmd}`);
|
|
60
|
+
execSync(cmd, { cwd: step.cwd, stdio: "inherit" });
|
|
45
61
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
console.log(` $ ${cmd}`);
|
|
50
|
-
execSync(cmd, { cwd: step.cwd, stdio: "inherit" });
|
|
51
|
-
}
|
|
52
|
-
catch (err) {
|
|
53
|
-
console.error(` Failed: ${cmd}`);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
console.error(` Failed: ${cmd}`);
|
|
64
|
+
process.exit(1);
|
|
56
65
|
}
|
|
57
|
-
console.log(` ${step.label} ready.\n`);
|
|
58
66
|
}
|
|
59
|
-
console.log(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
console.log(` ${step.label} ready.\n`);
|
|
68
|
+
}
|
|
69
|
+
printSetupDone();
|
|
70
|
+
}
|
|
71
|
+
function runNpmSetup() {
|
|
72
|
+
console.log("OpenTrust Setup (npm packages)\n");
|
|
73
|
+
const dataDir = path.join(projectRoot, "data");
|
|
74
|
+
if (!fs.existsSync(dataDir)) {
|
|
75
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
76
|
+
}
|
|
77
|
+
const env = {
|
|
78
|
+
...process.env,
|
|
79
|
+
DASHBOARD_DATA_DIR: dataDir,
|
|
80
|
+
DEV_MODE: "true",
|
|
81
|
+
};
|
|
82
|
+
// Load .env from project root if exists
|
|
83
|
+
const envFile = path.join(projectRoot, ".env");
|
|
84
|
+
if (fs.existsSync(envFile)) {
|
|
85
|
+
const content = fs.readFileSync(envFile, "utf-8");
|
|
86
|
+
for (const line of content.split("\n")) {
|
|
87
|
+
const trimmed = line.trim();
|
|
88
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
89
|
+
continue;
|
|
90
|
+
const eqIdx = trimmed.indexOf("=");
|
|
91
|
+
if (eqIdx > 0) {
|
|
92
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
93
|
+
const val = trimmed.slice(eqIdx + 1).trim();
|
|
94
|
+
if (!env[key])
|
|
95
|
+
env[key] = val;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Run db:migrate
|
|
100
|
+
const migrateScript = path.join(projectRoot, "node_modules", "@opentrust", "db", "dist", "migrate.js");
|
|
101
|
+
if (fs.existsSync(migrateScript)) {
|
|
102
|
+
console.log("Running database migrations...");
|
|
103
|
+
try {
|
|
104
|
+
execSync(`node ${migrateScript}`, { cwd: projectRoot, stdio: "inherit", env });
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
console.error(" Migration failed.");
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
console.log(" Migrations complete.\n");
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
console.log(" ⚠ @opentrust/db not found, skipping migrations.");
|
|
114
|
+
console.log(" Run 'npm install' first.\n");
|
|
115
|
+
}
|
|
116
|
+
// Run db:seed
|
|
117
|
+
const seedScript = path.join(projectRoot, "node_modules", "@opentrust", "db", "dist", "seed.js");
|
|
118
|
+
if (fs.existsSync(seedScript)) {
|
|
119
|
+
console.log("Seeding database...");
|
|
120
|
+
try {
|
|
121
|
+
execSync(`node ${seedScript}`, { cwd: projectRoot, stdio: "inherit", env });
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
console.error(" Seed failed.");
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
console.log(" Seed complete.\n");
|
|
128
|
+
}
|
|
129
|
+
printSetupDone();
|
|
130
|
+
}
|
|
131
|
+
function printSetupDone() {
|
|
132
|
+
console.log("-------------------------------------------");
|
|
133
|
+
console.log("Setup complete!");
|
|
134
|
+
console.log("-------------------------------------------");
|
|
135
|
+
console.log("\nRun 'opentrust start' to launch all services.");
|
|
136
|
+
console.log("Or start individually: 'opentrust start core'");
|
|
65
137
|
}
|
package/dist/lib/paths.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
export type ProjectMode = "monorepo" | "npm" | "none";
|
|
2
|
+
export declare const projectMode: ProjectMode;
|
|
3
|
+
export declare const projectRoot: string;
|
|
1
4
|
export declare function isProjectAvailable(): boolean;
|
|
2
5
|
export declare function requireProject(): void;
|
|
3
6
|
export declare function hasDockerCompose(): boolean;
|
|
7
|
+
/** Resolve a node_modules package entry point */
|
|
8
|
+
export declare function resolveNpmPackage(packageName: string): string | null;
|
|
9
|
+
/** Resolve a bin script from a node_modules package */
|
|
10
|
+
export declare function resolveNpmBin(packageName: string, binName: string): string | null;
|
|
4
11
|
export declare const paths: {
|
|
5
12
|
projectRoot: string;
|
|
6
13
|
runtime: string;
|
package/dist/lib/paths.js
CHANGED
|
@@ -3,35 +3,41 @@ import os from "node:os";
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
-
function
|
|
6
|
+
function detectProjectMode() {
|
|
7
7
|
// 1. OPENTRUST_HOME env var takes priority
|
|
8
8
|
if (process.env.OPENTRUST_HOME) {
|
|
9
|
-
|
|
9
|
+
const dir = path.resolve(process.env.OPENTRUST_HOME);
|
|
10
|
+
if (isMonorepoRoot(dir))
|
|
11
|
+
return { mode: "monorepo", root: dir };
|
|
12
|
+
if (isNpmProject(dir))
|
|
13
|
+
return { mode: "npm", root: dir };
|
|
14
|
+
return { mode: "none", root: dir };
|
|
10
15
|
}
|
|
11
|
-
// 2. Check if cwd looks like the opentrust project root
|
|
12
16
|
const cwd = process.cwd();
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
// 2. Check cwd
|
|
18
|
+
if (isMonorepoRoot(cwd))
|
|
19
|
+
return { mode: "monorepo", root: cwd };
|
|
20
|
+
if (isNpmProject(cwd))
|
|
21
|
+
return { mode: "npm", root: cwd };
|
|
22
|
+
// 3. Walk up from cwd
|
|
17
23
|
let dir = cwd;
|
|
18
24
|
while (true) {
|
|
19
25
|
const parent = path.dirname(dir);
|
|
20
26
|
if (parent === dir)
|
|
21
27
|
break;
|
|
22
28
|
dir = parent;
|
|
23
|
-
if (
|
|
24
|
-
return dir;
|
|
29
|
+
if (isMonorepoRoot(dir))
|
|
30
|
+
return { mode: "monorepo", root: dir };
|
|
31
|
+
if (isNpmProject(dir))
|
|
32
|
+
return { mode: "npm", root: dir };
|
|
25
33
|
}
|
|
26
|
-
// 4. Fallback: resolve relative to __dirname (
|
|
34
|
+
// 4. Fallback: resolve relative to __dirname (within monorepo)
|
|
27
35
|
const fallback = path.resolve(__dirname, "../../..");
|
|
28
|
-
if (
|
|
29
|
-
return fallback;
|
|
30
|
-
}
|
|
31
|
-
// 5. Last resort: use cwd and let commands fail with meaningful errors
|
|
32
|
-
return cwd;
|
|
36
|
+
if (isMonorepoRoot(fallback))
|
|
37
|
+
return { mode: "monorepo", root: fallback };
|
|
38
|
+
return { mode: "none", root: cwd };
|
|
33
39
|
}
|
|
34
|
-
function
|
|
40
|
+
function isMonorepoRoot(dir) {
|
|
35
41
|
try {
|
|
36
42
|
const pkgPath = path.join(dir, "package.json");
|
|
37
43
|
if (!fs.existsSync(pkgPath))
|
|
@@ -43,9 +49,26 @@ function isOpenTrustRoot(dir) {
|
|
|
43
49
|
return false;
|
|
44
50
|
}
|
|
45
51
|
}
|
|
46
|
-
|
|
52
|
+
function isNpmProject(dir) {
|
|
53
|
+
try {
|
|
54
|
+
const pkgPath = path.join(dir, "package.json");
|
|
55
|
+
if (!fs.existsSync(pkgPath))
|
|
56
|
+
return false;
|
|
57
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
58
|
+
if (pkg.name === "opentrust-project")
|
|
59
|
+
return true;
|
|
60
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
61
|
+
return !!deps["@opentrust/core"] || !!deps["@opentrust/dashboard"];
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const detected = detectProjectMode();
|
|
68
|
+
export const projectMode = detected.mode;
|
|
69
|
+
export const projectRoot = detected.root;
|
|
47
70
|
export function isProjectAvailable() {
|
|
48
|
-
return
|
|
71
|
+
return detected.mode !== "none";
|
|
49
72
|
}
|
|
50
73
|
export function requireProject() {
|
|
51
74
|
if (!isProjectAvailable()) {
|
|
@@ -62,6 +85,21 @@ export function requireProject() {
|
|
|
62
85
|
export function hasDockerCompose() {
|
|
63
86
|
return fs.existsSync(path.join(projectRoot, "docker-compose.yml"));
|
|
64
87
|
}
|
|
88
|
+
/** Resolve a node_modules package entry point */
|
|
89
|
+
export function resolveNpmPackage(packageName) {
|
|
90
|
+
const entryPoints = [
|
|
91
|
+
path.join(projectRoot, "node_modules", packageName, "dist", "index.js"),
|
|
92
|
+
path.join(projectRoot, "node_modules", packageName, "index.js"),
|
|
93
|
+
];
|
|
94
|
+
return entryPoints.find(p => fs.existsSync(p)) ?? null;
|
|
95
|
+
}
|
|
96
|
+
/** Resolve a bin script from a node_modules package */
|
|
97
|
+
export function resolveNpmBin(packageName, binName) {
|
|
98
|
+
const binPath = path.join(projectRoot, "node_modules", ".bin", binName);
|
|
99
|
+
if (fs.existsSync(binPath))
|
|
100
|
+
return binPath;
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
65
103
|
/** ~/.opentrust/ — runtime data (pid files, logs) */
|
|
66
104
|
const runtimeDir = path.join(os.homedir(), ".opentrust");
|
|
67
105
|
export const paths = {
|
|
@@ -1,38 +1,91 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { paths, projectMode, projectRoot, resolveNpmPackage } from "./paths.js";
|
|
5
|
+
function buildServices() {
|
|
6
|
+
if (projectMode === "npm") {
|
|
7
|
+
return buildNpmServices();
|
|
8
|
+
}
|
|
9
|
+
return buildMonorepoServices();
|
|
10
|
+
}
|
|
11
|
+
function buildMonorepoServices() {
|
|
12
|
+
return {
|
|
13
|
+
core: {
|
|
14
|
+
name: "Core",
|
|
15
|
+
cwd: paths.core,
|
|
16
|
+
command: "npx",
|
|
17
|
+
args: ["tsx", "src/index.ts"],
|
|
18
|
+
pidFile: paths.corePid,
|
|
19
|
+
logFile: paths.coreLog,
|
|
20
|
+
port: 53666,
|
|
21
|
+
healthUrl: "http://localhost:53666/health",
|
|
22
|
+
},
|
|
23
|
+
dashboard: {
|
|
24
|
+
name: "Dashboard",
|
|
25
|
+
cwd: paths.dashboard,
|
|
26
|
+
command: "npx",
|
|
27
|
+
args: ["turbo", "dev"],
|
|
28
|
+
pidFile: paths.dashboardPid,
|
|
29
|
+
logFile: paths.dashboardLog,
|
|
30
|
+
port: 53667,
|
|
31
|
+
healthUrl: "http://localhost:53667/health",
|
|
32
|
+
},
|
|
33
|
+
gateway: {
|
|
34
|
+
name: "Gateway",
|
|
35
|
+
cwd: paths.gateway,
|
|
36
|
+
command: "npx",
|
|
37
|
+
args: ["tsx", "src/index.ts"],
|
|
38
|
+
pidFile: paths.gatewayPid,
|
|
39
|
+
logFile: paths.gatewayLog,
|
|
40
|
+
port: 8900,
|
|
41
|
+
healthUrl: "http://localhost:8900/health",
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function buildNpmServices() {
|
|
46
|
+
const coreEntry = resolveNpmPackage("@opentrust/core");
|
|
47
|
+
const dashboardEntry = resolveNpmPackage("@opentrust/dashboard");
|
|
48
|
+
const gatewayEntry = resolveNpmPackage("@opentrust/gateway");
|
|
49
|
+
const dataDir = path.join(projectRoot, "data");
|
|
50
|
+
return {
|
|
51
|
+
core: {
|
|
52
|
+
name: "Core",
|
|
53
|
+
cwd: projectRoot,
|
|
54
|
+
command: "node",
|
|
55
|
+
args: [coreEntry || "node_modules/@opentrust/core/dist/index.js"],
|
|
56
|
+
pidFile: paths.corePid,
|
|
57
|
+
logFile: paths.coreLog,
|
|
58
|
+
port: 53666,
|
|
59
|
+
healthUrl: "http://localhost:53666/health",
|
|
60
|
+
},
|
|
61
|
+
dashboard: {
|
|
62
|
+
name: "Dashboard",
|
|
63
|
+
cwd: projectRoot,
|
|
64
|
+
command: "node",
|
|
65
|
+
args: [dashboardEntry || "node_modules/@opentrust/dashboard/dist/index.js"],
|
|
66
|
+
pidFile: paths.dashboardPid,
|
|
67
|
+
logFile: paths.dashboardLog,
|
|
68
|
+
port: 53667,
|
|
69
|
+
healthUrl: "http://localhost:53667/health",
|
|
70
|
+
env: {
|
|
71
|
+
DASHBOARD_MODE: "embedded",
|
|
72
|
+
DEV_MODE: "true",
|
|
73
|
+
DASHBOARD_DATA_DIR: dataDir,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
gateway: {
|
|
77
|
+
name: "Gateway",
|
|
78
|
+
cwd: projectRoot,
|
|
79
|
+
command: "node",
|
|
80
|
+
args: [gatewayEntry || "node_modules/@opentrust/gateway/dist/index.js"],
|
|
81
|
+
pidFile: paths.gatewayPid,
|
|
82
|
+
logFile: paths.gatewayLog,
|
|
83
|
+
port: 8900,
|
|
84
|
+
healthUrl: "http://localhost:8900/health",
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export const SERVICES = buildServices();
|
|
36
89
|
function ensureDirs() {
|
|
37
90
|
for (const dir of [paths.runtime, paths.logs]) {
|
|
38
91
|
if (!fs.existsSync(dir))
|
|
@@ -45,7 +98,7 @@ export function startService(key) {
|
|
|
45
98
|
console.error(`Unknown service: ${key}`);
|
|
46
99
|
return false;
|
|
47
100
|
}
|
|
48
|
-
if (!fs.existsSync(svc.cwd)) {
|
|
101
|
+
if (projectMode === "monorepo" && !fs.existsSync(svc.cwd)) {
|
|
49
102
|
console.error(` ${svc.name}: directory not found at ${svc.cwd}`);
|
|
50
103
|
return false;
|
|
51
104
|
}
|
|
@@ -58,7 +111,7 @@ export function startService(key) {
|
|
|
58
111
|
const logFd = fs.openSync(svc.logFile, "a");
|
|
59
112
|
const child = spawn(svc.command, svc.args, {
|
|
60
113
|
cwd: svc.cwd,
|
|
61
|
-
env: { ...process.env, FORCE_COLOR: "0" },
|
|
114
|
+
env: { ...process.env, FORCE_COLOR: "0", ...svc.env },
|
|
62
115
|
stdio: ["ignore", logFd, logFd],
|
|
63
116
|
detached: true,
|
|
64
117
|
});
|
|
@@ -85,7 +138,6 @@ export function stopService(key) {
|
|
|
85
138
|
return false;
|
|
86
139
|
}
|
|
87
140
|
try {
|
|
88
|
-
// Kill the process group (negative PID) to stop all children
|
|
89
141
|
process.kill(-status.pid, "SIGTERM");
|
|
90
142
|
}
|
|
91
143
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentrust/cli",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "CLI tool to manage OpenTrust AI Agent Runtime Security Platform — setup, start, stop, status, logs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"llm-security",
|
|
34
34
|
"ai-agent"
|
|
35
35
|
],
|
|
36
|
-
"homepage": "https://github.com/opentrust
|
|
36
|
+
"homepage": "https://github.com/opentrust/opentrust#readme",
|
|
37
37
|
"repository": {
|
|
38
38
|
"type": "git",
|
|
39
|
-
"url": "git+https://github.com/opentrust
|
|
39
|
+
"url": "git+https://github.com/opentrust/opentrust.git",
|
|
40
40
|
"directory": "cli"
|
|
41
41
|
},
|
|
42
42
|
"bugs": {
|
|
43
|
-
"url": "https://github.com/opentrust
|
|
43
|
+
"url": "https://github.com/opentrust/opentrust/issues"
|
|
44
44
|
},
|
|
45
45
|
"author": "OpenTrust",
|
|
46
46
|
"license": "Apache-2.0",
|