longtable 0.1.31 → 0.1.33

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/bin/longtable.mjs CHANGED
@@ -120,11 +120,16 @@ async function connect() {
120
120
 
121
121
  const auto = has("no-autostart") ? { started: false } : enableAutostart(process.execPath, binPath);
122
122
  if (!has("no-run") && !auto.started) {
123
- spawn(process.execPath, [binPath, "run"], { detached: true, stdio: "ignore", windowsHide: true }).unref();
123
+ // A stand-in until the start-up task runs it: it never ends a connection the task started.
124
+ spawn(process.execPath, [binPath, "run", "--backup"], { detached: true, stdio: "ignore", windowsHide: true }).unref();
124
125
  }
125
126
  const word = ai === "codex" ? "Codex" : "Claude";
126
127
  log(`connected to "${paired.table_name}" for ${paired.member_name} (${ai === "codex" ? codexVersion(codex) : claudeVersion(claude)})`);
127
- say(`Connected. ${paired.member_name}'s ${word} is now at "${paired.table_name}". It answers in the background whenever this computer is on.`);
128
+ say(auto.started || has("no-autostart")
129
+ ? `Connected. ${paired.member_name}'s ${word} is now at "${paired.table_name}". It answers in the background whenever this computer is on.`
130
+ // Said plainly when it could not be set to run by itself: today it runs from here, and from the next sign-in on
131
+ // Windows starts it, so closing this window takes it away until then.
132
+ : `Connected. ${paired.member_name}'s ${word} is now at "${paired.table_name}". It could not start in the background just now, so it is running from this window: leave it open for now. From the next time you sign in to this computer it starts by itself.`);
128
133
  const git = gitCanJoin();
129
134
  if (!git.ok) {
130
135
  log(`git cannot join two parts of work (${git.version})`);
@@ -186,7 +191,7 @@ try {
186
191
  // Started from an older copy (a cache, or an old start-up entry) while ~/.longtable/app holds a newer one: run that.
187
192
  const newerCopy = handOffTo();
188
193
  if (newerCopy) { log(`run: handing over to the newer copy in ${newerCopy}`); await import(pathToFileURL(newerCopy).href); }
189
- else await runLoop();
194
+ else await runLoop({ backup: args.includes("--backup") });
190
195
  }
191
196
  else if (command === "status") await status();
192
197
  else if (command === "disconnect") await disconnect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "longtable",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "description": "Brings your own Claude Code or Codex to your team's table on longtable.chat, quietly, on your own plan.",
5
5
  "homepage": "https://longtable.chat",
6
6
  "repository": {
package/src/autostart.mjs CHANGED
@@ -102,8 +102,11 @@ export function enableAutostart(nodePath, binPath) {
102
102
  rmSync(legacyStartup(), { force: true });
103
103
  const asked = Date.now();
104
104
  startTask(TASK);
105
- // Said started only when the connection really wrote its note; otherwise `connect` runs it itself.
106
- return { started: wroteNoteSince(asked, 20000), where: `Task Scheduler: ${TASK}` };
105
+ // Said started only when the connection really wrote its note; otherwise `connect` runs a stand-in itself. A
106
+ // first start can be slow (Windows looking over a new program), so it is asked once more and given a minute.
107
+ if (wroteNoteSince(asked, 20000)) return { started: true, where: `Task Scheduler: ${TASK}` };
108
+ try { startTask(TASK); } catch {}
109
+ return { started: wroteNoteSince(asked, 40000), where: `Task Scheduler: ${TASK}` };
107
110
  }
108
111
  // Every system runs the copy in ~/.longtable/app, which the connection keeps up to date itself, never the copy
109
112
  // that ran `connect` (on Mac and Linux that was a cache folder npm may clear).
package/src/run.mjs CHANGED
@@ -1060,7 +1060,7 @@ async function tellCommands(rpc, seat) {
1060
1060
  } catch (e) { log(`commands not sent: ${e.message}`); }
1061
1061
  }
1062
1062
 
1063
- export async function runLoop({ pollMs = 2000 } = {}) {
1063
+ export async function runLoop({ pollMs = 2000, backup = false } = {}) {
1064
1064
  const config = readConfig();
1065
1065
  if (!config.connections?.length) throw new Error("Not connected to any table yet.");
1066
1066
  const engines = { claude: findClaude(), codex: findCodex() };
@@ -1072,6 +1072,9 @@ export async function runLoop({ pollMs = 2000 } = {}) {
1072
1072
  // Only one connection runs on a computer. A second one would wipe the first one's work folder under it.
1073
1073
  const lock = join(home, "runner.pid");
1074
1074
  const old = runningConnection();
1075
+ // The stand-in `connect` starts when the start-up task was slow never ends the real one: it would leave a
1076
+ // connection tied to the window that ran `connect`, gone when that window closes. It steps aside instead.
1077
+ if (old && old !== process.pid && backup) { log(`a connection is already running (${old}); this stand-in steps aside`); process.exit(0); }
1075
1078
  if (old && old !== process.pid) { endConnection(old); log(`ended the connection that was already running (${old})`); }
1076
1079
  writeFileSync(lock, `${process.pid} ${Date.now()}`);
1077
1080
  const unlock = () => { try { if (runningConnection() === process.pid) rmSync(lock, { force: true }); } catch {} };
@@ -1123,9 +1126,10 @@ export async function runLoop({ pollMs = 2000 } = {}) {
1123
1126
  setInterval(checkRelease, 10 * 60 * 1000).unref?.();
1124
1127
  // Two lanes on one connection: long work in one, everything quick in the other, so an hour of work never keeps
1125
1128
  // the table from hearing people or answering a question.
1129
+ // Declared before the lanes start: they read it the moment a full-mode job arrives.
1130
+ let aside = 0;
1126
1131
  await Promise.all([lane("light"), lane("heavy")]);
1127
1132
 
1128
- let aside = 0;
1129
1133
  async function lane(name) {
1130
1134
  for (;;) {
1131
1135
  let worked = false;
@@ -1146,12 +1150,14 @@ export async function runLoop({ pollMs = 2000 } = {}) {
1146
1150
  busy++;
1147
1151
  // A quick job run as their full Claude Code can wait minutes on its person's answer. It works in a tree of its
1148
1152
  // own, so it runs alongside, and the lane goes on hearing the table (listening, clients, views) meanwhile.
1149
- if (name === "light" && job.full === true && aside < 2) {
1153
+ if (name === "light" && job.full === true && !["listen", "client"].includes(job.kind) && aside < 2) {
1150
1154
  aside++;
1151
1155
  work(rpc, s, engines, job).catch((e) => log(`job ${job.job_id} failed: ${e.message}`)).finally(() => { busy--; aside--; });
1152
1156
  continue;
1153
1157
  }
1154
- try { await work(rpc, s, engines, job); } finally { busy--; }
1158
+ // One job going wrong in a way nobody foresaw never takes the whole connection down: it is logged as a
1159
+ // tripwire and the lane goes on to the next.
1160
+ try { await work(rpc, s, engines, job); } catch (e) { log(`tripwire: job ${job.job_id} broke the lane: ${e.message}`); } finally { busy--; }
1155
1161
  }
1156
1162
  await new Promise((r) => setTimeout(r, worked ? 100 : name === "heavy" ? pollMs * 2 : pollMs));
1157
1163
  }