lazy-gravity 0.8.2 → 0.9.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/README.md CHANGED
@@ -230,7 +230,8 @@ Double-click **`start_antigravity_mac.command`** in the repo root.
230
230
  #### Windows
231
231
  Double-click **`start_antigravity_win.bat`** in the repo root.
232
232
 
233
- - **If it doesn't launch**: the executable may not be in your PATH. Right-click the file, edit it, and replace `"Antigravity.exe"` with the full install path (e.g. `"%LOCALAPPDATA%\Programs\Antigravity\Antigravity.exe"`).
233
+ - **If it doesn't launch**: verify that Antigravity IDE is installed at `"%LOCALAPPDATA%\Programs\Antigravity IDE\Antigravity IDE.exe"`. If it is installed elsewhere, right-click the file and update the executable path.
234
+ - **Upgrading to Antigravity 2.0?** The Windows executable was renamed to `Antigravity IDE.exe`. If you are still using the older `Antigravity.exe` installation, auto-launch will not find it. Please update Antigravity, or set the `ANTIGRAVITY_PATH` override in your `.env` file.
234
235
 
235
236
  #### Linux
236
237
  On Linux (especially when using AppImages), the `antigravity` command might not be globally available.
package/dist/bot/index.js CHANGED
@@ -873,6 +873,18 @@ const startBot = async (cliLogLevel) => {
873
873
  await cdp.disconnect().catch(() => { });
874
874
  }
875
875
  await bridge.pool.getOrConnect(workspacePath, { name: selectedAccount });
876
+ }, async ({ channelId, userId }) => {
877
+ const accountName = (0, accountUtils_1.resolveScopedAccountName)({
878
+ channelId,
879
+ userId,
880
+ sessionAccountName: chatSessionRepo.findByChannelId(channelId)?.activeAccountName ?? null,
881
+ parentChannelId: null,
882
+ selectedAccountByChannel: bridge.selectedAccountByChannel,
883
+ channelPrefRepo,
884
+ accountPrefRepo,
885
+ accounts: config.antigravityAccounts,
886
+ });
887
+ await (0, antigravityLauncher_1.startAntigravity)(accountPorts[accountName] ?? 9222);
876
888
  });
