@tameflare/cli 0.8.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.
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.statusCommand = statusCommand;
4
+ const commander_1 = require("commander");
5
+ const utils_1 = require("../utils");
6
+ function statusCommand() {
7
+ const cmd = new commander_1.Command("status")
8
+ .description("Show gateway and process status")
9
+ .action(async () => {
10
+ (0, utils_1.requireGateway)();
11
+ try {
12
+ const status = await (0, utils_1.gatewayRequest)("GET", "/internal/status");
13
+ console.log("[TF] Gateway Status");
14
+ console.log(" Status: ", status.status);
15
+ console.log(" Enforcement: ", status.enforcement_level);
16
+ console.log(" Proxy mode: ", status.proxy_mode);
17
+ console.log(" Processes: ", status.processes_active);
18
+ console.log("");
19
+ console.log("[TF] Traffic");
20
+ console.log(" Total: ", status.traffic.total);
21
+ console.log(" Allowed: ", status.traffic.allowed);
22
+ console.log(" Denied: ", status.traffic.denied);
23
+ // List processes
24
+ const processes = await (0, utils_1.gatewayRequest)("GET", "/internal/processes");
25
+ if (processes && processes.length > 0) {
26
+ console.log("");
27
+ console.log("[TF] Active Processes");
28
+ const rows = processes.map((p) => [
29
+ p.name,
30
+ String(p.port),
31
+ String(p.request_count),
32
+ p.last_activity ? new Date(p.last_activity).toLocaleTimeString() : "-",
33
+ ]);
34
+ console.log((0, utils_1.formatTable)(["Name", "Port", "Requests", "Last Activity"], rows));
35
+ }
36
+ }
37
+ catch (err) {
38
+ console.error("[TF] Gateway is not running.");
39
+ console.error(" Start it with: tf init");
40
+ }
41
+ });
42
+ return cmd;
43
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function stopCommand(): Command;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stopCommand = stopCommand;
4
+ const commander_1 = require("commander");
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ const utils_1 = require("../utils");
8
+ function stopCommand() {
9
+ const cmd = new commander_1.Command("stop")
10
+ .description("Stop the TameFlare gateway")
11
+ .action(async () => {
12
+ (0, utils_1.requireGateway)();
13
+ const pidFile = (0, path_1.join)((0, utils_1.getTfDir)(), "gateway.pid");
14
+ if (!(0, fs_1.existsSync)(pidFile)) {
15
+ console.log("[TF] No running gateway found (no PID file).");
16
+ return;
17
+ }
18
+ const pid = parseInt((0, fs_1.readFileSync)(pidFile, "utf-8").trim(), 10);
19
+ try {
20
+ process.kill(pid, "SIGTERM");
21
+ console.log(`[TF] Gateway (PID ${pid}) stopped.`);
22
+ }
23
+ catch (err) {
24
+ if (err.code === "ESRCH") {
25
+ console.log("[TF] Gateway process not found (already stopped).");
26
+ }
27
+ else {
28
+ console.error(`[TF] Failed to stop gateway: ${err.message}`);
29
+ }
30
+ }
31
+ // Clean up PID file
32
+ try {
33
+ (0, fs_1.unlinkSync)(pidFile);
34
+ }
35
+ catch {
36
+ // Ignore
37
+ }
38
+ });
39
+ return cmd;
40
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const init_1 = require("./commands/init");
6
+ const run_1 = require("./commands/run");
7
+ const status_1 = require("./commands/status");
8
+ const stop_1 = require("./commands/stop");
9
+ const logs_1 = require("./commands/logs");
10
+ const kill_switch_1 = require("./commands/kill-switch");
11
+ const connector_1 = require("./commands/connector");
12
+ const approvals_1 = require("./commands/approvals");
13
+ const program = new commander_1.Command();
14
+ program
15
+ .name("tf")
16
+ .description("TameFlare — Govern and secure AI gateway traffic")
17
+ .version("0.8.0");
18
+ program.addCommand((0, init_1.initCommand)());
19
+ program.addCommand((0, run_1.runCommand)());
20
+ program.addCommand((0, status_1.statusCommand)());
21
+ program.addCommand((0, stop_1.stopCommand)());
22
+ program.addCommand((0, logs_1.logsCommand)());
23
+ program.addCommand((0, kill_switch_1.killSwitchCommand)());
24
+ program.addCommand((0, connector_1.connectorCommand)());
25
+ program.addCommand((0, connector_1.permissionsCommand)());
26
+ program.addCommand((0, approvals_1.approvalsCommand)());
27
+ program.parse();
@@ -0,0 +1,7 @@
1
+ export declare function getTfDir(): string;
2
+ export declare function getConfigPath(): string;
3
+ export declare function getGatewayUrl(): string;
4
+ export declare function isGatewayInitialized(): boolean;
5
+ export declare function gatewayRequest(method: string, path: string, body?: any): Promise<any>;
6
+ export declare function requireGateway(): void;
7
+ export declare function formatTable(headers: string[], rows: string[][]): string;
package/dist/utils.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTfDir = getTfDir;
4
+ exports.getConfigPath = getConfigPath;
5
+ exports.getGatewayUrl = getGatewayUrl;
6
+ exports.isGatewayInitialized = isGatewayInitialized;
7
+ exports.gatewayRequest = gatewayRequest;
8
+ exports.requireGateway = requireGateway;
9
+ exports.formatTable = formatTable;
10
+ const fs_1 = require("fs");
11
+ const path_1 = require("path");
12
+ const GATEWAY_PORT = 9443;
13
+ function getTfDir() {
14
+ return (0, path_1.join)(process.cwd(), ".tf");
15
+ }
16
+ function getConfigPath() {
17
+ return (0, path_1.join)(getTfDir(), "config.yaml");
18
+ }
19
+ function getGatewayUrl() {
20
+ return `http://127.0.0.1:${GATEWAY_PORT}`;
21
+ }
22
+ function isGatewayInitialized() {
23
+ return (0, fs_1.existsSync)(getConfigPath());
24
+ }
25
+ async function gatewayRequest(method, path, body) {
26
+ const url = `${getGatewayUrl()}${path}`;
27
+ const headers = {
28
+ "Content-Type": "application/json",
29
+ };
30
+ try {
31
+ const response = await fetch(url, {
32
+ method,
33
+ headers,
34
+ body: body ? JSON.stringify(body) : undefined,
35
+ });
36
+ if (!response.ok) {
37
+ const error = await response.json().catch(() => ({
38
+ error: response.statusText,
39
+ }));
40
+ throw new Error(`Gateway error (${response.status}): ${error.error || error.message || response.statusText}`);
41
+ }
42
+ return response.json();
43
+ }
44
+ catch (err) {
45
+ if (err.cause?.code === "ECONNREFUSED") {
46
+ throw new Error("Gateway is not running. Start it with 'tf init' first.");
47
+ }
48
+ throw err;
49
+ }
50
+ }
51
+ function requireGateway() {
52
+ if (!isGatewayInitialized()) {
53
+ console.error("Error: TameFlare not initialized. Run 'tf init' first.");
54
+ process.exit(1);
55
+ }
56
+ }
57
+ function formatTable(headers, rows) {
58
+ const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length)));
59
+ const sep = widths.map((w) => "-".repeat(w + 2)).join("+");
60
+ const headerRow = headers.map((h, i) => ` ${h.padEnd(widths[i])} `).join("|");
61
+ const dataRows = rows.map((row) => row.map((cell, i) => ` ${(cell ?? "").padEnd(widths[i])} `).join("|"));
62
+ return [headerRow, sep, ...dataRows].join("\n");
63
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@tameflare/cli",
3
+ "version": "0.8.0",
4
+ "description": "TameFlare CLI — secure and govern AI agent traffic through a transparent proxy gateway",
5
+ "bin": {
6
+ "tf": "dist/index.js"
7
+ },
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "dev": "tsc --watch",
11
+ "prepublishOnly": "tsc"
12
+ },
13
+ "dependencies": {
14
+ "commander": "^12.1.0"
15
+ },
16
+ "devDependencies": {
17
+ "typescript": "^5.7.0",
18
+ "@types/node": "^22.0.0"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ "engines": {
25
+ "node": ">=18.0.0"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/agentfirewall/agentfirewall",
30
+ "directory": "packages/cli"
31
+ },
32
+ "homepage": "https://tameflare.com",
33
+ "bugs": {
34
+ "url": "https://github.com/agentfirewall/agentfirewall/issues"
35
+ },
36
+ "keywords": [
37
+ "tameflare",
38
+ "ai",
39
+ "agent",
40
+ "firewall",
41
+ "proxy",
42
+ "gateway",
43
+ "security",
44
+ "governance",
45
+ "cli"
46
+ ],
47
+ "license": "ELv2"
48
+ }