@ekkos/cli 0.2.9 → 0.2.11
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/dist/agent/daemon.d.ts +86 -0
- package/dist/agent/daemon.js +297 -0
- package/dist/agent/pty-runner.d.ts +51 -0
- package/dist/agent/pty-runner.js +184 -0
- package/dist/cache/LocalSessionStore.d.ts +34 -21
- package/dist/cache/LocalSessionStore.js +169 -53
- package/dist/cache/capture.d.ts +19 -11
- package/dist/cache/capture.js +243 -76
- package/dist/cache/types.d.ts +14 -1
- package/dist/commands/agent.d.ts +44 -0
- package/dist/commands/agent.js +300 -0
- package/dist/commands/doctor.d.ts +10 -0
- package/dist/commands/doctor.js +175 -87
- package/dist/commands/hooks.d.ts +109 -0
- package/dist/commands/hooks.js +668 -0
- package/dist/commands/run.d.ts +2 -0
- package/dist/commands/run.js +357 -85
- package/dist/commands/setup-remote.d.ts +20 -0
- package/dist/commands/setup-remote.js +467 -0
- package/dist/index.js +116 -1
- package/dist/restore/RestoreOrchestrator.d.ts +17 -3
- package/dist/restore/RestoreOrchestrator.js +64 -22
- package/dist/utils/paths.d.ts +125 -0
- package/dist/utils/paths.js +283 -0
- package/dist/utils/state.d.ts +2 -0
- package/package.json +1 -1
- package/templates/ekkos-manifest.json +223 -0
- package/templates/helpers/json-parse.cjs +101 -0
- package/templates/hooks/assistant-response.ps1 +256 -0
- package/templates/hooks/assistant-response.sh +124 -64
- package/templates/hooks/session-start.ps1 +107 -2
- package/templates/hooks/session-start.sh +201 -166
- package/templates/hooks/stop.ps1 +124 -3
- package/templates/hooks/stop.sh +470 -843
- package/templates/hooks/user-prompt-submit.ps1 +107 -22
- package/templates/hooks/user-prompt-submit.sh +403 -393
- package/templates/project-stubs/session-start.ps1 +63 -0
- package/templates/project-stubs/session-start.sh +55 -0
- package/templates/project-stubs/stop.ps1 +63 -0
- package/templates/project-stubs/stop.sh +55 -0
- package/templates/project-stubs/user-prompt-submit.ps1 +63 -0
- package/templates/project-stubs/user-prompt-submit.sh +55 -0
- package/templates/shared/hooks-enabled.json +22 -0
- package/templates/shared/session-words.json +45 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ekkos agent - Agent management commands for remote terminal
|
|
4
|
+
*
|
|
5
|
+
* Subcommands:
|
|
6
|
+
* - daemon: Run the agent daemon (used by service)
|
|
7
|
+
* - start: Start the agent service
|
|
8
|
+
* - stop: Stop the agent service
|
|
9
|
+
* - restart: Restart the agent service
|
|
10
|
+
* - status: Check agent status
|
|
11
|
+
* - uninstall: Remove agent service
|
|
12
|
+
*/
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
47
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.agentDaemon = agentDaemon;
|
|
51
|
+
exports.agentStart = agentStart;
|
|
52
|
+
exports.agentStop = agentStop;
|
|
53
|
+
exports.agentRestart = agentRestart;
|
|
54
|
+
exports.agentStatus = agentStatus;
|
|
55
|
+
exports.agentUninstall = agentUninstall;
|
|
56
|
+
exports.agentLogs = agentLogs;
|
|
57
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
58
|
+
const os = __importStar(require("os"));
|
|
59
|
+
const fs = __importStar(require("fs"));
|
|
60
|
+
const path = __importStar(require("path"));
|
|
61
|
+
const child_process_1 = require("child_process");
|
|
62
|
+
const state_1 = require("../utils/state");
|
|
63
|
+
const daemon_1 = require("../agent/daemon");
|
|
64
|
+
/**
|
|
65
|
+
* Run the agent daemon (foreground)
|
|
66
|
+
*/
|
|
67
|
+
async function agentDaemon(options = {}) {
|
|
68
|
+
const verbose = options.verbose || false;
|
|
69
|
+
// Load device info
|
|
70
|
+
const deviceFilePath = path.join(state_1.EKKOS_DIR, 'device.json');
|
|
71
|
+
if (!fs.existsSync(deviceFilePath)) {
|
|
72
|
+
console.error(chalk_1.default.red('Device not configured. Run `ekkos setup-remote` first.'));
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
const deviceData = JSON.parse(fs.readFileSync(deviceFilePath, 'utf-8'));
|
|
76
|
+
if (!deviceData.deviceToken) {
|
|
77
|
+
console.error(chalk_1.default.red('Device not paired. Run `ekkos setup-remote` first.'));
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
if (verbose) {
|
|
81
|
+
console.log(chalk_1.default.cyan(`Starting ekkOS agent daemon...`));
|
|
82
|
+
console.log(chalk_1.default.gray(` Device: ${deviceData.deviceName}`));
|
|
83
|
+
console.log(chalk_1.default.gray(` Platform: ${deviceData.platform}/${deviceData.arch}`));
|
|
84
|
+
}
|
|
85
|
+
// Start the daemon
|
|
86
|
+
const daemon = new daemon_1.AgentDaemon({
|
|
87
|
+
deviceToken: deviceData.deviceToken,
|
|
88
|
+
deviceId: deviceData.deviceId,
|
|
89
|
+
deviceName: deviceData.deviceName,
|
|
90
|
+
verbose,
|
|
91
|
+
});
|
|
92
|
+
await daemon.start();
|
|
93
|
+
// Handle shutdown signals
|
|
94
|
+
const shutdown = async () => {
|
|
95
|
+
console.log(chalk_1.default.gray('\nShutting down agent...'));
|
|
96
|
+
await daemon.stop();
|
|
97
|
+
process.exit(0);
|
|
98
|
+
};
|
|
99
|
+
process.on('SIGINT', shutdown);
|
|
100
|
+
process.on('SIGTERM', shutdown);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Start the agent service
|
|
104
|
+
*/
|
|
105
|
+
async function agentStart(options = {}) {
|
|
106
|
+
const platform = os.platform();
|
|
107
|
+
try {
|
|
108
|
+
if (platform === 'darwin') {
|
|
109
|
+
const plistPath = path.join(os.homedir(), 'Library', 'LaunchAgents', 'dev.ekkos.agent.plist');
|
|
110
|
+
if (!fs.existsSync(plistPath)) {
|
|
111
|
+
console.log(chalk_1.default.yellow('Agent not installed. Run `ekkos setup-remote` first.'));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
(0, child_process_1.execSync)(`launchctl load "${plistPath}" 2>/dev/null || true`, { encoding: 'utf-8' });
|
|
115
|
+
console.log(chalk_1.default.green('Agent started.'));
|
|
116
|
+
}
|
|
117
|
+
else if (platform === 'win32') {
|
|
118
|
+
(0, child_process_1.execSync)('schtasks /run /tn "ekkOS Agent"', { encoding: 'utf-8' });
|
|
119
|
+
console.log(chalk_1.default.green('Agent started.'));
|
|
120
|
+
}
|
|
121
|
+
else if (platform === 'linux') {
|
|
122
|
+
(0, child_process_1.execSync)('systemctl --user start ekkos-agent', { encoding: 'utf-8' });
|
|
123
|
+
console.log(chalk_1.default.green('Agent started.'));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
console.error(chalk_1.default.red(`Failed to start agent: ${err.message}`));
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Stop the agent service
|
|
133
|
+
*/
|
|
134
|
+
async function agentStop(options = {}) {
|
|
135
|
+
const platform = os.platform();
|
|
136
|
+
try {
|
|
137
|
+
if (platform === 'darwin') {
|
|
138
|
+
const plistPath = path.join(os.homedir(), 'Library', 'LaunchAgents', 'dev.ekkos.agent.plist');
|
|
139
|
+
(0, child_process_1.execSync)(`launchctl unload "${plistPath}" 2>/dev/null || true`, { encoding: 'utf-8' });
|
|
140
|
+
console.log(chalk_1.default.green('Agent stopped.'));
|
|
141
|
+
}
|
|
142
|
+
else if (platform === 'win32') {
|
|
143
|
+
(0, child_process_1.execSync)('taskkill /im "node.exe" /fi "windowtitle eq ekkOS*" /f 2>nul', { encoding: 'utf-8' });
|
|
144
|
+
console.log(chalk_1.default.green('Agent stopped.'));
|
|
145
|
+
}
|
|
146
|
+
else if (platform === 'linux') {
|
|
147
|
+
(0, child_process_1.execSync)('systemctl --user stop ekkos-agent', { encoding: 'utf-8' });
|
|
148
|
+
console.log(chalk_1.default.green('Agent stopped.'));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
// May not be running
|
|
153
|
+
console.log(chalk_1.default.gray('Agent was not running.'));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Restart the agent service
|
|
158
|
+
*/
|
|
159
|
+
async function agentRestart(options = {}) {
|
|
160
|
+
await agentStop(options);
|
|
161
|
+
await agentStart(options);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Check agent status
|
|
165
|
+
*/
|
|
166
|
+
async function agentStatus(options = {}) {
|
|
167
|
+
const platform = os.platform();
|
|
168
|
+
let running = false;
|
|
169
|
+
let statusOutput = '';
|
|
170
|
+
try {
|
|
171
|
+
if (platform === 'darwin') {
|
|
172
|
+
statusOutput = (0, child_process_1.execSync)('launchctl list | grep dev.ekkos.agent || true', { encoding: 'utf-8' });
|
|
173
|
+
running = statusOutput.includes('dev.ekkos.agent');
|
|
174
|
+
}
|
|
175
|
+
else if (platform === 'win32') {
|
|
176
|
+
statusOutput = (0, child_process_1.execSync)('schtasks /query /tn "ekkOS Agent" 2>nul || true', { encoding: 'utf-8' });
|
|
177
|
+
running = statusOutput.includes('Running');
|
|
178
|
+
}
|
|
179
|
+
else if (platform === 'linux') {
|
|
180
|
+
statusOutput = (0, child_process_1.execSync)('systemctl --user is-active ekkos-agent 2>/dev/null || true', { encoding: 'utf-8' });
|
|
181
|
+
running = statusOutput.trim() === 'active';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
running = false;
|
|
186
|
+
}
|
|
187
|
+
console.log('');
|
|
188
|
+
console.log(chalk_1.default.cyan.bold(' ekkOS Agent Status'));
|
|
189
|
+
console.log('');
|
|
190
|
+
// Check device info
|
|
191
|
+
const deviceFilePath = path.join(state_1.EKKOS_DIR, 'device.json');
|
|
192
|
+
if (!fs.existsSync(deviceFilePath)) {
|
|
193
|
+
console.log(chalk_1.default.yellow(' Not configured. Run `ekkos setup-remote` first.'));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const deviceData = JSON.parse(fs.readFileSync(deviceFilePath, 'utf-8'));
|
|
197
|
+
console.log(` Device: ${chalk_1.default.white(deviceData.deviceName)}`);
|
|
198
|
+
console.log(` ID: ${chalk_1.default.gray(deviceData.deviceId.slice(0, 8))}...`);
|
|
199
|
+
console.log(` Paired: ${deviceData.deviceToken ? chalk_1.default.green('Yes') : chalk_1.default.red('No')}`);
|
|
200
|
+
console.log(` Service: ${running ? chalk_1.default.green('Running') : chalk_1.default.red('Stopped')}`);
|
|
201
|
+
console.log('');
|
|
202
|
+
// Check cloud connection
|
|
203
|
+
if (deviceData.deviceToken) {
|
|
204
|
+
console.log(chalk_1.default.gray(' Checking cloud connection...'));
|
|
205
|
+
try {
|
|
206
|
+
const authToken = (0, state_1.getAuthToken)();
|
|
207
|
+
const state = (0, state_1.getState)();
|
|
208
|
+
if (authToken && state?.userId) {
|
|
209
|
+
const MEMORY_API_URL = process.env.MEMORY_API_URL || 'https://mcp.ekkos.dev';
|
|
210
|
+
const response = await fetch(`${MEMORY_API_URL}/api/v1/relay/devices/${state.userId}`, {
|
|
211
|
+
headers: { 'Authorization': `Bearer ${authToken}` },
|
|
212
|
+
});
|
|
213
|
+
if (response.ok) {
|
|
214
|
+
const data = await response.json();
|
|
215
|
+
const device = data.devices?.find((d) => d.deviceId === deviceData.deviceId);
|
|
216
|
+
if (device?.online) {
|
|
217
|
+
console.log(` Cloud: ${chalk_1.default.green('Connected')}`);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
console.log(` Cloud: ${chalk_1.default.yellow('Offline')}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
console.log(` Cloud: ${chalk_1.default.gray('Unable to check')}`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
console.log('');
|
|
230
|
+
// Show log location
|
|
231
|
+
console.log(chalk_1.default.gray(` Logs: ${path.join(state_1.EKKOS_DIR, 'agent.out.log')}`));
|
|
232
|
+
console.log('');
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Uninstall the agent service
|
|
236
|
+
*/
|
|
237
|
+
async function agentUninstall(options = {}) {
|
|
238
|
+
const platform = os.platform();
|
|
239
|
+
console.log(chalk_1.default.cyan('Uninstalling ekkOS agent...'));
|
|
240
|
+
try {
|
|
241
|
+
if (platform === 'darwin') {
|
|
242
|
+
const plistPath = path.join(os.homedir(), 'Library', 'LaunchAgents', 'dev.ekkos.agent.plist');
|
|
243
|
+
(0, child_process_1.execSync)(`launchctl unload "${plistPath}" 2>/dev/null || true`, { encoding: 'utf-8' });
|
|
244
|
+
if (fs.existsSync(plistPath)) {
|
|
245
|
+
fs.unlinkSync(plistPath);
|
|
246
|
+
}
|
|
247
|
+
console.log(chalk_1.default.green(' ✓ Service removed'));
|
|
248
|
+
}
|
|
249
|
+
else if (platform === 'win32') {
|
|
250
|
+
(0, child_process_1.execSync)('schtasks /delete /tn "ekkOS Agent" /f 2>nul || true', { encoding: 'utf-8' });
|
|
251
|
+
console.log(chalk_1.default.green(' ✓ Scheduled task removed'));
|
|
252
|
+
}
|
|
253
|
+
else if (platform === 'linux') {
|
|
254
|
+
(0, child_process_1.execSync)('systemctl --user disable ekkos-agent 2>/dev/null || true', { encoding: 'utf-8' });
|
|
255
|
+
(0, child_process_1.execSync)('systemctl --user stop ekkos-agent 2>/dev/null || true', { encoding: 'utf-8' });
|
|
256
|
+
const servicePath = path.join(os.homedir(), '.config', 'systemd', 'user', 'ekkos-agent.service');
|
|
257
|
+
if (fs.existsSync(servicePath)) {
|
|
258
|
+
fs.unlinkSync(servicePath);
|
|
259
|
+
}
|
|
260
|
+
console.log(chalk_1.default.green(' ✓ Service removed'));
|
|
261
|
+
}
|
|
262
|
+
// Remove device token (but keep device ID for potential re-pairing)
|
|
263
|
+
const deviceFilePath = path.join(state_1.EKKOS_DIR, 'device.json');
|
|
264
|
+
if (fs.existsSync(deviceFilePath)) {
|
|
265
|
+
const deviceData = JSON.parse(fs.readFileSync(deviceFilePath, 'utf-8'));
|
|
266
|
+
delete deviceData.deviceToken;
|
|
267
|
+
delete deviceData.pairedAt;
|
|
268
|
+
fs.writeFileSync(deviceFilePath, JSON.stringify(deviceData, null, 2));
|
|
269
|
+
console.log(chalk_1.default.green(' ✓ Device token removed'));
|
|
270
|
+
}
|
|
271
|
+
console.log('');
|
|
272
|
+
console.log(chalk_1.default.green('Agent uninstalled. Run `ekkos setup-remote` to set up again.'));
|
|
273
|
+
console.log('');
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
console.error(chalk_1.default.red(`Failed to uninstall: ${err.message}`));
|
|
277
|
+
process.exit(1);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Show agent logs
|
|
282
|
+
*/
|
|
283
|
+
async function agentLogs(options = {}) {
|
|
284
|
+
const logPath = path.join(state_1.EKKOS_DIR, 'agent.out.log');
|
|
285
|
+
if (!fs.existsSync(logPath)) {
|
|
286
|
+
console.log(chalk_1.default.gray('No logs found.'));
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (options.follow) {
|
|
290
|
+
// Use tail -f
|
|
291
|
+
const tail = (0, child_process_1.spawn)('tail', ['-f', logPath], { stdio: 'inherit' });
|
|
292
|
+
tail.on('close', () => process.exit(0));
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
// Show last 50 lines
|
|
296
|
+
const content = fs.readFileSync(logPath, 'utf-8');
|
|
297
|
+
const lines = content.split('\n').slice(-50);
|
|
298
|
+
console.log(lines.join('\n'));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ekkOS CLI: doctor command
|
|
3
|
+
* Checks system prerequisites for ekkOS
|
|
4
|
+
*
|
|
5
|
+
* Per ekkOS Onboarding Spec v1.2 + Addendum:
|
|
6
|
+
* - Node gate: Node >= 18 required (FAIL if missing)
|
|
7
|
+
* - PTY gate: WARN on Windows if missing (monitor-only mode available)
|
|
8
|
+
* - Hooks gate: Verifies hook installation
|
|
9
|
+
* - NO jq checks (jq dependency eliminated)
|
|
10
|
+
*/
|
|
1
11
|
type GateStatus = 'PASS' | 'FAIL' | 'WARN';
|
|
2
12
|
interface Check {
|
|
3
13
|
name: string;
|