@tenux/cli 0.0.9 → 0.0.11
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/dist/{chunk-3OM63UZS.js → chunk-KPADLCUM.js} +25 -6
- package/dist/cli.js +13 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -43,6 +43,7 @@ function updateConfig(partial) {
|
|
|
43
43
|
// src/lib/supabase.ts
|
|
44
44
|
import { createClient } from "@supabase/supabase-js";
|
|
45
45
|
var client = null;
|
|
46
|
+
var initialized = false;
|
|
46
47
|
function getSupabase() {
|
|
47
48
|
if (client) return client;
|
|
48
49
|
const config = loadConfig();
|
|
@@ -52,16 +53,34 @@ function getSupabase() {
|
|
|
52
53
|
autoRefreshToken: true
|
|
53
54
|
}
|
|
54
55
|
});
|
|
56
|
+
client.auth.onAuthStateChange((_event, session) => {
|
|
57
|
+
if (session?.access_token && session?.refresh_token) {
|
|
58
|
+
updateConfig({
|
|
59
|
+
accessToken: session.access_token,
|
|
60
|
+
refreshToken: session.refresh_token
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return client;
|
|
65
|
+
}
|
|
66
|
+
async function initSupabaseSession() {
|
|
67
|
+
if (initialized) return;
|
|
68
|
+
const config = loadConfig();
|
|
69
|
+
const sb = getSupabase();
|
|
55
70
|
if (config.accessToken && config.refreshToken) {
|
|
56
|
-
|
|
71
|
+
const { error } = await sb.auth.setSession({
|
|
57
72
|
access_token: config.accessToken,
|
|
58
73
|
refresh_token: config.refreshToken
|
|
59
74
|
});
|
|
75
|
+
if (error) {
|
|
76
|
+
throw new Error(`Failed to restore session: ${error.message}`);
|
|
77
|
+
}
|
|
60
78
|
}
|
|
61
|
-
|
|
79
|
+
initialized = true;
|
|
62
80
|
}
|
|
63
81
|
function resetSupabase() {
|
|
64
82
|
client = null;
|
|
83
|
+
initialized = false;
|
|
65
84
|
}
|
|
66
85
|
|
|
67
86
|
// src/lib/relay.ts
|
|
@@ -215,16 +234,15 @@ async function handleClaudeQuery(command, supabase) {
|
|
|
215
234
|
];
|
|
216
235
|
if (model) args.push("--model", model);
|
|
217
236
|
if (session_id) args.push("--resume", session_id);
|
|
218
|
-
args.push("-p", prompt);
|
|
219
237
|
const isWindows = process.platform === "win32";
|
|
220
238
|
const claudeBin = isWindows ? "claude.cmd" : "claude";
|
|
221
239
|
const proc = spawn(claudeBin, args, {
|
|
222
240
|
cwd,
|
|
223
241
|
shell: isWindows,
|
|
224
|
-
stdio: ["
|
|
225
|
-
// env is omitted — Node inherits parent process.env automatically.
|
|
226
|
-
// Spreading env on Windows can lose system variables and cause ENOENT.
|
|
242
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
227
243
|
});
|
|
244
|
+
proc.stdin.write(prompt);
|
|
245
|
+
proc.stdin.end();
|
|
228
246
|
let seq = 0;
|
|
229
247
|
let capturedSessionId = null;
|
|
230
248
|
let batch = [];
|
|
@@ -322,6 +340,7 @@ export {
|
|
|
322
340
|
saveConfig,
|
|
323
341
|
updateConfig,
|
|
324
342
|
getSupabase,
|
|
343
|
+
initSupabaseSession,
|
|
325
344
|
resetSupabase,
|
|
326
345
|
Relay,
|
|
327
346
|
handleClaudeQuery
|
package/dist/cli.js
CHANGED
|
@@ -5,10 +5,11 @@ import {
|
|
|
5
5
|
getConfigPath,
|
|
6
6
|
getSupabase,
|
|
7
7
|
handleClaudeQuery,
|
|
8
|
+
initSupabaseSession,
|
|
8
9
|
loadConfig,
|
|
9
10
|
saveConfig,
|
|
10
11
|
updateConfig
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-KPADLCUM.js";
|
|
12
13
|
|
|
13
14
|
// src/cli.ts
|
|
14
15
|
import { Command } from "commander";
|
|
@@ -230,13 +231,23 @@ program.command("start").description("Start the agent and listen for commands").
|
|
|
230
231
|
console.log(chalk.dim(" Projects:"), config.projectsDir);
|
|
231
232
|
console.log();
|
|
232
233
|
const supabase = getSupabase();
|
|
234
|
+
try {
|
|
235
|
+
await initSupabaseSession();
|
|
236
|
+
} catch (err) {
|
|
237
|
+
console.log(chalk.red("\u2717"), `Session expired: ${err.message}`);
|
|
238
|
+
console.log(chalk.dim(" Run `tenux login` to re-authenticate."));
|
|
239
|
+
process.exit(1);
|
|
240
|
+
}
|
|
233
241
|
await supabase.from("devices").update({
|
|
234
242
|
name: config.deviceName,
|
|
235
243
|
is_online: true,
|
|
236
244
|
last_seen_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
237
245
|
}).eq("id", config.deviceId);
|
|
238
246
|
const heartbeat = setInterval(async () => {
|
|
239
|
-
await supabase.from("devices").update({ last_seen_at: (/* @__PURE__ */ new Date()).toISOString(), is_online: true }).eq("id", config.deviceId);
|
|
247
|
+
const { error } = await supabase.from("devices").update({ last_seen_at: (/* @__PURE__ */ new Date()).toISOString(), is_online: true }).eq("id", config.deviceId);
|
|
248
|
+
if (error) {
|
|
249
|
+
console.log(chalk.red("\u2717"), chalk.dim(`Heartbeat failed: ${error.message}`));
|
|
250
|
+
}
|
|
240
251
|
}, 3e4);
|
|
241
252
|
const relay = new Relay(supabase);
|
|
242
253
|
const shutdown = async () => {
|
package/dist/index.js
CHANGED