kcode-cli 1.3.19 → 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,41 +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
- "$owner = New-Object System.Windows.Forms.Form",
121564
- "$owner.StartPosition = [System.Windows.Forms.FormStartPosition]::Manual",
121565
- "$owner.Left = -32000",
121566
- "$owner.Top = -32000",
121567
- "$owner.Width = 1",
121568
- "$owner.Height = 1",
121569
- "$owner.ShowInTaskbar = $false",
121570
- "$owner.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedToolWindow",
121571
- "$owner.Opacity = 0",
121572
- "$owner.TopMost = $true",
121573
- "$null = $owner.Show()",
121574
- "$owner.Activate()",
121575
121596
  "$dialog = $null",
121597
+ "$result = @{ status = 'cancelled' }",
121576
121598
  "try {",
121577
121599
  " $dialog = New-Object System.Windows.Forms.FolderBrowserDialog",
121578
121600
  ` $dialog.Description = ${description}`,
121579
121601
  " $dialog.ShowNewFolderButton = $false",
121580
- " if ($dialog.ShowDialog($owner) -eq [System.Windows.Forms.DialogResult]::OK) {",
121581
- " [Console]::Out.Write($dialog.SelectedPath)",
121602
+ " $status = $dialog.ShowDialog()",
121603
+ " if ($status -eq [System.Windows.Forms.DialogResult]::OK) {",
121604
+ " $result = @{ status = 'selected'; path = $dialog.SelectedPath }",
121582
121605
  " }",
121583
121606
  "} finally {",
121584
121607
  " if ($dialog) { $dialog.Dispose() }",
121585
- " $owner.Close()",
121586
- " $owner.Dispose()",
121587
- "}"
121608
+ "}",
121609
+ "[Console]::Out.Write(($result | ConvertTo-Json -Compress))"
121588
121610
  ].join("\n");
121611
+ }
121612
+ function createWindowsPickerCommand(title, strategy) {
121613
+ const script = createWindowsPickerScript(title, strategy);
121589
121614
  return {
121590
121615
  file: "powershell.exe",
121591
- args: ["-NoLogo", "-NoProfile", "-NonInteractive", "-STA", "-Command", script]
121616
+ args: ["-NoLogo", "-NoProfile", "-NonInteractive", "-STA", "-Command", script],
121617
+ strategy,
121618
+ title
121592
121619
  };
121593
121620
  }
121621
+ function createWindowsDirectoryPickerCommand(title) {
121622
+ return createWindowsPickerCommand(title, "owner");
121623
+ }
121594
121624
  function createMacDirectoryPickerCommand(title) {
121595
121625
  const prompt2 = quoteAppleScript(title?.trim() || "Select a project");
121596
121626
  return {
@@ -121651,6 +121681,55 @@ function unexpectedFailure(command3, error2) {
121651
121681
  `Failed to open directory picker via ${command3.file}${detail ? `: ${detail}` : ""}`
121652
121682
  );
121653
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
+ }
121654
121733
  async function runLinuxDirectoryPicker(options2, deps) {
121655
121734
  if (isMissingDisplay(deps.env)) {
121656
121735
  throw new DirectoryPickerUnsupportedError("Directory picker is unavailable because no graphical display is active");
@@ -121676,13 +121755,50 @@ async function runLinuxDirectoryPicker(options2, deps) {
121676
121755
  }
121677
121756
  throw new DirectoryPickerUnsupportedError("Directory picker is unavailable on this Linux environment");
121678
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
+ }
121679
121774
  async function runWindowsDirectoryPicker(command3, deps) {
121680
121775
  if (activeWindowsPicker) {
121776
+ debugLogger61.debug("Windows directory picker request dropped because another picker is active");
121681
121777
  return null;
121682
121778
  }
121683
- const task = deps.run(command3).then((result) => normalizePickedPath(result.stdout, deps.platform)).catch((error2) => {
121684
- throw unexpectedFailure(command3, error2);
121685
- });
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
+ })();
121686
121802
  const guarded = task.finally(() => {
121687
121803
  if (activeWindowsPicker === guarded) {
121688
121804
  activeWindowsPicker = void 0;
@@ -121719,10 +121835,12 @@ async function pickDirectory(options2 = {}, deps = {}) {
121719
121835
  }
121720
121836
  throw new DirectoryPickerUnsupportedError(`Directory picker is unavailable on platform ${platform3}`);
121721
121837
  }
121722
- var activeWindowsPicker, DirectoryPickerUnsupportedError, DirectoryPickerExecutionError;
121838
+ var activeWindowsPicker, debugLogger61, DirectoryPickerUnsupportedError, DirectoryPickerExecutionError;
121723
121839
  var init_picker = __esm({
121724
121840
  "../../apps/server/src/services/picker.ts"() {
121725
121841
  "use strict";
121842
+ init_debug();
121843
+ debugLogger61 = createDebugLogger("PICKER");
121726
121844
  DirectoryPickerUnsupportedError = class extends Error {
121727
121845
  constructor(message2) {
121728
121846
  super(message2);