877
889
  const chatHandler = new chatCommandHandler_1.ChatCommandHandler(chatSessionService, chatSessionRepo, workspaceBindingRepo, channelManager, workspaceService, bridge.pool, (channelId, userId) => (0, accountUtils_1.resolveScopedAccountName)({
878
890
  channelId,
@@ -1759,6 +1771,23 @@ async function handleSlashInteraction(interaction, handler, bridge, wsHandler, c
1759
1771
  }
1760
1772
  break;
1761
1773
  }
1774
+ case 'shutdown': {
1775
+ try {
1776
+ bridge.pool.disconnectAll();
1777
+ const ports = [...new Set(antigravityAccounts.map((account) => account.cdpPort))];
1778
+ const results = await Promise.all(ports.map((port) => (0, antigravityLauncher_1.stopAntigravity)(port)));
1779
+ const stopped = results.some((result) => result === 'stopped');
1780
+ await interaction.editReply({
1781
+ content: stopped
1782
+ ? '✅ Antigravity IDE shut down. Use `/project list` to start it again.'
1783
+ : 'ℹ️ Antigravity IDE is already stopped. Use `/project list` to start it.',
1784
+ });
1785
+ }
1786
+ catch (e) {
1787
+ await interaction.editReply({ content: `❌ Failed to shut down Antigravity IDE: ${e.message}` });
1788
+ }
1789
+ break;
1790
+ }
1762
1791
  case 'project': {
1763
1792
  const wsSub = interaction.options.getSubcommand(false);
1764
1793
  if (wsSub === 'create') {
@@ -50,6 +50,11 @@ const templateCommand = new discord_js_1.SlashCommandBuilder()
50
50
  const stopCommand = new discord_js_1.SlashCommandBuilder()
51
51
  .setName('stop')
52
52
  .setDescription((0, i18n_1.t)('Interrupt active LLM generation'));
53
+ /** /shutdown command definition */
54
+ const shutdownCommand = new discord_js_1.SlashCommandBuilder()
55
+ .setName('shutdown')
56
+ .setDescription((0, i18n_1.t)('Shut down Antigravity IDE'))
57
+ .setDefaultMemberPermissions(discord_js_1.PermissionFlagsBits.Administrator);
53
58
  /** /screenshot command definition */
54
59
  const screenshotCommand = new discord_js_1.SlashCommandBuilder()
55
60
  .setName('screenshot')
@@ -159,6 +164,7 @@ exports.slashCommands = [
159
164
  modelCommand,
160
165
  templateCommand,
161
166
  stopCommand,
167
+ shutdownCommand,
162
168
  screenshotCommand,
163
169
  statusCommand,
164
170
  autoAcceptCommand,
@@ -23,6 +23,7 @@ class WorkspaceCommandHandler {
23
23
  workspaceService;
24
24
  channelManager;
25
25
  onSessionChannelCreated;
26
+ ensureIdeRunning;
26
27
  processingWorkspaces = new Set();
27
28
  /**
28
29
  * Filters out stale bindings where the Discord channel no longer exists.
@@ -59,17 +60,22 @@ class WorkspaceCommandHandler {
59
60
  }
60
61
  return validBindings;
61
62
  }
62
- constructor(bindingRepo, chatSessionRepo, workspaceService, channelManager, onSessionChannelCreated) {
63
+ constructor(bindingRepo, chatSessionRepo, workspaceService, channelManager, onSessionChannelCreated, ensureIdeRunning) {
63
64
  this.bindingRepo = bindingRepo;
64
65
  this.chatSessionRepo = chatSessionRepo;
65
66
  this.workspaceService = workspaceService;
66
67
  this.channelManager = channelManager;
67
68
  this.onSessionChannelCreated = onSessionChannelCreated;
69
+ this.ensureIdeRunning = ensureIdeRunning;
68
70
  }
69
71
  /**
70
72
  * /project list -- Display project list via select menu
71
73
  */
72
74
  async handleShow(interaction) {
75
+ await this.ensureIdeRunning?.({
76
+ channelId: interaction.channelId,
77
+ userId: interaction.user.id,
78
+ });
73
79
  const workspaces = this.workspaceService.scanWorkspaces();
74
80
  const { embeds, components } = (0, projectListUi_1.buildProjectListUI)(workspaces, 0);
75
81
  await interaction.editReply({ embeds, components });
@@ -33,11 +33,16 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.checkPort = checkPort;
37
+ exports.startAntigravity = startAntigravity;
38
+ exports.stopAntigravity = stopAntigravity;
36
39
  exports.ensureAntigravityRunning = ensureAntigravityRunning;
37
40
  const logger_1 = require("../utils/logger");
38
41
  const cdpPorts_1 = require("../utils/cdpPorts");
39
42
  const pathUtils_1 = require("../utils/pathUtils");
40
43
  const http = __importStar(require("http"));
44
+ const child_process_1 = require("child_process");
45
+ let lifecycleOperation = null;
41
46
  /**
42
47
  * Check if CDP responds on the specified port.
43
48
  */
@@ -63,6 +68,131 @@ function checkPort(port) {
63
68
  });
64
69
  });
65
70
  }
71
+ async function waitForPort(port, timeoutMs = 30000) {
72
+ const deadline = Date.now() + timeoutMs;
73
+ do {
74
+ if (await checkPort(port))
75
+ return true;
76
+ await new Promise((resolve) => setTimeout(resolve, 500));
77
+ } while (Date.now() < deadline);
78
+ return false;
79
+ }
80
+ function serializeLifecycle(operation) {
81
+ const pending = lifecycleOperation
82
+ ? lifecycleOperation.then(operation, operation)
83
+ : operation();
84
+ lifecycleOperation = pending;
85
+ pending.finally(() => {
86
+ if (lifecycleOperation === pending)
87
+ lifecycleOperation = null;
88
+ }).catch(() => { });
89
+ return pending;
90
+ }
91
+ function startAntigravity(port = cdpPorts_1.CDP_PORTS[0]) {
92
+ return serializeLifecycle(async () => {
93
+ if (await checkPort(port))
94
+ return 'already-running';
95
+ const executable = process.env.ANTIGRAVITY_PATH || (0, pathUtils_1.getAntigravityCliPath)();
96
+ const child = (0, child_process_1.spawn)(executable, [`--remote-debugging-port=${port}`], {
97
+ detached: true,
98
+ stdio: 'ignore',
99
+ windowsHide: true,
100
+ });
101
+ const spawnError = await new Promise((resolve) => {
102
+ child.on('error', resolve);
103
+ setTimeout(() => resolve(null), 100);
104
+ });
105
+ if (spawnError) {
106
+ throw spawnError;
107
+ }
108
+ child.unref();
109
+ if (!await waitForPort(port)) {
110
+ throw new Error(`Antigravity did not become ready on CDP port ${port}.`);
111
+ }
112
+ return 'started';
113
+ });
114
+ }
115
+ function stopAntigravity(port = cdpPorts_1.CDP_PORTS[0]) {
116
+ return serializeLifecycle(async () => {
117
+ if (!await checkPort(port))
118
+ return 'already-stopped';
119
+ const version = await getCdpVersion(port);
120
+ const browser = typeof version?.Browser === 'string' ? version.Browser.toLowerCase() : '';
121
+ if (!browser.includes('antigravity')) {
122
+ throw new Error(`Refusing to stop non-Antigravity CDP service on port ${port}.`);
123
+ }
124
+ await new Promise((resolve, reject) => {
125
+ if (process.platform === 'win32') {
126
+ const command = [
127
+ `$ownerPid=(Get-NetTCPConnection -State Listen -LocalPort ${port} -ErrorAction SilentlyContinue`,
128
+ '| Select-Object -First 1 -ExpandProperty OwningProcess);',
129
+ 'if ($ownerPid) { Stop-Process -Id $ownerPid -Force }',
130
+ ].join(' ');
131
+ (0, child_process_1.execFile)('powershell.exe', ['-NoProfile', '-Command', command], { windowsHide: true }, (error) => {
132
+ if (error)
133
+ reject(error);
134
+ else
135
+ resolve();
136
+ });
137
+ return;
138
+ }
139
+ (0, child_process_1.execFile)('lsof', ['-tiTCP:' + port, '-sTCP:LISTEN'], (lookupError, stdout) => {
140
+ if (lookupError)
141
+ return reject(lookupError);
142
+ const pid = String(stdout).trim().split(/\s+/)[0];
143
+ if (!/^\d+$/.test(pid))
144
+ return reject(new Error(`No listener PID found for CDP port ${port}.`));
145
+ (0, child_process_1.execFile)('kill', ['-TERM', pid], (killError) => killError ? reject(killError) : resolve());
146
+ });
147
+ });
148
+ return 'stopped';
149
+ });
150
+ }
151
+ function getCdpVersion(port) {
152
+ return new Promise((resolve, reject) => {
153
+ const req = http.get(`http://127.0.0.1:${port}/json/version`, (res) => {
154
+ let data = '';
155
+ res.on('data', (chunk) => (data += chunk));
156
+ res.on('end', () => {
157
+ try {
158
+ resolve(JSON.parse(data));
159
+ }
160
+ catch (error) {
161
+ reject(error);
162
+ }
163
+ });
164
+ });
165
+ req.on('error', reject);
166
+ req.setTimeout(2000, () => {
167
+ req.destroy();
168
+ reject(new Error(`Timed out reading CDP version from port ${port}.`));
169
+ });
170
+ });
171
+ }
172
+ function getCdpTargets(port) {
173
+ return new Promise((resolve, reject) => {
174
+ const req = http.get(`http://127.0.0.1:${port}/json/list`, (res) => {
175
+ let data = '';
176
+ res.on('data', (chunk) => (data += chunk));
177
+ res.on('end', () => {
178
+ try {
179
+ const parsed = JSON.parse(data);
180
+ if (!Array.isArray(parsed))
181
+ throw new Error('CDP target list is not an array');
182
+ resolve(parsed);
183
+ }
184
+ catch (error) {
185
+ reject(error);
186
+ }
187
+ });
188
+ });
189
+ req.on('error', reject);
190
+ req.setTimeout(2000, () => {
191
+ req.destroy();
192
+ reject(new Error(`Timed out reading CDP metadata from port ${port}.`));
193
+ });
194
+ });
195
+ }
66
196
  /**
67
197
  * Check if Antigravity is running with CDP ports.
68
198
  * If not running, output a warning log (no auto-start or restart).
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChatSessionService = void 0;
4
+ const logger_1 = require("../utils/logger");
4
5
  /** Script to get the state of the new chat button */
5
6
  const GET_NEW_CHAT_BUTTON_SCRIPT = `(() => {
6
7
  const btn = document.querySelector('[data-tooltip-id="new-conversation-tooltip"]');
@@ -25,7 +26,14 @@ const GET_CHAT_TITLE_SCRIPT = `(() => {
25
26
  const header = panel.querySelector('div[class*="border-b"]');
26
27
  if (!header) return { title: '', hasActiveChat: false };
27
28
  const titleEl = header.querySelector('div[class*="text-ellipsis"]');
28
- const title = titleEl ? (titleEl.textContent || '').trim() : '';
29
+ let title = titleEl ? (titleEl.textContent || '').trim() : '';
30
+ if (!title || title === 'Agent') {
31
+ const activeRow = Array.from(panel.querySelectorAll('div[class*="focusBackground"]'))
32
+ .find((el) => el instanceof HTMLElement && el.offsetParent !== null);
33
+ const activeTitle = activeRow?.querySelector('span.text-sm span, span.text-sm');
34
+ const activeText = activeTitle ? (activeTitle.textContent || '').trim() : '';
35
+ if (activeText) title = activeText;
36
+ }
29
37
  // "Agent" is the default empty chat title
30
38
  const hasActiveChat = title.length > 0 && title !== 'Agent';
31
39
  return { title: title || '(Untitled)', hasActiveChat };
@@ -44,7 +52,14 @@ const GET_SESSION_VIEW_STATE_SCRIPT = `(() => {
44
52
  }
45
53
  const header = panel.querySelector('div[class*="border-b"]');
46
54
  const titleEl = header?.querySelector('div[class*="text-ellipsis"]');
47
- const title = titleEl ? (titleEl.textContent || '').trim() : '';
55
+ let title = titleEl ? (titleEl.textContent || '').trim() : '';
56
+ if (!title || title === 'Agent') {
57
+ const activeRow = Array.from(panel.querySelectorAll('div[class*="focusBackground"]'))
58
+ .find((el) => el instanceof HTMLElement && el.offsetParent !== null);
59
+ const activeTitle = activeRow?.querySelector('span.text-sm span, span.text-sm');
60
+ const activeText = activeTitle ? (activeTitle.textContent || '').trim() : '';
61
+ if (activeText) title = activeText;
62
+ }
48
63
  const hasActiveChat = title.length > 0 && title !== 'Agent';
49
64
 
50
65
  const bodyCandidates = Array.from(panel.querySelectorAll(
@@ -461,15 +476,21 @@ function buildActivateViaPastConversationsScript(title) {
461
476
  }
462
477
 
463
478
  let selected = clickByPatterns([wanted, wantedLoose], '[role="option"], li, button, [data-testid*="conversation"]');
464
- if (!selected && input) {
465
- pressEnter(input);
466
- await wait(220);
467
- selected = true;
479
+ if (selected) {
480
+ const selectedOption = pickBest(
481
+ asArray(document.querySelectorAll('[role="option"], li, button, [data-testid*="conversation"]')),
482
+ [wanted, wantedLoose],
483
+ );
484
+ const selectedClickable = getClickable(selectedOption);
485
+ if (selectedClickable) {
486
+ selectedClickable.focus();
487
+ pressEnter(selectedClickable);
488
+ }
468
489
  }
469
490
  if (!selected) {
470
491
  return { ok: false, error: 'Conversation not found in Past Conversations' };
471
492
  }
472
- return { ok: true };
493
+ return { ok: true, matchedTitle: wantedRaw };
473
494
  })();
474
495
  })()`;
475
496
  }
@@ -878,6 +899,18 @@ class ChatSessionService {
878
899
  }
879
900
  return { ok: true };
880
901
  }
902
+ // Current Antigravity builds keep the header at the generic "Agent"
903
+ // label even after an exact Past Conversations option is selected.
904
+ // The selection script only reports success after matching the wanted
905
+ // title inside this workspace's conversation picker.
906
+ if (usedPastConversations &&
907
+ after.title.trim() === 'Agent' &&
908
+ pastResult?.matchedTitle?.trim() === title.trim()) {
909
+ logger_1.logger.debug(`[ChatSession] Accepting Agent-header bypass: ` +
910
+ `usedPastConversations=true observedTitle="${after.title}" targetTitle="${title}"`);
911
+ await this.closePanelWithEscape(cdpService);
912
+ return { ok: true };
913
+ }
881
914
  if (!warmupConsumed && allowVisibilityWarmupMs > 0 && after.title.trim() === 'Agent') {
882
915
  warmupConsumed = true;
883
916
  startedAt = Date.now();
@@ -898,6 +931,13 @@ class ChatSessionService {
898
931
  await this.closePanelWithEscape(cdpService);
899
932
  return { ok: true };
900
933
  }
934
+ if (afterPast.title.trim() === 'Agent' &&
935
+ viaPast.matchedTitle?.trim() === title.trim()) {
936
+ logger_1.logger.debug(`[ChatSession] Accepting Agent-header bypass: ` +
937
+ `usedPastConversations=true observedTitle="${afterPast.title}" targetTitle="${title}"`);
938
+ await this.closePanelWithEscape(cdpService);
939
+ return { ok: true };
940
+ }
901
941
  return {
902
942
  ok: false,
903
943
  error: `Past Conversations selected a different chat (expected="${title}", actual="${afterPast.title}")`,
@@ -933,7 +973,12 @@ class ChatSessionService {
933
973
  });
934
974
  const value = result?.result?.value;
935
975
  if (value?.ok) {
936
- return { ok: true };
976
+ return {
977
+ ok: true,
978
+ ...(typeof value.matchedTitle === 'string'
979
+ ? { matchedTitle: value.matchedTitle }
980
+ : {}),
981
+ };
937
982
  }
938
983
  if (value?.error && typeof value.error === 'string') {
939
984
  lastError = value.error;
@@ -22,9 +22,9 @@ function getAntigravityCliPath() {
22
22
  if (process.platform === 'win32') {
23
23
  const localAppData = process.env.LOCALAPPDATA;
24
24
  if (localAppData) {
25
- return `${localAppData}\\Programs\\Antigravity\\Antigravity.exe`;
25
+ return `${localAppData}\\Programs\\Antigravity IDE\\Antigravity IDE.exe`;
26
26
  }
27
- return 'Antigravity.exe'; // Fallback if LOCALAPPDATA is undefined
27
+ return 'Antigravity IDE.exe'; // Fallback if LOCALAPPDATA is undefined
28
28
  }
29
29
  // Default for Linux or any unknown OS, assuming 'antigravity' is in the system PATH
30
30
  return 'antigravity';
@@ -50,7 +50,7 @@ function getAntigravityCdpHint(port = 9222) {
50
50
  case 'darwin':
51
51
  return `open -a ${APP_NAME} --args --remote-debugging-port=${port}`;
52
52
  case 'win32':
53
- return `${APP_NAME}.exe --remote-debugging-port=${port}`;
53
+ return `"${APP_NAME} IDE.exe" --remote-debugging-port=${port}`;
54
54
  default:
55
55
  return `${APP_NAME.toLowerCase()} --remote-debugging-port=${port}`;
56
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lazy-gravity",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "Control Antigravity from anywhere — a local, secure bot (Discord + Telegram) that lets you remotely operate Antigravity on your home PC from your smartphone.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {