linkgravity 1.2.1 → 1.2.2

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/README.md CHANGED
@@ -1,33 +1,32 @@
1
- # LinkGravity (lgy)
1
+ # LinkGravity
2
2
 
3
- A Discord bot interface for the Antigravity (agy) agentic AI system. It translates Antigravity CLI prompts into Discord UI components and provides voice interaction capabilities.
3
+ A Discord bot interface for the Antigravity agentic AI system. It translates Antigravity CLI prompts into Discord UI components and provides voice interaction capabilities.
4
4
 
5
5
  ## Features
6
6
 
7
7
  - **Environment Sync:** Automatically syncs with the host's `~/.gemini` configuration.
8
- - **Voice Interaction:** Supports voice channels with adaptive VAD (Voice Activity Detection) to segment speech and filter environmental noise, plus live "listening..." feedback while you're still talking.
8
+ - **Voice Interaction:** Supports voice channels with adaptive voice activity detection to segment speech and filter environmental noise, plus live "listening..." feedback while you're still talking.
9
9
  - **Wake Word Recognition:** Uses phoneme-level similarity to detect wake words and activate voice commands.
10
- - **CLI Prompt Interception:** Converts CLI prompts (`ask_question`, `run_command` approvals) into interactive Discord buttons.
11
- - **Command Security:** Parses chained shell commands (`&&`, `||`, `;`) and requires individual approval for each command. Supports prefix-based scope whitelisting.
12
- - **Multi-Modal Input:** Attach any file (not just images) for the AI to read; audio attachments (`.ogg`/`.mp3`/`.m4a`/`.wav`) are transcribed to text automatically.
10
+ - **Approval Flow:** Command and tool-call approvals become interactive Discord buttons. Chained shell commands are approved individually, and any approval can be scoped to auto-allow that command or tool going forward - something plain `agy` doesn't do.
11
+ - **Multi-Modal Input:** Attach files for the AI to read, including audio, which gets transcribed to text automatically.
13
12
 
14
- ## Prerequisites
13
+ ## Requirements
15
14
 
16
15
  - Node.js >= 18
17
16
  - Python >= 3.10
18
- - `agy` (Antigravity CLI) installed on this machine
19
- - `ffmpeg` on your PATH (needed for TTS/voice playback)
20
- - A Discord bot token, and at least one server/channel to allow it in
17
+ - Antigravity CLI installed on this machine
18
+ - A messenger bot token, and at least one server/channel to allow it in
19
+ - **Discord** - currently the only one supported
21
20
 
22
21
  ### Creating the Discord bot
23
22
 
