@kiki_agent/daemon 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.cjs +87 -22
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -50983,7 +50983,7 @@ var require_promisify = __commonJS({
50983
50983
  util.toFastProperties(obj2);
50984
50984
  return obj2;
50985
50985
  }
50986
- function promisify4(callback, receiver, multiArgs) {
50986
+ function promisify5(callback, receiver, multiArgs) {
50987
50987
  return makeNodePromisified(
50988
50988
  callback,
50989
50989
  receiver,
@@ -51003,7 +51003,7 @@ var require_promisify = __commonJS({
51003
51003
  options = Object(options);
51004
51004
  var receiver = options.context === void 0 ? THIS : options.context;
51005
51005
  var multiArgs = !!options.multiArgs;
51006
- var ret2 = promisify4(fn, receiver, multiArgs);
51006
+ var ret2 = promisify5(fn, receiver, multiArgs);
51007
51007
  util.copyDescriptors(fn, ret2, propsFilter);
51008
51008
  return ret2;
51009
51009
  };
@@ -57558,7 +57558,7 @@ var require_excel = __commonJS({
57558
57558
  });
57559
57559
 
57560
57560
  // src/cli.ts
57561
- var import_child_process5 = require("child_process");
57561
+ var import_child_process6 = require("child_process");
57562
57562
  var import_fs15 = __toESM(require("fs"));
57563
57563
  var import_path11 = __toESM(require("path"));
57564
57564
 
@@ -67861,11 +67861,48 @@ async function runGoalTask(input) {
67861
67861
  }
67862
67862
  }
67863
67863
 
67864
- // ../../src/lib/server/runtimeEnvValidation.ts
67865
- var import_promises2 = require("fs/promises");
67864
+ // ../../src/lib/server/runtime/selectWorkingDirectory.ts
67866
67865
  var import_child_process3 = require("child_process");
67867
67866
  var import_util2 = require("util");
67868
67867
  var execFileAsync2 = (0, import_util2.promisify)(import_child_process3.execFile);
67868
+ function normalizeSelectedPath(path13) {
67869
+ const trimmed = path13.trim();
67870
+ if (trimmed === "/") return trimmed;
67871
+ return trimmed.replace(/\/+$/, "");
67872
+ }
67873
+ async function pickDirectoryWithOsascript() {
67874
+ if (process.platform !== "darwin") {
67875
+ throw new Error("\u5F53\u524D\u7CFB\u7EDF\u4E0D\u652F\u6301\u539F\u751F\u76EE\u5F55\u9009\u62E9\u5668\uFF0C\u8BF7\u624B\u52A8\u8F93\u5165\u8DEF\u5F84");
67876
+ }
67877
+ try {
67878
+ const { stdout } = await execFileAsync2(
67879
+ "osascript",
67880
+ [
67881
+ "-e",
67882
+ 'set selectedFolder to choose folder with prompt "\u9009\u62E9 KiKi Runtime \u5DE5\u4F5C\u76EE\u5F55"',
67883
+ "-e",
67884
+ "POSIX path of selectedFolder"
67885
+ ],
67886
+ {
67887
+ timeout: 5 * 60 * 1e3,
67888
+ maxBuffer: 1024 * 1024
67889
+ }
67890
+ );
67891
+ return { path: normalizeSelectedPath(stdout) };
67892
+ } catch (error) {
67893
+ const message = error instanceof Error ? error.message : "\u76EE\u5F55\u9009\u62E9\u5931\u8D25";
67894
+ if (message.includes("User canceled")) {
67895
+ return { canceled: true };
67896
+ }
67897
+ throw error;
67898
+ }
67899
+ }
67900
+
67901
+ // ../../src/lib/server/runtimeEnvValidation.ts
67902
+ var import_promises2 = require("fs/promises");
67903
+ var import_child_process4 = require("child_process");
67904
+ var import_util3 = require("util");
67905
+ var execFileAsync3 = (0, import_util3.promisify)(import_child_process4.execFile);
67869
67906
  var runtimeDefinitions = {
67870
67907
  claude: {
67871
67908
  label: "Claude CLI",
@@ -67896,7 +67933,7 @@ async function pathExists(path13) {
67896
67933
  }
67897
67934
  async function getRuntimeVersion(runtimeKind, cliPath) {
67898
67935
  const definition = runtimeDefinitions[runtimeKind];
67899
- const { stdout, stderr } = await execFileAsync2(cliPath, definition.versionArgs, {
67936
+ const { stdout, stderr } = await execFileAsync3(cliPath, definition.versionArgs, {
67900
67937
  timeout: 1e4,
67901
67938
  maxBuffer: 512 * 1024
67902
67939
  });
@@ -68060,7 +68097,7 @@ function provisionUserWorkspace(userId) {
68060
68097
  }
68061
68098
 
68062
68099
  // ../../src/lib/daemon/remoteDaemonLoop.ts
68063
- var DAEMON_VERSION = "0.2.0";
68100
+ var DAEMON_VERSION = "0.2.1";
68064
68101
  var POLL_PATH = "/api/machine-tunnel/poll";
68065
68102
  var RESULT_PATH = "/api/machine-tunnel/result";
68066
68103
  var RECONNECT_DELAY_MS = 5e3;
@@ -68145,6 +68182,34 @@ async function runRemoteDaemonLoop(input) {
68145
68182
  }
68146
68183
  return;
68147
68184
  }
68185
+ if (command.type === "select_directory") {
68186
+ try {
68187
+ const picked = await pickDirectoryWithOsascript();
68188
+ if ("canceled" in picked) {
68189
+ await postResult({
68190
+ type: "select_directory",
68191
+ requestId: command.requestId,
68192
+ ok: true,
68193
+ canceled: true
68194
+ });
68195
+ return;
68196
+ }
68197
+ await postResult({
68198
+ type: "select_directory",
68199
+ requestId: command.requestId,
68200
+ ok: true,
68201
+ path: picked.path
68202
+ });
68203
+ } catch (error) {
68204
+ await postResult({
68205
+ type: "select_directory",
68206
+ requestId: command.requestId,
68207
+ ok: false,
68208
+ error: error instanceof Error ? error.message : "\u76EE\u5F55\u9009\u62E9\u5931\u8D25"
68209
+ });
68210
+ }
68211
+ return;
68212
+ }
68148
68213
  if (command.type === "execute") {
68149
68214
  if (runningJobs.has(command.jobId)) return;
68150
68215
  runningJobs.add(command.jobId);
@@ -68379,9 +68444,9 @@ function collectDaemonServiceEnv(installEnv = process.env, home = import_os3.def
68379
68444
  var import_fs14 = __toESM(require("fs"));
68380
68445
  var import_os4 = __toESM(require("os"));
68381
68446
  var import_path10 = __toESM(require("path"));
68382
- var import_child_process4 = require("child_process");
68383
- var import_util3 = require("util");
68384
- var execFileAsync3 = (0, import_util3.promisify)(import_child_process4.execFile);
68447
+ var import_child_process5 = require("child_process");
68448
+ var import_util4 = require("util");
68449
+ var execFileAsync4 = (0, import_util4.promisify)(import_child_process5.execFile);
68385
68450
  var MAC_LABEL = "com.kiki.daemon";
68386
68451
  var LINUX_UNIT = "kiki-daemon.service";
68387
68452
  function kikiHome() {
@@ -68492,18 +68557,18 @@ async function installService(ctx) {
68492
68557
  const id = await uid();
68493
68558
  if (!id) throw new Error("\u65E0\u6CD5\u8BC6\u522B\u5F53\u524D\u7528\u6237\uFF0C\u65E0\u6CD5\u5B89\u88C5 LaunchAgent");
68494
68559
  const domain = `gui/${id}`;
68495
- await execFileAsync3("launchctl", ["bootout", domain, target]).catch(() => void 0);
68496
- await execFileAsync3("launchctl", ["bootstrap", domain, target]);
68497
- await execFileAsync3("launchctl", ["kickstart", "-k", `${domain}/${MAC_LABEL}`]);
68560
+ await execFileAsync4("launchctl", ["bootout", domain, target]).catch(() => void 0);
68561
+ await execFileAsync4("launchctl", ["bootstrap", domain, target]);
68562
+ await execFileAsync4("launchctl", ["kickstart", "-k", `${domain}/${MAC_LABEL}`]);
68498
68563
  return { kind: "launchd", path: target };
68499
68564
  }
68500
68565
  if (process.platform === "linux") {
68501
68566
  const target = linuxUnitPath();
68502
68567
  import_fs14.default.mkdirSync(import_path10.default.dirname(target), { recursive: true });
68503
68568
  import_fs14.default.writeFileSync(target, buildLinuxUnit(ctx), "utf8");
68504
- await execFileAsync3("systemctl", ["--user", "daemon-reload"]);
68505
- await execFileAsync3("systemctl", ["--user", "enable", "--now", LINUX_UNIT]);
68506
- await execFileAsync3("loginctl", ["enable-linger", import_os4.default.userInfo().username]).catch(() => void 0);
68569
+ await execFileAsync4("systemctl", ["--user", "daemon-reload"]);
68570
+ await execFileAsync4("systemctl", ["--user", "enable", "--now", LINUX_UNIT]);
68571
+ await execFileAsync4("loginctl", ["enable-linger", import_os4.default.userInfo().username]).catch(() => void 0);
68507
68572
  return { kind: "systemd", path: target };
68508
68573
  }
68509
68574
  throw new Error(
@@ -68516,16 +68581,16 @@ async function uninstallService() {
68516
68581
  const target = macPlistPath();
68517
68582
  const id = await uid();
68518
68583
  if (id && import_fs14.default.existsSync(target)) {
68519
- await execFileAsync3("launchctl", ["bootout", `gui/${id}`, target]).catch(() => void 0);
68584
+ await execFileAsync4("launchctl", ["bootout", `gui/${id}`, target]).catch(() => void 0);
68520
68585
  }
68521
68586
  if (import_fs14.default.existsSync(target)) import_fs14.default.unlinkSync(target);
68522
68587
  return { kind: "launchd", path: target };
68523
68588
  }
68524
68589
  if (process.platform === "linux") {
68525
68590
  const target = linuxUnitPath();
68526
- await execFileAsync3("systemctl", ["--user", "disable", "--now", LINUX_UNIT]).catch(() => void 0);
68591
+ await execFileAsync4("systemctl", ["--user", "disable", "--now", LINUX_UNIT]).catch(() => void 0);
68527
68592
  if (import_fs14.default.existsSync(target)) import_fs14.default.unlinkSync(target);
68528
- await execFileAsync3("systemctl", ["--user", "daemon-reload"]).catch(() => void 0);
68593
+ await execFileAsync4("systemctl", ["--user", "daemon-reload"]).catch(() => void 0);
68529
68594
  return { kind: "systemd", path: target };
68530
68595
  }
68531
68596
  throw new Error(`\u5F53\u524D\u5E73\u53F0 ${process.platform} \u6682\u4E0D\u652F\u6301\u81EA\u52A8\u5378\u8F7D\u540E\u53F0\u670D\u52A1`);
@@ -68538,7 +68603,7 @@ async function serviceStatus() {
68538
68603
  if (installed) {
68539
68604
  const id = await uid();
68540
68605
  if (id) {
68541
- const result = await execFileAsync3("launchctl", ["print", `gui/${id}/${MAC_LABEL}`]).catch(() => null);
68606
+ const result = await execFileAsync4("launchctl", ["print", `gui/${id}/${MAC_LABEL}`]).catch(() => null);
68542
68607
  running = Boolean(result && /state = running/.test(result.stdout));
68543
68608
  }
68544
68609
  }
@@ -68547,7 +68612,7 @@ async function serviceStatus() {
68547
68612
  if (process.platform === "linux") {
68548
68613
  const target = linuxUnitPath();
68549
68614
  const installed = import_fs14.default.existsSync(target);
68550
- const result = await execFileAsync3("systemctl", ["--user", "is-active", LINUX_UNIT]).catch((error) => error);
68615
+ const result = await execFileAsync4("systemctl", ["--user", "is-active", LINUX_UNIT]).catch((error) => error);
68551
68616
  const running = Boolean(result && typeof result.stdout === "string" && result.stdout.trim() === "active");
68552
68617
  return { kind: "systemd", installed, running, path: target };
68553
68618
  }
@@ -68576,7 +68641,7 @@ function resolveInstallScriptPath() {
68576
68641
  return current;
68577
68642
  }
68578
68643
  try {
68579
- const bin = (0, import_child_process5.execFileSync)("which", ["kiki-daemon"], { encoding: "utf8" }).trim();
68644
+ const bin = (0, import_child_process6.execFileSync)("which", ["kiki-daemon"], { encoding: "utf8" }).trim();
68580
68645
  if (bin && !bin.includes("_npx")) {
68581
68646
  return import_fs15.default.realpathSync(bin);
68582
68647
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiki_agent/daemon",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Kiki 本地执行节点 daemon:连接云端编排器并在本机运行任务。",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",