@tiens.nguyen/gu-cli 1.0.905 → 1.0.907

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.
@@ -7,13 +7,15 @@ import argparse
7
7
  import logging
8
8
  import shutil
9
9
  import subprocess
10
+ import tempfile
10
11
  from pathlib import Path
11
12
 
12
- from office.soffice import get_soffice_env
13
+ from office.soffice import get_soffice_env, soffice_binary
13
14
 
14
15
  logger = logging.getLogger(__name__)
15
16
 
16
- LIBREOFFICE_PROFILE = "/tmp/libreoffice_docx_profile"
17
+ LIBREOFFICE_PROFILE = (Path(tempfile.gettempdir()) / "libreoffice_docx_profile").as_posix()
18
+ PROFILE_URI = Path(LIBREOFFICE_PROFILE).as_uri()
17
19
  MACRO_DIR = f"{LIBREOFFICE_PROFILE}/user/basic/Standard"
18
20
 
19
21
  ACCEPT_CHANGES_MACRO = """<?xml version="1.0" encoding="UTF-8"?>
@@ -56,9 +58,9 @@ def accept_changes(
56
58
  return None, "Error: Failed to setup LibreOffice macro"
57
59
 
58
60
  cmd = [
59
- "soffice",
61
+ soffice_binary(),
60
62
  "--headless",
61
- f"-env:UserInstallation=file://{LIBREOFFICE_PROFILE}",
63
+ f"-env:UserInstallation={PROFILE_URI}",
62
64
  "--norestore",
63
65
  "vnd.sun.star.script:Standard.Module1.AcceptAllTrackedChanges?language=Basic&location=application",
64
66
  str(output_path.absolute()),
@@ -98,9 +100,9 @@ def _setup_libreoffice_macro() -> bool:
98
100
  if not macro_dir.exists():
99
101
  subprocess.run(
100
102
  [
101
- "soffice",
103
+ soffice_binary(),
102
104
  "--headless",
103
- f"-env:UserInstallation=file://{LIBREOFFICE_PROFILE}",
105
+ f"-env:UserInstallation={PROFILE_URI}",
104
106
  "--terminate_after_init",
105
107
  ],
106
108
  capture_output=True,
@@ -17,16 +17,42 @@ callers that build their own argv (they must pass -env:UserInstallation too).
17
17
 
18
18
  import contextlib
19
19
  import os
20
+ import shutil
20
21
  import socket
21
22
  import subprocess
23
+ import sys
22
24
  import tempfile
23
25
  from collections.abc import Iterable
24
26
  from pathlib import Path
25
27
 
26
28
 
29
+ def soffice_binary() -> str:
30
+ """Path to soffice. On Windows (and macOS) LibreOffice is rarely on PATH, so look in its usual
31
+ install folders; fall back to the bare name so a missing install still raises FileNotFoundError."""
32
+ found = shutil.which("soffice")
33
+ if found:
34
+ return found
35
+ candidates = []
36
+ if sys.platform == "win32":
37
+ for var in ("ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"):
38
+ base = os.environ.get(var)
39
+ if base:
40
+ candidates.append(Path(base) / "LibreOffice" / "program" / "soffice.exe")
41
+ local = os.environ.get("LOCALAPPDATA")
42
+ if local:
43
+ candidates.append(Path(local) / "Programs" / "LibreOffice" / "program" / "soffice.exe")
44
+ elif sys.platform == "darwin":
45
+ candidates.append(Path("/Applications/LibreOffice.app/Contents/MacOS/soffice"))
46
+ for candidate in candidates:
47
+ if candidate.is_file():
48
+ return str(candidate)
49
+ return "soffice"
50
+
51
+
27
52
  def get_soffice_env() -> dict:
28
53
  env = os.environ.copy()
29
- env["SAL_USE_VCLPLUGIN"] = "svp"
54
+ if sys.platform != "win32": # the headless "svp" VCL plugin does not exist on Windows builds
55
+ env["SAL_USE_VCLPLUGIN"] = "svp"
30
56
 
31
57
  if _needs_shim():
32
58
  shim = _ensure_shim()
@@ -43,7 +69,7 @@ def run_soffice(args: Iterable[str], **kwargs) -> subprocess.CompletedProcess:
43
69
  tempfile.TemporaryDirectory(prefix="lo_profile_", ignore_cleanup_errors=True)
44
70
  )
45
71
  args = [f"-env:UserInstallation={Path(profile).as_uri()}"] + args
46
- return subprocess.run(["soffice"] + args, env=get_soffice_env(), **kwargs)
72
+ return subprocess.run([soffice_binary()] + args, env=get_soffice_env(), **kwargs)
47
73
 
48
74
 
49
75
 
@@ -51,8 +77,14 @@ _SHIM_SO = Path(tempfile.gettempdir()) / "lo_socket_shim.so"
51
77
 
52
78
 
53
79
  def _needs_shim() -> bool:
80
+ # The shim is an LD_PRELOAD library: Linux only. Windows Python has no socket.AF_UNIX at all.
81
+ if sys.platform != "linux":
82
+ return False
83
+ af_unix = getattr(socket, "AF_UNIX", None)
84
+ if af_unix is None:
85
+ return False
54
86
  try:
55
- s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
87
+ s = socket.socket(af_unix, socket.SOCK_STREAM)
56
88
  s.close()
57
89
  return False
58
90
  except OSError:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: pdf
3
- description: Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.
3
+ description: Use for any PDF task: read or extract text and tables, merge, split, rotate, watermark, fill forms, encrypt, extract images, OCR, or create a PDF.
4
4
  license: Complete terms in LICENSE.txt
5
5
  ---
6
6
 
@@ -7,6 +7,7 @@ from pdf2image import convert_from_path
7
7
 
8
8
 
9
9
  def convert(pdf_path, output_dir, max_dim=1000):
10
+ os.makedirs(output_dir, exist_ok=True)
10
11
  images = convert_from_path(pdf_path, dpi=200)
11
12
 
12
13
  for i, image in enumerate(images):
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: pptx
3
- description: "Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations as PowerPoint (.pptx) files; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email, summary, or creating a different type of slide deck); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user asks for a PowerPoint or .pptx file, or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. When the user asks for a deck, slides or a presentation without naming a file format, use this skill."
3
+ description: "Use when a .pptx or .potx is involved, or the user wants slides, a deck or a presentation: create, read, edit, combine, split, templates, speaker notes."
4
4
  license: Complete terms in LICENSE.txt
5
5
  ---
6
6
 
@@ -17,16 +17,42 @@ callers that build their own argv (they must pass -env:UserInstallation too).
17
17
 
18
18
  import contextlib
19
19
  import os
20
+ import shutil
20
21
  import socket
21
22
  import subprocess
23
+ import sys
22
24
  import tempfile
23
25
  from collections.abc import Iterable
24
26
  from pathlib import Path
25
27
 
26
28
 
29
+ def soffice_binary() -> str:
30
+ """Path to soffice. On Windows (and macOS) LibreOffice is rarely on PATH, so look in its usual
31
+ install folders; fall back to the bare name so a missing install still raises FileNotFoundError."""
32
+ found = shutil.which("soffice")
33
+ if found:
34
+ return found
35
+ candidates = []
36
+ if sys.platform == "win32":
37
+ for var in ("ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"):
38
+ base = os.environ.get(var)
39
+ if base:
40
+ candidates.append(Path(base) / "LibreOffice" / "program" / "soffice.exe")
41
+ local = os.environ.get("LOCALAPPDATA")
42
+ if local:
43
+ candidates.append(Path(local) / "Programs" / "LibreOffice" / "program" / "soffice.exe")
44
+ elif sys.platform == "darwin":
45
+ candidates.append(Path("/Applications/LibreOffice.app/Contents/MacOS/soffice"))
46
+ for candidate in candidates:
47
+ if candidate.is_file():
48
+ return str(candidate)
49
+ return "soffice"
50
+
51
+
27
52
  def get_soffice_env() -> dict:
28
53
  env = os.environ.copy()
29
- env["SAL_USE_VCLPLUGIN"] = "svp"
54
+ if sys.platform != "win32": # the headless "svp" VCL plugin does not exist on Windows builds
55
+ env["SAL_USE_VCLPLUGIN"] = "svp"
30
56
 
31
57
  if _needs_shim():
32
58
  shim = _ensure_shim()
@@ -43,7 +69,7 @@ def run_soffice(args: Iterable[str], **kwargs) -> subprocess.CompletedProcess:
43
69
  tempfile.TemporaryDirectory(prefix="lo_profile_", ignore_cleanup_errors=True)
44
70
  )
45
71
  args = [f"-env:UserInstallation={Path(profile).as_uri()}"] + args
46
- return subprocess.run(["soffice"] + args, env=get_soffice_env(), **kwargs)
72
+ return subprocess.run([soffice_binary()] + args, env=get_soffice_env(), **kwargs)
47
73
 
48
74
 
49
75
 
@@ -51,8 +77,14 @@ _SHIM_SO = Path(tempfile.gettempdir()) / "lo_socket_shim.so"
51
77
 
52
78
 
53
79
  def _needs_shim() -> bool:
80
+ # The shim is an LD_PRELOAD library: Linux only. Windows Python has no socket.AF_UNIX at all.
81
+ if sys.platform != "linux":
82
+ return False
83
+ af_unix = getattr(socket, "AF_UNIX", None)
84
+ if af_unix is None:
85
+ return False
54
86
  try:
55
- s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
87
+ s = socket.socket(af_unix, socket.SOCK_STREAM)
56
88
  s.close()
57
89
  return False
58
90
  except OSError:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: xlsx
3
- description: "Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like \"the xlsx in my downloads\") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved."
3
+ description: "Use when a spreadsheet (.xlsx, .xlsm, .csv, .tsv) is the input or output: open, edit, fix, clean, add formulas or charts, convert. Not for Word, HTML or the Google Sheets API."
4
4
  license: Complete terms in LICENSE.txt
5
5
  ---
6
6
 
@@ -17,16 +17,42 @@ callers that build their own argv (they must pass -env:UserInstallation too).
17
17
 
18
18
  import contextlib
19
19
  import os
20
+ import shutil
20
21
  import socket
21
22
  import subprocess
23
+ import sys
22
24
  import tempfile
23
25
  from collections.abc import Iterable
24
26
  from pathlib import Path
25
27
 
26
28
 
29
+ def soffice_binary() -> str:
30
+ """Path to soffice. On Windows (and macOS) LibreOffice is rarely on PATH, so look in its usual
31
+ install folders; fall back to the bare name so a missing install still raises FileNotFoundError."""
32
+ found = shutil.which("soffice")
33
+ if found:
34
+ return found
35
+ candidates = []
36
+ if sys.platform == "win32":
37
+ for var in ("ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"):
38
+ base = os.environ.get(var)
39
+ if base:
40
+ candidates.append(Path(base) / "LibreOffice" / "program" / "soffice.exe")
41
+ local = os.environ.get("LOCALAPPDATA")
42
+ if local:
43
+ candidates.append(Path(local) / "Programs" / "LibreOffice" / "program" / "soffice.exe")
44
+ elif sys.platform == "darwin":
45
+ candidates.append(Path("/Applications/LibreOffice.app/Contents/MacOS/soffice"))
46
+ for candidate in candidates:
47
+ if candidate.is_file():
48
+ return str(candidate)
49
+ return "soffice"
50
+
51
+
27
52
  def get_soffice_env() -> dict:
28
53
  env = os.environ.copy()
29
- env["SAL_USE_VCLPLUGIN"] = "svp"
54
+ if sys.platform != "win32": # the headless "svp" VCL plugin does not exist on Windows builds
55
+ env["SAL_USE_VCLPLUGIN"] = "svp"
30
56
 
31
57
  if _needs_shim():
32
58
  shim = _ensure_shim()
@@ -43,7 +69,7 @@ def run_soffice(args: Iterable[str], **kwargs) -> subprocess.CompletedProcess:
43
69
  tempfile.TemporaryDirectory(prefix="lo_profile_", ignore_cleanup_errors=True)
44
70
  )
45
71
  args = [f"-env:UserInstallation={Path(profile).as_uri()}"] + args
46
- return subprocess.run(["soffice"] + args, env=get_soffice_env(), **kwargs)
72
+ return subprocess.run([soffice_binary()] + args, env=get_soffice_env(), **kwargs)
47
73
 
48
74
 
49
75
 
@@ -51,8 +77,14 @@ _SHIM_SO = Path(tempfile.gettempdir()) / "lo_socket_shim.so"
51
77
 
52
78
 
53
79
  def _needs_shim() -> bool:
80
+ # The shim is an LD_PRELOAD library: Linux only. Windows Python has no socket.AF_UNIX at all.
81
+ if sys.platform != "linux":
82
+ return False
83
+ af_unix = getattr(socket, "AF_UNIX", None)
84
+ if af_unix is None:
85
+ return False
54
86
  try:
55
- s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
87
+ s = socket.socket(af_unix, socket.SOCK_STREAM)
56
88
  s.close()
57
89
  return False
58
90
  except OSError:
@@ -18,10 +18,13 @@ import time
18
18
  import zipfile
19
19
  from pathlib import Path
20
20
 
21
- from office.soffice import get_soffice_env, run_soffice
21
+ from office.soffice import get_soffice_env, run_soffice, soffice_binary
22
22
 
23
23
  MACRO_FILENAME = "Module1.xba"
24
- SOFFICE_MISSING = "soffice not found on PATH; LibreOffice is required to recalculate"
24
+ SOFFICE_MISSING = (
25
+ "soffice not found; LibreOffice is required to recalculate "
26
+ "(Windows: winget install TheDocumentFoundation.LibreOffice, macOS: brew install --cask libreoffice)"
27
+ )
25
28
 
26
29
  MAX_LOCATIONS = 100
27
30
 
@@ -198,7 +201,7 @@ def _recalc_with_profile(filename, abs_path, timeout, profile_dir: Path):
198
201
  before = _stamp(abs_path)
199
202
 
200
203
  cmd = [
201
- "soffice",
204
+ soffice_binary(),
202
205
  "--headless",
203
206
  "--norestore",
204
207
  f"-env:UserInstallation={profile_url}",
package/skills.mjs CHANGED
@@ -46,7 +46,8 @@ export const SKILL_NAME_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
46
46
  * (`overrides: "core"`), except the LOCKED ones other features depend on.
47
47
  */
48
48
  export function coreSkillsDir() {
49
- return join(dirname(fileURLToPath(import.meta.url)), "skills", "core");
49
+ // GU_CORE_SKILLS_DIR: a test (or a packager) can point at another folder; unset = the package's own.
50
+ return process.env.GU_CORE_SKILLS_DIR || join(dirname(fileURLToPath(import.meta.url)), "skills", "core");
50
51
  }
51
52
  /** Core skills a personal skill may not replace: hooks and the resume flow rely on them. */
52
53
  export const LOCKED_CORE_SKILLS = ["gu-session-memory-orchestration"];
@@ -3369,6 +3369,29 @@ export function rankSlashCommands(cmds, typed) {
3369
3369
  return scored.map((s) => s.c);
3370
3370
  }
3371
3371
 
3372
+ /**
3373
+ * THE ROW ENTER WILL RUN WHEN THE USER HAS NOT PRESSED ↑/↓ (GH: "/mo" + Enter should be /model).
3374
+ * `cmds` is the ranked list from rankSlashCommands. Returns its index, or -1 for "run what was typed".
3375
+ * - the typed word is exactly a command name or alias → that command
3376
+ * - exactly ONE command has a name/alias that STARTS with it → that command
3377
+ * - several do ("/m" → /model, /mcp), arguments were typed ("/model x"), or none → -1
3378
+ */
3379
+ export function autoSelectSlash(cmds, typed) {
3380
+ const parts = String(typed ?? "").trim().split(/\s+/);
3381
+ if (parts.length !== 1 || !parts[0].startsWith("/")) return -1;
3382
+ const word = parts[0].toLowerCase();
3383
+ if (word === "/") return -1;
3384
+ const all = (c) => [c.name, ...(c.aliases ?? [])].map((n) => String(n).toLowerCase());
3385
+ const list = cmds ?? [];
3386
+ const exact = list.findIndex((c) => all(c).includes(word));
3387
+ if (exact >= 0) return exact;
3388
+ const starts = [];
3389
+ list.forEach((c, i) => {
3390
+ if (all(c).some((n) => n.startsWith(word))) starts.push(i);
3391
+ });
3392
+ return starts.length === 1 ? starts[0] : -1;
3393
+ }
3394
+
3372
3395
  /**
3373
3396
  * Which slice of the ranked list is on screen. `sel` -1 = nothing highlighted (window at the top).
3374
3397
  * → { from, to, above, below, top } — above/below are how many are hidden on each side.