kcode-cli 1.3.18 → 1.3.20

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/cli.js CHANGED
@@ -121556,22 +121556,71 @@ import { execFile as execFile4 } from "node:child_process";
121556
121556
  function quoteAppleScript(value) {
121557
121557
  return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
121558
121558
  }
121559
- function createWindowsDirectoryPickerCommand(title) {
121559
+ function createWindowsPickerScript(title, strategy) {
121560
121560
  const description = JSON.stringify(title?.trim() || "Select a project");
121561
- const script = [
121561
+ if (strategy === "owner") {
121562
+ return [
121563
+ "Add-Type -AssemblyName System.Windows.Forms",
121564
+ "$owner = $null",
121565
+ "$dialog = $null",
121566
+ "$result = @{ status = 'cancelled' }",
121567
+ "try {",
121568
+ " $owner = New-Object System.Windows.Forms.Form",
121569
+ " $owner.StartPosition = [System.Windows.Forms.FormStartPosition]::Manual",
121570
+ " $owner.Left = -32000",
121571
+ " $owner.Top = -32000",
121572
+ " $owner.Width = 1",
121573
+ " $owner.Height = 1",
121574
+ " $owner.ShowInTaskbar = $false",
121575
+ " $owner.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedToolWindow",
121576
+ " $owner.Opacity = 0",
121577
+ " $owner.TopMost = $true",
121578
+ " $null = $owner.Show()",
121579
+ " $owner.Activate()",
121580
+ " $dialog = New-Object System.Windows.Forms.FolderBrowserDialog",
121581
+ ` $dialog.Description = ${description}`,
121582
+ " $dialog.ShowNewFolderButton = $false",
121583
+ " $status = $dialog.ShowDialog($owner)",
121584
+ " if ($status -eq [System.Windows.Forms.DialogResult]::OK) {",
121585
+ " $result = @{ status = 'selected'; path = $dialog.SelectedPath }",
121586
+ " }",
121587
+ "} finally {",
121588
+ " if ($dialog) { $dialog.Dispose() }",
121589
+ " if ($owner) { $owner.Close(); $owner.Dispose() }",
121590
+ "}",
121591
+ "[Console]::Out.Write(($result | ConvertTo-Json -Compress))"
121592
+ ].join("\n");
121593
+ }
121594
+ return [
121562
121595
  "Add-Type -AssemblyName System.Windows.Forms",
121563
- "$dialog = New-Object System.Windows.Forms.FolderBrowserDialog",
121564
- `$dialog.Description = ${description}`,
121565
- "$dialog.ShowNewFolderButton = $false",
121566
- "if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {",
121567
- " [Console]::Out.Write($dialog.SelectedPath)",
121568
- "}"
121596
+ "$dialog = $null",
121597
+ "$result = @{ status = 'cancelled' }",
121598
+ "try {",
121599
+ " $dialog = New-Object System.Windows.Forms.FolderBrowserDialog",
121600
+ ` $dialog.Description = ${description}`,
121601
+ " $dialog.ShowNewFolderButton = $false",
121602
+ " $status = $dialog.ShowDialog()",
121603
+ " if ($status -eq [System.Windows.Forms.DialogResult]::OK) {",
121604
+ " $result = @{ status = 'selected'; path = $dialog.SelectedPath }",
121605
+ " }",
121606
+ "} finally {",
121607
+ " if ($dialog) { $dialog.Dispose() }",
121608
+ "}",
121609
+ "[Console]::Out.Write(($result | ConvertTo-Json -Compress))"
121569
121610
  ].join("\n");
121611
+ }
121612
+ function createWindowsPickerCommand(title, strategy) {
121613
+ const script = createWindowsPickerScript(title, strategy);
121570
121614
  return {
121571
121615
  file: "powershell.exe",
121572
- args: ["-NoLogo", "-NoProfile", "-NonInteractive", "-STA", "-Command", script]
121616
+ args: ["-NoLogo", "-NoProfile", "-NonInteractive", "-STA", "-Command", script],
121617
+ strategy,
121618
+ title
121573
121619
  };
121574
121620
  }
121621
+ function createWindowsDirectoryPickerCommand(title) {
121622
+ return createWindowsPickerCommand(title, "owner");
121623
+ }
121575
121624
  function createMacDirectoryPickerCommand(title) {
121576
121625
  const prompt2 = quoteAppleScript(title?.trim() || "Select a project");
121577
121626
  return {
@@ -121632,6 +121681,55 @@ function unexpectedFailure(command3, error2) {
121632
121681
  `Failed to open directory picker via ${command3.file}${detail ? `: ${detail}` : ""}`
121633
121682
  );
121634
121683
  }
121684
+ function invalidWindowsPickerResult(command3, detail) {
121685
+ return new DirectoryPickerExecutionError(
121686
+ `Failed to open directory picker via ${command3.file}: invalid ${command3.strategy} picker result (${detail})`
121687
+ );
121688
+ }
121689
+ function parseWindowsPickerResult(result) {
121690
+ const raw2 = result.stdout.trim();
121691
+ if (!raw2) {
121692
+ return {
121693
+ kind: "invalid",
121694
+ detail: "empty stdout"
121695
+ };
121696
+ }
121697
+ try {
121698
+ const parsed = JSON.parse(raw2);
121699
+ if (parsed?.status === "selected" && typeof parsed.path === "string" && parsed.path.trim()) {
121700
+ return {
121701
+ kind: "selected",
121702
+ path: parsed.path
121703
+ };
121704
+ }
121705
+ if (parsed?.status === "cancelled") {
121706
+ return {
121707
+ kind: "cancelled"
121708
+ };
121709
+ }
121710
+ return {
121711
+ kind: "invalid",
121712
+ detail: `unexpected payload ${raw2}`
121713
+ };
121714
+ } catch (error2) {
121715
+ const reason = error2 instanceof Error ? error2.message : String(error2);
121716
+ return {
121717
+ kind: "invalid",
121718
+ detail: `invalid JSON (${reason})`
121719
+ };
121720
+ }
121721
+ }
121722
+ function logWindowsPickerResult(command3, result, parsed, startedAt) {
121723
+ debugLogger61.debug("Windows directory picker completed", {
121724
+ strategy: command3.strategy,
121725
+ elapsedMs: Date.now() - startedAt,
121726
+ stderr: result.stderr.trim() || void 0,
121727
+ stdout: result.stdout.trim() || void 0,
121728
+ outcome: parsed.kind,
121729
+ path: parsed.kind === "selected" ? parsed.path : void 0,
121730
+ detail: parsed.kind === "invalid" ? parsed.detail : void 0
121731
+ });
121732
+ }
121635
121733
  async function runLinuxDirectoryPicker(options2, deps) {
121636
121734
  if (isMissingDisplay(deps.env)) {
121637
121735
  throw new DirectoryPickerUnsupportedError("Directory picker is unavailable because no graphical display is active");
@@ -121657,6 +121755,58 @@ async function runLinuxDirectoryPicker(options2, deps) {
121657
121755
  }
121658
121756
  throw new DirectoryPickerUnsupportedError("Directory picker is unavailable on this Linux environment");
121659
121757
  }
121758
+ async function runWindowsPickerCommand(command3, deps) {
121759
+ const startedAt = Date.now();
121760
+ try {
121761
+ const result = await deps.run(command3);
121762
+ const parsed = parseWindowsPickerResult(result);
121763
+ logWindowsPickerResult(command3, result, parsed, startedAt);
121764
+ return parsed;
121765
+ } catch (error2) {
121766
+ debugLogger61.error("Windows directory picker failed", {
121767
+ strategy: command3.strategy,
121768
+ elapsedMs: Date.now() - startedAt,
121769
+ error: error2
121770
+ });
121771
+ throw unexpectedFailure(command3, error2);
121772
+ }
121773
+ }
121774
+ async function runWindowsDirectoryPicker(command3, deps) {
121775
+ if (activeWindowsPicker) {
121776
+ debugLogger61.debug("Windows directory picker request dropped because another picker is active");
121777
+ return null;
121778
+ }
121779
+ const ownerCommand = command3;
121780
+ const task = (async () => {
121781
+ const initialCommand = ownerCommand.strategy === "owner" ? ownerCommand : createWindowsPickerCommand(ownerCommand.title, "owner");
121782
+ const plainCommand = createWindowsPickerCommand(initialCommand.title, "plain");
121783
+ const ownerResult = await runWindowsPickerCommand(initialCommand, deps);
121784
+ if (ownerResult.kind === "selected") {
121785
+ return normalizePickedPath(ownerResult.path, deps.platform);
121786
+ }
121787
+ if (ownerResult.kind === "cancelled") {
121788
+ return null;
121789
+ }
121790
+ debugLogger61.warn("Windows directory picker owner strategy returned an invalid result, retrying plain dialog", {
121791
+ detail: ownerResult.detail
121792
+ });
121793
+ const plainResult = await runWindowsPickerCommand(plainCommand, deps);
121794
+ if (plainResult.kind === "selected") {
121795
+ return normalizePickedPath(plainResult.path, deps.platform);
121796
+ }
121797
+ if (plainResult.kind === "cancelled") {
121798
+ return null;
121799
+ }
121800
+ throw invalidWindowsPickerResult(plainCommand, plainResult.detail);
121801
+ })();
121802
+ const guarded = task.finally(() => {
121803
+ if (activeWindowsPicker === guarded) {
121804
+ activeWindowsPicker = void 0;
121805
+ }
121806
+ });
121807
+ activeWindowsPicker = guarded;
121808
+ return await guarded;
121809
+ }
121660
121810
  async function pickDirectory(options2 = {}, deps = {}) {
121661
121811
  const platform3 = deps.platform ?? process7.platform;
121662
121812
  const env = deps.env ?? process7.env;
@@ -121664,12 +121814,7 @@ async function pickDirectory(options2 = {}, deps = {}) {
121664
121814
  const resolved = { platform: platform3, env, run: run2 };
121665
121815
  if (platform3 === "win32") {
121666
121816
  const command3 = createWindowsDirectoryPickerCommand(options2.title);
121667
- try {
121668
- const result = await resolved.run(command3);
121669
- return normalizePickedPath(result.stdout, platform3);
121670
- } catch (error2) {
121671
- throw unexpectedFailure(command3, error2);
121672
- }
121817
+ return await runWindowsDirectoryPicker(command3, resolved);
121673
121818
  }
121674
121819
  if (platform3 === "darwin") {
121675
121820
  const command3 = createMacDirectoryPickerCommand(options2.title);
@@ -121690,10 +121835,12 @@ async function pickDirectory(options2 = {}, deps = {}) {
121690
121835
  }
121691
121836
  throw new DirectoryPickerUnsupportedError(`Directory picker is unavailable on platform ${platform3}`);
121692
121837
  }
121693
- var DirectoryPickerUnsupportedError, DirectoryPickerExecutionError;
121838
+ var activeWindowsPicker, debugLogger61, DirectoryPickerUnsupportedError, DirectoryPickerExecutionError;
121694
121839
  var init_picker = __esm({
121695
121840
  "../../apps/server/src/services/picker.ts"() {
121696
121841
  "use strict";
121842
+ init_debug();
121843
+ debugLogger61 = createDebugLogger("PICKER");
121697
121844
  DirectoryPickerUnsupportedError = class extends Error {
121698
121845
  constructor(message2) {
121699
121846
  super(message2);