@diologue/local-agent 0.5.0 → 0.6.0

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.mjs CHANGED
@@ -726,9 +726,9 @@ var getDiff = async (cwd) => {
726
726
  return [trackedDiff, ...untrackedDiffs].filter((part) => part.trim().length > 0).join("\n");
727
727
  };
728
728
  var runGitWithStdin = async (cwd, args, input) => {
729
- const { execFile: execFile2 } = await import("node:child_process");
729
+ const { execFile: execFile3 } = await import("node:child_process");
730
730
  return new Promise((resolve, reject) => {
731
- const child = execFile2(
731
+ const child = execFile3(
732
732
  "git",
733
733
  args,
734
734
  {
@@ -848,6 +848,73 @@ var validateRepoPath = async (raw) => {
848
848
  return resolved;
849
849
  };
850
850
 
851
+ // src/lib/pick-directory.ts
852
+ import { execFile as execFile2 } from "node:child_process";
853
+ import { homedir } from "node:os";
854
+ var PROMPT = "Select a git repository";
855
+ var dialogSpec = (platform) => {
856
+ switch (platform) {
857
+ case "darwin":
858
+ return {
859
+ cmd: "osascript",
860
+ args: [
861
+ "-e",
862
+ `set theFolder to choose folder with prompt "${PROMPT}"`,
863
+ "-e",
864
+ "POSIX path of theFolder"
865
+ ]
866
+ };
867
+ case "linux":
868
+ return {
869
+ cmd: "zenity",
870
+ args: ["--file-selection", "--directory", `--title=${PROMPT}`]
871
+ };
872
+ case "win32":
873
+ return {
874
+ cmd: "powershell",
875
+ args: [
876
+ "-NoProfile",
877
+ "-Command",
878
+ `Add-Type -AssemblyName System.Windows.Forms;$d = New-Object System.Windows.Forms.FolderBrowserDialog;$d.Description = '${PROMPT}';if ($d.ShowDialog() -eq 'OK') { Write-Output $d.SelectedPath }`
879
+ ]
880
+ };
881
+ default:
882
+ return null;
883
+ }
884
+ };
885
+ var run = (cmd, args) => new Promise((resolve, reject) => {
886
+ execFile2(
887
+ cmd,
888
+ args,
889
+ // Folder dialogs can sit open a while; cap it so the request can't hang
890
+ // forever if the user wanders off. Killing it reads as "cancelled".
891
+ { timeout: 12e4, windowsHide: true },
892
+ (err, stdout) => {
893
+ if (err) reject(err);
894
+ else resolve(stdout);
895
+ }
896
+ );
897
+ });
898
+ var pickDirectory = async () => {
899
+ const spec = dialogSpec(process.platform);
900
+ if (!spec) return { ok: false, reason: "unsupported" };
901
+ const attempt = async (cmd, args) => {
902
+ try {
903
+ const out = (await run(cmd, args)).trim();
904
+ return out ? { ok: true, path: out } : { ok: false, reason: "cancelled" };
905
+ } catch (err) {
906
+ const code = err.code;
907
+ if (code === "ENOENT") return { ok: false, reason: "no_gui" };
908
+ return { ok: false, reason: "cancelled" };
909
+ }
910
+ };
911
+ const result = await attempt(spec.cmd, spec.args);
912
+ if (!result.ok && result.reason === "no_gui" && process.platform === "linux") {
913
+ return attempt("kdialog", ["--getexistingdirectory", homedir()]);
914
+ }
915
+ return result;
916
+ };
917
+
851
918
  // src/routes/repo.ts
852
919
  var selectRepoSchema = z.object({
853
920
  path: z.string().min(1)
@@ -917,6 +984,23 @@ var createRepoRouter = (state) => {
917
984
  throw err;
918
985
  }
919
986
  });
987
+ router.post("/browse", async (_req, res) => {
988
+ const result = await pickDirectory();
989
+ if (result.ok) {
990
+ const body = { path: result.path };
991
+ res.json(body);
992
+ return;
993
+ }
994
+ if (result.reason === "cancelled") {
995
+ const body = { cancelled: true };
996
+ res.json(body);
997
+ return;
998
+ }
999
+ res.status(501).json({
1000
+ error: result.reason,
1001
+ message: "No desktop folder dialog is available on this machine. Type the repo path instead."
1002
+ });
1003
+ });
920
1004
  router.get("/status", async (_req, res) => {
921
1005
  const repo = state.getSelectedRepo();
922
1006
  if (!repo) {