troxy-cli 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/init.js +80 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "troxy-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "AI payment control — protect your agent's payments with policies",
5
5
  "type": "module",
6
6
  "bin": {
package/src/init.js CHANGED
@@ -1,9 +1,10 @@
1
- import fs from 'fs';
2
- import os from 'os';
3
- import path from 'path';
4
- import readline from 'readline';
5
- import { saveConfig } from './config.js';
6
- import { evaluatePayment } from './api.js';
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+ import readline from 'readline';
5
+ import { execSync } from 'child_process';
6
+ import { saveConfig } from './config.js';
7
+ import { evaluatePayment } from './api.js';
7
8
 
8
9
  function prompt(question) {
9
10
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
@@ -109,10 +110,83 @@ export async function runInit({ key } = {}) {
109
110
  console.log('\n Restart your MCP client to activate Troxy.');
110
111
  }
111
112
 
113
+ // Install background service so MCP server survives reboots
114
+ console.log('\n Setting up background service...');
115
+ try {
116
+ installService(key, agentName);
117
+ console.log(' Background service installed ✓');
118
+ } catch (err) {
119
+ console.log(` Background service ✗ (${err.message})`);
120
+ console.log(' You can start it manually with: troxy mcp &');
121
+ }
122
+
112
123
  console.log('\n Your payments are now protected.');
113
124
  console.log(' Dashboard → https://dashboard.troxy.ai\n');
114
125
  }
115
126
 
127
+ function installService(apiKey, agentName) {
128
+ const platform = process.platform;
129
+ const troxy = process.execPath.replace(/node$/, 'troxy') ;
130
+
131
+ if (platform === 'linux') {
132
+ const unit = `[Unit]
133
+ Description=Troxy MCP Server
134
+ After=network.target
135
+
136
+ [Service]
137
+ ExecStart=${troxy} mcp
138
+ Restart=always
139
+ RestartSec=10
140
+ User=${os.userInfo().username}
141
+ Environment=TROXY_API_KEY=${apiKey}
142
+ Environment=TROXY_AGENT_NAME=${agentName}
143
+
144
+ [Install]
145
+ WantedBy=multi-user.target
146
+ `;
147
+ fs.writeFileSync('/tmp/troxy-mcp.service', unit);
148
+ execSync('sudo mv /tmp/troxy-mcp.service /etc/systemd/system/troxy-mcp.service');
149
+ execSync('sudo systemctl daemon-reload');
150
+ execSync('sudo systemctl enable troxy-mcp');
151
+ execSync('sudo systemctl restart troxy-mcp');
152
+
153
+ } else if (platform === 'darwin') {
154
+ const plist = `<?xml version="1.0" encoding="UTF-8"?>
155
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
156
+ <plist version="1.0">
157
+ <dict>
158
+ <key>Label</key>
159
+ <string>ai.troxy.mcp</string>
160
+ <key>ProgramArguments</key>
161
+ <array>
162
+ <string>${troxy}</string>
163
+ <string>mcp</string>
164
+ </array>
165
+ <key>EnvironmentVariables</key>
166
+ <dict>
167
+ <key>TROXY_API_KEY</key>
168
+ <string>${apiKey}</string>
169
+ <key>TROXY_AGENT_NAME</key>
170
+ <string>${agentName}</string>
171
+ </dict>
172
+ <key>RunAtLoad</key>
173
+ <true/>
174
+ <key>KeepAlive</key>
175
+ <true/>
176
+ </dict>
177
+ </plist>
178
+ `;
179
+ const plistPath = path.join(os.homedir(), 'Library/LaunchAgents/ai.troxy.mcp.plist');
180
+ fs.mkdirSync(path.dirname(plistPath), { recursive: true });
181
+ fs.writeFileSync(plistPath, plist);
182
+ try { execSync(`launchctl unload ${plistPath} 2>/dev/null`); } catch {}
183
+ execSync(`launchctl load ${plistPath}`);
184
+
185
+ } else {
186
+ throw new Error('Auto-start not supported on this platform. Start manually: troxy mcp &');
187
+ }
188
+ }
189
+
116
190
  function mcpEntry(apiKey) {
117
191
  return {
118
192
  troxy: {