@tenux/cli 0.0.15 → 0.0.17

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.
@@ -59,6 +59,7 @@ function getSupabase() {
59
59
  accessToken: session.access_token,
60
60
  refreshToken: session.refresh_token
61
61
  });
62
+ client.realtime.setAuth(session.access_token);
62
63
  }
63
64
  });
64
65
  return client;
@@ -75,6 +76,7 @@ async function initSupabaseSession() {
75
76
  if (error) {
76
77
  throw new Error(`Failed to restore session: ${error.message}`);
77
78
  }
79
+ sb.realtime.setAuth(config.accessToken);
78
80
  }
79
81
  initialized = true;
80
82
  }
@@ -90,6 +92,9 @@ var Relay = class {
90
92
  channel = null;
91
93
  handlers = /* @__PURE__ */ new Map();
92
94
  deviceId;
95
+ pollTimer = null;
96
+ processing = false;
97
+ // guard against overlapping poll + realtime
93
98
  constructor(supabase) {
94
99
  this.supabase = supabase;
95
100
  this.deviceId = loadConfig().deviceId;
@@ -123,11 +128,16 @@ var Relay = class {
123
128
  console.log(chalk.green("\u2713"), "Listening for commands");
124
129
  }
125
130
  });
131
+ this.pollTimer = setInterval(() => this.processPending(), 5e3);
126
132
  }
127
133
  /**
128
134
  * Stop listening.
129
135
  */
130
136
  async stop() {
137
+ if (this.pollTimer) {
138
+ clearInterval(this.pollTimer);
139
+ this.pollTimer = null;
140
+ }
131
141
  if (this.channel) {
132
142
  await this.supabase.removeChannel(this.channel);
133
143
  this.channel = null;
@@ -137,21 +147,28 @@ var Relay = class {
137
147
  * Process any commands that arrived while the agent was offline.
138
148
  */
139
149
  async processPending() {
140
- const { data: pending } = await this.supabase.from("commands").select("*").eq("device_id", this.deviceId).eq("status", "pending").order("created_at", { ascending: true });
141
- if (pending && pending.length > 0) {
142
- console.log(
143
- chalk.yellow("\u26A1"),
144
- `Processing ${pending.length} pending command(s)`
145
- );
146
- for (const cmd of pending) {
147
- await this.dispatch(cmd);
150
+ if (this.processing) return;
151
+ this.processing = true;
152
+ try {
153
+ const { data: pending } = await this.supabase.from("commands").select("*").eq("device_id", this.deviceId).eq("status", "pending").order("created_at", { ascending: true });
154
+ if (pending && pending.length > 0) {
155
+ console.log(
156
+ chalk.yellow("\u26A1"),
157
+ `Processing ${pending.length} pending command(s)`
158
+ );
159
+ for (const cmd of pending) {
160
+ await this.dispatch(cmd);
161
+ }
148
162
  }
163
+ } catch {
149
164
  }
165
+ this.processing = false;
150
166
  }
151
167
  /**
152
168
  * Dispatch a command to the appropriate handler.
153
169
  */
154
170
  async dispatch(command) {
171
+ if (command.status !== "pending") return;
155
172
  const handler = this.handlers.get(command.type);
156
173
  if (!handler) {
157
174
  console.log(
package/dist/cli.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  loadConfig,
10
10
  saveConfig,
11
11
  updateConfig
12
- } from "./chunk-IQO7AGGC.js";
12
+ } from "./chunk-QPS4CXAL.js";
13
13
 
14
14
  // src/cli.ts
15
15
  import { Command } from "commander";
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { SupabaseClient } from '@supabase/supabase-js';
2
2
 
3
3
  /**
4
- * Relay — Supabase Realtime subscription for incoming commands.
4
+ * Relay — Listens for incoming commands via Supabase.
5
5
  *
6
- * Listens to INSERT events on the `commands` table filtered by device_id.
7
- * Dispatches each command to the appropriate handler.
6
+ * Uses Realtime subscription (when available) AND polling fallback (every 5s)
7
+ * to ensure commands are always picked up, even when Realtime is unreliable.
8
8
  */
9
9
 
10
10
  interface Command {
@@ -24,6 +24,8 @@ declare class Relay {
24
24
  private channel;
25
25
  private handlers;
26
26
  private deviceId;
27
+ private pollTimer;
28
+ private processing;
27
29
  constructor(supabase: SupabaseClient);
28
30
  /**
29
31
  * Register a handler for a command type (e.g., "git.clone", "claude.query").
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  resetSupabase,
8
8
  saveConfig,
9
9
  updateConfig
10
- } from "./chunk-IQO7AGGC.js";
10
+ } from "./chunk-QPS4CXAL.js";
11
11
  export {
12
12
  Relay,
13
13
  configExists,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenux/cli",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Tenux — mobile-first IDE for 10x engineering",
5
5
  "author": "Antelogic LLC",
6
6
  "license": "MIT",