24
23
  In the [Discord Developer Portal](https://discord.com/developers/applications), create an application and bot, then:
25
24
 
26
- - Under **Bot**, enable the **Message Content** privileged intent (required - the bot reads message text/attachments).
25
+ - Under **Bot**, enable the **Message Content** privileged intent - required, since the bot reads message text/attachments.
27
26
  - Under **OAuth2 → URL Generator**, select the **bot** and **applications.commands** scopes, then these bot permissions:
28
27
  - Send Messages, Send Messages in Threads, Create Public Threads
29
28
  - Read Message History, Attach Files, Embed Links, Add Reactions
30
- - Connect, Speak (for voice channel support)
29
+ - Connect, Speak - for voice channel support
31
30
  - Use the generated URL to invite the bot to your server.
32
31
 
33
32
  ## Installation
@@ -36,7 +35,7 @@ In the [Discord Developer Portal](https://discord.com/developers/applications),
36
35
  npm install -g linkgravity
37
36
  ```
38
37
 
39
- This runs a postinstall step that creates a Python virtual environment at `~/.gemini/linkgravity/venv/` (kept outside the package install location on purpose - see `npm-scripts/venv-paths.js`) and installs `requirements.txt` into it - no manual `pip install` needed.
38
+ Sets up its own Python environment automatically - no manual `pip install` needed.
40
39
 
41
40
  ## Setup
42
41
 
@@ -46,11 +45,11 @@ Run the configuration wizard once to set your bot token, allowed servers/channel
46
45
  lgy setup
47
46
  ```
48
47
 
49
- This writes to `~/.gemini/linkgravity/lgy.json` (outside the package directory, so `npm update`/reinstall never touches it). You can re-run `lgy setup` any time to change settings later - each field keeps its current value if you leave it empty.
48
+ This writes to `~/.gemini/linkgravity/lgy.json`, outside the package directory, so `npm update`/reinstall never touches it. You can re-run `lgy setup` any time to change settings later - each field keeps its current value if you leave it empty.
50
49
 
51
50
  During setup you'll be asked for one or more Discord servers to allow, and optionally specific channels within each:
52
51
 
53
- - Leave the channel list empty for a server → **the whole server** is allowed (any channel can start a session).
52
+ - Leave the channel list empty for a server → **the whole server** is allowed - any channel can start a session.
54
53
  - List specific channel IDs for a server → **only those channels** in that server are allowed.
55
54
 
56
55
  A new session is only ever started with the **`/new`** slash command in Discord - never just by typing a message. `/new` works both in a regular channel and from inside an existing thread.
@@ -58,57 +57,35 @@ A new session is only ever started with the **`/new`** slash command in Discord
58
57
  ## Usage
59
58
 
60
59
  ```bash
61
- lgy start # Start the bot as a background daemon (via PM2)
60
+ lgy start # Start the bot as a background daemon via PM2
62
61
  lgy stop # Stop it
63
62
  lgy restart # Restart it
64
- lgy logs # View live logs (add -f to follow, --tail N for more lines)
63
+ lgy logs # View live logs - add -f to follow, --tail N for more lines
65
64
  lgy enable # Register the bot to auto-start on system boot
66
65
  lgy disable # Remove it from system boot
67
- lgy # Interactive menu (same commands, picked from a list)
66
+ lgy # Interactive menu - same commands, picked from a list
68
67
  ```
69
68
 
70
69
  ## Development
71
70
 
72
- This project uses [Ruff](https://docs.astral.sh/ruff/) for Python linting/formatting and [Prettier](https://prettier.io/) for the Node.js side. `npm install` sets both up automatically (installs `requirements-dev.txt` into the venv at `~/.gemini/linkgravity/venv/`, registers git hooks) - manual install is only needed if you want to run them yourself outside of a commit. The venv lives outside this checkout (see `npm-scripts/venv-paths.js` for why), so on macOS/Linux:
73
-
74
71
  ```bash
75
- ~/.gemini/linkgravity/venv/bin/ruff check src/ # lint
76
- ~/.gemini/linkgravity/venv/bin/ruff format src/ # format
77
-
78
- npm run format:check # check JS formatting
79
- npm run format # format JS
72
+ npm i
80
73
  ```
81
74
 
82
- (On Windows, replace `venv/bin/ruff` with `venv\Scripts\ruff.exe` under the same `~/.gemini/linkgravity/` directory.)
83
-
84
- Git hooks (via [pre-commit](https://pre-commit.com/), config in `.pre-commit-config.yaml`) run automatically once you `npm install`:
85
-
86
- - **pre-commit**: runs `ruff` (lint + format) and `prettier` on staged files, auto-fixing what it can.
87
- - **commit-msg**: enforces [Conventional Commits](https://www.conventionalcommits.org/) (e.g. `fix: ...`, `feat: ...`, `docs: ...`) via [conventional-pre-commit](https://github.com/compilerla/conventional-pre-commit).
88
-
89
- If a hook doesn't seem to be running, check `git config --get core.hooksPath` - it should be unset (or point at `.git/hooks`, pre-commit's default). A leftover `.husky` value from an older checkout will silently make git skip pre-commit's hooks entirely; `git config --unset core.hooksPath` fixes it.
75
+ That's it - it wires up [Ruff](https://docs.astral.sh/ruff/) for Python and [Prettier](https://prettier.io/) for Node, plus git hooks that lint/format on commit and enforce [Conventional Commits](https://www.conventionalcommits.org/) commit messages.
90
76
 
91
77
  ## Debugging
92
78
 
93
- Set `LOG_LEVEL=DEBUG` in your shell before `lgy restart` for verbose logs, including agy's raw stdout for each turn (`lgy` passes your shell's environment through to the daemon on restart). Defaults to `INFO`. Use `lgy logs -t` (or `--timestamp`) to include timestamps - they're stripped by default.
94
-
95
- ## Known Issues
96
-
97
- **Wake word false positives on short words** (e.g. "시리", "잼민이"): Rustpotter's phoneme matching carries less signal for 1-2 syllable words, so genuine-match and unrelated-speech score distributions overlap - no single threshold cleanly separates them. Current mitigations in `voice-service/index.js`'s `getDetectorForUser` and `cogs/voice_cog.py`'s `handle_stt_input`:
98
-
99
- - `score_mode: Max` (each of the 5 enrollment samples can cover a different natural tone/pace, instead of requiring all 5 to be delivered consistently like `Median` did)
100
- - `min_scores: 4` (requires a candidate to keep winning across several frames, compensating for `Max` being more permissive per-frame)
101
- - The STT-based text cross-check is tightened specifically for short wake words (similarity floor 0.55, vs. 0.35 for longer ones) - this is currently doing most of the real work of rejecting false positives
102
-
103
- This isn't fully solved. If issues persist after real-world use, prefer these over further threshold guessing:
79
+ ```bash
80
+ LOG_LEVEL=DEBUG lgy start
81
+ ```
104
82
 
105
- 1. Encourage re-enrolling with a longer/more distinctive wake word (a 1-2 syllable word is close to a hard ceiling for this approach, regardless of tuning)
106
- 2. Log `bestWakeScore` + outcome (no raw audio) during a trial period and re-tune the constants above against that data instead of guessing
83
+ Use `lgy logs -t` to include timestamps.
107
84
 
108
85
  ## Security Warning
109
86
 
110
87
  This bot gives an AI agent broad access to the machine it runs on - **that's inherent to what it does, so don't expose it publicly or run it somewhere you don't fully trust its users.**
111
88
 
112
- - `allowed_user_ids` (set via `lgy setup`) is your primary access control - always set it.
113
- - Tool calls (including shell commands) go through an approval flow in Discord by default; treat anyone in `allowed_user_ids` as having effectively full control of this machine.
89
+ - `allowed_user_ids`, set via `lgy setup`, is your primary access control - always set it.
90
+ - Tool calls, including shell commands, go through an approval flow in Discord by default; treat anyone in `allowed_user_ids` as having effectively full control of this machine.
114
91
  - Your Discord token and other settings live in `~/.gemini/linkgravity/lgy.json`, outside this repo/package directory - never commit or share that file.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkgravity",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Discord bot bridge for the Antigravity (agy) CLI, with voice interaction support",
5
5
  "scripts": {
6
6
  "postinstall": "node npm-scripts/postinstall.js",
@@ -337,7 +337,7 @@ class EnrollmentManager:
337
337
  except aiohttp.ClientError as e:
338
338
  self.logger.warning(f"Failed to invalidate cached detector for {user_id}: {e}")
339
339
 
340
- self.bot_settings["wake_words"] = session["word"]
340
+ self.bot_settings.setdefault("wake_words", {})[user_id] = session["word"]
341
341
  self.save_bot_settings(self.bot_settings)
342
342
 
343
343
  del self._enrollment[user_id]
@@ -174,12 +174,13 @@ class VoiceCog(commands.Cog):
174
174
  vc_chan = interaction.user.voice.channel
175
175
  guild_id = interaction.guild_id
176
176
 
177
- has_wake_word = bool(self.bot_settings.get("wake_words"))
177
+ wake_word_map = self.bot_settings.get("wake_words") or {}
178
+ has_wake_word = bool(wake_word_map)
178
179
  active_timer = self.bot_settings.get("active_timer", 60)
179
180
 
180
181
  if has_wake_word:
181
- wake_words_raw = self.bot_settings["wake_words"]
182
- ww_list = [f"`{w.strip()}`" for w in wake_words_raw.split(",") if w.strip()]
182
+ # dict.fromkeys dedupes while keeping first-registered order (each user has their own word).
183
+ ww_list = [f"`{w.strip()}`" for w in dict.fromkeys(wake_word_map.values()) if w.strip()]
183
184
  ww_str = ", ".join(ww_list[:-1]) + f", or {ww_list[-1]}" if len(ww_list) > 1 else ww_list[0]
184
185
  msg = (
185
186
  f"🎤 Connected to `{vc_chan.name}`.\n"
@@ -274,7 +275,7 @@ class VoiceCog(commands.Cog):
274
275
  and tts_voice is None
275
276
  and tts_enabled is None
276
277
  ):
277
- curr_wake = self.bot_settings.get("wake_words", "None")
278
+ curr_wake = (self.bot_settings.get("wake_words") or {}).get(str(interaction.user.id), "None")
278
279
  curr_timer = self.bot_settings.get("active_timer", 60)
279
280
  curr_thresh = self.bot_settings.get("voice_threshold", 3000)
280
281
  curr_tts = self.bot_settings.get("tts_voice", "en-US-AriaNeural")
package/src/config.py CHANGED
@@ -7,6 +7,10 @@ WORKSPACE_DIR = Path.home() / ".gemini" / "linkgravity"
7
7
  WORKSPACE_DIR.mkdir(parents=True, exist_ok=True)
8
8
  DATA_DIR = WORKSPACE_DIR / "data"
9
9
  DATA_DIR.mkdir(parents=True, exist_ok=True)
10
+ # Per-user wake-word recordings + built .rpw reference (see EnrollmentManager).
11
+ # Defined early so load_bot_settings' migration below can read it.
12
+ WAKE_REF_DIR = WORKSPACE_DIR / "wake_refs"
13
+ WAKE_REF_DIR.mkdir(parents=True, exist_ok=True)
10
14
 
11
15
  LGY_CONFIG_FILE = WORKSPACE_DIR / "lgy.json"
12
16
 
@@ -14,7 +18,8 @@ DEFAULT_LGY_CONFIG = {
14
18
  "discord_token": "",
15
19
  "session_scopes": [],
16
20
  "allowed_user_ids": "",
17
- "wake_words": "Jarvis",
21
+ # user_id (str) -> registered word, one per person (see EnrollmentManager._commit_enrollment).
22
+ "wake_words": {},
18
23
  "active_timer": 60,
19
24
  "voice_threshold": 3000,
20
25
  "tts_voice": "ko-KR-SunHiNeural",
@@ -33,10 +38,26 @@ class _PrintLogger:
33
38
  print(f"[config] {msg}")
34
39
 
35
40
 
41
+ def _migrate_legacy_wake_words():
42
+ """Pre-1.3, wake_words was one global string shared by everyone and
43
+ overwritten by each /sound call. The .rpw files were always saved per
44
+ user_id though, so rebuild the real per-user mapping from those."""
45
+ migrated = {}
46
+ for user_dir in WAKE_REF_DIR.iterdir():
47
+ if not user_dir.is_dir():
48
+ continue
49
+ rpw = next(user_dir.glob("*.rpw"), None)
50
+ if rpw:
51
+ migrated[user_dir.name] = rpw.stem.replace("_", " ")
52
+ return migrated
53
+
54
+
36
55
  def load_bot_settings():
37
56
  data = safe_load_json(LGY_CONFIG_FILE, DEFAULT_LGY_CONFIG.copy(), logger=_PrintLogger())
38
57
  for k, v in DEFAULT_LGY_CONFIG.items():
39
58
  data.setdefault(k, v)
59
+ if isinstance(data.get("wake_words"), str):
60
+ data["wake_words"] = _migrate_legacy_wake_words()
40
61
  return data
41
62
 
42
63
 
@@ -93,12 +114,9 @@ def is_allowed_session_channel(channel) -> bool:
93
114
 
94
115
  TMP_FILE_DIR = WORKSPACE_DIR / "tmp-files"
95
116
  TMP_VOICE_DIR = WORKSPACE_DIR / "tmp-voice"
96
- # Per-user wake-word recordings + built .rpw reference (see EnrollmentManager).
97
- WAKE_REF_DIR = WORKSPACE_DIR / "wake_refs"
98
117
 
99
118
  TMP_FILE_DIR.mkdir(parents=True, exist_ok=True)
100
119
  TMP_VOICE_DIR.mkdir(parents=True, exist_ok=True)
101
- WAKE_REF_DIR.mkdir(parents=True, exist_ok=True)
102
120
 
103
121
  MAX_EMBED_LEN = 1900
104
122
  STREAM_RATE_LIMIT_SEC = 0.5