alink-cli 0.11.11 → 0.11.13
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/README.md +1 -0
- package/bin/agentlink.js +2 -0
- package/dist/bin.mjs +44 -6
- package/dist/bin.mjs.map +1 -1
- package/dist/ui.js +67 -2
- package/package.json +1 -1
package/dist/ui.js
CHANGED
|
@@ -48116,7 +48116,7 @@ var import_react20 = __toESM(require_react(), 1);
|
|
|
48116
48116
|
var import_react21 = __toESM(require_react(), 1);
|
|
48117
48117
|
|
|
48118
48118
|
// src/daemonControl.ts
|
|
48119
|
-
import { spawn } from "node:child_process";
|
|
48119
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
48120
48120
|
import {
|
|
48121
48121
|
chmodSync,
|
|
48122
48122
|
existsSync as existsSync2,
|
|
@@ -48133,6 +48133,16 @@ var STATE_DIR = process.env.AGENTLINK_STATE_DIR || join(homedir(), ".agentlink")
|
|
|
48133
48133
|
var CREDENTIAL_FILE = join(STATE_DIR, "credential");
|
|
48134
48134
|
var PID_FILE = join(STATE_DIR, "daemon.pid");
|
|
48135
48135
|
var STATUS_FILE = join(STATE_DIR, "status.json");
|
|
48136
|
+
var LAUNCH_AGENT_LABEL = "com.harmopath.agentlink.daemon";
|
|
48137
|
+
var CLI_VERSION = JSON.parse(
|
|
48138
|
+
readFileSync2(new URL("../package.json", import.meta.url), "utf8")
|
|
48139
|
+
).version;
|
|
48140
|
+
var LAUNCH_AGENT_FILE = join(
|
|
48141
|
+
homedir(),
|
|
48142
|
+
"Library",
|
|
48143
|
+
"LaunchAgents",
|
|
48144
|
+
`${LAUNCH_AGENT_LABEL}.plist`
|
|
48145
|
+
);
|
|
48136
48146
|
var DAEMON_LOCK_FILE = join(
|
|
48137
48147
|
resolve(process.env.T3CODE_HOME || join(homedir(), ".t3")),
|
|
48138
48148
|
"userdata",
|
|
@@ -48243,10 +48253,58 @@ function daemonPid() {
|
|
|
48243
48253
|
function isDaemonRunning() {
|
|
48244
48254
|
return daemonPid() !== void 0;
|
|
48245
48255
|
}
|
|
48256
|
+
function xml(value) {
|
|
48257
|
+
return value.replaceAll("&", "&").replaceAll('"', """).replaceAll("'", "'").replaceAll("<", "<").replaceAll(">", ">");
|
|
48258
|
+
}
|
|
48259
|
+
function launchAgentDomain() {
|
|
48260
|
+
return `gui/${process.getuid?.() ?? 0}`;
|
|
48261
|
+
}
|
|
48262
|
+
function canUseLaunchAgent() {
|
|
48263
|
+
return process.platform === "darwin" && STATE_DIR === join(homedir(), ".agentlink");
|
|
48264
|
+
}
|
|
48265
|
+
function startLaunchAgent(options) {
|
|
48266
|
+
const cliPath = fileURLToPath(new URL("../bin/agentlink.js", import.meta.url));
|
|
48267
|
+
const args = ["--no-tui", "--hub", normalizeHub(options.hub), "--dir", resolve(options.cwd)];
|
|
48268
|
+
const env3 = [
|
|
48269
|
+
options.approval ? ["AGENTLINK_APPROVAL", "1"] : void 0,
|
|
48270
|
+
options.approvalRenotifyMin !== void 0 ? ["AGENTLINK_APPROVAL_RENOTIFY_MIN", String(options.approvalRenotifyMin)] : void 0
|
|
48271
|
+
].filter((entry) => Boolean(entry));
|
|
48272
|
+
const environment = env3.length ? `<key>EnvironmentVariables</key><dict>${env3.map(([key, value]) => `<key>${xml(key)}</key><string>${xml(value)}</string>`).join("")}</dict>` : "";
|
|
48273
|
+
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
48274
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
48275
|
+
<plist version="1.0"><dict>
|
|
48276
|
+
<key>Label</key><string>${LAUNCH_AGENT_LABEL}</string>
|
|
48277
|
+
<key>ProgramArguments</key><array>${[process.execPath, cliPath, ...args].map((arg) => `<string>${xml(arg)}</string>`).join("")}</array>
|
|
48278
|
+
${environment}
|
|
48279
|
+
<key>RunAtLoad</key><true/><key>KeepAlive</key><true/>
|
|
48280
|
+
<key>StandardOutPath</key><string>${xml(join(STATE_DIR, "daemon.log"))}</string>
|
|
48281
|
+
<key>StandardErrorPath</key><string>${xml(join(STATE_DIR, "daemon.err.log"))}</string>
|
|
48282
|
+
</dict></plist>
|
|
48283
|
+
`;
|
|
48284
|
+
mkdirSync(join(homedir(), "Library", "LaunchAgents"), { recursive: true });
|
|
48285
|
+
writeFileSync(LAUNCH_AGENT_FILE, plist, { mode: 384 });
|
|
48286
|
+
spawnSync("launchctl", ["bootout", `${launchAgentDomain()}/${LAUNCH_AGENT_LABEL}`], {
|
|
48287
|
+
stdio: "ignore"
|
|
48288
|
+
});
|
|
48289
|
+
const result = spawnSync("launchctl", ["bootstrap", launchAgentDomain(), LAUNCH_AGENT_FILE], {
|
|
48290
|
+
encoding: "utf8"
|
|
48291
|
+
});
|
|
48292
|
+
if (result.status !== 0) {
|
|
48293
|
+
throw new Error(result.stderr.trim() || "launchd \u65E0\u6CD5\u542F\u52A8 daemon");
|
|
48294
|
+
}
|
|
48295
|
+
const status = spawnSync("launchctl", ["print", `${launchAgentDomain()}/${LAUNCH_AGENT_LABEL}`], {
|
|
48296
|
+
encoding: "utf8"
|
|
48297
|
+
}).stdout;
|
|
48298
|
+
const pid = Number(status.match(/^\s*pid = (\d+)$/m)?.[1]);
|
|
48299
|
+
if (!pid) throw new Error("launchd \u5DF2\u5B89\u88C5\uFF0C\u4F46 daemon \u5C1A\u672A\u542F\u52A8");
|
|
48300
|
+
writeStatus({ state: "starting", hub: normalizeHub(options.hub), startedAt: Date.now() });
|
|
48301
|
+
return pid;
|
|
48302
|
+
}
|
|
48246
48303
|
function startDaemon(options) {
|
|
48247
48304
|
if (isDaemonRunning()) {
|
|
48248
48305
|
throw new Error("daemon is already running");
|
|
48249
48306
|
}
|
|
48307
|
+
if (canUseLaunchAgent()) return startLaunchAgent(options);
|
|
48250
48308
|
const { machineToken, enckey } = parseCredential(options.credential);
|
|
48251
48309
|
const cwd2 = resolve(options.cwd);
|
|
48252
48310
|
const daemonPath = options.daemonPath ? resolve(options.daemonPath) : fileURLToPath(new URL("../dist/bin.mjs", import.meta.url));
|
|
@@ -48261,7 +48319,8 @@ function startDaemon(options) {
|
|
|
48261
48319
|
...process.env,
|
|
48262
48320
|
T3CODE_HUB_URL: normalizeHub(options.hub),
|
|
48263
48321
|
T3CODE_HUB_MACHINE_TOKEN: machineToken,
|
|
48264
|
-
T3CODE_HUB_ENCKEY: enckey
|
|
48322
|
+
T3CODE_HUB_ENCKEY: enckey,
|
|
48323
|
+
AGENTLINK_CLI_VERSION: CLI_VERSION
|
|
48265
48324
|
};
|
|
48266
48325
|
if (process.versions.electron) env3.ELECTRON_RUN_AS_NODE = "1";
|
|
48267
48326
|
if (options.approval) env3.AGENTLINK_APPROVAL = "1";
|
|
@@ -48282,6 +48341,12 @@ function startDaemon(options) {
|
|
|
48282
48341
|
return child.pid;
|
|
48283
48342
|
}
|
|
48284
48343
|
async function stopDaemon(timeoutMs = 1e4) {
|
|
48344
|
+
if (canUseLaunchAgent() && existsSync2(LAUNCH_AGENT_FILE)) {
|
|
48345
|
+
spawnSync("launchctl", ["bootout", `${launchAgentDomain()}/${LAUNCH_AGENT_LABEL}`], {
|
|
48346
|
+
stdio: "ignore"
|
|
48347
|
+
});
|
|
48348
|
+
rmSync(LAUNCH_AGENT_FILE, { force: true });
|
|
48349
|
+
}
|
|
48285
48350
|
const pid = daemonPid();
|
|
48286
48351
|
if (!pid) {
|
|
48287
48352
|
return;
|
package/package.json
CHANGED