lazy-gravity 0.5.1 → 0.5.3

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.
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.openAction = openAction;
37
37
  const net = __importStar(require("net"));
38
+ const http = __importStar(require("http"));
38
39
  const os = __importStar(require("os"));
39
40
  const child_process_1 = require("child_process");
40
41
  const cdpPorts_1 = require("../../utils/cdpPorts");
@@ -45,6 +46,7 @@ const C = {
45
46
  dim: '\x1b[2m',
46
47
  cyan: '\x1b[36m',
47
48
  green: '\x1b[32m',
49
+ yellow: '\x1b[33m',
48
50
  red: '\x1b[31m',
49
51
  };
50
52
  /**
@@ -110,6 +112,44 @@ function openLinux(port) {
110
112
  }
111
113
  });
112
114
  }
115
+ /**
116
+ * Poll CDP endpoint until it responds or timeout is reached.
117
+ */
118
+ function waitForCdp(port, timeoutMs = 15000, intervalMs = 1000) {
119
+ const start = Date.now();
120
+ return new Promise((resolve) => {
121
+ const check = () => {
122
+ const req = http.get(`http://127.0.0.1:${port}/json/list`, (res) => {
123
+ let data = '';
124
+ res.on('data', (chunk) => (data += chunk));
125
+ res.on('end', () => {
126
+ try {
127
+ const parsed = JSON.parse(data);
128
+ if (Array.isArray(parsed)) {
129
+ resolve(true);
130
+ return;
131
+ }
132
+ }
133
+ catch { /* not ready */ }
134
+ retry();
135
+ });
136
+ });
137
+ req.on('error', () => retry());
138
+ req.setTimeout(2000, () => {
139
+ req.destroy();
140
+ retry();
141
+ });
142
+ };
143
+ const retry = () => {
144
+ if (Date.now() - start >= timeoutMs) {
145
+ resolve(false);
146
+ return;
147
+ }
148
+ setTimeout(check, intervalMs);
149
+ };
150
+ check();
151
+ });
152
+ }
113
153
  async function openAction() {
114
154
  const platform = os.platform();
115
155
  console.log(`\n ${C.cyan}Searching for an available CDP port...${C.reset}`);
@@ -133,7 +173,15 @@ async function openAction() {
133
173
  else {
134
174
  await openLinux(port);
135
175
  }
136
- console.log(` ${C.green}${APP_NAME} opened on CDP port ${port}${C.reset}`);
176
+ console.log(` ${C.dim}Waiting for CDP to respond on port ${port}...${C.reset}`);
177
+ const ready = await waitForCdp(port);
178
+ if (ready) {
179
+ console.log(` ${C.green}${APP_NAME} is ready on CDP port ${port}${C.reset}`);
180
+ }
181
+ else {
182
+ console.log(` ${C.yellow}${APP_NAME} launched but CDP not yet responding on port ${port}${C.reset}`);
183
+ console.log(` ${C.dim}It may still be starting up. Try running start in a few seconds.${C.reset}`);
184
+ }
137
185
  console.log(` ${C.dim}Run ${C.reset}${C.cyan}lazy-gravity start${C.reset}${C.dim} to connect the bot.${C.reset}\n`);
138
186
  }
139
187
  catch (error) {
@@ -81,10 +81,14 @@ async function ensureAntigravityRunning() {
81
81
  logger_1.logger.warn('='.repeat(70));
82
82
  logger_1.logger.warn(' Antigravity CDP ports are not responding');
83
83
  logger_1.logger.warn('');
84
- logger_1.logger.warn(' Please run AntigravityDebug.command before starting the Bot');
84
+ logger_1.logger.warn(' Run the following command to open Antigravity with CDP enabled:');
85
+ logger_1.logger.warn('');
86
+ logger_1.logger.warn(' lazy-gravity open');
85
87
  logger_1.logger.warn('');
86
88
  logger_1.logger.warn(' Or manually:');
87
89
  logger_1.logger.warn(` ${(0, pathUtils_1.getAntigravityCdpHint)(9222)}`);
90
+ logger_1.logger.warn('');
91
+ logger_1.logger.warn(' Then run: lazy-gravity start');
88
92
  logger_1.logger.warn('='.repeat(70));
89
93
  logger_1.logger.warn('');
90
94
  }
@@ -123,6 +123,18 @@ class CdpService extends events_1.EventEmitter {
123
123
  (t.url?.includes('workbench') || t.title?.includes('Antigravity') || t.title?.includes('Cascade')) &&
124
124
  !t.title?.includes('Launchpad'));
125
125
  }
126
+ // No workbench page found — try to open the chat panel automatically
127
+ // before falling back to Launchpad
128
+ if (!target) {
129
+ const anyPage = allPages.find(t => t.webSocketDebuggerUrl);
130
+ if (anyPage) {
131
+ logger_1.logger.debug('[CdpService] No workbench page found. Attempting to open chat panel via Cmd+L / Ctrl+L...');
132
+ await this.openChatPanelViaKeyboard(anyPage.webSocketDebuggerUrl);
133
+ // Re-scan after opening chat panel
134
+ target = await this.findWorkbenchTarget();
135
+ }
136
+ }
137
+ // Last resort: accept Launchpad as target
126
138
  if (!target) {
127
139
  target = allPages.find(t => t.webSocketDebuggerUrl &&
128
140
  (t.url?.includes('workbench') || t.title?.includes('Antigravity') || t.title?.includes('Cascade') || t.title?.includes('Launchpad')));
@@ -578,6 +590,94 @@ class CdpService extends events_1.EventEmitter {
578
590
  }
579
591
  throw new Error(`Workbench page for workspace "${projectName}" not found within ${maxWaitMs / 1000} seconds`);
580
592
  }
593
+ /**
594
+ * Scan all CDP ports and return the first workbench-like target page.
595
+ */
596
+ async findWorkbenchTarget() {
597
+ let allPages = [];
598
+ for (const port of this.ports) {
599
+ try {
600
+ const list = await this.getJson(`http://127.0.0.1:${port}/json/list`);
601
+ allPages.push(...list);
602
+ }
603
+ catch {
604
+ // port not responding
605
+ }
606
+ }
607
+ return (allPages.find(t => t.type === 'page' &&
608
+ t.webSocketDebuggerUrl &&
609
+ !t.title?.includes('Launchpad') &&
610
+ !t.url?.includes('workbench-jetski-agent') &&
611
+ (t.url?.includes('workbench') || t.title?.includes('Antigravity') || t.title?.includes('Cascade'))) ??
612
+ allPages.find(t => t.webSocketDebuggerUrl &&
613
+ (t.url?.includes('workbench') || t.title?.includes('Antigravity') || t.title?.includes('Cascade')) &&
614
+ !t.title?.includes('Launchpad')) ??
615
+ null);
616
+ }
617
+ /**
618
+ * Temporarily connect to a page and send Cmd+L / Ctrl+L to open the chat panel.
619
+ */
620
+ async openChatPanelViaKeyboard(wsUrl) {
621
+ const tempWs = new ws_1.default(wsUrl);
622
+ let idCounter = 1;
623
+ try {
624
+ await new Promise((resolve, reject) => {
625
+ tempWs.on('open', resolve);
626
+ tempWs.on('error', reject);
627
+ setTimeout(() => reject(new Error('Timeout')), 5000);
628
+ });
629
+ const send = (method, params = {}) => new Promise((resolve, reject) => {
630
+ const id = idCounter++;
631
+ tempWs.send(JSON.stringify({ id, method, params }));
632
+ const timeout = setTimeout(() => reject(new Error('Timeout')), 3000);
633
+ const onMsg = (raw) => {
634
+ try {
635
+ const data = JSON.parse(raw.toString());
636
+ if (data.id === id) {
637
+ clearTimeout(timeout);
638
+ tempWs.off('message', onMsg);
639
+ resolve();
640
+ }
641
+ }
642
+ catch { /* ignore */ }
643
+ };
644
+ tempWs.on('message', onMsg);
645
+ });
646
+ const modifiers = process.platform === 'darwin' ? 4 : 2; // Meta : Ctrl
647
+ await send('Input.dispatchKeyEvent', {
648
+ type: 'keyDown',
649
+ key: 'l',
650
+ code: 'KeyL',
651
+ modifiers,
652
+ windowsVirtualKeyCode: 76,
653
+ nativeVirtualKeyCode: 76,
654
+ });
655
+ await send('Input.dispatchKeyEvent', {
656
+ type: 'keyUp',
657
+ key: 'l',
658
+ code: 'KeyL',
659
+ modifiers,
660
+ windowsVirtualKeyCode: 76,
661
+ nativeVirtualKeyCode: 76,
662
+ });
663
+ // Wait until a workbench target appears, up to a bounded timeout
664
+ const deadline = Date.now() + 10000;
665
+ while (Date.now() < deadline) {
666
+ await new Promise(r => setTimeout(r, 500));
667
+ if (await this.findWorkbenchTarget()) {
668
+ break;
669
+ }
670
+ }
671
+ }
672
+ catch (e) {
673
+ logger_1.logger.debug(`[CdpService] Failed to open chat panel automatically: ${e}`);
674
+ }
675
+ finally {
676
+ if (tempWs.readyState === ws_1.default.OPEN) {
677
+ tempWs.close();
678
+ }
679
+ }
680
+ }
581
681
  async runCommand(command, args) {
582
682
  await new Promise((resolve, reject) => {
583
683
  const child = (0, child_process_1.spawn)(command, args, { stdio: 'ignore' });
@@ -43,6 +43,7 @@ function buildProjectListPayload(workspaces, page = 0) {
43
43
  const safePage = Math.max(0, Math.min(page, totalPages - 1));
44
44
  let rc = (0, richContentBuilder_1.withTimestamp)((0, richContentBuilder_1.withColor)((0, richContentBuilder_1.withTitle)((0, richContentBuilder_1.withDescription)((0, richContentBuilder_1.createRichContent)(), (0, i18n_1.t)('Select a project to auto-create a category and session channel')), 'Projects'), 0x5865F2));
45
45
  if (workspaces.length === 0) {
46
+ rc = (0, richContentBuilder_1.withDescription)(rc, (0, i18n_1.t)('No projects found.\nCreate a project directory in your workspace base folder, then try again.'));
46
47
  return { richContent: rc, components: [] };
47
48
  }
48
49
  if (totalPages > 1) {
@@ -104,6 +105,7 @@ function buildProjectListUI(workspaces, page = 0) {
104
105
  .setDescription((0, i18n_1.t)('Select a project to auto-create a category and session channel'))
105
106
  .setTimestamp();
106
107
  if (workspaces.length === 0) {
108
+ embed.setDescription((0, i18n_1.t)('No projects found.\nCreate a project directory in your workspace base folder, then try again.'));
107
109
  return { embeds: [embed], components: [] };
108
110
  }
109
111
  const start = safePage * exports.ITEMS_PER_PAGE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lazy-gravity",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
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": {