Rebrand NanoClaw to EJClaw
This commit is contained in:
@@ -26,7 +26,7 @@ function parseArgs(args: string[]): { empty: boolean; json: string } {
|
||||
export async function run(args: string[]): Promise<void> {
|
||||
const { empty, json } = parseArgs(args);
|
||||
const homeDir = os.homedir();
|
||||
const configDir = path.join(homeDir, '.config', 'nanoclaw');
|
||||
const configDir = path.join(homeDir, '.config', 'ejclaw');
|
||||
const configFile = path.join(configDir, 'mount-allowlist.json');
|
||||
|
||||
if (isRoot()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Cross-platform detection utilities for NanoClaw setup.
|
||||
* Cross-platform detection utilities for EJClaw setup.
|
||||
*/
|
||||
import { execSync } from 'child_process';
|
||||
import fs from 'fs';
|
||||
|
||||
@@ -19,7 +19,7 @@ function generatePlist(
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.nanoclaw</string>
|
||||
<string>com.ejclaw</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>${nodePath}</string>
|
||||
@@ -39,9 +39,9 @@ function generatePlist(
|
||||
<string>${homeDir}</string>
|
||||
</dict>
|
||||
<key>StandardOutPath</key>
|
||||
<string>${projectRoot}/logs/nanoclaw.log</string>
|
||||
<string>${projectRoot}/logs/ejclaw.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>${projectRoot}/logs/nanoclaw.error.log</string>
|
||||
<string>${projectRoot}/logs/ejclaw.error.log</string>
|
||||
</dict>
|
||||
</plist>`;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ function generateSystemdUnit(
|
||||
isSystem: boolean,
|
||||
): string {
|
||||
return `[Unit]
|
||||
Description=NanoClaw Personal Assistant
|
||||
Description=EJClaw Personal Assistant
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
@@ -64,8 +64,8 @@ Restart=always
|
||||
RestartSec=5
|
||||
Environment=HOME=${homeDir}
|
||||
Environment=PATH=/usr/local/bin:/usr/bin:/bin:${homeDir}/.local/bin
|
||||
StandardOutput=append:${projectRoot}/logs/nanoclaw.log
|
||||
StandardError=append:${projectRoot}/logs/nanoclaw.error.log
|
||||
StandardOutput=append:${projectRoot}/logs/ejclaw.log
|
||||
StandardError=append:${projectRoot}/logs/ejclaw.error.log
|
||||
|
||||
[Install]
|
||||
WantedBy=${isSystem ? 'multi-user.target' : 'default.target'}`;
|
||||
@@ -75,16 +75,16 @@ describe('plist generation', () => {
|
||||
it('contains the correct label', () => {
|
||||
const plist = generatePlist(
|
||||
'/usr/local/bin/node',
|
||||
'/home/user/nanoclaw',
|
||||
'/home/user/ejclaw',
|
||||
'/home/user',
|
||||
);
|
||||
expect(plist).toContain('<string>com.nanoclaw</string>');
|
||||
expect(plist).toContain('<string>com.ejclaw</string>');
|
||||
});
|
||||
|
||||
it('uses the correct node path', () => {
|
||||
const plist = generatePlist(
|
||||
'/opt/node/bin/node',
|
||||
'/home/user/nanoclaw',
|
||||
'/home/user/ejclaw',
|
||||
'/home/user',
|
||||
);
|
||||
expect(plist).toContain('<string>/opt/node/bin/node</string>');
|
||||
@@ -93,20 +93,20 @@ describe('plist generation', () => {
|
||||
it('points to dist/index.js', () => {
|
||||
const plist = generatePlist(
|
||||
'/usr/local/bin/node',
|
||||
'/home/user/nanoclaw',
|
||||
'/home/user/ejclaw',
|
||||
'/home/user',
|
||||
);
|
||||
expect(plist).toContain('/home/user/nanoclaw/dist/index.js');
|
||||
expect(plist).toContain('/home/user/ejclaw/dist/index.js');
|
||||
});
|
||||
|
||||
it('sets log paths', () => {
|
||||
const plist = generatePlist(
|
||||
'/usr/local/bin/node',
|
||||
'/home/user/nanoclaw',
|
||||
'/home/user/ejclaw',
|
||||
'/home/user',
|
||||
);
|
||||
expect(plist).toContain('nanoclaw.log');
|
||||
expect(plist).toContain('nanoclaw.error.log');
|
||||
expect(plist).toContain('ejclaw.log');
|
||||
expect(plist).toContain('ejclaw.error.log');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -114,7 +114,7 @@ describe('systemd unit generation', () => {
|
||||
it('user unit uses default.target', () => {
|
||||
const unit = generateSystemdUnit(
|
||||
'/usr/bin/node',
|
||||
'/home/user/nanoclaw',
|
||||
'/home/user/ejclaw',
|
||||
'/home/user',
|
||||
false,
|
||||
);
|
||||
@@ -124,7 +124,7 @@ describe('systemd unit generation', () => {
|
||||
it('system unit uses multi-user.target', () => {
|
||||
const unit = generateSystemdUnit(
|
||||
'/usr/bin/node',
|
||||
'/home/user/nanoclaw',
|
||||
'/home/user/ejclaw',
|
||||
'/home/user',
|
||||
true,
|
||||
);
|
||||
@@ -134,7 +134,7 @@ describe('systemd unit generation', () => {
|
||||
it('contains restart policy', () => {
|
||||
const unit = generateSystemdUnit(
|
||||
'/usr/bin/node',
|
||||
'/home/user/nanoclaw',
|
||||
'/home/user/ejclaw',
|
||||
'/home/user',
|
||||
false,
|
||||
);
|
||||
@@ -145,32 +145,32 @@ describe('systemd unit generation', () => {
|
||||
it('sets correct ExecStart', () => {
|
||||
const unit = generateSystemdUnit(
|
||||
'/usr/bin/node',
|
||||
'/srv/nanoclaw',
|
||||
'/srv/ejclaw',
|
||||
'/home/user',
|
||||
false,
|
||||
);
|
||||
expect(unit).toContain(
|
||||
'ExecStart=/usr/bin/node /srv/nanoclaw/dist/index.js',
|
||||
'ExecStart=/usr/bin/node /srv/ejclaw/dist/index.js',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('WSL nohup fallback', () => {
|
||||
it('generates a valid wrapper script', () => {
|
||||
const projectRoot = '/home/user/nanoclaw';
|
||||
const projectRoot = '/home/user/ejclaw';
|
||||
const nodePath = '/usr/bin/node';
|
||||
const pidFile = path.join(projectRoot, 'nanoclaw.pid');
|
||||
const pidFile = path.join(projectRoot, 'ejclaw.pid');
|
||||
|
||||
// Simulate what service.ts generates
|
||||
const wrapper = `#!/bin/bash
|
||||
set -euo pipefail
|
||||
cd ${JSON.stringify(projectRoot)}
|
||||
nohup ${JSON.stringify(nodePath)} ${JSON.stringify(projectRoot)}/dist/index.js >> ${JSON.stringify(projectRoot)}/logs/nanoclaw.log 2>> ${JSON.stringify(projectRoot)}/logs/nanoclaw.error.log &
|
||||
nohup ${JSON.stringify(nodePath)} ${JSON.stringify(projectRoot)}/dist/index.js >> ${JSON.stringify(projectRoot)}/logs/ejclaw.log 2>> ${JSON.stringify(projectRoot)}/logs/ejclaw.error.log &
|
||||
echo $! > ${JSON.stringify(pidFile)}`;
|
||||
|
||||
expect(wrapper).toContain('#!/bin/bash');
|
||||
expect(wrapper).toContain('nohup');
|
||||
expect(wrapper).toContain(nodePath);
|
||||
expect(wrapper).toContain('nanoclaw.pid');
|
||||
expect(wrapper).toContain('ejclaw.pid');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,6 +20,9 @@ import {
|
||||
} from './platform.js';
|
||||
import { emitStatus } from './status.js';
|
||||
|
||||
const EJCLAW_SERVICE_NAME = 'ejclaw';
|
||||
const EJCLAW_LAUNCHD_LABEL = 'com.ejclaw';
|
||||
|
||||
export async function run(_args: string[]): Promise<void> {
|
||||
const projectRoot = process.cwd();
|
||||
const platform = getPlatform();
|
||||
@@ -77,7 +80,7 @@ function setupLaunchd(
|
||||
homeDir,
|
||||
'Library',
|
||||
'LaunchAgents',
|
||||
'com.nanoclaw.plist',
|
||||
`${EJCLAW_LAUNCHD_LABEL}.plist`,
|
||||
);
|
||||
fs.mkdirSync(path.dirname(plistPath), { recursive: true });
|
||||
|
||||
@@ -86,7 +89,7 @@ function setupLaunchd(
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.nanoclaw</string>
|
||||
<string>${EJCLAW_LAUNCHD_LABEL}</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>${nodePath}</string>
|
||||
@@ -106,9 +109,9 @@ function setupLaunchd(
|
||||
<string>${homeDir}</string>
|
||||
</dict>
|
||||
<key>StandardOutPath</key>
|
||||
<string>${projectRoot}/logs/nanoclaw.log</string>
|
||||
<string>${projectRoot}/logs/ejclaw.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>${projectRoot}/logs/nanoclaw.error.log</string>
|
||||
<string>${projectRoot}/logs/ejclaw.error.log</string>
|
||||
</dict>
|
||||
</plist>`;
|
||||
|
||||
@@ -128,7 +131,7 @@ function setupLaunchd(
|
||||
let serviceLoaded = false;
|
||||
try {
|
||||
const output = execSync('launchctl list', { encoding: 'utf-8' });
|
||||
serviceLoaded = output.includes('com.nanoclaw');
|
||||
serviceLoaded = output.includes(EJCLAW_LAUNCHD_LABEL);
|
||||
} catch {
|
||||
// launchctl list failed
|
||||
}
|
||||
@@ -160,7 +163,7 @@ function setupLinux(
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill any orphaned nanoclaw node processes left from previous runs or debugging.
|
||||
* Kill any orphaned ejclaw node processes left from previous runs or debugging.
|
||||
* Prevents connection conflicts when two instances connect to the same channel simultaneously.
|
||||
*/
|
||||
function killOrphanedProcesses(projectRoot: string): void {
|
||||
@@ -168,7 +171,7 @@ function killOrphanedProcesses(projectRoot: string): void {
|
||||
execSync(`pkill -f '${projectRoot}/dist/index\\.js' || true`, {
|
||||
stdio: 'ignore',
|
||||
});
|
||||
logger.info('Stopped any orphaned nanoclaw processes');
|
||||
logger.info('Stopped any orphaned ejclaw processes');
|
||||
} catch {
|
||||
// pkill not available or no orphans
|
||||
}
|
||||
@@ -186,7 +189,7 @@ function setupSystemd(
|
||||
let systemctlPrefix: string;
|
||||
|
||||
if (runningAsRoot) {
|
||||
unitPath = '/etc/systemd/system/nanoclaw.service';
|
||||
unitPath = `/etc/systemd/system/${EJCLAW_SERVICE_NAME}.service`;
|
||||
systemctlPrefix = 'systemctl';
|
||||
logger.info('Running as root — installing system-level systemd unit');
|
||||
} else {
|
||||
@@ -202,12 +205,12 @@ function setupSystemd(
|
||||
}
|
||||
const unitDir = path.join(homeDir, '.config', 'systemd', 'user');
|
||||
fs.mkdirSync(unitDir, { recursive: true });
|
||||
unitPath = path.join(unitDir, 'nanoclaw.service');
|
||||
unitPath = path.join(unitDir, `${EJCLAW_SERVICE_NAME}.service`);
|
||||
systemctlPrefix = 'systemctl --user';
|
||||
}
|
||||
|
||||
const unit = `[Unit]
|
||||
Description=NanoClaw Personal Assistant
|
||||
Description=EJClaw Personal Assistant
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
@@ -218,8 +221,8 @@ Restart=always
|
||||
RestartSec=5
|
||||
Environment=HOME=${homeDir}
|
||||
Environment=PATH=${path.dirname(nodePath)}:/usr/local/bin:/usr/bin:/bin:${homeDir}/.local/bin:${homeDir}/.npm-global/bin
|
||||
StandardOutput=append:${projectRoot}/logs/nanoclaw.log
|
||||
StandardError=append:${projectRoot}/logs/nanoclaw.error.log
|
||||
StandardOutput=append:${projectRoot}/logs/ejclaw.log
|
||||
StandardError=append:${projectRoot}/logs/ejclaw.error.log
|
||||
|
||||
[Install]
|
||||
WantedBy=${runningAsRoot ? 'multi-user.target' : 'default.target'}`;
|
||||
@@ -227,7 +230,7 @@ WantedBy=${runningAsRoot ? 'multi-user.target' : 'default.target'}`;
|
||||
fs.writeFileSync(unitPath, unit);
|
||||
logger.info({ unitPath }, 'Wrote systemd unit');
|
||||
|
||||
// Kill orphaned nanoclaw processes to avoid channel connection conflicts
|
||||
// Kill orphaned ejclaw processes to avoid channel connection conflicts
|
||||
killOrphanedProcesses(projectRoot);
|
||||
|
||||
// Enable and start
|
||||
@@ -238,13 +241,17 @@ WantedBy=${runningAsRoot ? 'multi-user.target' : 'default.target'}`;
|
||||
}
|
||||
|
||||
try {
|
||||
execSync(`${systemctlPrefix} enable nanoclaw`, { stdio: 'ignore' });
|
||||
execSync(`${systemctlPrefix} enable ${EJCLAW_SERVICE_NAME}`, {
|
||||
stdio: 'ignore',
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error({ err }, 'systemctl enable failed');
|
||||
}
|
||||
|
||||
try {
|
||||
execSync(`${systemctlPrefix} start nanoclaw`, { stdio: 'ignore' });
|
||||
execSync(`${systemctlPrefix} start ${EJCLAW_SERVICE_NAME}`, {
|
||||
stdio: 'ignore',
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error({ err }, 'systemctl start failed');
|
||||
}
|
||||
@@ -252,7 +259,9 @@ WantedBy=${runningAsRoot ? 'multi-user.target' : 'default.target'}`;
|
||||
// Verify
|
||||
let serviceLoaded = false;
|
||||
try {
|
||||
execSync(`${systemctlPrefix} is-active nanoclaw`, { stdio: 'ignore' });
|
||||
execSync(`${systemctlPrefix} is-active ${EJCLAW_SERVICE_NAME}`, {
|
||||
stdio: 'ignore',
|
||||
});
|
||||
serviceLoaded = true;
|
||||
} catch {
|
||||
// Not active
|
||||
@@ -276,12 +285,12 @@ function setupNohupFallback(
|
||||
): void {
|
||||
logger.warn('No systemd detected — generating nohup wrapper script');
|
||||
|
||||
const wrapperPath = path.join(projectRoot, 'start-nanoclaw.sh');
|
||||
const pidFile = path.join(projectRoot, 'nanoclaw.pid');
|
||||
const wrapperPath = path.join(projectRoot, 'start-ejclaw.sh');
|
||||
const pidFile = path.join(projectRoot, 'ejclaw.pid');
|
||||
|
||||
const lines = [
|
||||
'#!/bin/bash',
|
||||
'# start-nanoclaw.sh — Start NanoClaw without systemd',
|
||||
'# start-ejclaw.sh — Start EJClaw without systemd',
|
||||
`# To stop: kill \\$(cat ${pidFile})`,
|
||||
'',
|
||||
'set -euo pipefail',
|
||||
@@ -292,20 +301,20 @@ function setupNohupFallback(
|
||||
`if [ -f ${JSON.stringify(pidFile)} ]; then`,
|
||||
` OLD_PID=$(cat ${JSON.stringify(pidFile)} 2>/dev/null || echo "")`,
|
||||
' if [ -n "$OLD_PID" ] && kill -0 "$OLD_PID" 2>/dev/null; then',
|
||||
' echo "Stopping existing NanoClaw (PID $OLD_PID)..."',
|
||||
' echo "Stopping existing EJClaw (PID $OLD_PID)..."',
|
||||
' kill "$OLD_PID" 2>/dev/null || true',
|
||||
' sleep 2',
|
||||
' fi',
|
||||
'fi',
|
||||
'',
|
||||
'echo "Starting NanoClaw..."',
|
||||
'echo "Starting EJClaw..."',
|
||||
`nohup ${JSON.stringify(nodePath)} ${JSON.stringify(projectRoot + '/dist/index.js')} \\`,
|
||||
` >> ${JSON.stringify(projectRoot + '/logs/nanoclaw.log')} \\`,
|
||||
` 2>> ${JSON.stringify(projectRoot + '/logs/nanoclaw.error.log')} &`,
|
||||
` >> ${JSON.stringify(projectRoot + '/logs/ejclaw.log')} \\`,
|
||||
` 2>> ${JSON.stringify(projectRoot + '/logs/ejclaw.error.log')} &`,
|
||||
'',
|
||||
`echo $! > ${JSON.stringify(pidFile)}`,
|
||||
'echo "NanoClaw started (PID $!)"',
|
||||
`echo "Logs: tail -f ${projectRoot}/logs/nanoclaw.log"`,
|
||||
'echo "EJClaw started (PID $!)"',
|
||||
`echo "Logs: tail -f ${projectRoot}/logs/ejclaw.log"`,
|
||||
];
|
||||
const wrapper = lines.join('\n') + '\n';
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@ export async function run(_args: string[]): Promise<void> {
|
||||
const projectRoot = process.cwd();
|
||||
const platform = getPlatform();
|
||||
const homeDir = os.homedir();
|
||||
const launchdLabels = ['com.ejclaw', 'com.nanoclaw'];
|
||||
const systemdUnits = ['ejclaw', 'nanoclaw'];
|
||||
const pidFiles = ['ejclaw.pid', 'nanoclaw.pid'];
|
||||
|
||||
logger.info('Starting verification');
|
||||
|
||||
@@ -36,9 +39,10 @@ export async function run(_args: string[]): Promise<void> {
|
||||
if (mgr === 'launchd') {
|
||||
try {
|
||||
const output = execSync('launchctl list', { encoding: 'utf-8' });
|
||||
if (output.includes('com.nanoclaw')) {
|
||||
const matchedLabel = launchdLabels.find((label) => output.includes(label));
|
||||
if (matchedLabel) {
|
||||
// Check if it has a PID (actually running)
|
||||
const line = output.split('\n').find((l) => l.includes('com.nanoclaw'));
|
||||
const line = output.split('\n').find((l) => l.includes(matchedLabel));
|
||||
if (line) {
|
||||
const pidField = line.trim().split(/\s+/)[0];
|
||||
service = pidField !== '-' && pidField ? 'running' : 'stopped';
|
||||
@@ -49,15 +53,23 @@ export async function run(_args: string[]): Promise<void> {
|
||||
}
|
||||
} else if (mgr === 'systemd') {
|
||||
const prefix = isRoot() ? 'systemctl' : 'systemctl --user';
|
||||
try {
|
||||
execSync(`${prefix} is-active nanoclaw`, { stdio: 'ignore' });
|
||||
const activeUnit = systemdUnits.find((unit) => {
|
||||
try {
|
||||
execSync(`${prefix} is-active ${unit}`, { stdio: 'ignore' });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (activeUnit) {
|
||||
service = 'running';
|
||||
} catch {
|
||||
} else {
|
||||
try {
|
||||
const output = execSync(`${prefix} list-unit-files`, {
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
if (output.includes('nanoclaw')) {
|
||||
if (systemdUnits.some((unit) => output.includes(unit))) {
|
||||
service = 'stopped';
|
||||
}
|
||||
} catch {
|
||||
@@ -66,8 +78,10 @@ export async function run(_args: string[]): Promise<void> {
|
||||
}
|
||||
} else {
|
||||
// Check for nohup PID file
|
||||
const pidFile = path.join(projectRoot, 'nanoclaw.pid');
|
||||
if (fs.existsSync(pidFile)) {
|
||||
const pidFile = pidFiles
|
||||
.map((name) => path.join(projectRoot, name))
|
||||
.find((candidate) => fs.existsSync(candidate));
|
||||
if (pidFile) {
|
||||
try {
|
||||
const raw = fs.readFileSync(pidFile, 'utf-8').trim();
|
||||
const pid = Number(raw);
|
||||
@@ -144,6 +158,7 @@ export async function run(_args: string[]): Promise<void> {
|
||||
// 5. Check mount allowlist
|
||||
let mountAllowlist = 'missing';
|
||||
if (
|
||||
fs.existsSync(path.join(homeDir, '.config', 'ejclaw', 'mount-allowlist.json')) ||
|
||||
fs.existsSync(
|
||||
path.join(homeDir, '.config', 'nanoclaw', 'mount-allowlist.json'),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user