@adhdev/daemon-core 0.8.13 → 0.8.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -700,17 +700,35 @@ var init_terminal_screen = __esm({
700
700
  }
701
701
  });
702
702
 
703
+ // src/cli-adapters/spawn-env.ts
704
+ import {
705
+ sanitizeSpawnEnv,
706
+ applyTerminalColorEnv,
707
+ ensureNodePtySpawnHelperPermissions
708
+ } from "@adhdev/session-host-core";
709
+ var init_spawn_env = __esm({
710
+ "src/cli-adapters/spawn-env.ts"() {
711
+ "use strict";
712
+ }
713
+ });
714
+
703
715
  // src/cli-adapters/pty-transport.ts
704
716
  import * as os7 from "os";
705
- var pty, NodePtyRuntimeTransport, NodePtyTransportFactory;
717
+ function loadNodePty() {
718
+ if (cachedPty !== void 0) return cachedPty;
719
+ try {
720
+ cachedPty = __require("node-pty");
721
+ ensureNodePtySpawnHelperPermissions();
722
+ } catch {
723
+ cachedPty = null;
724
+ }
725
+ return cachedPty;
726
+ }
727
+ var cachedPty, NodePtyRuntimeTransport, NodePtyTransportFactory;
706
728
  var init_pty_transport = __esm({
707
729
  "src/cli-adapters/pty-transport.ts"() {
708
730
  "use strict";
709
- try {
710
- pty = __require("node-pty");
711
- } catch {
712
- pty = null;
713
- }
731
+ init_spawn_env();
714
732
  NodePtyRuntimeTransport = class {
715
733
  constructor(handle) {
716
734
  this.handle = handle;
@@ -741,6 +759,7 @@ var init_pty_transport = __esm({
741
759
  };
742
760
  NodePtyTransportFactory = class {
743
761
  spawn(command, args, options) {
762
+ const pty = loadNodePty();
744
763
  if (!pty) throw new Error("node-pty is not installed");
745
764
  let cwd = options.cwd;
746
765
  if (cwd) {
@@ -765,18 +784,6 @@ var init_pty_transport = __esm({
765
784
  }
766
785
  });
767
786
 
768
- // src/cli-adapters/spawn-env.ts
769
- import {
770
- sanitizeSpawnEnv,
771
- applyTerminalColorEnv,
772
- ensureNodePtySpawnHelperPermissions
773
- } from "@adhdev/session-host-core";
774
- var init_spawn_env = __esm({
775
- "src/cli-adapters/spawn-env.ts"() {
776
- "use strict";
777
- }
778
- });
779
-
780
787
  // src/cli-adapters/provider-cli-adapter.ts
781
788
  var provider_cli_adapter_exports = {};
782
789
  __export(provider_cli_adapter_exports, {
@@ -923,7 +930,7 @@ function normalizeCliProviderForRuntime(raw) {
923
930
  }
924
931
  };
925
932
  }
926
- var pty2, buildCliSpawnEnv, ProviderCliAdapter;
933
+ var buildCliSpawnEnv, ProviderCliAdapter;
927
934
  var init_provider_cli_adapter = __esm({
928
935
  "src/cli-adapters/provider-cli-adapter.ts"() {
929
936
  "use strict";
@@ -931,12 +938,6 @@ var init_provider_cli_adapter = __esm({
931
938
  init_terminal_screen();
932
939
  init_pty_transport();
933
940
  init_spawn_env();
934
- try {
935
- pty2 = __require("node-pty");
936
- ensureNodePtySpawnHelperPermissions((msg) => LOG.info("CLI", msg));
937
- } catch {
938
- LOG.error("CLI", "[ProviderCliAdapter] node-pty not found. Terminal features disabled.");
939
- }
940
941
  buildCliSpawnEnv = sanitizeSpawnEnv;
941
942
  ProviderCliAdapter = class _ProviderCliAdapter {
942
943
  constructor(provider, workingDir, extraArgs = [], transportFactory = new NodePtyTransportFactory()) {
@@ -1260,13 +1261,16 @@ var init_provider_cli_adapter = __esm({
1260
1261
  let shellArgs;
1261
1262
  const useShellUnix = !isWin && (!!spawnConfig.shell || !path7.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
1262
1263
  const isCmdShim = isWin && /\.(cmd|bat)$/i.test(binaryPath);
1263
- const useShell = isWin ? !!spawnConfig.shell || isCmdShim : useShellUnix;
1264
+ const useShellWin = isCmdShim || !path7.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
1265
+ const useShell = isWin ? useShellWin : useShellUnix;
1264
1266
  if (useShell) {
1265
1267
  if (!spawnConfig.shell && !isWin) {
1266
1268
  LOG.info("CLI", `[${this.cliType}] Using login shell (script shim or non-native binary)`);
1267
1269
  }
1268
1270
  if (isCmdShim) {
1269
1271
  LOG.info("CLI", `[${this.cliType}] Using cmd.exe shell for .cmd/.bat shim: ${binaryPath}`);
1272
+ } else if (isWin) {
1273
+ LOG.info("CLI", `[${this.cliType}] Using cmd.exe shell on Windows: ${binaryPath}`);
1270
1274
  }
1271
1275
  shellCmd = isWin ? "cmd.exe" : process.env.SHELL || "/bin/zsh";
1272
1276
  if (isWin) {
@@ -1276,6 +1280,9 @@ var init_provider_cli_adapter = __esm({
1276
1280
  shellArgs = ["-l", "-c", fullCmd];
1277
1281
  }
1278
1282
  } else {
1283
+ if (isWin && spawnConfig.shell) {
1284
+ LOG.info("CLI", `[${this.cliType}] Spawning Windows binary directly without cmd.exe: ${binaryPath}`);
1285
+ }
1279
1286
  shellCmd = binaryPath;
1280
1287
  shellArgs = allArgs;
1281
1288
  }
@@ -7247,8 +7254,24 @@ function handleSetIdeExtension(h, args) {
7247
7254
 
7248
7255
  // src/commands/workspace-commands.ts
7249
7256
  init_config();
7257
+ function loadWorkspaceConfig() {
7258
+ try {
7259
+ return loadConfig();
7260
+ } catch (e) {
7261
+ return { error: `Could not load config: ${e?.message || "unknown error"}` };
7262
+ }
7263
+ }
7264
+ function persistWorkspaceConfig(config) {
7265
+ try {
7266
+ saveConfig(config);
7267
+ return { ok: true };
7268
+ } catch (e) {
7269
+ return { error: `Could not save config: ${e?.message || "unknown error"}` };
7270
+ }
7271
+ }
7250
7272
  function handleWorkspaceList() {
7251
- const config = loadConfig();
7273
+ const config = loadWorkspaceConfig();
7274
+ if ("error" in config) return { success: false, error: config.error };
7252
7275
  const state = getWorkspaceState(config);
7253
7276
  return {
7254
7277
  success: true,
@@ -7262,31 +7285,37 @@ function handleWorkspaceAdd(args) {
7262
7285
  const label = (args?.label || "").trim() || void 0;
7263
7286
  const createIfMissing = args?.createIfMissing === true;
7264
7287
  if (!rawPath) return { success: false, error: "path required" };
7265
- const config = loadConfig();
7288
+ const config = loadWorkspaceConfig();
7289
+ if ("error" in config) return { success: false, error: config.error };
7266
7290
  const result = addWorkspaceEntry(config, rawPath, label, { createIfMissing });
7267
7291
  if ("error" in result) return { success: false, error: result.error };
7268
- saveConfig(result.config);
7292
+ const saveResult = persistWorkspaceConfig(result.config);
7293
+ if ("error" in saveResult) return { success: false, error: saveResult.error };
7269
7294
  const state = getWorkspaceState(result.config);
7270
7295
  return { success: true, entry: result.entry, ...state };
7271
7296
  }
7272
7297
  function handleWorkspaceRemove(args) {
7273
7298
  const id = (args?.id || "").trim();
7274
7299
  if (!id) return { success: false, error: "id required" };
7275
- const config = loadConfig();
7300
+ const config = loadWorkspaceConfig();
7301
+ if ("error" in config) return { success: false, error: config.error };
7276
7302
  const removed = (config.workspaces || []).find((w) => w.id === id);
7277
7303
  const result = removeWorkspaceEntry(config, id);
7278
7304
  if ("error" in result) return { success: false, error: result.error };
7279
- saveConfig(result.config);
7305
+ const saveResult = persistWorkspaceConfig(result.config);
7306
+ if ("error" in saveResult) return { success: false, error: saveResult.error };
7280
7307
  const state = getWorkspaceState(result.config);
7281
7308
  return { success: true, removedId: id, ...state };
7282
7309
  }
7283
7310
  function handleWorkspaceSetDefault(args) {
7284
7311
  const clear = args?.clear === true || args?.id === null || args?.id === "";
7285
7312
  if (clear) {
7286
- const config2 = loadConfig();
7313
+ const config2 = loadWorkspaceConfig();
7314
+ if ("error" in config2) return { success: false, error: config2.error };
7287
7315
  const result2 = setDefaultWorkspaceId(config2, null);
7288
7316
  if ("error" in result2) return { success: false, error: result2.error };
7289
- saveConfig(result2.config);
7317
+ const saveResult2 = persistWorkspaceConfig(result2.config);
7318
+ if ("error" in saveResult2) return { success: false, error: saveResult2.error };
7290
7319
  const state2 = getWorkspaceState(result2.config);
7291
7320
  return {
7292
7321
  success: true,
@@ -7298,7 +7327,9 @@ function handleWorkspaceSetDefault(args) {
7298
7327
  if (!pathArg && !idArg) {
7299
7328
  return { success: false, error: "id or path required (or clear: true)" };
7300
7329
  }
7301
- let config = loadConfig();
7330
+ const configResult = loadWorkspaceConfig();
7331
+ if ("error" in configResult) return { success: false, error: configResult.error };
7332
+ let config = configResult;
7302
7333
  let nextId;
7303
7334
  if (pathArg) {
7304
7335
  let w = findWorkspaceByPath(config, pathArg);
@@ -7314,7 +7345,8 @@ function handleWorkspaceSetDefault(args) {
7314
7345
  }
7315
7346
  const result = setDefaultWorkspaceId(config, nextId);
7316
7347
  if ("error" in result) return { success: false, error: result.error };
7317
- saveConfig(result.config);
7348
+ const saveResult = persistWorkspaceConfig(result.config);
7349
+ if ("error" in saveResult) return { success: false, error: saveResult.error };
7318
7350
  const state = getWorkspaceState(result.config);
7319
7351
  return { success: true, ...state };
7320
7352
  }
@@ -15948,10 +15980,10 @@ async function handleAutoImplement(ctx, type, req, res) {
15948
15980
  let isPty = false;
15949
15981
  const { spawn: spawnFn } = await import("child_process");
15950
15982
  try {
15951
- const pty3 = __require("node-pty");
15983
+ const pty = __require("node-pty");
15952
15984
  ctx.log(`Auto-implement spawn (PTY): ${shellCmd}`);
15953
15985
  const isWin2 = os17.platform() === "win32";
15954
- child = pty3.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
15986
+ child = pty.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
15955
15987
  name: "xterm-256color",
15956
15988
  cols: 120,
15957
15989
  rows: 40,