🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

xc-copilot-api

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xc-copilot-api - npm Package Compare versions

Comparing version
1.2.0
to
1.2.1
+2
-3
package.json
{
"name": "xc-copilot-api",
"version": "1.2.0",
"version": "1.2.1",
"description": "Turn GitHub Copilot into OpenAI/Anthropic API compatible server. Usable with Claude Code and Codex",

@@ -19,4 +19,3 @@ "keywords": [

"bin": {
"xc-copilot-api": "./dist/main.js",
"xc-copilot-api-daemon": "./dist/daemon-main.js"
"xc-copilot-api": "./dist/main.js"
},

@@ -23,0 +22,0 @@ "files": [

+62
-29

@@ -38,3 +38,3 @@ # Copilot API Proxy

- **OpenAI & Anthropic Compatibility**: Exposes GitHub Copilot as an OpenAI-compatible (`/v1/chat/completions`, `/v1/models`, `/v1/embeddings`) and Anthropic-compatible (`/v1/messages`) API.
- **Claude Code Integration**: Easily configure and launch [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) to use Copilot as its backend with a simple command-line flag (`--claude-code`).
- **Claude Code & Codex CLI Integration**: Configure [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) or Codex CLI to use Copilot as backend with `config --claude` or `config --codex`.
- **Usage Dashboard**: A web-based dashboard to monitor your Copilot API usage, view quotas, and see detailed statistics.

@@ -192,7 +192,25 @@ - **Rate Limit Control**: Manage API usage with rate-limiting options (`--rate-limit`) and a waiting mechanism (`--wait`) to prevent errors from rapid requests.

- `auth`: Run GitHub authentication flow without starting the server. This is typically used if you need to generate a token for use with the `--github-token` option, especially in non-interactive environments.
- `config`: Configure external AI tools (Claude Code, Codex CLI) to use Copilot API.
- `check-usage`: Show your current GitHub Copilot usage and quota information directly in the terminal (no server required).
- `debug`: Display diagnostic information including version, runtime details, file paths, and authentication status. Useful for troubleshooting and support.
A separate **[`xc-copilot-api-daemon`](docs/daemon.md)** CLI is available for managing the server as a background daemon (install, status, restart, stop, uninstall, logs) on macOS, Linux, and Windows.
### Running as a Background Service
Use [easy-service](https://github.com/billxc/easy-service) to run as a background service on macOS, Linux, and Windows:
```bash
# Install easy-service
uv tool install git+https://github.com/billxc/easy-service.git
# Install and start the service
easy-service install copilot-api -- npx -y xc-copilot-api@latest start
# Manage the service
easy-service status copilot-api
easy-service logs copilot-api -f
easy-service restart copilot-api
easy-service stop copilot-api
easy-service uninstall copilot-api
```
## Command Line Options

@@ -213,6 +231,12 @@

| --github-token | Provide GitHub token directly (must be generated using the `auth` subcommand) | none | -g |
| --claude-code | Generate a command to launch Claude Code with Copilot API config | false | -c |
| --show-token | Show GitHub and Copilot tokens on fetch and refresh | false | none |
| --proxy-env | Initialize proxy from environment variables | false | none |
### Config Command Options
| Option | Description | Default | Alias |
| ------- | ------------------------------------------------- | ------- | ----- |
| --claude | Configure Claude Code (`~/.claude/settings.json`) | false | -c |
| --codex | Configure Codex CLI (`~/.codex/config.toml`) | false | -x |
### Auth Command Options

@@ -334,24 +358,20 @@

This proxy can be used to power [Claude Code](https://docs.anthropic.com/en/claude-code), an experimental conversational AI assistant for developers from Anthropic.
This proxy can be used to power [Claude Code](https://docs.anthropic.com/en/claude-code).
There are two ways to configure Claude Code to use this proxy:
The quickest way to get started:
### Interactive Setup with `--claude-code` flag
```sh
# Start the server
npx xc-copilot-api@latest start
To get started, run the `start` command with the `--claude-code` flag:
```sh
npx xc-copilot-api@latest start --claude-code
# Configure Claude Code (writes to ~/.claude/settings.json)
npx xc-copilot-api@latest config --claude
```
You will be prompted to select a primary model and a "small, fast" model for background tasks. After selecting the models, a command will be copied to your clipboard. This command sets the necessary environment variables for Claude Code to use the proxy.
This merges the required `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN` into your existing settings without overwriting other configuration. A backup of your original config is saved as `settings.json.bak`.
Paste and run this command in a new terminal to launch Claude Code.
> **Note:** Copilot API natively understands Claude model names (e.g. `claude-sonnet-4.5`, `opus[1m]`), so you don't need to set `ANTHROPIC_MODEL` or other model environment variables — they just work.
### Manual Configuration with `settings.json`
If you prefer manual configuration, add the following to your `~/.claude/settings.json`:
Alternatively, you can configure Claude Code by creating a `.claude/settings.json` file in your project's root directory. This file should contain the environment variables needed by Claude Code. This way you don't need to run the interactive setup every time.
Here is an example `.claude/settings.json` file:
```json

@@ -361,14 +381,3 @@ {

"ANTHROPIC_BASE_URL": "http://localhost:4141",
"ANTHROPIC_AUTH_TOKEN": "dummy",
"ANTHROPIC_MODEL": "gpt-4.1",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-4.1",
"ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-4.1",
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
},
"permissions": {
"deny": [
"WebSearch"
]
"ANTHROPIC_AUTH_TOKEN": "Powered by xc copilot"
}

@@ -382,2 +391,26 @@ }

## Using with Codex CLI
```sh
# Start the server
npx xc-copilot-api@latest start
# Configure Codex CLI (writes to ~/.codex/config.toml)
npx xc-copilot-api@latest config --codex
```
A backup of your original config is saved as `config.toml.bak`.
If you prefer manual configuration, add the following to your `~/.codex/config.toml`:
```toml
model = "gpt-5.4"
model_provider = "copilot-api"
[model_providers.copilot-api]
name = "copilot-api"
base_url = "http://localhost:4141/v1"
wire_api = "responses"
```
## Running from Source

@@ -384,0 +417,0 @@

#!/usr/bin/env node
import { defineCommand, runMain } from "citty";
import { execSync, spawnSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
//#region src/daemon/shared.ts
const APP_DIR = path.join(os.homedir(), ".local", "share", "copilot-api");
const LOG_FILE = path.join(APP_DIR, "copilot-api.log");
const ERR_FILE = path.join(APP_DIR, "copilot-api.err");
function launcherPath() {
return path.join(APP_DIR, "launcher.sh");
}
function buildStartArgs(args) {
const cmd = ["xc-copilot-api", "start"];
if (args.port) cmd.push("--port", args.port);
if (args.verbose) cmd.push("--verbose");
if (args.accountType && args.accountType !== "individual") cmd.push("--account-type", args.accountType);
if (args.githubToken) cmd.push("--github-token", args.githubToken);
if (args.proxyEnv) cmd.push("--proxy-env");
return cmd;
}
function shellQuote(s) {
if (/^[\w./:@=-]+$/.test(s)) return s;
return `'${s.replace(/'/g, "'\\''")}'`;
}
function buildNpxCommand(args) {
const startArgs = buildStartArgs(args);
startArgs[0] = "xc-copilot-api@latest";
return [
"npx",
"-y",
...startArgs
].map(shellQuote).join(" ");
}
function buildDirectCommand(args) {
return buildStartArgs(args).map(shellQuote).join(" ");
}
function isMacOS() {
return process.platform === "darwin";
}
function isLinux() {
return process.platform === "linux";
}
function isWindows() {
return process.platform === "win32";
}
function assertSupported() {
if (!isMacOS() && !isLinux() && !isWindows()) {
console.error("Daemon management is only supported on macOS, Linux, and Windows.");
process.exit(1);
}
}
//#endregion
//#region src/daemon/macos.ts
const LAUNCHD_LABEL = "com.xc-copilot-api";
function plistPath() {
return path.join(os.homedir(), "Library", "LaunchAgents", `${LAUNCHD_LABEL}.plist`);
}
function installMacOS(args) {
const plist = plistPath();
const launcher = launcherPath();
fs.mkdirSync(APP_DIR, { recursive: true });
fs.mkdirSync(path.dirname(plist), { recursive: true });
const execCmd = args.npx ? buildNpxCommand(args) : buildDirectCommand(args);
fs.writeFileSync(launcher, [
"#!/bin/zsh -l",
"[ -f \"$HOME/.zshrc\" ] && source \"$HOME/.zshrc\"",
`exec ${execCmd}`,
""
].join("\n"));
fs.chmodSync(launcher, 493);
const plistContent = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>${LAUNCHD_LABEL}</string>
<key>ProgramArguments</key>
<array>
<string>${launcher}</string>
</array>
<key>WorkingDirectory</key>
<string>${os.homedir()}</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>${LOG_FILE}</string>
<key>StandardErrorPath</key>
<string>${ERR_FILE}</string>
</dict>
</plist>
`;
fs.writeFileSync(plist, plistContent);
console.log(`Installed LaunchAgent '${LAUNCHD_LABEL}'`);
console.log(` Plist: ${plist}`);
console.log(` Launcher: ${launcher}`);
console.log(` Log: ${LOG_FILE}`);
console.log(` Mode: ${args.npx ? "npx (auto-update)" : "direct"}`);
console.log(` Start: xc-copilot-api-daemon restart`);
}
function uninstallMacOS() {
stopMacOS();
const plist = plistPath();
if (fs.existsSync(plist)) {
fs.unlinkSync(plist);
console.log(`Removed LaunchAgent plist: ${plist}`);
}
const launcher = launcherPath();
if (fs.existsSync(launcher)) {
fs.unlinkSync(launcher);
console.log(`Removed launcher: ${launcher}`);
}
console.log(`Uninstalled daemon '${LAUNCHD_LABEL}'`);
}
function stopMacOS() {
const job = `${`gui/${process.getuid?.() ?? 501}`}/${LAUNCHD_LABEL}`;
const result = spawnSync("launchctl", ["bootout", job], {
encoding: "utf-8",
timeout: 15e3
});
if (result.status === 0) {
console.log(`Stopped LaunchAgent '${LAUNCHD_LABEL}'`);
return true;
}
const detail = (result.stderr || result.stdout || "").toLowerCase();
if (detail.includes("not find") || detail.includes("no such")) return true;
return false;
}
function startMacOS() {
const plist = plistPath();
if (!fs.existsSync(plist)) {
console.error(`LaunchAgent plist not found: ${plist}`);
console.error("Run 'xc-copilot-api-daemon install' first.");
return false;
}
const domain = `gui/${process.getuid?.() ?? 501}`;
const job = `${domain}/${LAUNCHD_LABEL}`;
const bootstrap = spawnSync("launchctl", [
"bootstrap",
domain,
plist
], {
encoding: "utf-8",
timeout: 1e4
});
if (bootstrap.status !== 0) {
const detail = (bootstrap.stderr || bootstrap.stdout || "").toLowerCase();
if (!detail.includes("already")) {
console.error(`launchctl bootstrap failed: ${detail.trim()}`);
return false;
}
}
const kick = spawnSync("launchctl", [
"kickstart",
"-k",
job
], {
encoding: "utf-8",
timeout: 15e3
});
if (kick.status !== 0) {
console.error(`launchctl kickstart failed: ${(kick.stderr || kick.stdout || "").trim()}`);
return false;
}
console.log(`Started LaunchAgent '${LAUNCHD_LABEL}'`);
return true;
}
function statusMacOS() {
const plist = plistPath();
if (!fs.existsSync(plist)) {
console.log("Daemon: not installed");
return;
}
console.log(`Daemon: installed`);
console.log(` Plist: ${plist}`);
const launcher = launcherPath();
if (fs.existsSync(launcher)) {
const execLine = fs.readFileSync(launcher, "utf-8").split("\n").find((l) => l.startsWith("exec "));
if (execLine) console.log(` Command: ${execLine.replace("exec ", "")}`);
}
const result = spawnSync("launchctl", ["list", LAUNCHD_LABEL], {
encoding: "utf-8",
timeout: 5e3
});
if (result.status === 0) {
const output = result.stdout.trim();
const pidLine = output.split("\n").find((l) => l.includes("PID") || l.match(/^\s*"PID"/));
const lastExitLine = output.split("\n").find((l) => l.includes("LastExitStatus"));
const pidMatch = output.match(/"PID"\s*=\s*(\d+)/);
const exitMatch = output.match(/"LastExitStatus"\s*=\s*(\d+)/);
if (pidMatch) console.log(` Status: running (PID ${pidMatch[1]})`);
else console.log(` Status: not running`);
if (exitMatch) console.log(` Last exit: ${exitMatch[1]}`);
if (pidLine);
if (lastExitLine);
} else console.log(" Status: not loaded");
if (fs.existsSync(LOG_FILE)) {
const stat = fs.statSync(LOG_FILE);
console.log(` Log: ${LOG_FILE} (${(stat.size / 1024).toFixed(1)} KB)`);
}
}
function findAllCopilotLaunchdJobs() {
const result = spawnSync("launchctl", ["list"], {
encoding: "utf-8",
timeout: 5e3
});
if (result.status !== 0) return [];
const jobs = [];
for (const line of result.stdout.split("\n")) {
if (!line.toLowerCase().includes("copilot")) continue;
const parts = line.trim().split(/\s+/);
if (parts.length < 3) continue;
const pid = parts[0] === "-" ? null : parts[0];
const label = parts[2];
const plist = path.join(os.homedir(), "Library", "LaunchAgents", `${label}.plist`);
jobs.push({
label,
pid,
plistPath: fs.existsSync(plist) ? plist : null
});
}
return jobs;
}
//#endregion
//#region src/daemon/linux.ts
const SYSTEMD_UNIT = "xc-copilot-api.service";
function systemdUnitPath() {
return path.join(os.homedir(), ".config", "systemd", "user", SYSTEMD_UNIT);
}
function installLinux(args) {
const unitPath = systemdUnitPath();
const launcher = launcherPath();
fs.mkdirSync(APP_DIR, { recursive: true });
fs.mkdirSync(path.dirname(unitPath), { recursive: true });
const execCmd = args.npx ? buildNpxCommand(args) : buildDirectCommand(args);
fs.writeFileSync(launcher, [
"#!/bin/bash -l",
"[ -f \"$HOME/.bashrc\" ] && source \"$HOME/.bashrc\"",
`exec ${execCmd}`,
""
].join("\n"));
fs.chmodSync(launcher, 493);
const unitContent = `[Unit]
Description=xc-copilot-api - GitHub Copilot OpenAI Compatible API
After=network.target
[Service]
Type=simple
ExecStart=${launcher}
Restart=on-failure
RestartSec=10
StandardOutput=append:${LOG_FILE}
StandardError=append:${ERR_FILE}
[Install]
WantedBy=default.target
`;
fs.writeFileSync(unitPath, unitContent);
spawnSync("systemctl", ["--user", "daemon-reload"], { encoding: "utf-8" });
spawnSync("systemctl", [
"--user",
"enable",
SYSTEMD_UNIT
], { encoding: "utf-8" });
console.log(`Installed systemd unit '${SYSTEMD_UNIT}'`);
console.log(` Unit: ${unitPath}`);
console.log(` Launcher: ${launcher}`);
console.log(` Log: ${LOG_FILE}`);
console.log(` Mode: ${args.npx ? "npx (auto-update)" : "direct"}`);
console.log(` Start: xc-copilot-api-daemon restart`);
}
function uninstallLinux() {
spawnSync("systemctl", [
"--user",
"stop",
SYSTEMD_UNIT
], { encoding: "utf-8" });
spawnSync("systemctl", [
"--user",
"disable",
SYSTEMD_UNIT
], { encoding: "utf-8" });
const unitPath = systemdUnitPath();
if (fs.existsSync(unitPath)) {
fs.unlinkSync(unitPath);
spawnSync("systemctl", ["--user", "daemon-reload"], { encoding: "utf-8" });
}
const launcher = launcherPath();
if (fs.existsSync(launcher)) fs.unlinkSync(launcher);
console.log(`Uninstalled systemd unit '${SYSTEMD_UNIT}'`);
}
function startLinux() {
const result = spawnSync("systemctl", [
"--user",
"start",
SYSTEMD_UNIT
], {
encoding: "utf-8",
timeout: 1e4
});
if (result.status !== 0) {
console.error(`systemd start failed: ${(result.stderr || result.stdout || "").trim()}`);
return false;
}
console.log(`Started systemd unit '${SYSTEMD_UNIT}'`);
return true;
}
function stopLinux() {
const result = spawnSync("systemctl", [
"--user",
"stop",
SYSTEMD_UNIT
], {
encoding: "utf-8",
timeout: 15e3
});
if (result.status !== 0) {
const detail = (result.stderr || result.stdout || "").trim();
if (!detail.includes("not loaded")) {
console.error(`systemd stop failed: ${detail}`);
return false;
}
}
console.log(`Stopped systemd unit '${SYSTEMD_UNIT}'`);
return true;
}
function statusLinux() {
const unitPath = systemdUnitPath();
if (!fs.existsSync(unitPath)) {
console.log("Daemon: not installed");
return;
}
console.log("Daemon: installed");
console.log(` Unit: ${unitPath}`);
const launcher = launcherPath();
if (fs.existsSync(launcher)) {
const execLine = fs.readFileSync(launcher, "utf-8").split("\n").find((l) => l.startsWith("exec "));
if (execLine) console.log(` Command: ${execLine.replace("exec ", "")}`);
}
const result = spawnSync("systemctl", [
"--user",
"status",
SYSTEMD_UNIT,
"--no-pager"
], {
encoding: "utf-8",
timeout: 5e3
});
console.log(result.stdout.trim());
}
function findAllCopilotSystemdUnits() {
const result = spawnSync("systemctl", [
"--user",
"list-units",
"--all",
"--no-pager",
"--plain"
], {
encoding: "utf-8",
timeout: 5e3
});
if (result.status !== 0) return [];
const units = [];
for (const line of result.stdout.split("\n")) if (line.toLowerCase().includes("copilot")) {
const unit = line.trim().split(/\s+/)[0];
if (unit) units.push(unit);
}
return units;
}
//#endregion
//#region src/daemon/windows.ts
const WINDOWS_TASK_NAME = "XcCopilotApi";
function windowsAppDir() {
const localAppData = process.env.LOCALAPPDATA || path.join(os.homedir(), "AppData", "Local");
return path.join(localAppData, "copilot-api");
}
function windowsLauncherCmdPath() {
return path.join(windowsAppDir(), "launcher.cmd");
}
function windowsLogFile() {
return path.join(windowsAppDir(), "copilot-api.log");
}
function buildWindowsCommand(args) {
const startArgs = buildStartArgs(args);
if (args.npx) {
startArgs[0] = "xc-copilot-api@latest";
return [
"npx",
"-y",
...startArgs
].map((s) => s.includes(" ") ? `"${s}"` : s).join(" ");
}
return startArgs.map((s) => s.includes(" ") ? `"${s}"` : s).join(" ");
}
function installWindows(args) {
const appDir = windowsAppDir();
const logFile = windowsLogFile();
const errFile = path.join(appDir, "copilot-api.err");
const launcherCmd = windowsLauncherCmdPath();
fs.mkdirSync(appDir, { recursive: true });
const cmdContent = [
"@echo off",
`cd /d "%USERPROFILE%"`,
`${buildWindowsCommand(args)} >> "${logFile}" 2>> "${errFile}"`,
""
].join("\r\n");
fs.writeFileSync(launcherCmd, cmdContent);
const psCmd = [
`$action = New-ScheduledTaskAction -Execute 'cmd.exe' -Argument '/c "${launcherCmd}"'`,
`$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME`,
`$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero)`,
`Register-ScheduledTask -TaskName '${WINDOWS_TASK_NAME}' -Action $action -Trigger $trigger -Settings $settings -Force`
].join("; ");
const result = spawnSync("powershell", [
"-NoProfile",
"-Command",
psCmd
], {
encoding: "utf-8",
timeout: 15e3
});
if (result.status !== 0) {
console.error(`Failed to create scheduled task: ${(result.stderr || "").trim()}`);
process.exit(1);
}
console.log(`Installed scheduled task '${WINDOWS_TASK_NAME}'`);
console.log(` Launcher: ${launcherCmd}`);
console.log(` Log: ${logFile}`);
console.log(` Mode: ${args.npx ? "npx (auto-update)" : "direct"}`);
console.log(` Start: xc-copilot-api-daemon restart`);
}
function uninstallWindows() {
stopWindows();
spawnSync("schtasks", [
"/delete",
"/tn",
WINDOWS_TASK_NAME,
"/f"
], {
encoding: "utf-8",
timeout: 1e4
});
const launcherCmd = windowsLauncherCmdPath();
if (fs.existsSync(launcherCmd)) fs.unlinkSync(launcherCmd);
console.log(`Uninstalled scheduled task '${WINDOWS_TASK_NAME}'`);
}
function startWindows() {
if (spawnSync("schtasks", [
"/run",
"/tn",
WINDOWS_TASK_NAME
], {
encoding: "utf-8",
timeout: 1e4
}).status !== 0) {
console.error(`Scheduled task '${WINDOWS_TASK_NAME}' not found.`);
console.error("Run 'xc-copilot-api-daemon install' first.");
return false;
}
console.log("Started xc-copilot-api (background)");
return true;
}
function findCopilotPids(filter) {
const wqlFilter = filter.replace(/\*/g, "%");
const result = spawnSync("powershell", [
"-NoProfile",
"-Command",
`Get-CimInstance Win32_Process -Filter "CommandLine LIKE '${wqlFilter}' AND ProcessId != $PID" | Select-Object -ExpandProperty ProcessId`
], {
encoding: "utf-8",
timeout: 1e4
});
if (result.status !== 0) return [];
return result.stdout.split("\n").map((l) => l.trim()).filter(Boolean);
}
function stopWindows() {
const result = spawnSync("powershell", [
"-NoProfile",
"-Command",
`Get-CimInstance Win32_Process -Filter "CommandLine LIKE '%copilot-api%' AND NOT (CommandLine LIKE '%daemon%') AND ProcessId != $PID" | Select-Object -ExpandProperty ProcessId`
], {
encoding: "utf-8",
timeout: 1e4
});
const pids = (result.status === 0 ? result.stdout : "").split("\n").map((l) => l.trim()).filter(Boolean);
for (const pid of pids) spawnSync("taskkill", [
"/PID",
pid,
"/F"
], {
encoding: "utf-8",
timeout: 5e3
});
if (pids.length > 0) {
console.log(`Stopped ${pids.length} process(es)`);
return true;
}
console.log("No copilot-api processes found.");
return true;
}
function statusWindows() {
const taskResult = spawnSync("schtasks", [
"/query",
"/tn",
WINDOWS_TASK_NAME,
"/fo",
"LIST"
], {
encoding: "utf-8",
timeout: 5e3
});
if (taskResult.status !== 0) {
console.log("Daemon: not installed");
return;
}
console.log("Daemon: installed");
const statusMatch = (taskResult.stdout || "").match(/Status:\s*(.+)/i);
if (statusMatch) console.log(` Task: ${statusMatch[1].trim()}`);
const launcherCmd = windowsLauncherCmdPath();
if (fs.existsSync(launcherCmd)) {
const lines = fs.readFileSync(launcherCmd, "utf-8").split(/\r?\n/).filter((l) => l && !l.startsWith("@") && !l.startsWith("cd "));
if (lines.length > 0) {
const cmd = lines[0].replace(/\s*>>.*$/, "").trim();
if (cmd) console.log(` Command: ${cmd}`);
}
}
const pids = findCopilotPids("*copilot-api*start*");
console.log(pids.length > 0 ? ` Status: running (PID ${pids.join(", ")})` : " Status: not running");
const logFile = windowsLogFile();
if (fs.existsSync(logFile)) {
const stat = fs.statSync(logFile);
console.log(` Log: ${logFile} (${(stat.size / 1024).toFixed(1)} KB)`);
}
}
//#endregion
//#region src/daemon/index.ts
function findAllCopilotProcesses() {
if (isWindows()) {
const result = spawnSync("powershell", [
"-NoProfile",
"-Command",
`Get-CimInstance Win32_Process -Filter "CommandLine LIKE '%copilot-api%' AND ProcessId != $PID" | ForEach-Object { "$($_.ProcessId)|$($_.CommandLine)" }`
], {
encoding: "utf-8",
timeout: 1e4
});
if (result.status !== 0) return [];
const procs = [];
for (const line of result.stdout.trim().split("\n")) {
if (!line.trim()) continue;
const sep = line.indexOf("|");
if (sep < 0) continue;
procs.push({
pid: line.slice(0, sep).trim(),
command: line.slice(sep + 1).trim()
});
}
return procs;
}
try {
const output = execSync("ps aux | grep -i copilot-api | grep -v grep", {
encoding: "utf-8",
timeout: 5e3
});
const procs = [];
for (const line of output.trim().split("\n")) {
if (!line) continue;
const parts = line.trim().split(/\s+/);
if (parts.length < 11) continue;
const pid = parts[1];
const command = parts.slice(10).join(" ");
procs.push({
pid,
command
});
}
return procs;
} catch {
return [];
}
}
function statusAll() {
if (isMacOS()) {
const jobs = findAllCopilotLaunchdJobs();
if (jobs.length > 0) {
console.log("=== LaunchAgent Jobs ===");
for (const job of jobs) {
console.log(`\n Label: ${job.label}`);
if (job.plistPath) console.log(` Plist: ${job.plistPath}`);
else console.log(` Plist: (not found)`);
console.log(` PID: ${job.pid ?? "not running"}`);
}
} else console.log("No copilot-api LaunchAgent jobs found.");
} else if (isWindows()) statusWindows();
else {
const units = findAllCopilotSystemdUnits();
if (units.length > 0) {
console.log("=== Systemd Units ===");
for (const unit of units) {
const r = spawnSync("systemctl", [
"--user",
"status",
unit,
"--no-pager"
], {
encoding: "utf-8",
timeout: 5e3
});
console.log(`\n--- ${unit} ---`);
console.log(r.stdout.trim());
}
} else console.log("No copilot-api systemd units found.");
}
const procs = findAllCopilotProcesses();
if (procs.length > 0) {
console.log("\n=== Processes ===");
for (const proc of procs) console.log(` PID ${proc.pid}: ${proc.command}`);
}
}
function stopAll() {
let stopped = 0;
if (isMacOS()) {
const jobs = findAllCopilotLaunchdJobs();
const domain = `gui/${process.getuid?.() ?? 501}`;
for (const job of jobs) {
const jobTarget = `${domain}/${job.label}`;
console.log(`Stopping LaunchAgent '${job.label}'...`);
spawnSync("launchctl", ["bootout", jobTarget], {
encoding: "utf-8",
timeout: 15e3
});
stopped++;
}
} else if (!isWindows()) {
const units = findAllCopilotSystemdUnits();
for (const unit of units) {
console.log(`Stopping systemd unit '${unit}'...`);
spawnSync("systemctl", [
"--user",
"stop",
unit
], {
encoding: "utf-8",
timeout: 15e3
});
stopped++;
}
}
const procs = findAllCopilotProcesses();
for (const proc of procs) {
console.log(`Killing PID ${proc.pid}: ${proc.command}`);
if (isWindows()) {
spawnSync("taskkill", [
"/PID",
proc.pid,
"/F"
], {
encoding: "utf-8",
timeout: 5e3
});
stopped++;
} else try {
process.kill(Number.parseInt(proc.pid, 10), "SIGTERM");
stopped++;
} catch {}
}
if (stopped === 0) console.log("No copilot-api processes found.");
else console.log(`\nStopped/killed ${stopped} item(s).`);
}
const installCmd = defineCommand({
meta: {
name: "install",
description: "Install xc-copilot-api daemon (launchd on macOS, systemd on Linux, Task Scheduler on Windows)"
},
args: {
npx: {
type: "boolean",
default: true,
description: "Use npx to run (auto-updates on restart). Set --no-npx to use direct binary."
},
port: {
alias: "p",
type: "string",
default: "4141",
description: "Port for the API server"
},
verbose: {
alias: "v",
type: "boolean",
default: false,
description: "Enable verbose logging"
},
"account-type": {
alias: "a",
type: "string",
default: "individual",
description: "Account type (individual, business, enterprise)"
},
"github-token": {
alias: "g",
type: "string",
description: "GitHub token to use"
},
"proxy-env": {
type: "boolean",
default: false,
description: "Initialize proxy from environment variables"
}
},
run({ args }) {
assertSupported();
const installArgs = {
npx: args.npx,
port: args.port,
verbose: args.verbose,
accountType: args["account-type"],
githubToken: args["github-token"],
proxyEnv: args["proxy-env"]
};
if (isMacOS()) installMacOS(installArgs);
else if (isWindows()) installWindows(installArgs);
else installLinux(installArgs);
}
});
const uninstallCmd = defineCommand({
meta: {
name: "uninstall",
description: "Uninstall the daemon"
},
run() {
assertSupported();
if (isMacOS()) uninstallMacOS();
else if (isWindows()) uninstallWindows();
else uninstallLinux();
}
});
const statusCmd = defineCommand({
meta: {
name: "status",
description: "Show daemon status (use --all to show all copilot-api instances)"
},
args: { all: {
type: "boolean",
default: false,
description: "Show all copilot-api related daemons and processes"
} },
run({ args }) {
assertSupported();
if (args.all) statusAll();
else if (isMacOS()) statusMacOS();
else if (isWindows()) statusWindows();
else statusLinux();
}
});
const restartCmd = defineCommand({
meta: {
name: "restart",
description: "Restart the daemon (npx mode fetches latest version automatically)"
},
run() {
assertSupported();
if (isMacOS()) {
if (!startMacOS()) process.exit(1);
} else if (isWindows()) {
stopWindows();
if (!startWindows()) process.exit(1);
} else {
stopLinux();
if (!startLinux()) process.exit(1);
}
}
});
const stopCmd = defineCommand({
meta: {
name: "stop",
description: "Stop the daemon (use --all to kill all copilot-api instances)"
},
args: { all: {
type: "boolean",
default: false,
description: "Stop all copilot-api related daemons and kill all processes"
} },
run({ args }) {
assertSupported();
if (args.all) stopAll();
else if (isMacOS()) {
if (!stopMacOS()) process.exit(1);
} else if (isWindows()) {
if (!stopWindows()) process.exit(1);
} else if (!stopLinux()) process.exit(1);
}
});
const logsCmd = defineCommand({
meta: {
name: "logs",
description: "Show recent daemon logs"
},
args: {
follow: {
alias: "f",
type: "boolean",
default: false,
description: "Follow log output (like tail -f)"
},
lines: {
alias: "n",
type: "string",
default: "50",
description: "Number of lines to show"
}
},
run({ args }) {
assertSupported();
const logPath = isWindows() ? windowsLogFile() : LOG_FILE;
if (!fs.existsSync(logPath)) {
console.log("No log file found.");
return;
}
if (isWindows()) if (args.follow) {
const { status } = spawnSync("powershell", ["-Command", `Get-Content -Path '${logPath}' -Wait -Tail ${args.lines}`], { stdio: "inherit" });
process.exit(status ?? 0);
} else {
const { status } = spawnSync("powershell", ["-Command", `Get-Content -Path '${logPath}' -Tail ${args.lines}`], { stdio: "inherit" });
process.exit(status ?? 0);
}
else if (args.follow) {
const { status } = spawnSync("tail", ["-f", logPath], { stdio: "inherit" });
process.exit(status ?? 0);
} else {
const { status } = spawnSync("tail", [
"-n",
args.lines,
logPath
], { stdio: "inherit" });
process.exit(status ?? 0);
}
}
});
const daemon = defineCommand({
meta: {
name: "xc-copilot-api-daemon",
description: "Manage xc-copilot-api daemon (install, status, restart, stop, uninstall, logs)"
},
subCommands: {
install: installCmd,
uninstall: uninstallCmd,
status: statusCmd,
restart: restartCmd,
stop: stopCmd,
logs: logsCmd
}
});
//#endregion
//#region src/daemon-main.ts
await runMain(daemon);
//#endregion
export { };
//# sourceMappingURL=daemon-main.js.map
{"version":3,"file":"daemon-main.js","names":["jobs: CopilotJob[]","units: string[]","procs: CopilotProcess[]","installArgs: DaemonInstallArgs"],"sources":["../src/daemon/shared.ts","../src/daemon/macos.ts","../src/daemon/linux.ts","../src/daemon/windows.ts","../src/daemon/index.ts","../src/daemon-main.ts"],"sourcesContent":["/* eslint-disable */\r\nimport os from \"node:os\"\r\nimport path from \"node:path\"\r\n\r\nexport const APP_DIR = path.join(os.homedir(), \".local\", \"share\", \"copilot-api\")\r\nexport const LOG_FILE = path.join(APP_DIR, \"copilot-api.log\")\r\nexport const ERR_FILE = path.join(APP_DIR, \"copilot-api.err\")\r\n\r\nexport interface DaemonInstallArgs {\r\n npx: boolean\r\n port?: string\r\n verbose: boolean\r\n accountType?: string\r\n githubToken?: string\r\n proxyEnv: boolean\r\n}\r\n\r\nexport interface CopilotProcess {\r\n pid: string\r\n command: string\r\n}\r\n\r\nexport function launcherPath(): string {\r\n return path.join(APP_DIR, \"launcher.sh\")\r\n}\r\n\r\nexport function buildStartArgs(args: DaemonInstallArgs): string[] {\r\n const cmd = [\"xc-copilot-api\", \"start\"]\r\n if (args.port) cmd.push(\"--port\", args.port)\r\n if (args.verbose) cmd.push(\"--verbose\")\r\n if (args.accountType && args.accountType !== \"individual\")\r\n cmd.push(\"--account-type\", args.accountType)\r\n if (args.githubToken) cmd.push(\"--github-token\", args.githubToken)\r\n if (args.proxyEnv) cmd.push(\"--proxy-env\")\r\n return cmd\r\n}\r\n\r\nexport function shellQuote(s: string): string {\r\n if (/^[\\w./:@=-]+$/.test(s)) return s\r\n return `'${s.replace(/'/g, \"'\\\\''\")}'`\r\n}\r\n\r\nexport function buildNpxCommand(args: DaemonInstallArgs): string {\r\n const startArgs = buildStartArgs(args)\r\n // -y skips install prompt; @latest ensures fresh version on every run\r\n startArgs[0] = \"xc-copilot-api@latest\"\r\n return [\"npx\", \"-y\", ...startArgs].map(shellQuote).join(\" \")\r\n}\r\n\r\nexport function buildDirectCommand(args: DaemonInstallArgs): string {\r\n const startArgs = buildStartArgs(args)\r\n return startArgs.map(shellQuote).join(\" \")\r\n}\r\n\r\nexport function isMacOS(): boolean {\r\n return process.platform === \"darwin\"\r\n}\r\n\r\nexport function isLinux(): boolean {\r\n return process.platform === \"linux\"\r\n}\r\n\r\nexport function isWindows(): boolean {\r\n return process.platform === \"win32\"\r\n}\r\n\r\nexport function assertSupported(): void {\r\n if (!isMacOS() && !isLinux() && !isWindows()) {\r\n console.error(\"Daemon management is only supported on macOS, Linux, and Windows.\")\r\n process.exit(1)\r\n }\r\n}\r\n","/* eslint-disable */\r\nimport { spawnSync } from \"node:child_process\"\r\nimport fs from \"node:fs\"\r\nimport os from \"node:os\"\r\nimport path from \"node:path\"\r\n\r\nimport {\r\n APP_DIR,\r\n ERR_FILE,\r\n LOG_FILE,\r\n buildDirectCommand,\r\n buildNpxCommand,\r\n launcherPath,\r\n} from \"./shared\"\r\nimport type { DaemonInstallArgs } from \"./shared\"\r\n\r\nconst LAUNCHD_LABEL = \"com.xc-copilot-api\"\r\n\r\nfunction plistPath(): string {\r\n return path.join(\r\n os.homedir(),\r\n \"Library\",\r\n \"LaunchAgents\",\r\n `${LAUNCHD_LABEL}.plist`,\r\n )\r\n}\r\n\r\nexport function installMacOS(args: DaemonInstallArgs): void {\r\n const plist = plistPath()\r\n const launcher = launcherPath()\r\n\r\n fs.mkdirSync(APP_DIR, { recursive: true })\r\n fs.mkdirSync(path.dirname(plist), { recursive: true })\r\n\r\n const execCmd = args.npx\r\n ? buildNpxCommand(args)\r\n : buildDirectCommand(args)\r\n\r\n // Launcher script sources login shell so PATH includes nvm, homebrew, etc.\r\n fs.writeFileSync(\r\n launcher,\r\n [\r\n \"#!/bin/zsh -l\",\r\n '[ -f \"$HOME/.zshrc\" ] && source \"$HOME/.zshrc\"',\r\n `exec ${execCmd}`,\r\n \"\",\r\n ].join(\"\\n\"),\r\n )\r\n fs.chmodSync(launcher, 0o755)\r\n\r\n const plistContent = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\r\n<plist version=\"1.0\">\r\n<dict>\r\n <key>Label</key>\r\n <string>${LAUNCHD_LABEL}</string>\r\n <key>ProgramArguments</key>\r\n <array>\r\n <string>${launcher}</string>\r\n </array>\r\n <key>WorkingDirectory</key>\r\n <string>${os.homedir()}</string>\r\n <key>RunAtLoad</key>\r\n <true/>\r\n <key>KeepAlive</key>\r\n <true/>\r\n <key>StandardOutPath</key>\r\n <string>${LOG_FILE}</string>\r\n <key>StandardErrorPath</key>\r\n <string>${ERR_FILE}</string>\r\n</dict>\r\n</plist>\r\n`\r\n fs.writeFileSync(plist, plistContent)\r\n\r\n console.log(`Installed LaunchAgent '${LAUNCHD_LABEL}'`)\r\n console.log(` Plist: ${plist}`)\r\n console.log(` Launcher: ${launcher}`)\r\n console.log(` Log: ${LOG_FILE}`)\r\n console.log(` Mode: ${args.npx ? \"npx (auto-update)\" : \"direct\"}`)\r\n console.log(` Start: xc-copilot-api-daemon restart`)\r\n}\r\n\r\nexport function uninstallMacOS(): void {\r\n stopMacOS()\r\n const plist = plistPath()\r\n if (fs.existsSync(plist)) {\r\n fs.unlinkSync(plist)\r\n console.log(`Removed LaunchAgent plist: ${plist}`)\r\n }\r\n const launcher = launcherPath()\r\n if (fs.existsSync(launcher)) {\r\n fs.unlinkSync(launcher)\r\n console.log(`Removed launcher: ${launcher}`)\r\n }\r\n console.log(`Uninstalled daemon '${LAUNCHD_LABEL}'`)\r\n}\r\n\r\nexport function stopMacOS(): boolean {\r\n const domain = `gui/${process.getuid?.() ?? 501}`\r\n const job = `${domain}/${LAUNCHD_LABEL}`\r\n const result = spawnSync(\"launchctl\", [\"bootout\", job], {\r\n encoding: \"utf-8\",\r\n timeout: 15000,\r\n })\r\n if (result.status === 0) {\r\n console.log(`Stopped LaunchAgent '${LAUNCHD_LABEL}'`)\r\n return true\r\n }\r\n const detail = (result.stderr || result.stdout || \"\").toLowerCase()\r\n if (detail.includes(\"not find\") || detail.includes(\"no such\")) {\r\n return true // not running\r\n }\r\n return false\r\n}\r\n\r\nexport function startMacOS(): boolean {\r\n const plist = plistPath()\r\n if (!fs.existsSync(plist)) {\r\n console.error(`LaunchAgent plist not found: ${plist}`)\r\n console.error(\"Run 'xc-copilot-api-daemon install' first.\")\r\n return false\r\n }\r\n\r\n const domain = `gui/${process.getuid?.() ?? 501}`\r\n const job = `${domain}/${LAUNCHD_LABEL}`\r\n\r\n // Bootstrap (load) the daemon\r\n const bootstrap = spawnSync(\"launchctl\", [\"bootstrap\", domain, plist], {\r\n encoding: \"utf-8\",\r\n timeout: 10000,\r\n })\r\n if (bootstrap.status !== 0) {\r\n const detail = (bootstrap.stderr || bootstrap.stdout || \"\").toLowerCase()\r\n if (!detail.includes(\"already\")) {\r\n console.error(`launchctl bootstrap failed: ${detail.trim()}`)\r\n return false\r\n }\r\n }\r\n\r\n // Kickstart -k kills existing instance and restarts\r\n const kick = spawnSync(\"launchctl\", [\"kickstart\", \"-k\", job], {\r\n encoding: \"utf-8\",\r\n timeout: 15000,\r\n })\r\n if (kick.status !== 0) {\r\n console.error(\r\n `launchctl kickstart failed: ${(kick.stderr || kick.stdout || \"\").trim()}`,\r\n )\r\n return false\r\n }\r\n\r\n console.log(`Started LaunchAgent '${LAUNCHD_LABEL}'`)\r\n return true\r\n}\r\n\r\nexport function statusMacOS(): void {\r\n const plist = plistPath()\r\n if (!fs.existsSync(plist)) {\r\n console.log(\"Daemon: not installed\")\r\n return\r\n }\r\n\r\n console.log(`Daemon: installed`)\r\n console.log(` Plist: ${plist}`)\r\n\r\n const launcher = launcherPath()\r\n if (fs.existsSync(launcher)) {\r\n const content = fs.readFileSync(launcher, \"utf-8\")\r\n const execLine = content\r\n .split(\"\\n\")\r\n .find((l) => l.startsWith(\"exec \"))\r\n if (execLine) {\r\n console.log(` Command: ${execLine.replace(\"exec \", \"\")}`)\r\n }\r\n }\r\n\r\n // Check if running via launchctl\r\n const result = spawnSync(\"launchctl\", [\"list\", LAUNCHD_LABEL], {\r\n encoding: \"utf-8\",\r\n timeout: 5000,\r\n })\r\n if (result.status === 0) {\r\n const output = result.stdout.trim()\r\n // Parse PID and status from launchctl list output\r\n const pidLine = output\r\n .split(\"\\n\")\r\n .find((l) => l.includes(\"PID\") || l.match(/^\\s*\"PID\"/))\r\n const lastExitLine = output\r\n .split(\"\\n\")\r\n .find((l) => l.includes(\"LastExitStatus\"))\r\n\r\n // launchctl list <label> outputs key-value pairs\r\n const pidMatch = output.match(/\"PID\"\\s*=\\s*(\\d+)/)\r\n const exitMatch = output.match(/\"LastExitStatus\"\\s*=\\s*(\\d+)/)\r\n\r\n if (pidMatch) {\r\n console.log(` Status: running (PID ${pidMatch[1]})`)\r\n } else {\r\n console.log(` Status: not running`)\r\n }\r\n if (exitMatch) {\r\n console.log(` Last exit: ${exitMatch[1]}`)\r\n }\r\n if (pidLine) void pidLine // suppress unused\r\n if (lastExitLine) void lastExitLine // suppress unused\r\n } else {\r\n console.log(\" Status: not loaded\")\r\n }\r\n\r\n // Show recent log\r\n if (fs.existsSync(LOG_FILE)) {\r\n const stat = fs.statSync(LOG_FILE)\r\n console.log(\r\n ` Log: ${LOG_FILE} (${(stat.size / 1024).toFixed(1)} KB)`,\r\n )\r\n }\r\n}\r\n\r\nexport interface CopilotJob {\r\n label: string\r\n pid: string | null\r\n plistPath: string | null\r\n}\r\n\r\nexport function findAllCopilotLaunchdJobs(): CopilotJob[] {\r\n const result = spawnSync(\"launchctl\", [\"list\"], {\r\n encoding: \"utf-8\",\r\n timeout: 5000,\r\n })\r\n if (result.status !== 0) return []\r\n\r\n const jobs: CopilotJob[] = []\r\n for (const line of result.stdout.split(\"\\n\")) {\r\n if (!line.toLowerCase().includes(\"copilot\")) continue\r\n const parts = line.trim().split(/\\s+/)\r\n if (parts.length < 3) continue\r\n const pid = parts[0] === \"-\" ? null : parts[0]\r\n const label = parts[2]\r\n const plist = path.join(\r\n os.homedir(),\r\n \"Library\",\r\n \"LaunchAgents\",\r\n `${label}.plist`,\r\n )\r\n jobs.push({\r\n label,\r\n pid,\r\n plistPath: fs.existsSync(plist) ? plist : null,\r\n })\r\n }\r\n return jobs\r\n}\r\n","/* eslint-disable */\r\nimport { spawnSync } from \"node:child_process\"\r\nimport fs from \"node:fs\"\r\nimport os from \"node:os\"\r\nimport path from \"node:path\"\r\n\r\nimport {\r\n APP_DIR,\r\n ERR_FILE,\r\n LOG_FILE,\r\n buildDirectCommand,\r\n buildNpxCommand,\r\n launcherPath,\r\n} from \"./shared\"\r\nimport type { DaemonInstallArgs } from \"./shared\"\r\n\r\nconst SYSTEMD_UNIT = \"xc-copilot-api.service\"\r\n\r\nfunction systemdUnitPath(): string {\r\n return path.join(\r\n os.homedir(),\r\n \".config\",\r\n \"systemd\",\r\n \"user\",\r\n SYSTEMD_UNIT,\r\n )\r\n}\r\n\r\nexport function installLinux(args: DaemonInstallArgs): void {\r\n const unitPath = systemdUnitPath()\r\n const launcher = launcherPath()\r\n\r\n fs.mkdirSync(APP_DIR, { recursive: true })\r\n fs.mkdirSync(path.dirname(unitPath), { recursive: true })\r\n\r\n const execCmd = args.npx\r\n ? buildNpxCommand(args)\r\n : buildDirectCommand(args)\r\n\r\n // Launcher script sources login shell\r\n fs.writeFileSync(\r\n launcher,\r\n [\r\n \"#!/bin/bash -l\",\r\n '[ -f \"$HOME/.bashrc\" ] && source \"$HOME/.bashrc\"',\r\n `exec ${execCmd}`,\r\n \"\",\r\n ].join(\"\\n\"),\r\n )\r\n fs.chmodSync(launcher, 0o755)\r\n\r\n const unitContent = `[Unit]\r\nDescription=xc-copilot-api - GitHub Copilot OpenAI Compatible API\r\nAfter=network.target\r\n\r\n[Service]\r\nType=simple\r\nExecStart=${launcher}\r\nRestart=on-failure\r\nRestartSec=10\r\nStandardOutput=append:${LOG_FILE}\r\nStandardError=append:${ERR_FILE}\r\n\r\n[Install]\r\nWantedBy=default.target\r\n`\r\n fs.writeFileSync(unitPath, unitContent)\r\n\r\n spawnSync(\"systemctl\", [\"--user\", \"daemon-reload\"], { encoding: \"utf-8\" })\r\n spawnSync(\"systemctl\", [\"--user\", \"enable\", SYSTEMD_UNIT], {\r\n encoding: \"utf-8\",\r\n })\r\n\r\n console.log(`Installed systemd unit '${SYSTEMD_UNIT}'`)\r\n console.log(` Unit: ${unitPath}`)\r\n console.log(` Launcher: ${launcher}`)\r\n console.log(` Log: ${LOG_FILE}`)\r\n console.log(` Mode: ${args.npx ? \"npx (auto-update)\" : \"direct\"}`)\r\n console.log(` Start: xc-copilot-api-daemon restart`)\r\n}\r\n\r\nexport function uninstallLinux(): void {\r\n spawnSync(\"systemctl\", [\"--user\", \"stop\", SYSTEMD_UNIT], {\r\n encoding: \"utf-8\",\r\n })\r\n spawnSync(\"systemctl\", [\"--user\", \"disable\", SYSTEMD_UNIT], {\r\n encoding: \"utf-8\",\r\n })\r\n const unitPath = systemdUnitPath()\r\n if (fs.existsSync(unitPath)) {\r\n fs.unlinkSync(unitPath)\r\n spawnSync(\"systemctl\", [\"--user\", \"daemon-reload\"], {\r\n encoding: \"utf-8\",\r\n })\r\n }\r\n const launcher = launcherPath()\r\n if (fs.existsSync(launcher)) {\r\n fs.unlinkSync(launcher)\r\n }\r\n console.log(`Uninstalled systemd unit '${SYSTEMD_UNIT}'`)\r\n}\r\n\r\nexport function startLinux(): boolean {\r\n const result = spawnSync(\r\n \"systemctl\",\r\n [\"--user\", \"start\", SYSTEMD_UNIT],\r\n { encoding: \"utf-8\", timeout: 10000 },\r\n )\r\n if (result.status !== 0) {\r\n console.error(\r\n `systemd start failed: ${(result.stderr || result.stdout || \"\").trim()}`,\r\n )\r\n return false\r\n }\r\n console.log(`Started systemd unit '${SYSTEMD_UNIT}'`)\r\n return true\r\n}\r\n\r\nexport function stopLinux(): boolean {\r\n const result = spawnSync(\r\n \"systemctl\",\r\n [\"--user\", \"stop\", SYSTEMD_UNIT],\r\n { encoding: \"utf-8\", timeout: 15000 },\r\n )\r\n if (result.status !== 0) {\r\n const detail = (result.stderr || result.stdout || \"\").trim()\r\n if (!detail.includes(\"not loaded\")) {\r\n console.error(`systemd stop failed: ${detail}`)\r\n return false\r\n }\r\n }\r\n console.log(`Stopped systemd unit '${SYSTEMD_UNIT}'`)\r\n return true\r\n}\r\n\r\nexport function statusLinux(): void {\r\n const unitPath = systemdUnitPath()\r\n if (!fs.existsSync(unitPath)) {\r\n console.log(\"Daemon: not installed\")\r\n return\r\n }\r\n\r\n console.log(\"Daemon: installed\")\r\n console.log(` Unit: ${unitPath}`)\r\n\r\n const launcher = launcherPath()\r\n if (fs.existsSync(launcher)) {\r\n const content = fs.readFileSync(launcher, \"utf-8\")\r\n const execLine = content\r\n .split(\"\\n\")\r\n .find((l) => l.startsWith(\"exec \"))\r\n if (execLine) {\r\n console.log(` Command: ${execLine.replace(\"exec \", \"\")}`)\r\n }\r\n }\r\n\r\n const result = spawnSync(\r\n \"systemctl\",\r\n [\"--user\", \"status\", SYSTEMD_UNIT, \"--no-pager\"],\r\n { encoding: \"utf-8\", timeout: 5000 },\r\n )\r\n // systemctl status returns non-zero if daemon is not running, that's ok\r\n console.log(result.stdout.trim())\r\n}\r\n\r\nexport function findAllCopilotSystemdUnits(): string[] {\r\n const result = spawnSync(\r\n \"systemctl\",\r\n [\"--user\", \"list-units\", \"--all\", \"--no-pager\", \"--plain\"],\r\n { encoding: \"utf-8\", timeout: 5000 },\r\n )\r\n if (result.status !== 0) return []\r\n const units: string[] = []\r\n for (const line of result.stdout.split(\"\\n\")) {\r\n if (line.toLowerCase().includes(\"copilot\")) {\r\n const unit = line.trim().split(/\\s+/)[0]\r\n if (unit) units.push(unit)\r\n }\r\n }\r\n return units\r\n}\r\n","/* eslint-disable */\r\nimport { spawnSync } from \"node:child_process\"\r\nimport fs from \"node:fs\"\r\nimport os from \"node:os\"\r\nimport path from \"node:path\"\r\n\r\nimport { buildStartArgs } from \"./shared\"\r\nimport type { DaemonInstallArgs } from \"./shared\"\r\n\r\nconst WINDOWS_TASK_NAME = \"XcCopilotApi\"\r\n\r\nfunction windowsAppDir(): string {\r\n const localAppData = process.env.LOCALAPPDATA || path.join(os.homedir(), \"AppData\", \"Local\")\r\n return path.join(localAppData, \"copilot-api\")\r\n}\r\n\r\nfunction windowsLauncherCmdPath(): string {\r\n return path.join(windowsAppDir(), \"launcher.cmd\")\r\n}\r\n\r\nexport function windowsLogFile(): string {\r\n return path.join(windowsAppDir(), \"copilot-api.log\")\r\n}\r\n\r\nfunction buildWindowsCommand(args: DaemonInstallArgs): string {\r\n const startArgs = buildStartArgs(args)\r\n if (args.npx) {\r\n startArgs[0] = \"xc-copilot-api@latest\"\r\n const parts = [\"npx\", \"-y\", ...startArgs]\r\n return parts.map((s) => (s.includes(\" \") ? `\"${s}\"` : s)).join(\" \")\r\n }\r\n return startArgs.map((s) => (s.includes(\" \") ? `\"${s}\"` : s)).join(\" \")\r\n}\r\n\r\nexport function installWindows(args: DaemonInstallArgs): void {\r\n const appDir = windowsAppDir()\r\n const logFile = windowsLogFile()\r\n const errFile = path.join(appDir, \"copilot-api.err\")\r\n const launcherCmd = windowsLauncherCmdPath()\r\n\r\n fs.mkdirSync(appDir, { recursive: true })\r\n\r\n const execCmd = buildWindowsCommand(args)\r\n\r\n // CMD launcher script with log redirection\r\n const cmdContent = [\r\n \"@echo off\",\r\n `cd /d \"%USERPROFILE%\"`,\r\n `${execCmd} >> \"${logFile}\" 2>> \"${errFile}\"`,\r\n \"\",\r\n ].join(\"\\r\\n\")\r\n fs.writeFileSync(launcherCmd, cmdContent)\r\n\r\n // Register as a scheduled task (on-logon trigger, no admin needed)\r\n const psCmd = [\r\n `$action = New-ScheduledTaskAction -Execute 'cmd.exe' -Argument '/c \"${launcherCmd}\"'`,\r\n `$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME`,\r\n `$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero)`,\r\n `Register-ScheduledTask -TaskName '${WINDOWS_TASK_NAME}' -Action $action -Trigger $trigger -Settings $settings -Force`,\r\n ].join(\"; \")\r\n const result = spawnSync(\"powershell\", [\r\n \"-NoProfile\", \"-Command\", psCmd,\r\n ], { encoding: \"utf-8\", timeout: 15000 })\r\n\r\n if (result.status !== 0) {\r\n console.error(`Failed to create scheduled task: ${(result.stderr || \"\").trim()}`)\r\n process.exit(1)\r\n }\r\n\r\n console.log(`Installed scheduled task '${WINDOWS_TASK_NAME}'`)\r\n console.log(` Launcher: ${launcherCmd}`)\r\n console.log(` Log: ${logFile}`)\r\n console.log(` Mode: ${args.npx ? \"npx (auto-update)\" : \"direct\"}`)\r\n console.log(` Start: xc-copilot-api-daemon restart`)\r\n}\r\n\r\nexport function uninstallWindows(): void {\r\n stopWindows()\r\n\r\n // Remove scheduled task\r\n spawnSync(\"schtasks\", [\r\n \"/delete\",\r\n \"/tn\", WINDOWS_TASK_NAME,\r\n \"/f\",\r\n ], { encoding: \"utf-8\", timeout: 10000 })\r\n\r\n const launcherCmd = windowsLauncherCmdPath()\r\n if (fs.existsSync(launcherCmd)) fs.unlinkSync(launcherCmd)\r\n\r\n console.log(`Uninstalled scheduled task '${WINDOWS_TASK_NAME}'`)\r\n}\r\n\r\nexport function startWindows(): boolean {\r\n const result = spawnSync(\"schtasks\", [\r\n \"/run\",\r\n \"/tn\", WINDOWS_TASK_NAME,\r\n ], { encoding: \"utf-8\", timeout: 10000 })\r\n\r\n if (result.status !== 0) {\r\n console.error(`Scheduled task '${WINDOWS_TASK_NAME}' not found.`)\r\n console.error(\"Run 'xc-copilot-api-daemon install' first.\")\r\n return false\r\n }\r\n\r\n console.log(\"Started xc-copilot-api (background)\")\r\n return true\r\n}\r\n\r\nexport function findCopilotPids(filter: string): string[] {\r\n // Use WQL filter; exclude the PowerShell process itself ($PID) to avoid self-matching\r\n const wqlFilter = filter.replace(/\\*/g, \"%\")\r\n const result = spawnSync(\"powershell\", [\r\n \"-NoProfile\", \"-Command\",\r\n `Get-CimInstance Win32_Process -Filter \"CommandLine LIKE '${wqlFilter}' AND ProcessId != $PID\" | Select-Object -ExpandProperty ProcessId`,\r\n ], { encoding: \"utf-8\", timeout: 10000 })\r\n\r\n if (result.status !== 0) return []\r\n return result.stdout.split(\"\\n\").map((l) => l.trim()).filter(Boolean)\r\n}\r\n\r\nexport function stopWindows(): boolean {\r\n // Find copilot-api processes excluding daemon management and self\r\n const result = spawnSync(\"powershell\", [\r\n \"-NoProfile\", \"-Command\",\r\n `Get-CimInstance Win32_Process -Filter \"CommandLine LIKE '%copilot-api%' AND NOT (CommandLine LIKE '%daemon%') AND ProcessId != $PID\" | Select-Object -ExpandProperty ProcessId`,\r\n ], { encoding: \"utf-8\", timeout: 10000 })\r\n\r\n const pids = (result.status === 0 ? result.stdout : \"\")\r\n .split(\"\\n\").map((l) => l.trim()).filter(Boolean)\r\n\r\n for (const pid of pids) {\r\n spawnSync(\"taskkill\", [\"/PID\", pid, \"/F\"], { encoding: \"utf-8\", timeout: 5000 })\r\n }\r\n\r\n if (pids.length > 0) {\r\n console.log(`Stopped ${pids.length} process(es)`)\r\n return true\r\n }\r\n\r\n console.log(\"No copilot-api processes found.\")\r\n return true\r\n}\r\n\r\nexport function statusWindows(): void {\r\n // Check scheduled task\r\n const taskResult = spawnSync(\"schtasks\", [\r\n \"/query\",\r\n \"/tn\", WINDOWS_TASK_NAME,\r\n \"/fo\", \"LIST\",\r\n ], { encoding: \"utf-8\", timeout: 5000 })\r\n\r\n if (taskResult.status !== 0) {\r\n console.log(\"Daemon: not installed\")\r\n return\r\n }\r\n\r\n console.log(\"Daemon: installed\")\r\n\r\n // Parse task status from schtasks output\r\n const statusMatch = (taskResult.stdout || \"\").match(/Status:\\s*(.+)/i)\r\n if (statusMatch) {\r\n console.log(` Task: ${statusMatch[1].trim()}`)\r\n }\r\n\r\n // Show command from CMD launcher\r\n const launcherCmd = windowsLauncherCmdPath()\r\n if (fs.existsSync(launcherCmd)) {\r\n const content = fs.readFileSync(launcherCmd, \"utf-8\")\r\n const lines = content.split(/\\r?\\n/).filter((l) => l && !l.startsWith(\"@\") && !l.startsWith(\"cd \"))\r\n if (lines.length > 0) {\r\n // Strip log redirection to show just the command\r\n const cmd = lines[0].replace(/\\s*>>.*$/, \"\").trim()\r\n if (cmd) console.log(` Command: ${cmd}`)\r\n }\r\n }\r\n\r\n // Check if running\r\n const pids = findCopilotPids(\"*copilot-api*start*\")\r\n\r\n console.log(pids.length > 0\r\n ? ` Status: running (PID ${pids.join(\", \")})`\r\n : \" Status: not running\")\r\n\r\n const logFile = windowsLogFile()\r\n if (fs.existsSync(logFile)) {\r\n const stat = fs.statSync(logFile)\r\n console.log(` Log: ${logFile} (${(stat.size / 1024).toFixed(1)} KB)`)\r\n }\r\n}\r\n","/* eslint-disable */\r\nimport { execSync, spawnSync } from \"node:child_process\"\r\nimport fs from \"node:fs\"\r\n\r\nimport { defineCommand } from \"citty\"\r\n\r\nimport { findAllCopilotLaunchdJobs } from \"./macos\"\r\nimport { installMacOS, startMacOS, statusMacOS, stopMacOS, uninstallMacOS } from \"./macos\"\r\nimport { findAllCopilotSystemdUnits } from \"./linux\"\r\nimport { installLinux, startLinux, statusLinux, stopLinux, uninstallLinux } from \"./linux\"\r\nimport { installWindows, startWindows, statusWindows, stopWindows, uninstallWindows, windowsLogFile } from \"./windows\"\r\nimport {\r\n LOG_FILE,\r\n assertSupported,\r\n isMacOS,\r\n isLinux,\r\n isWindows,\r\n} from \"./shared\"\r\nimport type { CopilotProcess, DaemonInstallArgs } from \"./shared\"\r\n\r\n// ---------------------------------------------------------------------------\r\n// --all: find all copilot-api related processes\r\n// ---------------------------------------------------------------------------\r\n\r\nfunction findAllCopilotProcesses(): CopilotProcess[] {\r\n if (isWindows()) {\r\n const result = spawnSync(\"powershell\", [\r\n \"-NoProfile\", \"-Command\",\r\n `Get-CimInstance Win32_Process -Filter \"CommandLine LIKE '%copilot-api%' AND ProcessId != $PID\" | ForEach-Object { \"$($_.ProcessId)|$($_.CommandLine)\" }`,\r\n ], { encoding: \"utf-8\", timeout: 10000 })\r\n if (result.status !== 0) return []\r\n const procs: CopilotProcess[] = []\r\n for (const line of result.stdout.trim().split(\"\\n\")) {\r\n if (!line.trim()) continue\r\n const sep = line.indexOf(\"|\")\r\n if (sep < 0) continue\r\n procs.push({ pid: line.slice(0, sep).trim(), command: line.slice(sep + 1).trim() })\r\n }\r\n return procs\r\n }\r\n\r\n try {\r\n const output = execSync(\r\n \"ps aux | grep -i copilot-api | grep -v grep\",\r\n { encoding: \"utf-8\", timeout: 5000 },\r\n )\r\n const procs: CopilotProcess[] = []\r\n for (const line of output.trim().split(\"\\n\")) {\r\n if (!line) continue\r\n const parts = line.trim().split(/\\s+/)\r\n if (parts.length < 11) continue\r\n const pid = parts[1]\r\n const command = parts.slice(10).join(\" \")\r\n procs.push({ pid, command })\r\n }\r\n return procs\r\n } catch {\r\n return []\r\n }\r\n}\r\n\r\nfunction statusAll(): void {\r\n if (isMacOS()) {\r\n const jobs = findAllCopilotLaunchdJobs()\r\n if (jobs.length > 0) {\r\n console.log(\"=== LaunchAgent Jobs ===\")\r\n for (const job of jobs) {\r\n console.log(`\\n Label: ${job.label}`)\r\n if (job.plistPath) console.log(` Plist: ${job.plistPath}`)\r\n else console.log(` Plist: (not found)`)\r\n console.log(` PID: ${job.pid ?? \"not running\"}`)\r\n }\r\n } else {\r\n console.log(\"No copilot-api LaunchAgent jobs found.\")\r\n }\r\n } else if (isWindows()) {\r\n statusWindows()\r\n } else {\r\n const units = findAllCopilotSystemdUnits()\r\n if (units.length > 0) {\r\n console.log(\"=== Systemd Units ===\")\r\n for (const unit of units) {\r\n const r = spawnSync(\r\n \"systemctl\",\r\n [\"--user\", \"status\", unit, \"--no-pager\"],\r\n { encoding: \"utf-8\", timeout: 5000 },\r\n )\r\n console.log(`\\n--- ${unit} ---`)\r\n console.log(r.stdout.trim())\r\n }\r\n } else {\r\n console.log(\"No copilot-api systemd units found.\")\r\n }\r\n }\r\n\r\n const procs = findAllCopilotProcesses()\r\n if (procs.length > 0) {\r\n console.log(\"\\n=== Processes ===\")\r\n for (const proc of procs) {\r\n console.log(` PID ${proc.pid}: ${proc.command}`)\r\n }\r\n }\r\n}\r\n\r\nfunction stopAll(): void {\r\n let stopped = 0\r\n\r\n if (isMacOS()) {\r\n const jobs = findAllCopilotLaunchdJobs()\r\n const domain = `gui/${process.getuid?.() ?? 501}`\r\n for (const job of jobs) {\r\n const jobTarget = `${domain}/${job.label}`\r\n console.log(`Stopping LaunchAgent '${job.label}'...`)\r\n spawnSync(\"launchctl\", [\"bootout\", jobTarget], {\r\n encoding: \"utf-8\",\r\n timeout: 15000,\r\n })\r\n stopped++\r\n }\r\n } else if (!isWindows()) {\r\n const units = findAllCopilotSystemdUnits()\r\n for (const unit of units) {\r\n console.log(`Stopping systemd unit '${unit}'...`)\r\n spawnSync(\"systemctl\", [\"--user\", \"stop\", unit], {\r\n encoding: \"utf-8\",\r\n timeout: 15000,\r\n })\r\n stopped++\r\n }\r\n }\r\n\r\n // Kill remaining processes\r\n const procs = findAllCopilotProcesses()\r\n for (const proc of procs) {\r\n console.log(`Killing PID ${proc.pid}: ${proc.command}`)\r\n if (isWindows()) {\r\n spawnSync(\"taskkill\", [\"/PID\", proc.pid, \"/F\"], { encoding: \"utf-8\", timeout: 5000 })\r\n stopped++\r\n } else {\r\n try {\r\n process.kill(Number.parseInt(proc.pid, 10), \"SIGTERM\")\r\n stopped++\r\n } catch {\r\n // already dead\r\n }\r\n }\r\n }\r\n\r\n if (stopped === 0) {\r\n console.log(\"No copilot-api processes found.\")\r\n } else {\r\n console.log(`\\nStopped/killed ${stopped} item(s).`)\r\n }\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// CLI subcommands\r\n// ---------------------------------------------------------------------------\r\n\r\nconst installCmd = defineCommand({\r\n meta: {\r\n name: \"install\",\r\n description:\r\n \"Install xc-copilot-api daemon (launchd on macOS, systemd on Linux, Task Scheduler on Windows)\",\r\n },\r\n args: {\r\n npx: {\r\n type: \"boolean\",\r\n default: true,\r\n description:\r\n \"Use npx to run (auto-updates on restart). Set --no-npx to use direct binary.\",\r\n },\r\n port: {\r\n alias: \"p\",\r\n type: \"string\",\r\n default: \"4141\",\r\n description: \"Port for the API server\",\r\n },\r\n verbose: {\r\n alias: \"v\",\r\n type: \"boolean\",\r\n default: false,\r\n description: \"Enable verbose logging\",\r\n },\r\n \"account-type\": {\r\n alias: \"a\",\r\n type: \"string\",\r\n default: \"individual\",\r\n description: \"Account type (individual, business, enterprise)\",\r\n },\r\n \"github-token\": {\r\n alias: \"g\",\r\n type: \"string\",\r\n description: \"GitHub token to use\",\r\n },\r\n \"proxy-env\": {\r\n type: \"boolean\",\r\n default: false,\r\n description: \"Initialize proxy from environment variables\",\r\n },\r\n },\r\n run({ args }) {\r\n assertSupported()\r\n const installArgs: DaemonInstallArgs = {\r\n npx: args.npx,\r\n port: args.port,\r\n verbose: args.verbose,\r\n accountType: args[\"account-type\"],\r\n githubToken: args[\"github-token\"],\r\n proxyEnv: args[\"proxy-env\"],\r\n }\r\n if (isMacOS()) {\r\n installMacOS(installArgs)\r\n } else if (isWindows()) {\r\n installWindows(installArgs)\r\n } else {\r\n installLinux(installArgs)\r\n }\r\n },\r\n})\r\n\r\nconst uninstallCmd = defineCommand({\r\n meta: {\r\n name: \"uninstall\",\r\n description: \"Uninstall the daemon\",\r\n },\r\n run() {\r\n assertSupported()\r\n if (isMacOS()) {\r\n uninstallMacOS()\r\n } else if (isWindows()) {\r\n uninstallWindows()\r\n } else {\r\n uninstallLinux()\r\n }\r\n },\r\n})\r\n\r\nconst statusCmd = defineCommand({\r\n meta: {\r\n name: \"status\",\r\n description: \"Show daemon status (use --all to show all copilot-api instances)\",\r\n },\r\n args: {\r\n all: {\r\n type: \"boolean\",\r\n default: false,\r\n description:\r\n \"Show all copilot-api related daemons and processes\",\r\n },\r\n },\r\n run({ args }) {\r\n assertSupported()\r\n if (args.all) {\r\n statusAll()\r\n } else if (isMacOS()) {\r\n statusMacOS()\r\n } else if (isWindows()) {\r\n statusWindows()\r\n } else {\r\n statusLinux()\r\n }\r\n },\r\n})\r\n\r\nconst restartCmd = defineCommand({\r\n meta: {\r\n name: \"restart\",\r\n description:\r\n \"Restart the daemon (npx mode fetches latest version automatically)\",\r\n },\r\n run() {\r\n assertSupported()\r\n if (isMacOS()) {\r\n if (!startMacOS()) process.exit(1)\r\n } else if (isWindows()) {\r\n stopWindows()\r\n if (!startWindows()) process.exit(1)\r\n } else {\r\n stopLinux()\r\n if (!startLinux()) process.exit(1)\r\n }\r\n },\r\n})\r\n\r\nconst stopCmd = defineCommand({\r\n meta: {\r\n name: \"stop\",\r\n description: \"Stop the daemon (use --all to kill all copilot-api instances)\",\r\n },\r\n args: {\r\n all: {\r\n type: \"boolean\",\r\n default: false,\r\n description:\r\n \"Stop all copilot-api related daemons and kill all processes\",\r\n },\r\n },\r\n run({ args }) {\r\n assertSupported()\r\n if (args.all) {\r\n stopAll()\r\n } else if (isMacOS()) {\r\n if (!stopMacOS()) process.exit(1)\r\n } else if (isWindows()) {\r\n if (!stopWindows()) process.exit(1)\r\n } else {\r\n if (!stopLinux()) process.exit(1)\r\n }\r\n },\r\n})\r\n\r\nconst logsCmd = defineCommand({\r\n meta: {\r\n name: \"logs\",\r\n description: \"Show recent daemon logs\",\r\n },\r\n args: {\r\n follow: {\r\n alias: \"f\",\r\n type: \"boolean\",\r\n default: false,\r\n description: \"Follow log output (like tail -f)\",\r\n },\r\n lines: {\r\n alias: \"n\",\r\n type: \"string\",\r\n default: \"50\",\r\n description: \"Number of lines to show\",\r\n },\r\n },\r\n run({ args }) {\r\n assertSupported()\r\n const logPath = isWindows() ? windowsLogFile() : LOG_FILE\r\n if (!fs.existsSync(logPath)) {\r\n console.log(\"No log file found.\")\r\n return\r\n }\r\n\r\n if (isWindows()) {\r\n // Windows: use powershell Get-Content\r\n if (args.follow) {\r\n const { status } = spawnSync(\"powershell\", [\"-Command\", `Get-Content -Path '${logPath}' -Wait -Tail ${args.lines}`], { stdio: \"inherit\" })\r\n process.exit(status ?? 0)\r\n } else {\r\n const { status } = spawnSync(\"powershell\", [\"-Command\", `Get-Content -Path '${logPath}' -Tail ${args.lines}`], { stdio: \"inherit\" })\r\n process.exit(status ?? 0)\r\n }\r\n } else {\r\n if (args.follow) {\r\n const { status } = spawnSync(\"tail\", [\"-f\", logPath], { stdio: \"inherit\" })\r\n process.exit(status ?? 0)\r\n } else {\r\n const { status } = spawnSync(\"tail\", [\"-n\", args.lines, logPath], { stdio: \"inherit\" })\r\n process.exit(status ?? 0)\r\n }\r\n }\r\n },\r\n})\r\n\r\n// ---------------------------------------------------------------------------\r\n// Main daemon command\r\n// ---------------------------------------------------------------------------\r\n\r\nexport const daemon = defineCommand({\r\n meta: {\r\n name: \"xc-copilot-api-daemon\",\r\n description:\r\n \"Manage xc-copilot-api daemon (install, status, restart, stop, uninstall, logs)\",\r\n },\r\n subCommands: {\r\n install: installCmd,\r\n uninstall: uninstallCmd,\r\n status: statusCmd,\r\n restart: restartCmd,\r\n stop: stopCmd,\r\n logs: logsCmd,\r\n },\r\n})\r\n","#!/usr/bin/env node\n\nimport { runMain } from \"citty\"\n\nimport { daemon } from \"./daemon/index\"\n\nawait runMain(daemon)\n"],"mappings":";;;;;;;;AAIA,MAAa,UAAU,KAAK,KAAK,GAAG,SAAS,EAAE,UAAU,SAAS,cAAc;AAChF,MAAa,WAAW,KAAK,KAAK,SAAS,kBAAkB;AAC7D,MAAa,WAAW,KAAK,KAAK,SAAS,kBAAkB;AAgB7D,SAAgB,eAAuB;AACrC,QAAO,KAAK,KAAK,SAAS,cAAc;;AAG1C,SAAgB,eAAe,MAAmC;CAChE,MAAM,MAAM,CAAC,kBAAkB,QAAQ;AACvC,KAAI,KAAK,KAAM,KAAI,KAAK,UAAU,KAAK,KAAK;AAC5C,KAAI,KAAK,QAAS,KAAI,KAAK,YAAY;AACvC,KAAI,KAAK,eAAe,KAAK,gBAAgB,aAC3C,KAAI,KAAK,kBAAkB,KAAK,YAAY;AAC9C,KAAI,KAAK,YAAa,KAAI,KAAK,kBAAkB,KAAK,YAAY;AAClE,KAAI,KAAK,SAAU,KAAI,KAAK,cAAc;AAC1C,QAAO;;AAGT,SAAgB,WAAW,GAAmB;AAC5C,KAAI,gBAAgB,KAAK,EAAE,CAAE,QAAO;AACpC,QAAO,IAAI,EAAE,QAAQ,MAAM,QAAQ,CAAC;;AAGtC,SAAgB,gBAAgB,MAAiC;CAC/D,MAAM,YAAY,eAAe,KAAK;AAEtC,WAAU,KAAK;AACf,QAAO;EAAC;EAAO;EAAM,GAAG;EAAU,CAAC,IAAI,WAAW,CAAC,KAAK,IAAI;;AAG9D,SAAgB,mBAAmB,MAAiC;AAElE,QAD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